Creating a Timesheet in Project Server 2007using PSI and impersona

M

meliacooper

I am attempting to create a timesheet for a user in project server. I can
create the timesheet but it is a surrogate timesheet. I have have checked
the headers generated from ImpersonateTSByResUID, however the timesheet is
still created as a surrogate. Am I missing anything here? I have already
looked at the examples on MSDN but am still not able to succesfully create
the timesheet as the correct user. Thanks in advance for any help!

TimesheetDerived timesheetDerived = null;
timesheetDerived =
ImpersonateTSByResUID(resDS.Resources[0].RES_IS_WINDOWS_USER,
resDS.Resources[0].RES_UID, resDS.Resources[0].WRES_ACCOUNT, siteID, "1033",
tsWSUrl);
TimeSheetWS.TimesheetDataSet timesheetDs = new
TimeSheetWS.TimesheetDataSet();
TimeSheetWS.TimesheetDataSet.HeadersRow headersRow =
timesheetDs.Headers.NewHeadersRow(); headersRow.RES_UID =
resourceGuid; headersRow.TS_UID = Guid.NewGuid();
headersRow.WPRD_UID = periodUid;
//headersRow.TS_CREATOR_RES_UID = resourceGuid;
headersRow.TS_NAME = "TS - " + PSIAdmin.GetTSPeriodName(periodUid) + " - " +
index.ToString(); headersRow.TS_COMMENTS = "Timesheet using
PSI"; headersRow.TS_ENTRY_MODE_ENUM =
(byte)PSLibrary.TimesheetEnum.EntryMode.Daily
timesheetDs.Headers.AddHeadersRow(headersRow);
// Create the timesheet with the default line types
specified by the admin
timesheetDerived.CreateTimesheet(timesheetDs,
TimeSheetWS.PreloadType.Default); return headersRow.TS_UID;

private static TimesheetDerived ImpersonateTSByResUID(bool
isWindowsUser, Guid resUID, string userAcct, Guid siteID, string lcID, string
url) { TimesheetDerived timesheetDerived = new
TimesheetDerived(); timesheetDerived.Url = url;
timesheetDerived.Credentials = CredentialCache.DefaultCredentials;
TimesheetDerived.SetImpersonationContext(isWindowsUser, userAcct, resUID,
Guid.NewGuid(), siteID, lcID); return timesheetDerived; }
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; } }
 
M

Marc Soester [MVP]

Hi meliacooper,

try to repost your question to the project server developer forum here
http://www.microsoft.com/communitie...f21-f0d3-4245-947f-dcae163d51af&lang=en&cr=US

You will have more luck getting an answer :)
hope this helps
--
Marc Soester [MVP]
http://www.i-pmo.com.au


meliacooper said:
I am attempting to create a timesheet for a user in project server. I can
create the timesheet but it is a surrogate timesheet. I have have checked
the headers generated from ImpersonateTSByResUID, however the timesheet is
still created as a surrogate. Am I missing anything here? I have already
looked at the examples on MSDN but am still not able to succesfully create
the timesheet as the correct user. Thanks in advance for any help!

TimesheetDerived timesheetDerived = null;
timesheetDerived =
ImpersonateTSByResUID(resDS.Resources[0].RES_IS_WINDOWS_USER,
resDS.Resources[0].RES_UID, resDS.Resources[0].WRES_ACCOUNT, siteID, "1033",
tsWSUrl);
TimeSheetWS.TimesheetDataSet timesheetDs = new
TimeSheetWS.TimesheetDataSet();
TimeSheetWS.TimesheetDataSet.HeadersRow headersRow =
timesheetDs.Headers.NewHeadersRow(); headersRow.RES_UID =
resourceGuid; headersRow.TS_UID = Guid.NewGuid();
headersRow.WPRD_UID = periodUid;
//headersRow.TS_CREATOR_RES_UID = resourceGuid;
headersRow.TS_NAME = "TS - " + PSIAdmin.GetTSPeriodName(periodUid) + " - " +
index.ToString(); headersRow.TS_COMMENTS = "Timesheet using
PSI"; headersRow.TS_ENTRY_MODE_ENUM =
(byte)PSLibrary.TimesheetEnum.EntryMode.Daily
timesheetDs.Headers.AddHeadersRow(headersRow);
// Create the timesheet with the default line types
specified by the admin
timesheetDerived.CreateTimesheet(timesheetDs,
TimeSheetWS.PreloadType.Default); return headersRow.TS_UID;

private static TimesheetDerived ImpersonateTSByResUID(bool
isWindowsUser, Guid resUID, string userAcct, Guid siteID, string lcID, string
url) { TimesheetDerived timesheetDerived = new
TimesheetDerived(); timesheetDerived.Url = url;
timesheetDerived.Credentials = CredentialCache.DefaultCredentials;
TimesheetDerived.SetImpersonationContext(isWindowsUser, userAcct, resUID,
Guid.NewGuid(), siteID, lcID); return timesheetDerived; }
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; } }
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top