Statusing.ImportTimesheet method
Imports verified tasks in the specified timesheet period
Namespace: WebSvcStatusing
Assembly: ProjectServerServices (in ProjectServerServices.dll)
Syntax
'Declaration
<SoapDocumentMethodAttribute("https://schemas.microsoft.com/office/project/server/webservices/Statusing/ImportTimesheet", RequestNamespace := "https://schemas.microsoft.com/office/project/server/webservices/Statusing/", _
ResponseNamespace := "https://schemas.microsoft.com/office/project/server/webservices/Statusing/", _
Use := SoapBindingUse.Literal, ParameterStyle := SoapParameterStyle.Wrapped)> _
Public Sub ImportTimesheet ( _
periodUID As Guid _
)
'Usage
Dim instance As Statusing
Dim periodUID As Guid
instance.ImportTimesheet(periodUID)
[SoapDocumentMethodAttribute("https://schemas.microsoft.com/office/project/server/webservices/Statusing/ImportTimesheet", RequestNamespace = "https://schemas.microsoft.com/office/project/server/webservices/Statusing/",
ResponseNamespace = "https://schemas.microsoft.com/office/project/server/webservices/Statusing/",
Use = SoapBindingUse.Literal, ParameterStyle = SoapParameterStyle.Wrapped)]
public void ImportTimesheet(
Guid periodUID
)
Parameters
periodUID
Type: System.GuidTime period unique ID for the timesheet.
Remarks
Project Server Permissions
No permissions are required. This method reads data for only the current logged-on resource.
Examples
The following code example has an extensive preparation. It creates a project, enterprise resources, and a timesheet. Then it imports the timesheet to update the status.
For critical information about running this code example, see Prerequisites for ASMX-based code samples in Project 2013.
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Data;
using System.Web.Services.Protocols;
using System.Threading;
using PSLibrary = Microsoft.Office.Project.Server.Library;
namespace Microsoft.SDK.Project.Samples.ImportTimesheet
{
class Program
{
[STAThread]
static void Main()
{
try{
#region Setup
const string PROJECT_SERVER_URI = "https://ServerName/ProjectServerName/"; // <<--Change to match your project server and directory
const string TIMESHEET_SERVICE_PATH = "_vti_bin/psi/timesheet.asmx";
const string RESOURCE_SERVICE_PATH = "_vti_bin/psi/resource.asmx";
const string ADMIN_SERVICE_PATH = "_vti_bin/psi/admin.asmx";
const string QUEUESYSTEM_SERVICE_PATH = "_vti_bin/psi/queuesystem.asmx";
const string STATUSING_SERVICE_PATH = "_vti_bin/psi/statusing.asmx";
const string PROJECT_SERVICE_PATH = "_vti_bin/psi/project.asmx";
Guid jobUid;
// Set up the services,
SvcTimeSheet.TimeSheet timeSheetSvc = new SvcTimeSheet.TimeSheet();
timeSheetSvc.UseDefaultCredentials = true;
timeSheetSvc.Url = PROJECT_SERVER_URI + TIMESHEET_SERVICE_PATH;
CodeSample_TimeSheetUtilities timeSheetUtils = new CodeSample_TimeSheetUtilities(timeSheetSvc);
SvcResource.Resource resourceSvc = new SvcResource.Resource();
resourceSvc.Url = PROJECT_SERVER_URI + RESOURCE_SERVICE_PATH;
resourceSvc.UseDefaultCredentials = true;
CodeSample_ResourceUtilities resourceUtils = new CodeSample_ResourceUtilities(resourceSvc);
SvcAdmin.Admin adminSvc = new SvcAdmin.Admin();
adminSvc.Url = PROJECT_SERVER_URI + ADMIN_SERVICE_PATH;
adminSvc.UseDefaultCredentials = true;
SvcQueueSystem.QueueSystem q = new SvcQueueSystem.QueueSystem();
q.Url = PROJECT_SERVER_URI + QUEUESYSTEM_SERVICE_PATH;
q.UseDefaultCredentials = true;
SvcStatusing.Statusing statusingSvc = new SvcStatusing.Statusing();
statusingSvc.Url = PROJECT_SERVER_URI + STATUSING_SERVICE_PATH;
statusingSvc.UseDefaultCredentials = true;
SvcProject.Project projectSvc = new SvcProject.Project();
projectSvc.Url = PROJECT_SERVER_URI + PROJECT_SERVICE_PATH;
projectSvc.UseDefaultCredentials = true;
#endregion
#region Prepare project, resources, and timesheet
Guid sampleResourceUid = resourceUtils.EnsureLertchai();
Console.WriteLine("Reading time periods");
SvcAdmin.TimePeriodDataSet timePeriodDs = adminSvc.ReadPeriods(SvcAdmin.PeriodState.Open);
Guid periodUid = timeSheetUtils.FindFirstEmptyPeriod(resourceUtils.myUid, timePeriodDs);
SvcAdmin.TimePeriodDataSet.TimePeriodsRow timePeriodsRow = timePeriodDs.TimePeriods.FindByWPRD_UID(periodUid);
// Create project for that date.
// Publish it.
Console.WriteLine("Creating a project in that period");
Guid projectUid = CodeSample_ProjectUtilities.CreateSampleProject(projectSvc, q, resourceSvc, timePeriodsRow.WPRD_START_DATE, resourceUtils);
Console.WriteLine("Creating a timesheet");
Guid timeSheetUid = timeSheetUtils.CreateTimeSheetFor(resourceUtils.myUid, resourceUtils.myUid, periodUid);
SvcTimeSheet.TimesheetDataSet timesheetDs = timeSheetSvc.ReadTimesheet(timeSheetUid);
SvcTimeSheet.TimesheetDataSet.ActualsRow actualsRow ;
List<Guid> assignments = new List<Guid>();
List<Guid> tsLines = new List<Guid>();
CodeSampleUtilities.WriteTablesFormated("timesheet",timesheetDs.Tables);
foreach (SvcTimeSheet.TimesheetDataSet.ActualsRow row in timesheetDs.Actuals)
{
row.TS_ACT_VALUE = row.TS_ACT_PLAN_VALUE;
assignments.Add(row.LinesRow.ASSN_UID);
}
SvcStatusing.StatusingAssignmentsDataSet assignmentDs = statusingSvc.ReadAssignments((Guid[])assignments.ToArray());
CodeSampleUtilities.WriteTablesFormated("Assignments Before Update:", assignmentDs.Tables);
jobUid = Guid.NewGuid();
timeSheetSvc.QueueUpdateTimesheet(jobUid, timeSheetUid, timesheetDs);
CodeSampleUtilities.WaitForQueue(q, jobUid);
#endregion
#region Import Timesheet
SvcStatusing.ImportTimesheetDataSet importTimeSheetDs = statusingSvc.ReadImportTimesheetData(periodUid);
CodeSampleUtilities.WriteTablesFormated("New data from timesheets:", importTimeSheetDs.Tables);
statusingSvc.ImportTimesheet(periodUid);
assignmentDs = statusingSvc.ReadAssignments((Guid[])assignments.ToArray());
CodeSampleUtilities.WriteTablesFormated("Updated assignments (ASSN_ACT_WORK is updated):", assignmentDs.Tables);
#endregion
}
catch (SoapException ex)
{
ExceptionHandlers.HandleSoapException(ex);
}
catch (WebException ex)
{
ExceptionHandlers.HandleWebException(ex);
}
catch (Exception ex)
{
ExceptionHandlers.HandleException(ex);
}
finally
{
ExceptionHandlers.ResetConsole();
}
}
}
class ExceptionHandlers
{
public static void HandleSoapException(SoapException ex)
{
PSLibrary.PSClientError error = new PSLibrary.PSClientError(ex);
PSLibrary.PSErrorInfo[] errors = error.GetAllErrors();
string errMess = "==============================\r\nError: \r\n";
for (int i = 0; i < errors.Length; i++)
{
errMess += "\n" + ex.Message.ToString() + "\r\n";
errMess += "".PadRight(30, '=') + "\r\nPSCLientError Output:\r\n \r\n";
errMess += errors[i].ErrId.ToString() + "\n";
for (int j = 0; j < errors[i].ErrorAttributes.Length; j++)
{
errMess += "\r\n\t" + errors[i].ErrorAttributeNames()[j] + ": "
+ errors[i].ErrorAttributes[j];
}
errMess += "\r\n".PadRight(30, '=');
}
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(errMess);
}
public static void HandleWebException(WebException ex)
{
string errMess = ex.Message.ToString() +
"\n\nLog on, or check the Project Server Queuing Service";
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Error: " + errMess);
}
public static void HandleException(Exception ex)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Error: " + ex.Message);
}
public static void ResetConsole()
{
Console.ResetColor();
Console.WriteLine("\r\n\r\nPress any key...");
Console.ReadKey();
}
}
class CodeSampleUtilities
{
// Write all contents of a table collection to the console.
public static void WriteTablesToConsole(System.Data.DataTableCollection theTables)
{
Console.ForegroundColor = ConsoleColor.DarkGreen;
foreach (System.Data.DataTable table in theTables)
{
int[] columnWidths = new int[table.Columns.Count];
int tableWidth = 0;
string dataString;
Console.WriteLine("Table: " + table.TableName);
// Write out the column names and get their spacing.
StringBuilder tableRow = new StringBuilder();
for (int i = 0; i < table.Columns.Count; i++)
{
columnWidths[i] = GetColumnWidth(table.Columns[i]);
tableRow.Append(table.Columns[i].ColumnName.PadRight(columnWidths[i]));
tableWidth += columnWidths[i];
}
// Add a space so it will not wrap.
tableWidth += 1;
// Make the console as wide as the widest table.
Console.BufferWidth = (Console.BufferWidth > tableWidth ? Console.BufferWidth : tableWidth);
tableRow.Append("\r\n");
Console.Write(tableRow.ToString());
// Write out the data.
foreach (DataRow row in table.Rows)
{
tableRow = new StringBuilder();
for (int i = 0; i < table.Columns.Count; i++)
{
dataString = row[i].ToString();
// truncate output if it is wider than
// the desired column width
if (dataString.Length >= columnWidths[i])
{
dataString = dataString.Substring(0, columnWidths[i] - 1);
}
// Add the output to the stringbuilder and pad right to fill
// up to the column width.
tableRow.Append(dataString.PadRight(columnWidths[i]));
}
tableRow.Append("\r\n");
Console.Write(tableRow.ToString());
}
Console.Write("\r\n".PadLeft(tableWidth, '-'));
}
Console.ResetColor();
}
// Helper function for WriteTablesToConsole.
private static int GetColumnWidth(DataColumn column)
{
// Note: Might not handle byte[]data types well.
const int MAX_COL_WIDTH = 40;
int dataWidth = 0;
//Return 12 for numbers, 30 for dates, and string width for strings.
switch (column.DataType.UnderlyingSystemType.ToString())
{
case "System.Boolean":
case "System.Byte":
case "System.Byte[]":
case "System.Char":
case "System.Decimal":
case "System.Double":
case "System.Int16":
case "System.Int32":
case "System.Int64":
case "System.SByte":
case "System.Single":
case "System.UInt16":
case "System.UInt32":
case "System.UInt64":
dataWidth = 12;
break;
case "System.DateTime":
case "System.TimeSpan":
dataWidth = 30;
break;
case "System.Guid":
dataWidth = 37;
break;
case "System.String":
// If it has a maxlength, use it.
if (column.MaxLength > 0)
{
dataWidth = column.MaxLength;
}
else
{
// Otherwise, use the max col width.
dataWidth = MAX_COL_WIDTH;
}
break;
default:
dataWidth = column.ColumnName.Length;
break;
}
// Truncate if over the maxlength.
if (dataWidth > MAX_COL_WIDTH)
{
dataWidth = MAX_COL_WIDTH;
}
// Always be at least as wide as the colum name.
return (column.ColumnName.Length > (dataWidth) ? column.ColumnName.Length + 1 : dataWidth);
}
public static void WriteTablesFormated(string Title, System.Data.DataTableCollection theTables)
{
WriteSeparator();
Console.WriteLine(Title);
CodeSampleUtilities.WriteTablesToConsole(theTables);
}
public static void WriteSeparator()
{
Console.ForegroundColor = ConsoleColor.DarkYellow;
Console.WriteLine("".PadRight(Console.BufferWidth, '='));
Console.ResetColor();
}
// Wait for the job to finish.
// Outputs job status to the console.
static public void WaitForQueue(SvcQueueSystem.QueueSystem q, Guid jobId)
{
SvcQueueSystem.JobState jobState;
const int QUEUE_WAIT_TIME = 1; // one second
bool jobDone = false;
string xmlError = string.Empty;
int wait = 0;
//Wait for the project to get through the queue.
// - Get the estimated wait time in seconds.
wait = q.GetJobWaitTime(jobId);
// - Wait for it
Console.Write("Waiting on queue. Estimate: {0} seconds.\r\n ", wait);
// - Wait until it is done.
do
{
// - Get the job state.
jobState = q.GetJobCompletionState(jobId, out xmlError);
if (jobState == SvcQueueSystem.JobState.Success)
{
jobDone = true;
}
else
{
if (jobState == SvcQueueSystem.JobState.Unknown
|| jobState == SvcQueueSystem.JobState.Failed
|| jobState == SvcQueueSystem.JobState.FailedNotBlocking
|| jobState == SvcQueueSystem.JobState.CorrelationBlocked
|| jobState == SvcQueueSystem.JobState.Canceled)
{
// If the job failed, error out.
throw (new ApplicationException("Queue request " + jobState + " for Job ID " + jobId + ".\r\n" + xmlError));
}
else
{
//Console.WriteLine("Job State: " + jobState + " for Job ID: " + jobId);
Console.Write("~");
Thread.Sleep(QUEUE_WAIT_TIME * 1000);
}
}
}
while (!jobDone);
Console.Write("\r\n");
}
}
class CodeSample_TimeSheetUtilities
{
SvcTimeSheet.TimeSheet timeSheetSvc;
public CodeSample_TimeSheetUtilities(SvcTimeSheet.TimeSheet theTimeSheetSvc)
{
timeSheetSvc = theTimeSheetSvc;
}
public Guid CreateTimeSheetFor(Guid resourceGuid, Guid mgrUid,Guid periodUid)
{
SvcTimeSheet.TimesheetDataSet timesheetDs = new SvcTimeSheet.TimesheetDataSet();
SvcTimeSheet.TimesheetDataSet.HeadersRow headersRow = timesheetDs.Headers.NewHeadersRow();
headersRow.RES_UID = resourceGuid;
headersRow.TS_UID = Guid.NewGuid();
headersRow.WPRD_UID = periodUid;
headersRow.TS_CREATOR_RES_UID = mgrUid;
headersRow.TS_NAME = "Timesheet ";
headersRow.TS_COMMENTS = "Timesheet for code sample";
headersRow.TS_ENTRY_MODE_ENUM = (byte)PSLibrary.TimesheetEnum.EntryMode.Weekly;
timesheetDs.Headers.AddHeadersRow(headersRow);
// Create the timesheet with the default line types specified by the admin.
timeSheetSvc.CreateTimesheet(timesheetDs, SvcTimeSheet.PreloadType.Default);
return headersRow.TS_UID;
}
public Guid FindFirstEmptyPeriod(Guid resUid, SvcAdmin.TimePeriodDataSet timePeriodDs)
{
SvcTimeSheet.TimesheetDataSet timeSheetDs;
for (int i = 0; i < timePeriodDs.TimePeriods.Count; i++)
{
timeSheetDs = timeSheetSvc.ReadTimesheetByPeriod(resUid, timePeriodDs.TimePeriods[i].WPRD_UID, SvcTimeSheet.Navigation.Current);
if (timeSheetDs.Headers.Count == 0)
{
return timePeriodDs.TimePeriods[i].WPRD_UID;
}
}
return Guid.Empty;
}
}
class CodeSample_ResourceUtilities
{
private SvcResource.Resource m_resourceSvc;
private Guid m_MyUid;
private Guid sampleResource = Guid.Empty;
public CodeSample_ResourceUtilities(SvcResource.Resource theResourceSvc)
{
m_resourceSvc = theResourceSvc;
m_MyUid = resourceSvc.GetCurrentUserUid();
}
public Guid myUid
{
get { return m_MyUid; }
}
public SvcResource.Resource resourceSvc
{
get {return m_resourceSvc;}
}
public Guid EnsureLertchai()
{
return EnsureSampleResource("Lertchai Treetawatchaiwong", "LT");
}
public Guid EnsureSampleResource(string name,string inits)
{
Guid resGuid = GetResourceGuid(name);
if (resGuid == Guid.Empty)
{
resGuid = this.CreateResource(name, inits, myUid);
}
return resGuid;
}
public Guid GetResourceGuid(string resourceName)
{
SvcResource.ResourceDataSet resourceDs = new SvcResource.ResourceDataSet();
PSLibrary.Filter resourceFilter = new Microsoft.Office.Project.Server.Library.Filter();
resourceFilter.FilterTableName = resourceDs.Resources.TableName;
resourceFilter.Fields.Add(new PSLibrary.Filter.Field(resourceDs.Resources.TableName, resourceDs.Resources.RES_UIDColumn.ColumnName, PSLibrary.Filter.SortOrderTypeEnum.None));
resourceFilter.Fields.Add(new PSLibrary.Filter.Field(resourceDs.Resources.TableName, resourceDs.Resources.RES_NAMEColumn.ColumnName, PSLibrary.Filter.SortOrderTypeEnum.None));
PSLibrary.Filter.FieldOperator existingResource = new PSLibrary.Filter.FieldOperator(PSLibrary.Filter.FieldOperationType.Equal, resourceDs.Resources.RES_NAMEColumn.ColumnName, resourceName);
resourceFilter.Criteria = existingResource;
resourceDs = resourceSvc.ReadResources(resourceFilter.GetXml(), false);
if (resourceDs.Resources.Count >= 1)
{
return resourceDs.Resources[0].RES_UID;
}
else
{
return Guid.Empty;
}
}
private Guid CreateResource(string resourceName, string initials, Guid timesheetMgr)
{
SvcResource.ResourceDataSet resourceDs = new SvcResource.ResourceDataSet();
SvcResource.ResourceDataSet.ResourcesRow resourceRow = resourceDs.Resources.NewResourcesRow();
resourceRow.RES_UID = Guid.NewGuid();
resourceRow.RES_NAME = resourceName;
resourceRow.RES_INITIALS = initials;
resourceRow.RES_TYPE = (int)PSLibrary.Resource.Type.WorkResource;
resourceRow.RES_TIMESHEET_MGR_UID = timesheetMgr;
resourceDs.Resources.AddResourcesRow(resourceRow);
resourceSvc.CreateResources(resourceDs, false, true);
return resourceRow.RES_UID;
}
}
class CodeSample_ProjectUtilities
{
static public Guid CreateSampleProject(SvcProject.Project projectSvc, SvcQueueSystem.QueueSystem q, SvcResource.Resource resourceSvc, DateTime startDate,CodeSample_ResourceUtilities resourceUtils)
{
SvcProject.ProjectDataSet projectDs = new SvcProject.ProjectDataSet();
Guid jobId;
Guid sessionUid = Guid.NewGuid();
const string SESSION_DESC = "Test Utility";
// Create the project.
SvcProject.ProjectDataSet.ProjectRow projectRow = projectDs.Project.NewProjectRow();
Guid projectId = Guid.NewGuid();
projectRow.PROJ_UID = projectId;
projectRow.PROJ_NAME = "Its a wonderful project at " + DateTime.Now.ToShortDateString().Replace("/", "") + " " + DateTime.Now.ToShortTimeString().Replace(":", "") + " " + DateTime.Now.Millisecond.ToString();
projectRow.PROJ_TYPE = (int)PSLibrary.Project.ProjectType.Project;
projectDs.Project.AddProjectRow(projectRow);
// Add some tasks.
SvcProject.ProjectDataSet.TaskRow taskOne = projectDs.Task.NewTaskRow();
taskOne.PROJ_UID = projectId;
taskOne.TASK_UID = Guid.NewGuid();
taskOne.TASK_NAME = "Task One";
taskOne.TASK_DUR_FMT = (int)PSLibrary.Task.DurationFormat.Hour;
taskOne.TASK_DUR = 10 * 60 * 8 * 3;//Three eight hour days
taskOne.TASK_CONSTRAINT_DATE = startDate;
taskOne.TASK_START_DATE = startDate;
projectDs.Task.AddTaskRow(taskOne);
SvcProject.ProjectDataSet.TaskRow taskTwo = projectDs.Task.NewTaskRow();
taskTwo.PROJ_UID = projectId;
taskTwo.TASK_UID = Guid.NewGuid();
taskTwo.TASK_NAME = "Task Two";
taskTwo.TASK_DUR = 10 * 60 * 6;// 6 hours
taskTwo.TASK_DUR_FMT = (int)PSLibrary.Task.DurationFormat.EHour; // Duration Estimate and should be displayed in hours
projectDs.Task.AddTaskRow(taskTwo);
// Make second task dependent on first task.
SvcProject.ProjectDataSet.DependencyRow dependency = projectDs.Dependency.NewDependencyRow();
dependency.LINK_UID = Guid.NewGuid();
dependency.PROJ_UID = projectId;
dependency.LINK_PRED_UID = taskOne.TASK_UID;
dependency.LINK_SUCC_UID = taskTwo.TASK_UID;
dependency.LINK_TYPE = 1;//Finish to Start
dependency.LINK_LAG_FMT = (int)PSLibrary.Task.DurationFormat.Hour;
dependency.LINK_LAG = 0;
projectDs.Dependency.AddDependencyRow(dependency);
// Add a summary task.
SvcProject.ProjectDataSet.TaskRow taskOthers = projectDs.Task.NewTaskRow();
taskOthers.PROJ_UID = projectId;
taskOthers.TASK_UID = Guid.NewGuid();
taskOthers.TASK_NAME = "Related Tasks";
projectDs.Task.AddTaskRow(taskOthers);
// Add some subtasks.
SvcProject.ProjectDataSet.TaskRow taskThree = projectDs.Task.NewTaskRow();
taskThree.PROJ_UID = projectId;
taskThree.TASK_UID = Guid.NewGuid();
taskThree.TASK_NAME = "Task Three";
taskThree.TASK_PARENT_UID = taskOthers.TASK_UID;
taskThree.TASK_OUTLINE_LEVEL = 2;
taskThree.TASK_DUR = 9600; //Two days
taskThree.TASK_DUR_FMT = (int)PSLibrary.Task.DurationFormat.Day;
projectDs.Task.AddTaskRow(taskThree);
SvcProject.ProjectDataSet.TaskRow taskFour = projectDs.Task.NewTaskRow();
taskFour.PROJ_UID = projectId;
taskFour.TASK_UID = Guid.NewGuid();
taskFour.TASK_NAME = "Task Four";
taskFour.TASK_PARENT_UID = taskOthers.TASK_UID;
taskFour.TASK_DUR = 4800; //One day
taskFour.TASK_DUR_FMT = (int)PSLibrary.Task.DurationFormat.Hour;
taskFour.TASK_OUTLINE_LEVEL = 2;
projectDs.Task.AddTaskRow(taskFour);
// Make fourth task dependent on third task.
dependency = projectDs.Dependency.NewDependencyRow();
dependency.LINK_UID = Guid.NewGuid();
dependency.PROJ_UID = projectId;
dependency.LINK_PRED_UID = taskThree.TASK_UID;
dependency.LINK_SUCC_UID = taskFour.TASK_UID;
dependency.LINK_TYPE = 1;//Finish to Start
dependency.LINK_LAG = 0;
projectDs.Dependency.AddDependencyRow(dependency);
// Make other tasks dependent on second task.
dependency = projectDs.Dependency.NewDependencyRow();
dependency.LINK_UID = Guid.NewGuid();
dependency.PROJ_UID = projectId;
dependency.LINK_PRED_UID = taskTwo.TASK_UID;
dependency.LINK_SUCC_UID = taskOthers.TASK_UID;
dependency.LINK_TYPE = 1;//Finish to Start
dependency.LINK_LAG = 0;
projectDs.Dependency.AddDependencyRow(dependency);
//Add some local project resources.
SvcProject.ProjectDataSet.ProjectResourceRow resourceOne = projectDs.ProjectResource.NewProjectResourceRow();
resourceOne.PROJ_UID = projectId;
resourceOne.RES_UID = Guid.NewGuid();
resourceOne.RES_NAME = "Brynja Sigrídur Blomsterberg";
resourceOne.RES_INITIALS = "BSB";
projectDs.ProjectResource.AddProjectResourceRow(resourceOne);
CreateAssignment(projectDs, taskOne.TASK_UID, resourceOne.RES_UID);
CreateAssignment(projectDs, taskTwo.TASK_UID, resourceOne.RES_UID);
SvcProject.ProjectDataSet.ProjectResourceRow resourceTwo = projectDs.ProjectResource.NewProjectResourceRow();
resourceTwo.PROJ_UID = projectId;
resourceTwo.RES_UID = Guid.NewGuid();
resourceTwo.RES_NAME = "Ioannis Xylaras";
resourceTwo.RES_INITIALS = "IX";
projectDs.ProjectResource.AddProjectResourceRow(resourceTwo);
CreateAssignment(projectDs, taskOne.TASK_UID, resourceTwo.RES_UID);
CreateAssignment(projectDs, taskTwo.TASK_UID, resourceTwo.RES_UID);
CreateAssignment(projectDs, taskThree.TASK_UID, resourceTwo.RES_UID);
CreateAssignment(projectDs, taskFour.TASK_UID, resourceTwo.RES_UID);
// Save the project to the database.
jobId = Guid.NewGuid();
projectSvc.QueueCreateProject(jobId, projectDs, false);
CodeSampleUtilities.WaitForQueue(q, jobId);
// Add or retrieve an enterprise resource.
SvcResource.ResourceDataSet resourceDs = resourceSvc.ReadResource(resourceUtils.EnsureLertchai());
// Add the resource to the team.
SvcProject.ProjectTeamDataSet projectTeamDs = new SvcProject.ProjectTeamDataSet();
ProjectTeamAddResource(projectTeamDs, projectId, resourceDs.Resources[0].RES_UID, resourceDs.Resources[0].RES_UID);
// Add the current user to the team.
Guid myUid = resourceSvc.GetCurrentUserUid();
ProjectTeamAddResource(projectTeamDs, projectId, myUid, myUid);
projectSvc.CheckOutProject(projectId, sessionUid, SESSION_DESC);
// Save the team!
jobId = Guid.NewGuid();
projectSvc.QueueUpdateProjectTeam(jobId, sessionUid, projectId, projectTeamDs);
CodeSampleUtilities.WaitForQueue(q, jobId);
// Read the project back in to get the updated team.
projectDs = projectSvc.ReadProject(projectId, SvcProject.DataStoreEnum.WorkingStore);
// Add the resource to an assignment.
CreateAssignment(projectDs, taskOne.TASK_UID, resourceDs.Resources[0].RES_UID, projectId);
CreateAssignment(projectDs, taskTwo.TASK_UID, myUid,projectId);
// Save enterprise assignment.
jobId = Guid.NewGuid();
// Get only the added rows.
projectDs = (SvcProject.ProjectDataSet)projectDs.GetChanges(DataRowState.Added);
projectSvc.QueueAddToProject(jobId, sessionUid, projectDs, false);
CodeSampleUtilities.WaitForQueue(q, jobId);
// Check in the project.
jobId = Guid.NewGuid();
projectSvc.QueueCheckInProject(jobId, projectId, false, sessionUid, SESSION_DESC);
CodeSampleUtilities.WaitForQueue(q, jobId);
// Publish the project.
jobId = Guid.NewGuid();
projectSvc.QueuePublish(jobId, projectId, false, String.Empty);
CodeSampleUtilities.WaitForQueue(q, jobId);
return projectRow.PROJ_UID;
}
// Helper function for CreateSampleProject.
// Makes a simple assignment.
private static void CreateAssignment(SvcProject.ProjectDataSet projectDs, Guid taskGuid, Guid resourceGuid)
{
CreateAssignment(projectDs, taskGuid, resourceGuid, projectDs.Project[0].PROJ_UID);
}
private static void CreateAssignment(SvcProject.ProjectDataSet projectDs, Guid taskGuid, Guid resourceGuid, Guid projectId)
{
SvcProject.ProjectDataSet.AssignmentRow assnRow = projectDs.Assignment.NewAssignmentRow();
assnRow.PROJ_UID = projectId;
assnRow.ASSN_UID = Guid.NewGuid();
assnRow.TASK_UID = taskGuid;
assnRow.RES_UID = resourceGuid;
projectDs.Assignment.AddAssignmentRow(assnRow);
}
// Helper function for Create Project.
// Adds an enterprise resource to the project
// so they can used on the project.
public static void ProjectTeamAddResource(SvcProject.ProjectTeamDataSet projTeamDataSet, Guid projGuid, Guid resGuid, Guid newResGuid)
{
SvcProject.ProjectTeamDataSet.ProjectTeamRow projTeamRow = projTeamDataSet.ProjectTeam.NewProjectTeamRow();
projTeamRow.PROJ_UID = projGuid;
projTeamRow.RES_UID = resGuid;
projTeamRow.NEW_RES_UID = newResGuid;
projTeamDataSet.ProjectTeam.AddProjectTeamRow(projTeamRow);
}
}
}