Hi Chris, Thanks for your response. Please find code below:
using System;
using System.Data;
using System.Collections.Specialized;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using Microsoft.SharePoint;
using PSLibrary = Microsoft.Office.Project.Server.Library;
using MNR.Framework.TimesheetWebSvc;
using MNR.Data;
using MNR.MiddleTier.Data;
namespace MNR.Reporting.PSI.Data.Timesheets
{
[Serializable]
public class TimesheetDataObject : ObjectBase
{
#region Constants
#endregion
#region Data Members
public static TimesheetListDataSet.TimesheetsDataTable Timesheet =
new TimesheetListDataSet.TimesheetsDataTable();
private TimesheetListDataSet m_TimesheetListDataSet = null;
private TimesheetDataSet m_TimesheetDataSet = null;
private TimesheetListDataSet.TimesheetsDataTable
m_TimesheetDataTable = null;
private TimesheetListDataSet.TimesheetsRow m_TimesheetRow = null;
private TimesheetHeaderDataObjectCollection m_Headers = null;
private TimesheetLineDataObjectCollection m_Lines = null;
#endregion
#region Constructors
public TimesheetDataObject() : base() { }
public TimesheetDataObject(DataRow WsTimesheetRow)
{
this.LoadData(WsTimesheetRow);
}
#endregion
#region Properties
public TimesheetListDataSet TimesheetListDataSet
{
get { return this.m_TimesheetListDataSet; }
}
public TimesheetDataSet TimesheetDataSet
{
get { return this.m_TimesheetDataSet; }
}
public TimesheetListDataSet.TimesheetsDataTable TimesheetDataTable
{
get { return this.m_TimesheetDataTable; }
}
public TimesheetListDataSet.TimesheetsRow TimesheetRow
{
get { return this.m_TimesheetRow; }
set { this.LoadData(value); }
}
public Guid ID
{
get { return (Guid)this[Timesheet.TS_UIDColumn.ColumnName]; }
set { this[Timesheet.TS_UIDColumn.ColumnName] = value; }
}
public Guid ResourceID
{
get { return (Guid)this[Timesheet.RES_UIDColumn.ColumnName]; }
set { this[Timesheet.RES_UIDColumn.ColumnName] = value; }
}
public string Name
{
get { return (string)this[Timesheet.TS_NAMEColumn.ColumnName]; }
set { this[Timesheet.TS_NAMEColumn.ColumnName] = value; }
}
public Guid TimePeriodID
{
get { return (Guid)this[Timesheet.WPRD_UIDColumn.ColumnName]; }
set { this[Timesheet.WPRD_UIDColumn.ColumnName] = value; }
}
public string TimePeriodName
{
get { return (string)this[Timesheet.WPRD_NAMEColumn.ColumnName]; }
set { this[Timesheet.WPRD_NAMEColumn.ColumnName] = value; }
}
public DateTime StartDate
{
get { return
(DateTime)this[Timesheet.WPRD_START_DATEColumn.ColumnName]; }
set { this[Timesheet.WPRD_START_DATEColumn.ColumnName] = value; }
}
public DateTime FinishDate
{
get { return
(DateTime)this[Timesheet.WPRD_FINISH_DATEColumn.ColumnName]; }
set { this[Timesheet.WPRD_FINISH_DATEColumn.ColumnName] = value; }
}
public TimesheetHeaderDataObjectCollection Headers
{
get { return this.m_Headers; }
}
public TimesheetLineDataObjectCollection Lines
{
get { return this.m_Lines; }
}
#endregion
#region Methods
protected override void OnInitialise()
{
this.AddProperty(Timesheet.TS_UIDColumn.ColumnName,
typeof(Guid), Guid.Empty);
this.AddProperty(Timesheet.RES_UIDColumn.ColumnName,
typeof(Guid), Guid.Empty);
this.AddProperty(Timesheet.TS_NAMEColumn.ColumnName,
typeof(string), string.Empty);
this.AddProperty(Timesheet.WPRD_UIDColumn.ColumnName,
typeof(Guid), Guid.Empty);
this.AddProperty(Timesheet.WPRD_NAMEColumn.ColumnName,
typeof(string), string.Empty);
this.AddProperty(Timesheet.WPRD_START_DATEColumn.ColumnName,
typeof(DateTime), DateTime.MinValue);
this.AddProperty(Timesheet.WPRD_FINISH_DATEColumn.ColumnName,
typeof(DateTime), DateTime.MinValue);
}
protected override void OnPostLoad(object DataSource)
{
base.OnPostLoad(DataSource);
if ((DataSource!=null) && (DataSource is
TimesheetListDataSet.TimesheetsRow))
{
this.m_TimesheetRow =
(TimesheetListDataSet.TimesheetsRow)DataSource;
if ((this.m_TimesheetRow.Table!=null) &&
(this.m_TimesheetRow.Table is TimesheetListDataSet.TimesheetsDataTable))
this.m_TimesheetDataTable =
(TimesheetListDataSet.TimesheetsDataTable)this.m_TimesheetRow.Table;
if ((this.m_TimesheetDataTable != null) &&
(this.m_TimesheetDataTable.DataSet != null) &&
(this.m_TimesheetDataTable.DataSet is TimesheetListDataSet))
this.m_TimesheetListDataSet =
(TimesheetListDataSet)this.m_TimesheetDataTable.DataSet;
}
}
public void ReadData(Timesheets TimesheetSvc)
{
if ((TimesheetSvc != null) && (TimesheetSvc.Timesheetservice !=
null) && (!this.ID.Equals(Guid.Empty)))
{
if (this.m_Headers != null)
{
this.m_Headers.Dispose();
this.m_Headers = null;
}
if (this.m_Headers != null)
{
this.m_Lines.Dispose();
this.m_Lines = null;
}
TimesheetDataSet TimesheetDataSet =
TimesheetSvc.Timesheetservice.ReadTimesheet(this.ID);
this.m_Headers = new
TimesheetHeaderDataObjectCollection(TimesheetDataSet);
this.m_Lines = new
TimesheetLineDataObjectCollection(TimesheetDataSet);
this.m_TimesheetDataSet = TimesheetDataSet;
}
}
public void Create(Guid CreatorId, Timesheets TimesheetSvc, string
Name, string Comments)
{
if ((TimesheetSvc!=null) && ((this.Headers == null) ||
(this.Headers.Count < 1)))
{
this.m_TimesheetDataSet = new TimesheetDataSet();
this.ID = Guid.NewGuid();
TimesheetDataSet.HeadersRow headersRow =
this.m_TimesheetDataSet.Headers.NewHeadersRow();
headersRow.RES_UID = this.ResourceID;
headersRow.TS_UID = this.ID;
headersRow.WPRD_UID = this.TimePeriodID;
headersRow.TS_CREATOR_RES_UID = CreatorId;
headersRow.TS_NAME = Name;
headersRow.TS_COMMENTS = Comments;
headersRow.TS_ENTRY_MODE_ENUM =
(byte)PSLibrary.TimesheetEnum.EntryMode.Daily;
headersRow.TS_STATUS_ENUM =
(byte)PSLibrary.TimesheetEnum.Status.InProgress;
this.m_TimesheetDataSet.Headers.AddHeadersRow(headersRow);
// Create the timesheet with the default line types
specified by the admin
TimesheetSvc.Timesheetservice.CreateTimesheet(this.m_TimesheetDataSet,
MNR.Framework.TimesheetWebSvc.PreloadType.Default);
this.ReadData(TimesheetSvc);
}
}
public System.Guid
AddUnverifiedLine(MNR.Reporting.PSI.Data.QueueSystems Queue, Timesheets
TimesheetSvc,string ProjectName,string ExternalTaskId, string NameDesc,
string Comment, Admins.TimesheetLineClassDataObject LineClass)
{
if ((TimesheetSvc != null) && (this.TimesheetDataSet != null) &&
(!this.ID.Equals(Guid.Empty)) && (LineClass!=null) &&
(!LineClass.ID.Equals(Guid.Empty)))
{
TimesheetDataSet.LinesRow line =
this.TimesheetDataSet.Lines.NewLinesRow();
line.TS_UID = this.ID;
line.TS_LINE_UID = Guid.NewGuid();
line.TS_LINE_CLASS_UID = LineClass.ID;
line.TS_LINE_COMMENT = Comment;
line.TS_LINE_STATUS =
(byte)PSLibrary.TimesheetEnum.LineStatus.NotApplicable;
line.TS_LINE_VALIDATION_TYPE =
(byte)PSLibrary.TimesheetEnum.ValidationType.Unverified;
if ((NameDesc!=null) && (NameDesc.Length>0))
line.TS_LINE_CACHED_ASSIGN_NAME = NameDesc;
else
line.TS_LINE_CACHED_ASSIGN_NAME = ExternalTaskId;
line.TS_LINE_CACHED_PROJ_NAME = ProjectName;
this.TimesheetDataSet.Lines.AddLinesRow(line);
TimesheetSvc.Timesheetservice.PrepareTimesheetLine(this.ID,
ref this.m_TimesheetDataSet, new Guid[] { line.TS_LINE_UID });
Guid jobUid = Guid.NewGuid();
TimesheetSvc.Timesheetservice.QueueUpdateTimesheet(jobUid,
this.ID, this.m_TimesheetDataSet);
Queue.WaitForQueue(jobUid);
return line.TS_LINE_UID;
}
return Guid.Empty;
}
protected override void OnDispose()
{
base.OnDispose();
if (this.m_Headers != null)
{
this.m_Headers.Dispose();
this.m_Headers = null;
}
if (this.m_Headers != null)
{
this.m_Lines.Dispose();
this.m_Lines = null;
}
}
#endregion
}
/// <summary>
/// Summary description for TimesheetDataObjectCollection
/// Author, Date: Administrator, 2006/11/26 10:23:51 PM
/// Purpose:
/// </summary>
[Serializable]
public class TimesheetDataObjectCollection : ObjectBaseCollection
{
#region Data Members
private TimesheetListDataSet m_TimesheetDataSet = null;
private TimesheetListDataSet.TimesheetsDataTable
m_TimesheetDataTable = null;
#endregion
#region Constructor
public TimesheetDataObjectCollection()
: base(typeof(TimesheetDataObject))
{ }
public TimesheetDataObjectCollection(TimesheetListDataSet
TimesheetsDs)
: this()
{ this.Retrieve(TimesheetsDs); }
public
TimesheetDataObjectCollection(TimesheetListDataSet.TimesheetsDataTable
Timesheets)
: this()
{ this.Retrieve(Timesheets); }
#endregion
#region Properties
public TimesheetListDataSet TimesheetListDataSet
{
get { return this.m_TimesheetDataSet; }
}
public TimesheetListDataSet.TimesheetsDataTable TimesheetDataTable
{
get { return this.m_TimesheetDataTable; }
set { this.Retrieve(value); }
}
public new TimesheetDataObject this[int index]
{
get
{
return (TimesheetDataObject)base[index];
}
set
{
base[index] = value;
}
}
public TimesheetDataObject this[string Name]
{
get
{
if ((Name != null) && (Name.Length > 0))
{
for (int index = 0; index < this.Count; index++)
{
if (this[index].Name.ToUpper() == Name.ToUpper())
return this[index];
}
}
return null;
}
}
public TimesheetDataObject this[Guid UID]
{
get
{
for (int index = 0; index < this.Count; index++)
{
if (this[index].ID == UID)
return this[index];
}
return null;
}
}
#endregion
#region Protected/Overriden Methods
protected override void OnInitialise()
{
base.OnInitialise();
}
protected override void OnPostRetrieve(object DataSource)
{
base.OnPostRetrieve(DataSource);
if ((DataSource != null) && (DataSource is
TimesheetListDataSet.TimesheetsDataTable))
{
this.m_TimesheetDataTable =
(TimesheetListDataSet.TimesheetsDataTable)DataSource;
if ((this.m_TimesheetDataTable != null) &&
(this.m_TimesheetDataTable.DataSet != null) &&
(this.m_TimesheetDataTable.DataSet is TimesheetListDataSet))
this.m_TimesheetDataSet =
(TimesheetListDataSet)this.m_TimesheetDataTable.DataSet;
}
}
#endregion
#region DataObjectCollection Methods
/// <summary>Add an Object to the List
/// </summary>
/// <param name="value">Object to add to the list</param>
/// <returns>Index of the Object</returns>
public int Add(TimesheetDataObject value)
{
return base.Add(value);
}
/// <summary>Get the Index of an object in the List
/// </summary>
/// <param name="value">Object to Find</param>
/// <returns>Index of the Object</returns>
public int IndexOf(TimesheetDataObject value)
{
return base.IndexOf(value);
}
/// <summary>Insert an Object into a specific position
/// </summary>
/// <param name="value">Position</param>
/// <returns>Object to insert</returns>
public void Insert(int index, TimesheetDataObject value)
{
base.Insert(index, value);
}
/// <summary>Remove An Object From the List
/// </summary>
/// <param name="value">Object to Remove</param>
/// <returns></returns>
public void Remove(TimesheetDataObject value)
{
base.Remove(value);
}
/// <summary>Check if an Object exists in the List
/// </summary>
/// <param name="value">Object to Check for</param>
/// <returns></returns>
public bool Contains(TimesheetDataObject value)
{
return (List.Contains(value));
}
#endregion
#region Public Methods
public void Retrieve(TimesheetListDataSet TimesheetsDs)
{
if ((TimesheetsDs != null) && (TimesheetsDs.Timesheets != null))
this.Retrieve(TimesheetsDs.Timesheets);
}
#endregion
#region Private Methods
#endregion
}
}
Chris Boyd said:
Can you show us a code snippet of your impersonation code?
--
Chris Boyd
MS Project
Program Manager
Blog:
http://blogs.msdn.com/project_programmability/
paul said:
We have written a windows service that is responsible for synchronising
Timesheet Lines for all Resources from an external source to PWA via the
Project Server Interface (PSI). The windows service runs as a user that has
All Administrator Rights in Project Server. The Service is able to create
Timesheets and Timesheet Lines for the user that it is running as,however
fails to create Timesheet Lines for any other Resource in PWA. Below is the
error message that is return by the Queuing Service:
Error summary/areas:
There has been an error processing a timesheet for which you are/were
responsible. Check your approvals list to locate the offending timesheet if
one exists. The error condidtion may be related to the fact that Timesheets
are a state driven feature; therefore, the allowable values for processing
are dependent upon the existing value which for this transaction was 0. Refer
to the documentation to determine which status transitions are allowable and
submit the transaction.
TimesheetIncorrectMode
Queue
GeneralQueueJobFailed
Error details:
<?xml version="1.0" encoding="utf-16"?>
<errinfo>
<general>
<class name="There has been an error processing a timesheet for which
you are/were responsible. Check your approvals list to locate the offending
timesheet if one exists. The error condidtion may be related to the fact that
Timesheets are a state driven feature; therefore, the allowable values for
processing are dependent upon the existing value which for this transaction
was 0. Refer to the documentation to determine which status transitions are
allowable and submit the transaction.">
<error id="3204" name="TimesheetIncorrectMode"
uid="e7d928f7-8941-4004-ba7e-81ebfe9058cb" mode="0" />
</class>
<class name="Queue">
<error id="26000" name="GeneralQueueJobFailed"
uid="87687593-ef03-4c04-acc9-3f0b97730b44"
JobUID="8f499647-b2f4-4d1f-bdfc-9b515af8820c" ComputerName="1IBRMSP06"
GroupType="TimesheetUpdate" MessageType="UpdateTimesheetMessage"
MessageId="1" Stage="" />
</class>
</general>
</errinfo>
Below is the code snippet and in the line in bold is where it breaks:
TimesheetDataSet.LinesRow line =
this.TimesheetDataSet.Lines.NewLinesRow();
line.TS_UID = this.ID;
line.TS_LINE_UID = Guid.NewGuid();
line.TS_LINE_CLASS_UID = LineClass.ID;
line.TS_LINE_COMMENT = Comment;
line.TS_LINE_STATUS =
(byte)PSLibrary.TimesheetEnum.LineStatus.NotApplicable;
line.TS_LINE_VALIDATION_TYPE =
(byte)PSLibrary.TimesheetEnum.ValidationType.Unverified;
if ((NameDesc!=null) && (NameDesc.Length>0))
line.TS_LINE_CACHED_ASSIGN_NAME = NameDesc;
else
line.TS_LINE_CACHED_ASSIGN_NAME = ExternalTaskId;
line.TS_LINE_CACHED_PROJ_NAME = ProjectName;
line.ASSN_UID = this.ResourceID;
this.TimesheetDataSet.Lines.AddLinesRow(line);
TimesheetSvc.Timesheetservice.PrepareTimesheetLine(this.ID,
ref this.m_TimesheetDataSet, new Guid[] { line.TS_LINE_UID });
Guid jobUid = Guid.NewGuid();
TimesheetSvc.Timesheetservice.QueueUpdateTimesheet(jobUid,
this.ID, this.m_TimesheetDataSet);
Queue.WaitForQueue(jobUid);
I have checked the user's permissions in PWA via the "Manage Users" and the
has Administrator Priviledges.