|
|
|
date: Wed, 20 Aug 2008 03:01:04 -0700,
group: microsoft.public.project.developer
back
problem in updating custom field on publishing event of Project Se
I am having a problem while updating a custom field value of a specific
project when OnPublishing event of project server raises. When I log on the
Project Web Access with svc-emp user then it works fine and value of custom
field updates, but when I log on on Project web access with different user it
raises an exception that CICOCheckedOutToOtherUser. Following is my code,
please any solution...
using System;
using System.Diagnostics;
using Microsoft.Office.Project.Server.Events;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Web.Services.Protocols;
using System.Data;
using System.Threading;
using PSLibrary = Microsoft.Office.Project.Server.Library;
namespace SaveProjectAttribute
{
public class AddAttributeOnSave : ProjectEventReceiver
{
public override void
OnPublishing(Microsoft.Office.Project.Server.Library.PSContextInfo
contextInfo, ProjectPrePublishEventArgs e)
{
base.OnPublishing(contextInfo, e);
const string ls_projURL = "http://ruh-003-cr-001/pmo/";
const string ls_CustomField = "TestCF";
const string ls_LookupTableValue = "";
bool verbose = true;
const string PROJECT_SERVICE_PATH = "_vti_bin/psi/Project.asmx";
const string LOGIN_SERVICE_PATH =
"_vti_bin/psi/LoginWindows.asmx";
bool isWindowsAccount = contextInfo.IsWindowsUser;
Guid trackingGuid = new
Guid(contextInfo.TrackingGuid.ToByteArray());
string lcid = contextInfo.Lcid;
string userNTAccount = contextInfo.UserName;
Guid resourceGuid = new Guid(contextInfo.UserGuid.ToByteArray());
Guid siteId = new Guid(contextInfo.SiteGuid.ToByteArray());
ProjectDerived ws_Project = new ProjectDerived();
LoginWindowsDerived loginWindows = new LoginWindowsDerived();
LoginWindowsDerived.SetImpersonationContext(isWindowsAccount,
userNTAccount, resourceGuid, trackingGuid, siteId, lcid);
ProjectDerived.SetImpersonationContext(isWindowsAccount,
userNTAccount, resourceGuid, trackingGuid, siteId, lcid);
loginWindows.Url = ls_projURL + LOGIN_SERVICE_PATH;
loginWindows.Credentials = CredentialCache.DefaultCredentials;
ws_Project.Url = ls_projURL + PROJECT_SERVICE_PATH;
ws_Project.Credentials = CredentialCache.DefaultCredentials;
WSProject.ProjectDataSet lo_projs = null;
WSProject.ProjectDataSet lo_projDS;
Guid lo_projGUID;
string ls_projName;
CustomField cf = new CustomField(ls_projURL, ls_CustomField);
LookupTable lt = new LookupTable(ls_projURL, cf.LookupTableGUID);
try
{
// Read all the projects on the server
lo_projs = ws_Project.ReadProjectList();
DataRowCollection lo_projects =
lo_projs.Tables[lo_projs.Project.TableName].Rows;
lo_projDS = ws_Project.ReadProjectEntities(e.ProjectGuid,
32, WSProject.DataStoreEnum.WorkingStore);
foreach (WSProject.ProjectDataSet.ProjectCustomFieldsRow row
in lo_projDS.ProjectCustomFields)
{
if (row.MD_PROP_UID == cf.CustomFieldGUID)
{
row.TEXT_VALUE = "Finally Got You!";
Guid jobid = Guid.NewGuid();
ws_Project.QueueUpdateProject(jobid,
contextInfo.UserGuid, lo_projDS, false);
}
}
}
catch (SoapException lo_ex1)
{
if (verbose)
System.Console.WriteLine("Error: " + lo_ex1.Message);
}
catch (WebException lo_ex)
{
if (verbose)
System.Console.WriteLine("Error: " + lo_ex.Message);
}
catch (Exception lo_ex)
{
if (verbose)
System.Console.WriteLine("Unknown Error: " +
lo_ex.Message);
}
System.Console.WriteLine("Done!");
}
}
class LoginWindowsDerived : WSLoginWindows.LoginWindows
{
private static String ContextString = String.Empty;
protected override WebRequest GetWebRequest(Uri uri)
{
//here we are overriding the GetWebRequest method and adding the
2 web request headers
WebRequest webRequest = base.GetWebRequest(uri);
if (ContextString != String.Empty)
{
webRequest.UseDefaultCredentials = true;
bool isImpersonating =
(System.Security.Principal.WindowsIdentity.GetCurrent(true) != null);
webRequest.Credentials =
CredentialCache.DefaultNetworkCredentials;
webRequest.Headers.Add("PjAuth", ContextString);
webRequest.Headers.Add("ForwardFrom",
"/_vti_bin/psi/LoginWindows.asmx");
webRequest.PreAuthenticate = true;
}
return webRequest;
}
public static void SetImpersonationContext(bool isWindowsUser,
String userNTAccount, Guid userGuid, Guid trackingGuid, Guid siteId, String
lcid)
{
ContextString = GetImpersonationContext(isWindowsUser,
userNTAccount, userGuid, trackingGuid, siteId, lcid);
}
private static String GetImpersonationContext(bool isWindowsUser,
String userNTAccount, Guid userGuid, Guid trackingGuid, Guid siteId, String
lcid)
{
PSLibrary.PSContextInfo contextInfo = new
PSLibrary.PSContextInfo(isWindowsUser, userNTAccount, userGuid, trackingGuid,
siteId, lcid);
String contextString =
PSLibrary.PSContextInfo.SerializeToString(contextInfo);
return contextString;
}
}
class ProjectDerived : WSProject.Project
{
private static String ContextString = String.Empty;
protected override WebRequest GetWebRequest(Uri uri)
{
//here we are overriding the GetWebRequest method and adding the
2 web request headers
WebRequest webRequest = base.GetWebRequest(uri);
if (ContextString != String.Empty)
{
webRequest.UseDefaultCredentials = true;
bool isImpersonating =
(System.Security.Principal.WindowsIdentity.GetCurrent(true) != null);
webRequest.Credentials =
CredentialCache.DefaultNetworkCredentials;
webRequest.Headers.Add("PjAuth", ContextString);
webRequest.Headers.Add("ForwardFrom",
"/_vti_bin/psi/project.asmx");
webRequest.PreAuthenticate = true;
}
return webRequest;
}
public static void SetImpersonationContext(bool isWindowsUser,
String userNTAccount, Guid userGuid, Guid trackingGuid, Guid siteId, String
lcid)
{
ContextString = GetImpersonationContext(isWindowsUser,
userNTAccount, userGuid, trackingGuid, siteId, lcid);
}
private static String GetImpersonationContext(bool isWindowsUser,
String userNTAccount, Guid userGuid, Guid trackingGuid, Guid siteId, String
lcid)
{
PSLibrary.PSContextInfo contextInfo = new
PSLibrary.PSContextInfo(isWindowsUser, userNTAccount, userGuid, trackingGuid,
siteId, lcid);
String contextString =
PSLibrary.PSContextInfo.SerializeToString(contextInfo);
return contextString;
}
}
}
date: Wed, 20 Aug 2008 03:01:04 -0700
author: M Azeem M
Re: problem in updating custom field on publishing event of Project Se
You need to get the real sessionUid -- use the ReadProjectEntities
method to read in the data for EntityType 1. This will return a
ProjectDataset. Use the GUID in PROJ_SESSION_UID for the session UID.
The way your code it is now, you're using the UserGuid of the user who
calls the Event Handler (always the service account) as the sessionUid,
which is why you are getting the error.
Also, if you're looking to run QueueUpdateProject as an impersonated
user, you need to run the method that exists in ProjectDerived, not the
one in WS_Project. Otherwise, the ImpersonationContext will not be used.
--
Stephen Sanderlin
Principal Consultant
MSProjectExperts
For Project Server Consulting: http://www.msprojectexperts.com
For Project Server Training: http://www.projectservertraining.com
Owner/Founder - EPMFAQ
http://www.epmfaq.com/
http://forums.epmfaq.com/
M Azeem wrote:
> I am having a problem while updating a custom field value of a
> specific project when OnPublishing event of project server raises.
> When I log on the Project Web Access with svc-emp user then it works
> fine and value of custom field updates, but when I log on on Project
> web access with different user it raises an exception that
> CICOCheckedOutToOtherUser. Following is my code, please any
> solution...
>
>
>
> using System;
> using System.Diagnostics;
> using Microsoft.Office.Project.Server.Events;
> using System.Collections.Generic;
> using System.Text;
> using System.Net;
> using System.Web.Services.Protocols;
> using System.Data;
> using System.Threading;
> using PSLibrary = Microsoft.Office.Project.Server.Library;
>
> namespace SaveProjectAttribute
> {
> public class AddAttributeOnSave : ProjectEventReceiver
> {
> public override void
> OnPublishing(Microsoft.Office.Project.Server.Library.PSContextInfo
> contextInfo, ProjectPrePublishEventArgs e)
> {
> base.OnPublishing(contextInfo, e);
>
> const string ls_projURL = "http://ruh-003-cr-001/pmo/";
> const string ls_CustomField = "TestCF";
> const string ls_LookupTableValue = "";
> bool verbose = true;
>
> const string PROJECT_SERVICE_PATH =
> "_vti_bin/psi/Project.asmx"; const string
> LOGIN_SERVICE_PATH = "_vti_bin/psi/LoginWindows.asmx";
>
> bool isWindowsAccount = contextInfo.IsWindowsUser;
> Guid trackingGuid = new
> Guid(contextInfo.TrackingGuid.ToByteArray());
> string lcid = contextInfo.Lcid;
> string userNTAccount = contextInfo.UserName;
> Guid resourceGuid = new
> Guid(contextInfo.UserGuid.ToByteArray()); Guid siteId =
> new Guid(contextInfo.SiteGuid.ToByteArray());
>
> ProjectDerived ws_Project = new ProjectDerived();
> LoginWindowsDerived loginWindows = new
> LoginWindowsDerived();
>
>
> LoginWindowsDerived.SetImpersonationContext(isWindowsAccount,
> userNTAccount, resourceGuid, trackingGuid, siteId, lcid);
> ProjectDerived.SetImpersonationContext(isWindowsAccount,
> userNTAccount, resourceGuid, trackingGuid, siteId, lcid);
>
> loginWindows.Url = ls_projURL + LOGIN_SERVICE_PATH;
> loginWindows.Credentials =
> CredentialCache.DefaultCredentials; ws_Project.Url =
> ls_projURL + PROJECT_SERVICE_PATH; ws_Project.Credentials
> = CredentialCache.DefaultCredentials;
>
> WSProject.ProjectDataSet lo_projs = null;
> WSProject.ProjectDataSet lo_projDS;
>
> Guid lo_projGUID;
> string ls_projName;
>
> CustomField cf = new CustomField(ls_projURL,
> ls_CustomField); LookupTable lt = new
> LookupTable(ls_projURL, cf.LookupTableGUID);
>
> try
> {
> // Read all the projects on the server
> lo_projs = ws_Project.ReadProjectList();
>
> DataRowCollection lo_projects =
> lo_projs.Tables[lo_projs.Project.TableName].Rows;
>
> lo_projDS =
> ws_Project.ReadProjectEntities(e.ProjectGuid, 32,
> WSProject.DataStoreEnum.WorkingStore);
>
> foreach
> (WSProject.ProjectDataSet.ProjectCustomFieldsRow row in
> lo_projDS.ProjectCustomFields) {
> if (row.MD_PROP_UID == cf.CustomFieldGUID)
> {
> row.TEXT_VALUE = "Finally Got You!";
>
> Guid jobid = Guid.NewGuid();
>
> ws_Project.QueueUpdateProject(jobid,
> contextInfo.UserGuid, lo_projDS, false);
> }
> }
> }
> catch (SoapException lo_ex1)
> {
> if (verbose)
> System.Console.WriteLine("Error: " +
> lo_ex1.Message); }
> catch (WebException lo_ex)
> {
> if (verbose)
> System.Console.WriteLine("Error: " +
> lo_ex.Message); }
> catch (Exception lo_ex)
> {
> if (verbose)
> System.Console.WriteLine("Unknown Error: " +
> lo_ex.Message);
> }
>
> System.Console.WriteLine("Done!");
> }
> }
>
> class LoginWindowsDerived : WSLoginWindows.LoginWindows
> {
> private static String ContextString = String.Empty;
>
> protected override WebRequest GetWebRequest(Uri uri)
> {
> //here we are overriding the GetWebRequest method and
> adding the 2 web request headers
> WebRequest webRequest = base.GetWebRequest(uri);
> if (ContextString != String.Empty)
> {
> webRequest.UseDefaultCredentials = true;
>
> bool isImpersonating =
> (System.Security.Principal.WindowsIdentity.GetCurrent(true) != null);
> webRequest.Credentials =
> CredentialCache.DefaultNetworkCredentials;
>
> webRequest.Headers.Add("PjAuth", ContextString);
> webRequest.Headers.Add("ForwardFrom",
> "/_vti_bin/psi/LoginWindows.asmx");
>
> webRequest.PreAuthenticate = true;
> }
> return webRequest;
> }
>
> public static void SetImpersonationContext(bool
> isWindowsUser, String userNTAccount, Guid userGuid, Guid
> trackingGuid, Guid siteId, String lcid)
> {
> ContextString = GetImpersonationContext(isWindowsUser,
> userNTAccount, userGuid, trackingGuid, siteId, lcid);
> }
>
> private static String GetImpersonationContext(bool
> isWindowsUser, String userNTAccount, Guid userGuid, Guid
> trackingGuid, Guid siteId, String lcid)
> {
> PSLibrary.PSContextInfo contextInfo = new
> PSLibrary.PSContextInfo(isWindowsUser, userNTAccount, userGuid,
> trackingGuid, siteId, lcid);
> String contextString =
> PSLibrary.PSContextInfo.SerializeToString(contextInfo);
> return contextString;
> }
> }
>
> class ProjectDerived : WSProject.Project
> {
> private static String ContextString = String.Empty;
>
> protected override WebRequest GetWebRequest(Uri uri)
> {
> //here we are overriding the GetWebRequest method and
> adding the 2 web request headers
> WebRequest webRequest = base.GetWebRequest(uri);
> if (ContextString != String.Empty)
> {
> webRequest.UseDefaultCredentials = true;
>
> bool isImpersonating =
> (System.Security.Principal.WindowsIdentity.GetCurrent(true) != null);
> webRequest.Credentials =
> CredentialCache.DefaultNetworkCredentials;
>
> webRequest.Headers.Add("PjAuth", ContextString);
> webRequest.Headers.Add("ForwardFrom",
> "/_vti_bin/psi/project.asmx");
>
> webRequest.PreAuthenticate = true;
> }
> return webRequest;
> }
>
> public static void SetImpersonationContext(bool
> isWindowsUser, String userNTAccount, Guid userGuid, Guid
> trackingGuid, Guid siteId, String lcid)
> {
> ContextString = GetImpersonationContext(isWindowsUser,
> userNTAccount, userGuid, trackingGuid, siteId, lcid);
> }
>
> private static String GetImpersonationContext(bool
> isWindowsUser, String userNTAccount, Guid userGuid, Guid
> trackingGuid, Guid siteId, String lcid)
> {
> PSLibrary.PSContextInfo contextInfo = new
> PSLibrary.PSContextInfo(isWindowsUser, userNTAccount, userGuid,
> trackingGuid, siteId, lcid);
> String contextString =
> PSLibrary.PSContextInfo.SerializeToString(contextInfo);
> return contextString;
> }
> }
> }
date: Thu, 21 Aug 2008 11:34:12 -0700
author: Stephen Sanderlin stephen DOTNOSPAM sanderlin NOSPAMAT msprojectexperts DOTNOSPAM com
Re: problem in updating custom field on publishing event of Projec
1) when imperonating user you have to call Web service from shared service
provider.
2) I can see that you try to set PJ_AUTH - but there is feature in MPS
which causing that ContextInfo.iswindowsuser==false for domain users.:) And
this feature weren't handled in your event handler)
PS on my blog are sample Eventhandler which can be used as inspiration.
--
Blog: http://www.projectserver.cz
"Stephen Sanderlin" wrote:
> You need to get the real sessionUid -- use the ReadProjectEntities
> method to read in the data for EntityType 1. This will return a
> ProjectDataset. Use the GUID in PROJ_SESSION_UID for the session UID.
>
> The way your code it is now, you're using the UserGuid of the user who
> calls the Event Handler (always the service account) as the sessionUid,
> which is why you are getting the error.
>
> Also, if you're looking to run QueueUpdateProject as an impersonated
> user, you need to run the method that exists in ProjectDerived, not the
> one in WS_Project. Otherwise, the ImpersonationContext will not be used.
>
> --
> Stephen Sanderlin
> Principal Consultant
> MSProjectExperts
> For Project Server Consulting: http://www.msprojectexperts.com
> For Project Server Training: http://www.projectservertraining.com
>
> Owner/Founder - EPMFAQ
> http://www.epmfaq.com/
> http://forums.epmfaq.com/
>
>
> M Azeem wrote:
>
> > I am having a problem while updating a custom field value of a
> > specific project when OnPublishing event of project server raises.
> > When I log on the Project Web Access with svc-emp user then it works
> > fine and value of custom field updates, but when I log on on Project
> > web access with different user it raises an exception that
> > CICOCheckedOutToOtherUser. Following is my code, please any
> > solution...
> >
> >
> >
> > using System;
> > using System.Diagnostics;
> > using Microsoft.Office.Project.Server.Events;
> > using System.Collections.Generic;
> > using System.Text;
> > using System.Net;
> > using System.Web.Services.Protocols;
> > using System.Data;
> > using System.Threading;
> > using PSLibrary = Microsoft.Office.Project.Server.Library;
> >
> > namespace SaveProjectAttribute
> > {
> > public class AddAttributeOnSave : ProjectEventReceiver
> > {
> > public override void
> > OnPublishing(Microsoft.Office.Project.Server.Library.PSContextInfo
> > contextInfo, ProjectPrePublishEventArgs e)
> > {
> > base.OnPublishing(contextInfo, e);
> >
> > const string ls_projURL = "http://ruh-003-cr-001/pmo/";
> > const string ls_CustomField = "TestCF";
> > const string ls_LookupTableValue = "";
> > bool verbose = true;
> >
> > const string PROJECT_SERVICE_PATH =
> > "_vti_bin/psi/Project.asmx"; const string
> > LOGIN_SERVICE_PATH = "_vti_bin/psi/LoginWindows.asmx";
> >
> > bool isWindowsAccount = contextInfo.IsWindowsUser;
> > Guid trackingGuid = new
> > Guid(contextInfo.TrackingGuid.ToByteArray());
> > string lcid = contextInfo.Lcid;
> > string userNTAccount = contextInfo.UserName;
> > Guid resourceGuid = new
> > Guid(contextInfo.UserGuid.ToByteArray()); Guid siteId =
> > new Guid(contextInfo.SiteGuid.ToByteArray());
> >
> > ProjectDerived ws_Project = new ProjectDerived();
> > LoginWindowsDerived loginWindows = new
> > LoginWindowsDerived();
> >
> >
> > LoginWindowsDerived.SetImpersonationContext(isWindowsAccount,
> > userNTAccount, resourceGuid, trackingGuid, siteId, lcid);
> > ProjectDerived.SetImpersonationContext(isWindowsAccount,
> > userNTAccount, resourceGuid, trackingGuid, siteId, lcid);
> >
> > loginWindows.Url = ls_projURL + LOGIN_SERVICE_PATH;
> > loginWindows.Credentials =
> > CredentialCache.DefaultCredentials; ws_Project.Url =
> > ls_projURL + PROJECT_SERVICE_PATH; ws_Project.Credentials
> > = CredentialCache.DefaultCredentials;
> >
> > WSProject.ProjectDataSet lo_projs = null;
> > WSProject.ProjectDataSet lo_projDS;
> >
> > Guid lo_projGUID;
> > string ls_projName;
> >
> > CustomField cf = new CustomField(ls_projURL,
> > ls_CustomField); LookupTable lt = new
> > LookupTable(ls_projURL, cf.LookupTableGUID);
> >
> > try
> > {
> > // Read all the projects on the server
> > lo_projs = ws_Project.ReadProjectList();
> >
> > DataRowCollection lo_projects =
> > lo_projs.Tables[lo_projs.Project.TableName].Rows;
> >
> > lo_projDS =
> > ws_Project.ReadProjectEntities(e.ProjectGuid, 32,
> > WSProject.DataStoreEnum.WorkingStore);
> >
> > foreach
> > (WSProject.ProjectDataSet.ProjectCustomFieldsRow row in
> > lo_projDS.ProjectCustomFields) {
> > if (row.MD_PROP_UID == cf.CustomFieldGUID)
> > {
> > row.TEXT_VALUE = "Finally Got You!";
> >
> > Guid jobid = Guid.NewGuid();
> >
> > ws_Project.QueueUpdateProject(jobid,
> > contextInfo.UserGuid, lo_projDS, false);
> > }
> > }
> > }
> > catch (SoapException lo_ex1)
> > {
> > if (verbose)
> > System.Console.WriteLine("Error: " +
> > lo_ex1.Message); }
> > catch (WebException lo_ex)
> > {
> > if (verbose)
> > System.Console.WriteLine("Error: " +
> > lo_ex.Message); }
> > catch (Exception lo_ex)
> > {
> > if (verbose)
> > System.Console.WriteLine("Unknown Error: " +
> > lo_ex.Message);
> > }
> >
> > System.Console.WriteLine("Done!");
> > }
> > }
> >
> > class LoginWindowsDerived : WSLoginWindows.LoginWindows
> > {
> > private static String ContextString = String.Empty;
> >
> > protected override WebRequest GetWebRequest(Uri uri)
> > {
> > //here we are overriding the GetWebRequest method and
> > adding the 2 web request headers
> > WebRequest webRequest = base.GetWebRequest(uri);
> > if (ContextString != String.Empty)
> > {
> > webRequest.UseDefaultCredentials = true;
> >
> > bool isImpersonating =
> > (System.Security.Principal.WindowsIdentity.GetCurrent(true) != null);
> > webRequest.Credentials =
> > CredentialCache.DefaultNetworkCredentials;
> >
> > webRequest.Headers.Add("PjAuth", ContextString);
> > webRequest.Headers.Add("ForwardFrom",
> > "/_vti_bin/psi/LoginWindows.asmx");
> >
> > webRequest.PreAuthenticate = true;
> > }
> > return webRequest;
> > }
> >
> > public static void SetImpersonationContext(bool
> > isWindowsUser, String userNTAccount, Guid userGuid, Guid
> > trackingGuid, Guid siteId, String lcid)
> > {
> > ContextString = GetImpersonationContext(isWindowsUser,
> > userNTAccount, userGuid, trackingGuid, siteId, lcid);
> > }
> >
> > private static String GetImpersonationContext(bool
> > isWindowsUser, String userNTAccount, Guid userGuid, Guid
> > trackingGuid, Guid siteId, String lcid)
> > {
> > PSLibrary.PSContextInfo contextInfo = new
> > PSLibrary.PSContextInfo(isWindowsUser, userNTAccount, userGuid,
> > trackingGuid, siteId, lcid);
> > String contextString =
> > PSLibrary.PSContextInfo.SerializeToString(contextInfo);
> > return contextString;
> > }
> > }
> >
> > class ProjectDerived : WSProject.Project
> > {
> > private static String ContextString = String.Empty;
> >
> > protected override WebRequest GetWebRequest(Uri uri)
> > {
> > //here we are overriding the GetWebRequest method and
> > adding the 2 web request headers
> > WebRequest webRequest = base.GetWebRequest(uri);
> > if (ContextString != String.Empty)
> > {
> > webRequest.UseDefaultCredentials = true;
> >
> > bool isImpersonating =
> > (System.Security.Principal.WindowsIdentity.GetCurrent(true) != null);
> > webRequest.Credentials =
> > CredentialCache.DefaultNetworkCredentials;
> >
> > webRequest.Headers.Add("PjAuth", ContextString);
> > webRequest.Headers.Add("ForwardFrom",
> > "/_vti_bin/psi/project.asmx");
> >
> > webRequest.PreAuthenticate = true;
> > }
> > return webRequest;
> > }
> >
> > public static void SetImpersonationContext(bool
> > isWindowsUser, String userNTAccount, Guid userGuid, Guid
> > trackingGuid, Guid siteId, String lcid)
> > {
> > ContextString = GetImpersonationContext(isWindowsUser,
> > userNTAccount, userGuid, trackingGuid, siteId, lcid);
> > }
> >
> > private static String GetImpersonationContext(bool
> > isWindowsUser, String userNTAccount, Guid userGuid, Guid
> > trackingGuid, Guid siteId, String lcid)
> > {
> > PSLibrary.PSContextInfo contextInfo = new
> > PSLibrary.PSContextInfo(isWindowsUser, userNTAccount, userGuid,
> > trackingGuid, siteId, lcid);
> > String contextString =
> > PSLibrary.PSContextInfo.SerializeToString(contextInfo);
> > return contextString;
> > }
> > }
> > }
>
date: Sun, 24 Aug 2008 12:34:15 -0700
author: Martin Winzig
Re: problem in updating custom field on publishing event of Projec
Thanks Stephen for your reply. I am already using ws_Project to update my
project info which is an object of ProjectDerived class. I got
PROJ_SESSION_UID from ProjectDS[0].PROJ_SESSION_UID after
ReadProjectEntitites. But still getting CICOCheckedOutToOtherUser, please
guide me its really urgent and very important for me.
Thanks once again.
"Stephen Sanderlin" wrote:
> You need to get the real sessionUid -- use the ReadProjectEntities
> method to read in the data for EntityType 1. This will return a
> ProjectDataset. Use the GUID in PROJ_SESSION_UID for the session UID.
>
> The way your code it is now, you're using the UserGuid of the user who
> calls the Event Handler (always the service account) as the sessionUid,
> which is why you are getting the error.
>
> Also, if you're looking to run QueueUpdateProject as an impersonated
> user, you need to run the method that exists in ProjectDerived, not the
> one in WS_Project. Otherwise, the ImpersonationContext will not be used.
>
> --
> Stephen Sanderlin
> Principal Consultant
> MSProjectExperts
> For Project Server Consulting: http://www.msprojectexperts.com
> For Project Server Training: http://www.projectservertraining.com
>
> Owner/Founder - EPMFAQ
> http://www.epmfaq.com/
> http://forums.epmfaq.com/
>
>
> M Azeem wrote:
>
> > I am having a problem while updating a custom field value of a
> > specific project when OnPublishing event of project server raises.
> > When I log on the Project Web Access with svc-emp user then it works
> > fine and value of custom field updates, but when I log on on Project
> > web access with different user it raises an exception that
> > CICOCheckedOutToOtherUser. Following is my code, please any
> > solution...
> >
> >
> >
> > using System;
> > using System.Diagnostics;
> > using Microsoft.Office.Project.Server.Events;
> > using System.Collections.Generic;
> > using System.Text;
> > using System.Net;
> > using System.Web.Services.Protocols;
> > using System.Data;
> > using System.Threading;
> > using PSLibrary = Microsoft.Office.Project.Server.Library;
> >
> > namespace SaveProjectAttribute
> > {
> > public class AddAttributeOnSave : ProjectEventReceiver
> > {
> > public override void
> > OnPublishing(Microsoft.Office.Project.Server.Library.PSContextInfo
> > contextInfo, ProjectPrePublishEventArgs e)
> > {
> > base.OnPublishing(contextInfo, e);
> >
> > const string ls_projURL = "http://ruh-003-cr-001/pmo/";
> > const string ls_CustomField = "TestCF";
> > const string ls_LookupTableValue = "";
> > bool verbose = true;
> >
> > const string PROJECT_SERVICE_PATH =
> > "_vti_bin/psi/Project.asmx"; const string
> > LOGIN_SERVICE_PATH = "_vti_bin/psi/LoginWindows.asmx";
> >
> > bool isWindowsAccount = contextInfo.IsWindowsUser;
> > Guid trackingGuid = new
> > Guid(contextInfo.TrackingGuid.ToByteArray());
> > string lcid = contextInfo.Lcid;
> > string userNTAccount = contextInfo.UserName;
> > Guid resourceGuid = new
> > Guid(contextInfo.UserGuid.ToByteArray()); Guid siteId =
> > new Guid(contextInfo.SiteGuid.ToByteArray());
> >
> > ProjectDerived ws_Project = new ProjectDerived();
> > LoginWindowsDerived loginWindows = new
> > LoginWindowsDerived();
> >
> >
> > LoginWindowsDerived.SetImpersonationContext(isWindowsAccount,
> > userNTAccount, resourceGuid, trackingGuid, siteId, lcid);
> > ProjectDerived.SetImpersonationContext(isWindowsAccount,
> > userNTAccount, resourceGuid, trackingGuid, siteId, lcid);
> >
> > loginWindows.Url = ls_projURL + LOGIN_SERVICE_PATH;
> > loginWindows.Credentials =
> > CredentialCache.DefaultCredentials; ws_Project.Url =
> > ls_projURL + PROJECT_SERVICE_PATH; ws_Project.Credentials
> > = CredentialCache.DefaultCredentials;
> >
> > WSProject.ProjectDataSet lo_projs = null;
> > WSProject.ProjectDataSet lo_projDS;
> >
> > Guid lo_projGUID;
> > string ls_projName;
> >
> > CustomField cf = new CustomField(ls_projURL,
> > ls_CustomField); LookupTable lt = new
> > LookupTable(ls_projURL, cf.LookupTableGUID);
> >
> > try
> > {
> > // Read all the projects on the server
> > lo_projs = ws_Project.ReadProjectList();
> >
> > DataRowCollection lo_projects =
> > lo_projs.Tables[lo_projs.Project.TableName].Rows;
> >
> > lo_projDS =
> > ws_Project.ReadProjectEntities(e.ProjectGuid, 32,
> > WSProject.DataStoreEnum.WorkingStore);
> >
> > foreach
> > (WSProject.ProjectDataSet.ProjectCustomFieldsRow row in
> > lo_projDS.ProjectCustomFields) {
> > if (row.MD_PROP_UID == cf.CustomFieldGUID)
> > {
> > row.TEXT_VALUE = "Finally Got You!";
> >
> > Guid jobid = Guid.NewGuid();
> >
> > ws_Project.QueueUpdateProject(jobid,
> > contextInfo.UserGuid, lo_projDS, false);
> > }
> > }
> > }
> > catch (SoapException lo_ex1)
> > {
> > if (verbose)
> > System.Console.WriteLine("Error: " +
> > lo_ex1.Message); }
> > catch (WebException lo_ex)
> > {
> > if (verbose)
> > System.Console.WriteLine("Error: " +
> > lo_ex.Message); }
> > catch (Exception lo_ex)
> > {
> > if (verbose)
> > System.Console.WriteLine("Unknown Error: " +
> > lo_ex.Message);
> > }
> >
> > System.Console.WriteLine("Done!");
> > }
> > }
> >
> > class LoginWindowsDerived : WSLoginWindows.LoginWindows
> > {
> > private static String ContextString = String.Empty;
> >
> > protected override WebRequest GetWebRequest(Uri uri)
> > {
> > //here we are overriding the GetWebRequest method and
> > adding the 2 web request headers
> > WebRequest webRequest = base.GetWebRequest(uri);
> > if (ContextString != String.Empty)
> > {
> > webRequest.UseDefaultCredentials = true;
> >
> > bool isImpersonating =
> > (System.Security.Principal.WindowsIdentity.GetCurrent(true) != null);
> > webRequest.Credentials =
> > CredentialCache.DefaultNetworkCredentials;
> >
> > webRequest.Headers.Add("PjAuth", ContextString);
> > webRequest.Headers.Add("ForwardFrom",
> > "/_vti_bin/psi/LoginWindows.asmx");
> >
> > webRequest.PreAuthenticate = true;
> > }
> > return webRequest;
> > }
> >
> > public static void SetImpersonationContext(bool
> > isWindowsUser, String userNTAccount, Guid userGuid, Guid
> > trackingGuid, Guid siteId, String lcid)
> > {
> > ContextString = GetImpersonationContext(isWindowsUser,
> > userNTAccount, userGuid, trackingGuid, siteId, lcid);
> > }
> >
> > private static String GetImpersonationContext(bool
> > isWindowsUser, String userNTAccount, Guid userGuid, Guid
> > trackingGuid, Guid siteId, String lcid)
> > {
> > PSLibrary.PSContextInfo contextInfo = new
> > PSLibrary.PSContextInfo(isWindowsUser, userNTAccount, userGuid,
> > trackingGuid, siteId, lcid);
> > String contextString =
> > PSLibrary.PSContextInfo.SerializeToString(contextInfo);
> > return contextString;
> > }
> > }
> >
> > class ProjectDerived : WSProject.Project
> > {
> > private static String ContextString = String.Empty;
> >
> > protected override WebRequest GetWebRequest(Uri uri)
> > {
> > //here we are overriding the GetWebRequest method and
> > adding the 2 web request headers
> > WebRequest webRequest = base.GetWebRequest(uri);
> > if (ContextString != String.Empty)
> > {
> > webRequest.UseDefaultCredentials = true;
> >
> > bool isImpersonating =
> > (System.Security.Principal.WindowsIdentity.GetCurrent(true) != null);
> > webRequest.Credentials =
> > CredentialCache.DefaultNetworkCredentials;
> >
> > webRequest.Headers.Add("PjAuth", ContextString);
> > webRequest.Headers.Add("ForwardFrom",
> > "/_vti_bin/psi/project.asmx");
> >
> > webRequest.PreAuthenticate = true;
> > }
> > return webRequest;
> > }
> >
> > public static void SetImpersonationContext(bool
> > isWindowsUser, String userNTAccount, Guid userGuid, Guid
> > trackingGuid, Guid siteId, String lcid)
> > {
> > ContextString = GetImpersonationContext(isWindowsUser,
> > userNTAccount, userGuid, trackingGuid, siteId, lcid);
> > }
> >
> > private static String GetImpersonationContext(bool
> > isWindowsUser, String userNTAccount, Guid userGuid, Guid
> > trackingGuid, Guid siteId, String lcid)
> > {
> > PSLibrary.PSContextInfo contextInfo = new
> > PSLibrary.PSContextInfo(isWindowsUser, userNTAccount, userGuid,
> > trackingGuid, siteId, lcid);
> > String contextString =
> > PSLibrary.PSContextInfo.SerializeToString(contextInfo);
> > return contextString;
> > }
> > }
> > }
>
date: Tue, 26 Aug 2008 07:44:01 -0700
author: M Azeem
Re: problem in updating custom field on publishing event of Projec
Hello Martin,
I tried this code
using( PSI _psi=new PSI(contextInfo))
{
_psi.Project.QueueUpdateProject(jobid, sessionID,
projectDs, false);
}
But getting same CICOCheckedOutToOtherUser error, any idea?
"Martin Winzig" wrote:
> 1) when imperonating user you have to call Web service from shared service
> provider.
> 2) I can see that you try to set PJ_AUTH - but there is feature in MPS
> which causing that ContextInfo.iswindowsuser==false for domain users.:) And
> this feature weren't handled in your event handler)
>
> PS on my blog are sample Eventhandler which can be used as inspiration.
>
>
> --
> Blog: http://www.projectserver.cz
>
>
> "Stephen Sanderlin" wrote:
>
> > You need to get the real sessionUid -- use the ReadProjectEntities
> > method to read in the data for EntityType 1. This will return a
> > ProjectDataset. Use the GUID in PROJ_SESSION_UID for the session UID.
> >
> > The way your code it is now, you're using the UserGuid of the user who
> > calls the Event Handler (always the service account) as the sessionUid,
> > which is why you are getting the error.
> >
> > Also, if you're looking to run QueueUpdateProject as an impersonated
> > user, you need to run the method that exists in ProjectDerived, not the
> > one in WS_Project. Otherwise, the ImpersonationContext will not be used.
> >
> > --
> > Stephen Sanderlin
> > Principal Consultant
> > MSProjectExperts
> > For Project Server Consulting: http://www.msprojectexperts.com
> > For Project Server Training: http://www.projectservertraining.com
> >
> > Owner/Founder - EPMFAQ
> > http://www.epmfaq.com/
> > http://forums.epmfaq.com/
> >
> >
> > M Azeem wrote:
> >
> > > I am having a problem while updating a custom field value of a
> > > specific project when OnPublishing event of project server raises.
> > > When I log on the Project Web Access with svc-emp user then it works
> > > fine and value of custom field updates, but when I log on on Project
> > > web access with different user it raises an exception that
> > > CICOCheckedOutToOtherUser. Following is my code, please any
> > > solution...
> > >
> > >
> > >
> > > using System;
> > > using System.Diagnostics;
> > > using Microsoft.Office.Project.Server.Events;
> > > using System.Collections.Generic;
> > > using System.Text;
> > > using System.Net;
> > > using System.Web.Services.Protocols;
> > > using System.Data;
> > > using System.Threading;
> > > using PSLibrary = Microsoft.Office.Project.Server.Library;
> > >
> > > namespace SaveProjectAttribute
> > > {
> > > public class AddAttributeOnSave : ProjectEventReceiver
> > > {
> > > public override void
> > > OnPublishing(Microsoft.Office.Project.Server.Library.PSContextInfo
> > > contextInfo, ProjectPrePublishEventArgs e)
> > > {
> > > base.OnPublishing(contextInfo, e);
> > >
> > > const string ls_projURL = "http://ruh-003-cr-001/pmo/";
> > > const string ls_CustomField = "TestCF";
> > > const string ls_LookupTableValue = "";
> > > bool verbose = true;
> > >
> > > const string PROJECT_SERVICE_PATH =
> > > "_vti_bin/psi/Project.asmx"; const string
> > > LOGIN_SERVICE_PATH = "_vti_bin/psi/LoginWindows.asmx";
> > >
> > > bool isWindowsAccount = contextInfo.IsWindowsUser;
> > > Guid trackingGuid = new
> > > Guid(contextInfo.TrackingGuid.ToByteArray());
> > > string lcid = contextInfo.Lcid;
> > > string userNTAccount = contextInfo.UserName;
> > > Guid resourceGuid = new
> > > Guid(contextInfo.UserGuid.ToByteArray()); Guid siteId =
> > > new Guid(contextInfo.SiteGuid.ToByteArray());
> > >
> > > ProjectDerived ws_Project = new ProjectDerived();
> > > LoginWindowsDerived loginWindows = new
> > > LoginWindowsDerived();
> > >
> > >
> > > LoginWindowsDerived.SetImpersonationContext(isWindowsAccount,
> > > userNTAccount, resourceGuid, trackingGuid, siteId, lcid);
> > > ProjectDerived.SetImpersonationContext(isWindowsAccount,
> > > userNTAccount, resourceGuid, trackingGuid, siteId, lcid);
> > >
> > > loginWindows.Url = ls_projURL + LOGIN_SERVICE_PATH;
> > > loginWindows.Credentials =
> > > CredentialCache.DefaultCredentials; ws_Project.Url =
> > > ls_projURL + PROJECT_SERVICE_PATH; ws_Project.Credentials
> > > = CredentialCache.DefaultCredentials;
> > >
> > > WSProject.ProjectDataSet lo_projs = null;
> > > WSProject.ProjectDataSet lo_projDS;
> > >
> > > Guid lo_projGUID;
> > > string ls_projName;
> > >
> > > CustomField cf = new CustomField(ls_projURL,
> > > ls_CustomField); LookupTable lt = new
> > > LookupTable(ls_projURL, cf.LookupTableGUID);
> > >
> > > try
> > > {
> > > // Read all the projects on the server
> > > lo_projs = ws_Project.ReadProjectList();
> > >
> > > DataRowCollection lo_projects =
> > > lo_projs.Tables[lo_projs.Project.TableName].Rows;
> > >
> > > lo_projDS =
> > > ws_Project.ReadProjectEntities(e.ProjectGuid, 32,
> > > WSProject.DataStoreEnum.WorkingStore);
> > >
> > > foreach
> > > (WSProject.ProjectDataSet.ProjectCustomFieldsRow row in
> > > lo_projDS.ProjectCustomFields) {
> > > if (row.MD_PROP_UID == cf.CustomFieldGUID)
> > > {
> > > row.TEXT_VALUE = "Finally Got You!";
> > >
> > > Guid jobid = Guid.NewGuid();
> > >
> > > ws_Project.QueueUpdateProject(jobid,
> > > contextInfo.UserGuid, lo_projDS, false);
> > > }
> > > }
> > > }
> > > catch (SoapException lo_ex1)
> > > {
> > > if (verbose)
> > > System.Console.WriteLine("Error: " +
> > > lo_ex1.Message); }
> > > catch (WebException lo_ex)
> > > {
> > > if (verbose)
> > > System.Console.WriteLine("Error: " +
> > > lo_ex.Message); }
> > > catch (Exception lo_ex)
> > > {
> > > if (verbose)
> > > System.Console.WriteLine("Unknown Error: " +
> > > lo_ex.Message);
> > > }
> > >
> > > System.Console.WriteLine("Done!");
> > > }
> > > }
> > >
> > > class LoginWindowsDerived : WSLoginWindows.LoginWindows
> > > {
> > > private static String ContextString = String.Empty;
> > >
> > > protected override WebRequest GetWebRequest(Uri uri)
> > > {
> > > //here we are overriding the GetWebRequest method and
> > > adding the 2 web request headers
> > > WebRequest webRequest = base.GetWebRequest(uri);
> > > if (ContextString != String.Empty)
> > > {
> > > webRequest.UseDefaultCredentials = true;
> > >
> > > bool isImpersonating =
> > > (System.Security.Principal.WindowsIdentity.GetCurrent(true) != null);
> > > webRequest.Credentials =
> > > CredentialCache.DefaultNetworkCredentials;
> > >
> > > webRequest.Headers.Add("PjAuth", ContextString);
> > > webRequest.Headers.Add("ForwardFrom",
> > > "/_vti_bin/psi/LoginWindows.asmx");
> > >
> > > webRequest.PreAuthenticate = true;
> > > }
> > > return webRequest;
> > > }
> > >
> > > public static void SetImpersonationContext(bool
> > > isWindowsUser, String userNTAccount, Guid userGuid, Guid
> > > trackingGuid, Guid siteId, String lcid)
> > > {
> > > ContextString = GetImpersonationContext(isWindowsUser,
> > > userNTAccount, userGuid, trackingGuid, siteId, lcid);
> > > }
> > >
> > > private static String GetImpersonationContext(bool
> > > isWindowsUser, String userNTAccount, Guid userGuid, Guid
> > > trackingGuid, Guid siteId, String lcid)
> > > {
> > > PSLibrary.PSContextInfo contextInfo = new
> > > PSLibrary.PSContextInfo(isWindowsUser, userNTAccount, userGuid,
> > > trackingGuid, siteId, lcid);
> > > String contextString =
> > > PSLibrary.PSContextInfo.SerializeToString(contextInfo);
> > > return contextString;
> > > }
> > > }
> > >
> > > class ProjectDerived : WSProject.Project
> > > {
> > > private static String ContextString = String.Empty;
> > >
> > > protected override WebRequest GetWebRequest(Uri uri)
> > > {
> > > //here we are overriding the GetWebRequest method and
> > > adding the 2 web request headers
> > > WebRequest webRequest = base.GetWebRequest(uri);
> > > if (ContextString != String.Empty)
> > > {
> > > webRequest.UseDefaultCredentials = true;
> > >
> > > bool isImpersonating =
> > > (System.Security.Principal.WindowsIdentity.GetCurrent(true) != null);
> > > webRequest.Credentials =
> > > CredentialCache.DefaultNetworkCredentials;
> > >
> > > webRequest.Headers.Add("PjAuth", ContextString);
> > > webRequest.Headers.Add("ForwardFrom",
> > > "/_vti_bin/psi/project.asmx");
> > >
> > > webRequest.PreAuthenticate = true;
> > > }
> > > return webRequest;
> > > }
> > >
> > > public static void SetImpersonationContext(bool
> > > isWindowsUser, String userNTAccount, Guid userGuid, Guid
> > > trackingGuid, Guid siteId, String lcid)
> > > {
> > > ContextString = GetImpersonationContext(isWindowsUser,
> > > userNTAccount, userGuid, trackingGuid, siteId, lcid);
> > > }
> > >
> > > private static String GetImpersonationContext(bool
> > > isWindowsUser, String userNTAccount, Guid userGuid, Guid
> > > trackingGuid, Guid siteId, String lcid)
> > > {
> > > PSLibrary.PSContextInfo contextInfo = new
> > > PSLibrary.PSContextInfo(isWindowsUser, userNTAccount, userGuid,
> > > trackingGuid, siteId, lcid);
> > > String contextString =
> > > PSLibrary.PSContextInfo.SerializeToString(contextInfo);
> > > return contextString;
> > > }
> > > }
> > > }
> >
date: Tue, 26 Aug 2008 23:16:00 -0700
author: M Azeem
Re: problem in updating custom field on publishing event of Projec
You shoud do it in another Event handler,
Thepublished project plan can be in different states, when the event on
Publishing is fired.
Project shoudl be opened in project profesional
Project is not checke to anyone.(publish from ProjTool)
So i think that you shoud implement this functionsality in OncheckIn event
handler. Whis is called when the project is closed.
1) THisSproject shoudl be published
--
Blog: http://www.projectserver.cz
"M Azeem" wrote:
> Hello Martin,
> I tried this code
>
> using( PSI _psi=new PSI(contextInfo))
> {
> _psi.Project.QueueUpdateProject(jobid, sessionID,
> projectDs, false);
>
> }
> But getting same CICOCheckedOutToOtherUser error, any idea?
>
> "Martin Winzig" wrote:
>
> > 1) when imperonating user you have to call Web service from shared service
> > provider.
> > 2) I can see that you try to set PJ_AUTH - but there is feature in MPS
> > which causing that ContextInfo.iswindowsuser==false for domain users.:) And
> > this feature weren't handled in your event handler)
> >
> > PS on my blog are sample Eventhandler which can be used as inspiration.
> >
> >
> > --
> > Blog: http://www.projectserver.cz
> >
> >
> > "Stephen Sanderlin" wrote:
> >
> > > You need to get the real sessionUid -- use the ReadProjectEntities
> > > method to read in the data for EntityType 1. This will return a
> > > ProjectDataset. Use the GUID in PROJ_SESSION_UID for the session UID.
> > >
> > > The way your code it is now, you're using the UserGuid of the user who
> > > calls the Event Handler (always the service account) as the sessionUid,
> > > which is why you are getting the error.
> > >
> > > Also, if you're looking to run QueueUpdateProject as an impersonated
> > > user, you need to run the method that exists in ProjectDerived, not the
> > > one in WS_Project. Otherwise, the ImpersonationContext will not be used.
> > >
> > > --
> > > Stephen Sanderlin
> > > Principal Consultant
> > > MSProjectExperts
> > > For Project Server Consulting: http://www.msprojectexperts.com
> > > For Project Server Training: http://www.projectservertraining.com
> > >
> > > Owner/Founder - EPMFAQ
> > > http://www.epmfaq.com/
> > > http://forums.epmfaq.com/
> > >
> > >
> > > M Azeem wrote:
> > >
> > > > I am having a problem while updating a custom field value of a
> > > > specific project when OnPublishing event of project server raises.
> > > > When I log on the Project Web Access with svc-emp user then it works
> > > > fine and value of custom field updates, but when I log on on Project
> > > > web access with different user it raises an exception that
> > > > CICOCheckedOutToOtherUser. Following is my code, please any
> > > > solution...
> > > >
> > > >
> > > >
> > > > using System;
> > > > using System.Diagnostics;
> > > > using Microsoft.Office.Project.Server.Events;
> > > > using System.Collections.Generic;
> > > > using System.Text;
> > > > using System.Net;
> > > > using System.Web.Services.Protocols;
> > > > using System.Data;
> > > > using System.Threading;
> > > > using PSLibrary = Microsoft.Office.Project.Server.Library;
> > > >
> > > > namespace SaveProjectAttribute
> > > > {
> > > > public class AddAttributeOnSave : ProjectEventReceiver
> > > > {
> > > > public override void
> > > > OnPublishing(Microsoft.Office.Project.Server.Library.PSContextInfo
> > > > contextInfo, ProjectPrePublishEventArgs e)
> > > > {
> > > > base.OnPublishing(contextInfo, e);
> > > >
> > > > const string ls_projURL = "http://ruh-003-cr-001/pmo/";
> > > > const string ls_CustomField = "TestCF";
> > > > const string ls_LookupTableValue = "";
> > > > bool verbose = true;
> > > >
> > > > const string PROJECT_SERVICE_PATH =
> > > > "_vti_bin/psi/Project.asmx"; const string
> > > > LOGIN_SERVICE_PATH = "_vti_bin/psi/LoginWindows.asmx";
> > > >
> > > > bool isWindowsAccount = contextInfo.IsWindowsUser;
> > > > Guid trackingGuid = new
> > > > Guid(contextInfo.TrackingGuid.ToByteArray());
> > > > string lcid = contextInfo.Lcid;
> > > > string userNTAccount = contextInfo.UserName;
> > > > Guid resourceGuid = new
> > > > Guid(contextInfo.UserGuid.ToByteArray()); Guid siteId =
> > > > new Guid(contextInfo.SiteGuid.ToByteArray());
> > > >
> > > > ProjectDerived ws_Project = new ProjectDerived();
> > > > LoginWindowsDerived loginWindows = new
> > > > LoginWindowsDerived();
> > > >
> > > >
> > > > LoginWindowsDerived.SetImpersonationContext(isWindowsAccount,
> > > > userNTAccount, resourceGuid, trackingGuid, siteId, lcid);
> > > > ProjectDerived.SetImpersonationContext(isWindowsAccount,
> > > > userNTAccount, resourceGuid, trackingGuid, siteId, lcid);
> > > >
> > > > loginWindows.Url = ls_projURL + LOGIN_SERVICE_PATH;
> > > > loginWindows.Credentials =
> > > > CredentialCache.DefaultCredentials; ws_Project.Url =
> > > > ls_projURL + PROJECT_SERVICE_PATH; ws_Project.Credentials
> > > > = CredentialCache.DefaultCredentials;
> > > >
> > > > WSProject.ProjectDataSet lo_projs = null;
> > > > WSProject.ProjectDataSet lo_projDS;
> > > >
> > > > Guid lo_projGUID;
> > > > string ls_projName;
> > > >
> > > > CustomField cf = new CustomField(ls_projURL,
> > > > ls_CustomField); LookupTable lt = new
> > > > LookupTable(ls_projURL, cf.LookupTableGUID);
> > > >
> > > > try
> > > > {
> > > > // Read all the projects on the server
> > > > lo_projs = ws_Project.ReadProjectList();
> > > >
> > > > DataRowCollection lo_projects =
> > > > lo_projs.Tables[lo_projs.Project.TableName].Rows;
> > > >
> > > > lo_projDS =
> > > > ws_Project.ReadProjectEntities(e.ProjectGuid, 32,
> > > > WSProject.DataStoreEnum.WorkingStore);
> > > >
> > > > foreach
> > > > (WSProject.ProjectDataSet.ProjectCustomFieldsRow row in
> > > > lo_projDS.ProjectCustomFields) {
> > > > if (row.MD_PROP_UID == cf.CustomFieldGUID)
> > > > {
> > > > row.TEXT_VALUE = "Finally Got You!";
> > > >
> > > > Guid jobid = Guid.NewGuid();
> > > >
> > > > ws_Project.QueueUpdateProject(jobid,
> > > > contextInfo.UserGuid, lo_projDS, false);
> > > > }
> > > > }
> > > > }
> > > > catch (SoapException lo_ex1)
> > > > {
> > > > if (verbose)
> > > > System.Console.WriteLine("Error: " +
> > > > lo_ex1.Message); }
> > > > catch (WebException lo_ex)
> > > > {
> > > > if (verbose)
> > > > System.Console.WriteLine("Error: " +
> > > > lo_ex.Message); }
> > > > catch (Exception lo_ex)
> > > > {
> > > > if (verbose)
> > > > System.Console.WriteLine("Unknown Error: " +
> > > > lo_ex.Message);
> > > > }
> > > >
> > > > System.Console.WriteLine("Done!");
> > > > }
> > > > }
> > > >
> > > > class LoginWindowsDerived : WSLoginWindows.LoginWindows
> > > > {
> > > > private static String ContextString = String.Empty;
> > > >
> > > > protected override WebRequest GetWebRequest(Uri uri)
> > > > {
> > > > //here we are overriding the GetWebRequest method and
> > > > adding the 2 web request headers
> > > > WebRequest webRequest = base.GetWebRequest(uri);
> > > > if (ContextString != String.Empty)
> > > > {
> > > > webRequest.UseDefaultCredentials = true;
> > > >
> > > > bool isImpersonating =
> > > > (System.Security.Principal.WindowsIdentity.GetCurrent(true) != null);
> > > > webRequest.Credentials =
> > > > CredentialCache.DefaultNetworkCredentials;
> > > >
> > > > webRequest.Headers.Add("PjAuth", ContextString);
> > > > webRequest.Headers.Add("ForwardFrom",
> > > > "/_vti_bin/psi/LoginWindows.asmx");
> > > >
> > > > webRequest.PreAuthenticate = true;
> > > > }
> > > > return webRequest;
> > > > }
> > > >
> > > > public static void SetImpersonationContext(bool
> > > > isWindowsUser, String userNTAccount, Guid userGuid, Guid
> > > > trackingGuid, Guid siteId, String lcid)
> > > > {
> > > > ContextString = GetImpersonationContext(isWindowsUser,
> > > > userNTAccount, userGuid, trackingGuid, siteId, lcid);
> > > > }
> > > >
> > > > private static String GetImpersonationContext(bool
> > > > isWindowsUser, String userNTAccount, Guid userGuid, Guid
> > > > trackingGuid, Guid siteId, String lcid)
> > > > {
> > > > PSLibrary.PSContextInfo contextInfo = new
> > > > PSLibrary.PSContextInfo(isWindowsUser, userNTAccount, userGuid,
> > > > trackingGuid, siteId, lcid);
> > > > String contextString =
> > > > PSLibrary.PSContextInfo.SerializeToString(contextInfo);
> > > > return contextString;
> > > > }
> > > > }
> > > >
> > > > class ProjectDerived : WSProject.Project
> > > > {
> > > > private static String ContextString = String.Empty;
> > > >
> > > > protected override WebRequest GetWebRequest(Uri uri)
> > > > {
> > > > //here we are overriding the GetWebRequest method and
> > > > adding the 2 web request headers
> > > > WebRequest webRequest = base.GetWebRequest(uri);
> > > > if (ContextString != String.Empty)
> > > > {
> > > > webRequest.UseDefaultCredentials = true;
> > > >
> > > > bool isImpersonating =
> > > > (System.Security.Principal.WindowsIdentity.GetCurrent(true) != null);
> > > > webRequest.Credentials =
> > > > CredentialCache.DefaultNetworkCredentials;
> > > >
> > > > webRequest.Headers.Add("PjAuth", ContextString);
> > > > webRequest.Headers.Add("ForwardFrom",
> > > > "/_vti_bin/psi/project.asmx");
> > > >
> > > > webRequest.PreAuthenticate = true;
> > > > }
> > > > return webRequest;
> > > > }
> > > >
> > > > public static void SetImpersonationContext(bool
> > > > isWindowsUser, String userNTAccount, Guid userGuid, Guid
> > > > trackingGuid, Guid siteId, String lcid)
> > > > {
> > > > ContextString = GetImpersonationContext(isWindowsUser,
> > > > userNTAccount, userGuid, trackingGuid, siteId, lcid);
> > > > }
> > > >
> > > > private static String GetImpersonationContext(bool
> > > > isWindowsUser, String userNTAccount, Guid userGuid, Guid
> > > > trackingGuid, Guid siteId, String lcid)
> > > > {
> > > > PSLibrary.PSContextInfo contextInfo = new
> > > > PSLibrary.PSContextInfo(isWindowsUser, userNTAccount, userGuid,
> > > > trackingGuid, siteId, lcid);
> > > > String contextString =
> > > > PSLibrary.PSContextInfo.SerializeToString(contextInfo);
> > > > return contextString;
> > > > }
> > > > }
> > > > }
> > >
date: Wed, 27 Aug 2008 01:43:00 -0700
author: Martin Winzig
Re: problem in updating custom field on publishing event of Projec
OK, Stephen, I have tried it on CheckIn event here is my code but again,
exceptions are being raised and strange thing is Exception object is null, so
I am unable to see what causing the exception please help
using System;
using System.Diagnostics;
using Microsoft.Office.Project.Server.Events;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Web.Services.Protocols;
using System.Data;
using System.Threading;
using PSLibrary = Microsoft.Office.Project.Server.Library;
namespace SaveProjectAttribute
{
public class AddAttributeOnSave : ProjectEventReceiver
{
public override void
OnCheckIn(Microsoft.Office.Project.Server.Library.PSContextInfo contextInfo,
ProjectPostEventArgs e)
{
base.OnCheckIn(contextInfo, e);
const string ls_projURL = "http://ruh-003-cr-001/pmo/";
const string ls_CustomField = "TestCF";
const string ls_LookupTableValue = "";
bool verbose = true;
const string PROJECT_SERVICE_PATH = "_vti_bin/psi/Project.asmx";
const string LOGIN_SERVICE_PATH = "_vti_bin/psi/LoginWindows.asmx";
bool isWindowsAccount = true;
Guid trackingGuid = new Guid(contextInfo.TrackingGuid.ToByteArray());
string lcid = contextInfo.Lcid;
string userNTAccount = contextInfo.UserName;
Guid resourceGuid = new Guid(contextInfo.UserGuid.ToByteArray());
Guid siteId = new Guid(contextInfo.SiteGuid.ToByteArray());
ProjectDerived ws_Project = new ProjectDerived();
LoginWindowsDerived loginWindows = new LoginWindowsDerived();
LoginWindowsDerived.SetImpersonationContext(isWindowsAccount, userNTAccount,
resourceGuid, trackingGuid, siteId, lcid);
ProjectDerived.SetImpersonationContext(isWindowsAccount, userNTAccount,
resourceGuid, trackingGuid, siteId, lcid);
loginWindows.Url = ls_projURL + LOGIN_SERVICE_PATH;
loginWindows.Credentials = CredentialCache.DefaultCredentials;
ws_Project.Url = ls_projURL + PROJECT_SERVICE_PATH;
ws_Project.Credentials = CredentialCache.DefaultCredentials;
WSProject.ProjectDataSet lo_projs = null;
WSProject.ProjectDataSet lo_projDS;
WSProject.ProjectDataSet lo_projDS1;
Guid lo_projGUID;
string ls_projName;
CustomField cf = new CustomField(ls_projURL, ls_CustomField);
LookupTable lt = new LookupTable(ls_projURL, cf.LookupTableGUID);
try
{
// Read all the projects on the server
lo_projs = ws_Project.ReadProjectList();
DataRowCollection lo_projects =
lo_projs.Tables[lo_projs.Project.TableName].Rows;
lo_projDS = ws_Project.ReadProjectEntities(e.ProjectGuid, 32,
WSProject.DataStoreEnum.WorkingStore);
lo_projDS1 = ws_Project.ReadProjectEntities(e.ProjectGuid, 1,
WSProject.DataStoreEnum.WorkingStore);
Guid jobid = Guid.NewGuid();
Guid sessionId = Guid.NewGuid();
foreach (WSProject.ProjectDataSet.ProjectCustomFieldsRow row in
lo_projDS.ProjectCustomFields)
{
if (row.MD_PROP_UID == cf.CustomFieldGUID)
{
row.TEXT_VALUE = "Finally Got You!";
ws_Project.CheckOutProject(e.ProjectGuid, sessionId, "");
ws_Project.QueueUpdateProject(jobid, sessionId, lo_projDS, false);
ws_Project.QueueCheckInProject(jobid, e.ProjectGuid, false, sessionId, "");
}
}
}
catch (SoapException lo_ex1)
{
if (verbose)
System.Console.WriteLine("Error: " + lo_ex1.Message);
}
catch (WebException lo_ex)
{
if (verbose)
System.Console.WriteLine("Error: " + lo_ex.Message);
}
catch (Exception lo_ex)
{
if (verbose)
System.Console.WriteLine("Unknown Error: " + lo_ex.Message);
}
System.Console.WriteLine("Done!");
}
}
class LoginWindowsDerived : WSLoginWindows.LoginWindows
{
private static String ContextString = String.Empty;
protected override WebRequest GetWebRequest(Uri uri)
{
//here we are overriding the GetWebRequest method and adding the 2 web
request headers
WebRequest webRequest = base.GetWebRequest(uri);
if (ContextString != String.Empty)
{
webRequest.UseDefaultCredentials = true;
bool isImpersonating =
(System.Security.Principal.WindowsIdentity.GetCurrent(true) != null);
webRequest.Credentials = CredentialCache.DefaultNetworkCredentials;
webRequest.Headers.Add("PjAuth", ContextString);
webRequest.Headers.Add("ForwardFrom", "/_vti_bin/psi/LoginWindows.asmx");
webRequest.PreAuthenticate = true;
}
return webRequest;
}
public static void SetImpersonationContext(bool isWindowsUser, String
userNTAccount, Guid userGuid, Guid trackingGuid, Guid siteId, String lcid)
{
ContextString = GetImpersonationContext(isWindowsUser, userNTAccount,
userGuid, trackingGuid, siteId, lcid);
}
private static String GetImpersonationContext(bool isWindowsUser, String
userNTAccount, Guid userGuid, Guid trackingGuid, Guid siteId, String lcid)
{
PSLibrary.PSContextInfo contextInfo = new
PSLibrary.PSContextInfo(isWindowsUser, userNTAccount, userGuid, trackingGuid,
siteId, lcid);
String contextString = PSLibrary.PSContextInfo.SerializeToString(contextInfo);
return contextString;
}
}
class ProjectDerived : WSProject.Project
{
private static String ContextString = String.Empty;
protected override WebRequest GetWebRequest(Uri uri)
{
//here we are overriding the GetWebRequest method and adding the 2 web
request headers
WebRequest webRequest = base.GetWebRequest(uri);
if (ContextString != String.Empty)
{
webRequest.UseDefaultCredentials = true;
bool isImpersonating =
(System.Security.Principal.WindowsIdentity.GetCurrent(true) != null);
webRequest.Credentials = CredentialCache.DefaultNetworkCredentials;
webRequest.Headers.Add("PjAuth", ContextString);
webRequest.Headers.Add("ForwardFrom", "/_vti_bin/psi/project.asmx");
webRequest.PreAuthenticate = true;
}
return webRequest;
}
public static void SetImpersonationContext(bool isWindowsUser, String
userNTAccount, Guid userGuid, Guid trackingGuid, Guid siteId, String lcid)
{
ContextString = GetImpersonationContext(isWindowsUser, userNTAccount,
userGuid, trackingGuid, siteId, lcid);
}
private static String GetImpersonationContext(bool isWindowsUser, String
userNTAccount, Guid userGuid, Guid trackingGuid, Guid siteId, String lcid)
{
PSLibrary.PSContextInfo contextInfo = new
PSLibrary.PSContextInfo(isWindowsUser, userNTAccount, userGuid, trackingGuid,
siteId, lcid);
String contextString = PSLibrary.PSContextInfo.SerializeToString(contextInfo);
return contextString;
}
}
}
"Stephen Sanderlin" wrote:
> Can you post your new code?
>
> As far as WS_Project, you are right -- my apologies. I need a new
> newsreader.
>
> --
> Stephen Sanderlin
> Principal Consultant
> MSProjectExperts
> For Project Server Consulting: http://www.msprojectexperts.com
> For Project Server Training: http://www.projectservertraining.com
>
> Owner/Founder - EPMFAQ
> http://www.epmfaq.com/
> http://forums.epmfaq.com/
>
>
> M Azeem wrote:
>
> > PROJECT
>
date: Tue, 2 Sep 2008 02:19:46 -0700
author: M Azeem
|
|