CSOM - 访问和更新Project Server 2013时间分段数据
我正在寻求使用.NET托管程序集访问和更新Project Server 2013时间分段数据的CSOM方法。非常感谢提供的任何示例代码。
I'm seeking the CSOM method to acess and update Project Server 2013 timephased data using .NET managed assemblies. Any sample code provided would be greatly appreciated.
嗨爱德华,
我正在进行中编写一个必须更新CSOM中时间分段数据的应用程序。当然我不能给你所有的代码,但你会在更新过程的下方找到。
I'm in the process of writing an application which has to update timephased data in CSOM. Of course I can not give you all the code, but you will find below the hearth of the Update Process.
在下面的示例代码中,我发送了一个实体,其中包含我要更新的所有数据:实现时间,计划时间,日期等...我想这很容易理解。
In the sample code below, I send an entity which contains all the data I want to update: Achieved Time, Planned Time, Day, etc...I guess it will be easy to understand.
代码应该在线或在本地工作。根据你的情况,你将不得不以不同的方式管理身份验证。
The code should work online or on premise. Depending of your context, youu will have to managed authentification differently.
我希望我能节省你一些时间,因为它没有真正记录好。
I hope I will make you save some time, because it's not really well documented.
BR,
@SylvainGrossNeo
@SylvainGrossNeo
/// <summary>
/// Principe:
/// L'entité timeSheetEntity possède les attributs qui permettent de créer un StatusAssignment
/// </summary>
/// <param name="timesheetEntity"></param>
public static void SaveTimeSheet(TimeSheetEntity timesheetEntity)
{
try
{
projContext = new ProjectContext(PwaPath);
if (IsProjectOnline)
projContext.ExecutingWebRequest += ClaimsHelper.clientContext_ExecutingWebRequest;
else
projContext.Credentials = new System.Net.NetworkCredential("XXXX", "YYY", "ZZZZ");
projContext.Load(projContext.TimeSheetPeriods, c => c.Where(p => p.Start <= DateTime.Now && p.End >= DateTime.Now).
IncludeWithDefaultProperties(p => p.TimeSheet,
p => p.TimeSheet.Lines.Where(l => l.ProjectName != "Administrative").
IncludeWithDefaultProperties(l => l.Assignment,
l => l.Assignment.Task,
l => l.Work)));
projContext.ExecuteQuery();
var maPeriod = projContext.TimeSheetPeriods.FirstOrDefault();
TimeSheetWorkCreationInformation workCreation = new TimeSheetWorkCreationInformation
{
ActualWork = string.Format("{0}h", timesheetEntity.AchievedTime),
Start = timesheetEntity.Day,
End = timesheetEntity.Day,
Comment = timesheetEntity.Comment,
NonBillableOvertimeWork = "0",
NonBillableWork = "0",
OvertimeWork = "0",
PlannedWork = string.Format("{0}h", timesheetEntity.PlannedTime)
};
var line = maPeriod.TimeSheet.Lines.Where(l => l.Id == timesheetEntity.UId).FirstOrDefault();
line.Work.Add(workCreation);
maPeriod.TimeSheet.Update();
if (maPeriod.TimeSheet.Status == TimeSheetStatus.Approved ||
maPeriod.TimeSheet.Status == TimeSheetStatus.Submitted ||
maPeriod.TimeSheet.Status == TimeSheetStatus.Rejected)
{
maPeriod.TimeSheet.Recall();
}
maPeriod.TimeSheet.Submit("GO");
projContext.ExecuteQuery();
}