public async Task <bool> RemoveAsync(EnterpriseResource enterpriseResource) { if (enterpriseResource == null) { throw new ArgumentNullException(nameof(enterpriseResource)); } bool result = false; try { var clientResult = _projectContext.EnterpriseResources.Remove(enterpriseResource); _projectContext.EnterpriseResources.Update(); await _projectContext.ExecuteQueryAsync(); result = clientResult.Value; } catch (Exception ex) { // TODO: LOG ERROR! throw new CsomClientException($"Unexcepted error removing an enterprise resource. " + $"Project context url is {_projectContext.Url}.", ex); } return(result); }
public override EventResult <EnterpriseResourceCollection> Execute() { EventResult <EnterpriseResourceCollection> result = new EventResult <EnterpriseResourceCollection>(); Param.Util.LoadEnterpriseResources(); int enterpriseResourceCount = Param.Util.ProjContext.EnterpriseResources.Count; Console.WriteLine("resource count is " + enterpriseResourceCount.ToString()); for (int cnt = enterpriseResourceCount - 1; cnt > -1; cnt--) { EnterpriseResource resource = Param.Util.ProjContext.EnterpriseResources[cnt]; if (ContainsResource(resource.Name, Param.Form.MaxResource)) { Console.WriteLine("resource name is " + resource.Name); //resource.DeleteObject(); //resource.ForceCheckIn(); ClientResult <bool> ret = Param.Util.ProjContext.EnterpriseResources.Remove(resource); //DeleteResource(); if (!ret.Value) { Console.WriteLine("resource name " + resource.Name + " is not deleted.."); } if (cnt == 0 || cnt % 20 == 0) { Param.Util.UpdateEnterpriseResource(); } } } Param.Util.UpdateEnterpriseResource(); result.Result = Param.Util.ProjContext.EnterpriseResources; return(result); }
private Guid CreateNewEngagement(Guid i_ResUID, Guid i_ProjUID, string i_AllocationPlanName, Guid i_AllocationPlanUID, DateTime i_StartDate, DateTime i_FinishDate, decimal i_WorkHours) { Guid res = Guid.NewGuid(); try { Eng newEng = new Eng(); newEng.Res = i_ResUID; newEng.Proj = i_ProjUID; newEng.Name = string.Format("{0} ( {1} )", i_AllocationPlanName, i_AllocationPlanUID.ToString()); newEng.Start = i_StartDate; newEng.Finish = i_FinishDate; newEng.Work = Math.Round(i_WorkHours, 2) * 60000; //newEng.Comment = i_Comment; string json = newEng.ToJson(); //res = PJContext.Current.PSI.PWAWebService.EngagementCreateApprovedEngagement(json); } catch (Exception ex) { //LogManager.WriteEntry("Error occured in CreateNewEngagement (EngagementsSynchManager.cs) mmethod. Details: " + ex.ToString(), EventLogEntryType.Error); res = Guid.Empty; } return(res); }
public async Task <EnterpriseResource> GetByIdAsync(Guid id) { if (id == null) { throw new ArgumentNullException(nameof(id)); } EnterpriseResource enterpriseResource = null; try { IEnumerable <EnterpriseResource> enterpriseResources = _projectContext.LoadQuery( _projectContext.EnterpriseResources.Where(p => p.Id == id)); await _projectContext.ExecuteQueryAsync(); if (enterpriseResources.Any()) { enterpriseResource = enterpriseResources.FirstOrDefault(); } } catch (Exception ex) { // TODO: LOG ERROR! throw new CsomClientException($"Unexcepted error getting a enterprise resource by id. " + $"id searched is {id}. " + $"Project context url is {_projectContext.Url}.", ex); } return(enterpriseResource); }
public GivenAnAssignmentClientInstance() { IApplicationContext applicationContext = new ApplicationContext(); IConfigurationRoot configurationRoot = ConfigurationRootFactory.Create(applicationContext); IConfigurationGetter configurationGetter = new ConfigurationGetter(configurationRoot); var projectContextOptions = configurationGetter.GetOptions <ProjectContextOptions>(); var clientOptions = configurationGetter.GetOptions <CsomClientOptions>(); var projectContext = ProjectContextFactory.Build(projectContextOptions); _projectClient = new ProjectClient(projectContext, clientOptions); _taskClient = new TaskClient(projectContext, clientOptions); _resourceClient = new EnterpriseResourceClient(projectContext, clientOptions); _client = new AssignmentClient(projectContext, clientOptions); _publishedProject = CreateTestProject().Result; _publishedTask = CreateTestTask().Result; _enterpriseResource = CreateTestResource().Result; _enterpriseResource2 = CreateTestResource().Result; _publishedProject = _projectClient.LinkToEnterpriseResources(_publishedProject, new [] { _enterpriseResource, _enterpriseResource2 }).Result; }
public static void ClearCsomObjects() { Log.WriteVerbose(new SourceInfo(), "Clearing all csom related static objects."); CsomHelper.ProjContext = null; CurrentUser = null; _currentResource = null; _currentResourceIsAssignable = false; }
private void LoadAssignments() { try { // Get the user name and their assignments self = EnterpriseResource.GetSelf(projContext); projContext.Load(self, r => r.Name, r => r.Assignments.IncludeWithDefaultProperties(assignment => assignment.Project)); projContext.ExecuteQuery(); lblUserName.Text = String.Format("Welcome {0}", self.Name); // Get the assignments and Project Name for the resource string name; Guid id; // Add each assignment to the list checkbox for (int j = 0; j < self.Assignments.Count; j++) { name = self.Assignments.ElementAt(j).Project.Name + ": " + self.Assignments.ElementAt(j).Name; id = self.Assignments.ElementAt(j).Id; Assignment assignment; if (self.Assignments.ElementAt(j).PercentComplete < 100) { assignment = new Assignment(name, id, false); chkAssignments.Items.Add(assignment); } else { assignment = new Assignment(name, id, true); chkAssignments.Items.Add(assignment, true); } assignment.Dirty = false; } } catch (ClientRequestException cre) { string msg = string.Format("Error: \n\n{1}", cre.GetBaseException().ToString()); throw new ArgumentException(msg); } catch (Exception ex) { string msg = string.Format("Error: \n\n{1}", ex.ToString()); throw new ArgumentException(msg); } }
private void UpdateProjectOwner() { List <PublishedProject> projectList = new List <PublishedProject>(); EnterpriseResource resource = null; LV_Projects.InvokeIfRequired(s => { ListView.SelectedListViewItemCollection selectedItems = s.SelectedItems; projectList.AddRange(selectedItems.Cast <ListViewItem>().Select(selectedItem => (PublishedProject)selectedItem.Tag)); }); LV_EnterpiseResources.InvokeIfRequired(s => resource = (EnterpriseResource)s.SelectedItems[0].Tag); if (resource == null) { Log.WriteWarning(new SourceInfo(), TB_Status, "No enterprise resource selected."); return; } List <QueueJob> jobs = new List <QueueJob>(); foreach (PublishedProject publishedproject in projectList) { if (!publishedproject.IsCheckedOut) { publishedproject.CheckOut(); } else if (!publishedproject.CheckedOutBy.IsNull() && publishedproject.CheckedOutBy.Title != CsomBase.CurrentResource.User.Title) { Log.WriteWarning(new SourceInfo(), TB_Status, "Project:{0} checked out to a different user:{1}, not changing the owner to {2}.", publishedproject.Name, publishedproject.Owner.Title, resource.User.Title); continue; } Log.WriteVerbose(new SourceInfo(), TB_Status, "Updating project:{0}, Setting owner to:{1}", publishedproject.Name, resource.Name); publishedproject.Owner = resource.User; jobs.Add(publishedproject.Draft.Update()); } Log.WriteVerbose(new SourceInfo(), TB_Status, _bgeProject, "Waiting for the Project Update job to complete."); CsomHelper.ExecuteAndWait(jobs, TB_Status); Log.WriteVerbose(new SourceInfo(), TB_Status, _bgeProject, "Loading Projects."); LoadProjects(); }
public override EventResult <EnterpriseResourceCollection> Execute() { EventResult <EnterpriseResourceCollection> result = new EventResult <EnterpriseResourceCollection>(); Param.Util.LoadEnterpriseResources(); int enterpriseResourceCount = Param.Util.ProjContext.EnterpriseResources.Count; for (int cnt = enterpriseResourceCount - 1; cnt > -1; cnt--) { EnterpriseResource resource = Param.Util.ProjContext.EnterpriseResources[cnt]; if (resource.IsGeneric) { System.Diagnostics.Debug.WriteLine(string.Format("user {0} is general!", resource.Name)); continue; } if (resource.ResourceType == EnterpriseResourceType.Cost) { System.Diagnostics.Debug.WriteLine(string.Format("user {0} is cost!", resource.Name)); continue; } EnterpriseResourceCostRateTableCollection enttbl = resource.CostRateTables; Param.Util.ProjContext.Load(enttbl, e => e.Include(c => c.CostRates)); Param.Util.ProjContext.ExecuteQuery(); for (int i = 0; i < enttbl.Count; i++) { EnterpriseResourceCostRateTable tbl = enttbl[i]; for (int j = 0; j < tbl.CostRates.Count; j++) { EnterpriseResourceCostRate col = tbl.CostRates[j]; col.StandardRate = Param.Form.GetStandardRate(); //Param.Util.ProjContext.Load(col, c => c.StandardRate); //Param.Util.ProjContext.Load(tbl); System.Diagnostics.Debug.WriteLine("user {0}'s standard rate is {1}", resource.Name, col.StandardRate); //Param.Util.ProjContext.Load(col); //Param.Util.ProjContext.ExecuteQuery(); } } } Param.Util.ProjContext.EnterpriseResources.Update(); Param.Util.ProjContext.ExecuteQuery(); result.Result = Param.Util.ProjContext.EnterpriseResources; return(result); }
private async System.Threading.Tasks.Task SetCostRate(EnterpriseResource enterpriseResource, CostRateCreationInformation creationInformation) { _projectContext.Load(enterpriseResource.CostRateTables); await _projectContext.ExecuteQueryAsync(); var defaultCostRateTable = enterpriseResource.CostRateTables.GetByName(CostRateTableName.A); _projectContext.Load(defaultCostRateTable.CostRates); await _projectContext.ExecuteQueryAsync(); // By default a line is added, we just need to modify the values in the line var costRate = defaultCostRateTable.CostRates.First(); costRate = _mapper.Map(creationInformation, costRate); _projectContext.EnterpriseResources.Update(); await _projectContext.ExecuteQueryAsync(); }
public bool Create(ResourcePoolModel model) { if (model == null) { throw new ArgumentException("The ResourcePoolModel is null."); } else { IEnumerable <EnterpriseResource> resources = GetEntities(); for (int i = 0; i < model.Count; i++) { string resourceName = model.NamePrefix + i.ToString(); if (resources.Any(item => item.Name == resourceName && item.ResourceType.ToString().ToLower() == model.Type.ToLower())) { // No need to do anything currently } else { EnterpriseResourceCreationInformation resourceInfo = new EnterpriseResourceCreationInformation() { Name = resourceName, ResourceType = model.Type.ConvertToResourceType() }; EnterpriseResource resource = BaseProjectContext.EnterpriseResources.Add(resourceInfo); int executePoint = 1000; if (i % executePoint == 0 || i == model.Count - 1) { ExcuteJobWithRetries(() => { LoggerHelper.Instance.Comment("About to Create Resource with Name: " + resourceInfo.Name); BaseProjectContext.EnterpriseResources.Update(); BaseProjectContext.ExecuteQuery(); LoggerHelper.Instance.Comment("Finish Creating Resource with Name: " + resourceInfo.Name); }, "Create Resource"); } } } BaseProjectContext.ExecuteQuery(); } return(true); }
// Loads a user as an enterprise resouce private EnterpriseResource GetUserResource(string userEmail) { try { Console.WriteLine("Loading user resource for '" + userEmail + "'"); // Since we can't trust that email is synced to project, get user by login name instead string claimsPrefix = "i:0#.f|membership|"; var loginName = claimsPrefix + userEmail; User user = context.Web.SiteUsers.GetByLoginName(loginName); EnterpriseResource res = context.EnterpriseResources.GetByUser(user); context.Load(res); context.ExecuteQuery(); Console.WriteLine(" Got resource: " + res.Name + " {" + res.Id + "}"); return(res); } catch (Exception ex) { Console.WriteLine("Error loading user: " + ex.Message); return(null); } }
private void CreateProjects() { IList <EnterpriseResource> enterpriseResources = null; List <QueueJob> projectCreationJobs = new List <QueueJob>(); if (RB_AssignExistingEnterpriseResources.Checked) { IEnumerable <EnterpriseResource> resList = ProjContext.LoadQuery(ProjContext.EnterpriseResources.Where(r => r.ResourceType == EnterpriseResourceType.Work)); ProjContext.ExecuteQuery(); enterpriseResources = resList.ToList(); } for (int projCount = 1; projCount <= numProjects.Value; projCount++) { string projName = txtProjName.Text + projCount; List <EnterpriseResource> projectTeam = new List <EnterpriseResource>(); PublishedProject newProject = ProjContext.Projects.Add(new ProjectCreationInformation { Name = projName }); //Build the team first. if (RB_AssignExistingEnterpriseResources.Checked) { if (enterpriseResources.Count > 0) { projectTeam = enterpriseResources.PickRandom((int)numTasks.Value); projectTeam.ForEach(p => newProject.Draft.ProjectResources.AddEnterpriseResource(p)); } else { Log.WriteWarning(new SourceInfo(), TB_Status, "No enterprise resources available in the server."); } } else if (RB_AssignToMe.Checked) { if (CsomBase.CurrentResourceIsAssignable) { newProject.Draft.ProjectResources.AddEnterpriseResource(CsomBase.CurrentResource); } else { Log.WriteWarning(new SourceInfo(), TB_Status, "Current user is not resource. Not creating assignments."); } } List <TaskCreationInformation> dtc = CreateTasks(); if (CB_Tasks.Checked) { foreach (var task in dtc) { newProject.Draft.Tasks.Add(task); if (RB_AssignExistingEnterpriseResources.Checked) { if (projectTeam.Count > 0) { EnterpriseResource res = projectTeam.PickRandom(); newProject.Draft.Assignments.Add(new AssignmentCreationInformation { TaskId = task.Id, ResourceId = res.Id }); } else { Log.WriteWarning(new SourceInfo(), TB_Status, "No enterprise resources available in the server. Not creating assignments."); } } else if (RB_AssignToMe.Checked) { if (CsomBase.CurrentResourceIsAssignable) { AssignmentCreationInformation assnCi = CreateAssignment(task.Id, CsomBase.CurrentResource.Id); newProject.Draft.Assignments.Add(assnCi); } else { Log.WriteWarning(new SourceInfo(), TB_Status, "Current user is not resource. Not creating assignments."); } } } } if (RB_UseLocalResources.Checked) { for (int localResourceCount = 1; localResourceCount <= numTasks.Value; localResourceCount++) { ProjectResourceCreationInformation localResourceCi = CreateLocalResource(localResourceCount); newProject.Draft.ProjectResources.Add(localResourceCi); if (chkResAssign.Checked) { AssignmentCreationInformation assnCi = CreateAssignment(dtc.PickRandom().Id, localResourceCi.Id); newProject.Draft.Assignments.Add(assnCi); } } } Log.WriteVerbose(new SourceInfo(), TB_Status, "Creating project {0} of {1} with name {2}.", projCount, numProjects.Value, projName); projectCreationJobs.Add(newProject.Draft.Update()); } Log.WriteVerbose(new SourceInfo(), TB_Status, _backgroundExecutorWithStatus, "Waiting for the Project creation queue job to complete."); CsomHelper.ExecuteAndWait(projectCreationJobs, TB_Status); }
public void UpdateManpower() { projContext = new ProjectContext(pwaPath); projContext.Load(projContext.EnterpriseResources); projContext.Load(projContext.CustomFields); projContext.ExecuteQuery(); if (projContext.EnterpriseResources.Count > 0) { foreach (var data in projContext.EnterpriseResources) { Console.WriteLine(data.Name); var resId = data.Id; EnterpriseResource res = projContext.EnterpriseResources.GetByGuid(resId); projContext.Load(res); projContext.Load(res.CustomFields); projContext.ExecuteQuery(); foreach (var dataExcel in dataInExcel) { if (dataExcel.UserName == res.Name) { if (dataExcel.Month == 1) { CustomField cField = projContext.CustomFields.First(c => c.Name == "Jan"); res[cField.InternalName] = dataExcel.Data * 100; projContext.EnterpriseResources.Update(); } else if (dataExcel.Month == 2) { CustomField cField = projContext.CustomFields.First(c => c.Name == "Feb"); res[cField.InternalName] = dataExcel.Data * 100; projContext.EnterpriseResources.Update(); } else if (dataExcel.Month == 3) { CustomField cField = projContext.CustomFields.First(c => c.Name == "Mar"); res[cField.InternalName] = dataExcel.Data * 100; projContext.EnterpriseResources.Update(); } else if (dataExcel.Month == 4) { CustomField cField = projContext.CustomFields.First(c => c.Name == "Apr"); res[cField.InternalName] = dataExcel.Data * 100; projContext.EnterpriseResources.Update(); } else if (dataExcel.Month == 5) { CustomField cField = projContext.CustomFields.First(c => c.Name == "May"); res[cField.InternalName] = dataExcel.Data * 100; projContext.EnterpriseResources.Update(); } else if (dataExcel.Month == 6) { CustomField cField = projContext.CustomFields.First(c => c.Name == "Yun"); res[cField.InternalName] = dataExcel.Data * 100; projContext.EnterpriseResources.Update(); } else if (dataExcel.Month == 7) { CustomField cField = projContext.CustomFields.First(c => c.Name == "Yul"); res[cField.InternalName] = dataExcel.Data * 100; projContext.EnterpriseResources.Update(); } else if (dataExcel.Month == 8) { CustomField cField = projContext.CustomFields.First(c => c.Name == "Aug"); res[cField.InternalName] = dataExcel.Data * 100; projContext.EnterpriseResources.Update(); } else if (dataExcel.Month == 9) { CustomField cField = projContext.CustomFields.First(c => c.Name == "Sen"); res[cField.InternalName] = dataExcel.Data * 100; projContext.EnterpriseResources.Update(); } else if (dataExcel.Month == 10) { CustomField cField = projContext.CustomFields.First(c => c.Name == "Okt"); res[cField.InternalName] = dataExcel.Data * 100; projContext.EnterpriseResources.Update(); } else if (dataExcel.Month == 11) { CustomField cField = projContext.CustomFields.First(c => c.Name == "Now"); res[cField.InternalName] = dataExcel.Data * 100; projContext.EnterpriseResources.Update(); } else if (dataExcel.Month == 12) { CustomField cField = projContext.CustomFields.First(c => c.Name == "Dec"); res[cField.InternalName] = dataExcel.Data * 100; projContext.EnterpriseResources.Update(); } projContext.ExecuteQuery(); } } } } }
public void TimesheetTest() { Guid guidYaroslav = Guid.Parse("9f52b233-4135-e511-80d0-00155d646d0b"); //string emailYaroslav = "*****@*****.**"; Guid guidAlex = Guid.Parse("a72f2f98-bd2f-e511-80c9-00155d60910a"); //string emailAlex = "*****@*****.**"; Guid guidKiryl = Guid.Parse("79d8d031-0801-e711-80d3-00155d74dc09"); //string emailKiryl = "*****@*****.**"; int oDataEntitesPerRequest = int.Parse(ConfigurationManager.AppSettings["ODataEntitesPerRequest"]); int oDataMaxQueryLength = int.Parse(ConfigurationManager.AppSettings["ODataMaxQueryLength"]); int requestTimeout = int.Parse(ConfigurationManager.AppSettings["RequestTimeout"]); bool isProjectOnline = Boolean.Parse(ConfigurationManager.AppSettings["IsProjectOnline"]); ProjectOnlineAccessService projectOnlineAccessService = new ProjectOnlineAccessService(ConfigurationManager .AppSettings["ProjectOnlineUrl"], ConfigurationManager.AppSettings["ProjectOnlineUserName"], ConfigurationManager.AppSettings["ProjectOnlinePassword"], isProjectOnline, Guid.NewGuid()); ProjectOnlineODataService projectOnlineODataService = new ProjectOnlineODataService(ConfigurationManager .AppSettings["ProjectOnlineUrl"], ConfigurationManager.AppSettings["ProjectOnlineUserName"], ConfigurationManager.AppSettings["ProjectOnlinePassword"], isProjectOnline); List <ODataAssignment> assignments = projectOnlineODataService .GetODataAssignments(Guid.Parse("8cc0d309-bd02-e711-80d4-00155d70390b")); ODataAssignment assignmentYaroslavYaroslavHours = assignments .FirstOrDefault(x => x.TaskName == "Yaroslav Hours" && x.ResourceId == guidYaroslav); ODataAssignment assignmentYaroslavAlexHours = assignments .FirstOrDefault(x => x.TaskName == "Alex Hours" && x.ResourceId == guidYaroslav); ODataAssignment assignmentKyrilKyrilHours = assignments .FirstOrDefault(x => x.TaskName == "Kyril Hours" && x.ResourceId == guidKiryl); ODataAssignment assignmentKyrilAlexHours = assignments .FirstOrDefault(x => x.TaskName == "Alex Hours" && x.ResourceId == guidKiryl); if (assignmentYaroslavYaroslavHours == null || assignmentYaroslavAlexHours == null || assignmentKyrilKyrilHours == null || assignmentKyrilAlexHours == null) { return; } //EnterpriseResource resourceAlex = projectOnlineAccessService.ProjectContext.EnterpriseResources.GetByGuid(guidAlex); //projectOnlineAccessService.ProjectContext.Load(resourceAlex.Assignments); //EnterpriseResource resourceKyril = projectOnlineAccessService.ProjectContext.EnterpriseResources.GetByGuid(guidKiryl); //projectOnlineAccessService.ProjectContext.Load(resourceKyril.Assignments); EnterpriseResource resourceYaroslav = projectOnlineAccessService.ProjectContext.EnterpriseResources.GetByGuid(guidYaroslav); TimePhase timePhaseYaroslav = resourceYaroslav.Assignments.GetTimePhase(new DateTime(2017, 8, 22), new DateTime(2017, 8, 22)); projectOnlineAccessService.ProjectContext.Load(resourceYaroslav.Assignments); projectOnlineAccessService.ProjectContext.Load(timePhaseYaroslav); projectOnlineAccessService.ProjectContext.Load(timePhaseYaroslav.Assignments); projectOnlineAccessService.ProjectContext.ExecuteQuery(); foreach (StatusAssignment statusAssignment in timePhaseYaroslav.Assignments) { if (statusAssignment.Id == assignmentYaroslavYaroslavHours.AssignmentId) { statusAssignment.ActualWork = "1h"; } if (statusAssignment.Id == assignmentYaroslavAlexHours.AssignmentId) { statusAssignment.ActualWork = "2h"; } if (statusAssignment.Id == assignmentKyrilKyrilHours.AssignmentId) { statusAssignment.ActualWork = "3h"; } if (statusAssignment.Id == assignmentKyrilAlexHours.AssignmentId) { statusAssignment.ActualWork = "4h"; } } timePhaseYaroslav.Assignments.Update(); timePhaseYaroslav.Assignments.SubmitAllStatusUpdates($"Submitted by CSOM on {DateTime.Now}"); projectOnlineAccessService.ProjectContext.ExecuteQuery(); var temp = 1; //projectOnlineAccessService.ProjectContext.Load(projectOnlineAccessService.ProjectContext.TimeSheetPeriods, c => c.Where(p => p.Start <= DateTime.Now && p.End >= DateTime.Now).IncludeWithDefaultProperties(p => p.TimeSheet, p => p.TimeSheet.Lines.Where(l => l.LineClass == TimeSheetLineClass.StandardLine).IncludeWithDefaultProperties(l => l.Assignment, l => l.Assignment.Task, l => l.Work))); //projectOnlineAccessService.ProjectContext.ExecuteQuery(); }
static void createPWAEngagement(string proj_uid, string res_uid, string dtfrom, string dtto, double pct, int isDraft, string calcfrom, string description) { int x = 0; Guid engagement = Guid.NewGuid(); //EngagementDataSet eds = PJContext.Current.PSI.EngagementWebService.ReadEngagementsForProject(i_ProjectUID); if (m_proj_uid != proj_uid) { if (x != 0) { draftProj.CheckIn(false); QueueJob qJob = projContext.Projects.Update(); JobState jobState = projContext.WaitForQueue(qJob, timeoutSeconds); } pubProj = projContext.Projects.GetByGuid(new Guid(proj_uid)); projContext.Load(pubProj); projContext.ExecuteQuery(); draftProj = pubProj.CheckOut(); m_proj_uid = proj_uid; } //setProj(proj_uid,res_uid); //res = projContext.EnterpriseResources.GetByGuid(new Guid(res_uid)); res = resources.GetByGuid(new Guid(res_uid)); projContext.Load(res); projContext.ExecuteQuery(); ProjectEngagementCreationInformation peci = new ProjectEngagementCreationInformation(); peci.Id = engagement; peci.Start = Convert.ToDateTime(dtfrom); peci.Finish = Convert.ToDateTime(dtto); peci.Resource = res; peci.MaxUnits = pct; //peci.Work = "8h" //peci.Description = description; //projContext.Load(draftProj.Engagements); //projContext.Load(pubProj.Engagements); //projContext.ExecuteQuery(); //if (calcfrom == "project") // draftProj.UtilizationType = ProjectUtilizationType.ProjectPlan; //else // draftProj.UtilizationType = ProjectUtilizationType.ResourceEngagements; if (isDraft == 1) { draftProj.Engagements.Add(peci).Status = EngagementStatus.Draft; } else { draftProj.Engagements.Add(peci).Status = EngagementStatus.Proposed; } draftProj.Engagements.Update(); //if (2 == 1) //{ // //Success: Retrieve all projects // //var projects = projContext.LoadQuery(projContext.Projects); // //projContext.ExecuteQuery(); // //approve proposed request // //projContext.Load(res.Engagements.GetById(engagement.ToString())); // //projContext.Load(projContext.EnterpriseResources.GetByGuid(res.Id).Engagements); // projContext.Load(res.Engagements); // projContext.ExecuteQuery(); // ResourceEngagement eng = res.Engagements.GetById(engagement.ToString()); // //projContext.Load(eng); // //projContext.ExecuteQuery(); //Too many resources: 4205. You cannot load dependent objects for more than 1000 resources. Use a filter to restrict your query // eng.Status = EngagementStatus.Approved; // res.Engagements.Update(); // qJob = projContext.Projects.Update(); // jobState = projContext.WaitForQueue(qJob, timeoutSeconds); //} x = x + 1; }
static void checkEngagement(string proj_uid, string res_uid = "4d6e3553-5ab1-e411-9a07-00155d509515", string alloc_uid = "zd6e3553-5ab1-e411-9a07-00155d509515") { res_uid = "8a8b380f-10ba-e411-ab5d-00155da4340f"; //bt pubProj = projContext.Projects.GetByGuid(new Guid(proj_uid)); projContext.Load(pubProj); projContext.ExecuteQuery(); draftProj = pubProj.CheckOut(); projContext.Load(draftProj.Engagements); projContext.ExecuteQuery(); ProjectEngagement pEng = null; foreach (ProjectEngagement pe in draftProj.Engagements) { projContext.Load(pe); projContext.Load(pe.Resource); projContext.ExecuteQuery(); if (pe.Resource.Id.ToString() == res_uid) { pEng = pe; res = pe.Resource; break; } } //ProjectEngagement pEng = draftProj.Engagements.First(e => e.Resource.Id.ToString() == res_uid ); //projContext.Load(pEng.Resource); //projContext.ExecuteQuery(); //res = pEng.Resource; if (pEng == null) { res = resources.GetByGuid(new Guid(res_uid)); projContext.Load(res); projContext.ExecuteQuery(); ProjectEngagementCreationInformation peci = new ProjectEngagementCreationInformation(); peci.Id = Guid.NewGuid(); peci.Start = Convert.ToDateTime("1/1/2019"); peci.Finish = Convert.ToDateTime("1/1/2019"); peci.Resource = res; peci.Work = "0h"; peci.Description = "RPM_" + alloc_uid; //projContext.Load(draftProj.Engagements); //projContext.Load(pubProj.Engagements); //projContext.ExecuteQuery(); //if (calcfrom == "project") // draftProj.UtilizationType = ProjectUtilizationType.ProjectPlan; //else // draftProj.UtilizationType = ProjectUtilizationType.ResourceEngagements; draftProj.Engagements.Add(peci).Status = EngagementStatus.Proposed; draftProj.Engagements.Update(); pEng = draftProj.Engagements.Last(); projContext.Load(pEng); projContext.Load(pEng.Resource); projContext.ExecuteQuery(); } ProjectEngagementTimephasedCollection petpc = pEng.GetTimephased(Convert.ToDateTime("5/1/2020"), Convert.ToDateTime("5/31/2020"), TimeScale.Months, EngagementContourType.Draft); projContext.Load(petpc); projContext.ExecuteQuery(); petpc[0].Work = "20h"; petpc[1].Work = "20h"; petpc[2].Work = "30h"; petpc[3].Work = "40h"; petpc[4].Work = "50h"; petpc[5].Work = "60h"; petpc[6].Work = "70h"; petpc[7].Work = "80h"; pEng.Status = EngagementStatus.Reproposed; draftProj.Engagements.Update(); draftProj.CheckIn(false); QueueJob qJob1 = projContext.Projects.Update(); JobState jobState = projContext.WaitForQueue(qJob1, timeoutSeconds); { //approve proposed request projContext.Load(res.Engagements); projContext.ExecuteQuery(); ResourceEngagement eng = res.Engagements.GetById(pEng.Id.ToString()); projContext.Load(eng); projContext.ExecuteQuery(); //Too many resources: 4205. You cannot load dependent objects for more than 1000 resources. Use a filter to restrict your query eng.Status = EngagementStatus.Approved; res.Engagements.Update(); QueueJob qJob = projContext.Projects.Update(); jobState = projContext.WaitForQueue(qJob, timeoutSeconds); } }
public static async Task <EnterpriseResourceCostRateTable> GetDefaultCostRateTableAsync(this EnterpriseResource enterpriseResource) { enterpriseResource.Context.Load(enterpriseResource.CostRateTables); await enterpriseResource.Context.ExecuteQueryAsync(); var costRateTable = enterpriseResource.CostRateTables.GetByName(CostRateTableName.A); enterpriseResource.Context.Load(costRateTable.CostRates); await enterpriseResource.Context.ExecuteQueryAsync(); return(costRateTable); }
static void SyncEngagments() { ProjectEngagement pEng = null; string res_uid = ""; string proj_uid = ""; string err = ""; string sql = "exec [MCG_RM_GetPendingUpdates_engagements]"; DataSet ds = new DataSet(); SqlDataAdapter da = new SqlDataAdapter(sql, cn); da.Fill(ds); foreach (DataRow r in ds.Tables[0].Rows) { res_uid = r["resourceuid"].ToString(); proj_uid = r["projectuid"].ToString(); pubProj = projContext.Projects.GetByGuid(new Guid(proj_uid)); projContext.Load(pubProj); projContext.ExecuteQuery(); draftProj = pubProj.CheckOut(); projContext.Load(draftProj.Engagements); projContext.ExecuteQuery(); if (!r.IsNull("engagementuid")) { pEng = draftProj.Engagements.GetByGuid(new Guid(r["engagementuid"].ToString())); } if (pEng == null) { res = projContext.EnterpriseResources.GetByGuid(new Guid(res_uid)); projContext.Load(res); projContext.ExecuteQuery(); ProjectEngagementCreationInformation peci = new ProjectEngagementCreationInformation(); peci.Id = Guid.NewGuid(); peci.Start = Convert.ToDateTime(r["start_dt"].ToString()); peci.Finish = Convert.ToDateTime(r["end_dt"].ToString()); peci.Resource = res; peci.Work = "0h"; peci.Description = "RPM_" + r["planuid"].ToString(); draftProj.Engagements.Add(peci).Status = EngagementStatus.Proposed; draftProj.Engagements.Update(); pEng = draftProj.Engagements.Last(); projContext.Load(pEng); projContext.ExecuteQuery(); } DataRow[] rows = ds.Tables[1].Select("resourceuid='" + res_uid + "' and projectuid='" + proj_uid + "'"); ProjectEngagementTimephasedCollection petpc = pEng.GetTimephased(Convert.ToDateTime(r["start_dt"]), Convert.ToDateTime(r["end_dt"]), TimeScale.Days, EngagementContourType.Draft); projContext.Load(petpc); projContext.ExecuteQuery(); foreach (DataRow row in rows) { petpc.GetByStart(Convert.ToDateTime(row["timebyday"].ToString())).Work = row["allocationwork"].ToString(); } pEng.Status = EngagementStatus.Reproposed; //this is needed draftProj.Engagements.Update(); draftProj.CheckIn(false); //this updates the last TBD engagement in PWA, Approved will remove Eng from PWA QueueJob qJob1 = projContext.Projects.Update(); JobState jobState = projContext.WaitForQueue(qJob1, timeoutSeconds); { //approve proposed request if (res == null) { res = projContext.EnterpriseResources.GetByGuid(new Guid(res_uid)); projContext.Load(res); projContext.Load(res.Engagements); projContext.ExecuteQuery(); } ResourceEngagement eng = res.Engagements.GetById(pEng.Id.ToString()); projContext.Load(eng); projContext.ExecuteQuery(); //Too many resources: 4205. You cannot load dependent objects for more than 1000 resources. Use a filter to restrict your query eng.Status = EngagementStatus.Approved; res.Engagements.Update(); QueueJob qJob = projContext.Projects.Update(); jobState = projContext.WaitForQueue(qJob, timeoutSeconds); } } }
static void testEngagement_old(DataSet ds) { string res_uid = ""; string proj_uid = ""; foreach (DataRow r in ds.Tables[1].Rows) { res_uid = r["resourceuid"].ToString(); proj_uid = r["projectuid"].ToString(); pubProj = projContext.Projects.GetByGuid(new Guid(proj_uid)); projContext.Load(pubProj); projContext.ExecuteQuery(); draftProj = pubProj.CheckOut(); projContext.Load(draftProj.Engagements); projContext.ExecuteQuery(); ProjectEngagement pEng = null; foreach (ProjectEngagement pe in draftProj.Engagements) { projContext.Load(pe); projContext.Load(pe.Resource); projContext.ExecuteQuery(); if (pe.Resource.Id.ToString().ToUpper() == res_uid.ToUpper()) { pEng = pe; res = pe.Resource; break; } } if (pEng == null) { res = resources.GetByGuid(new Guid(res_uid)); projContext.Load(res); projContext.ExecuteQuery(); ProjectEngagementCreationInformation peci = new ProjectEngagementCreationInformation(); peci.Id = Guid.NewGuid(); peci.Start = Convert.ToDateTime("1/1/2019"); peci.Finish = Convert.ToDateTime("1/1/2019"); peci.Resource = res; peci.Work = "0h"; peci.Description = "RPM_" + "alloc_uid"; draftProj.Engagements.Add(peci).Status = EngagementStatus.Proposed; draftProj.Engagements.Update(); pEng = draftProj.Engagements.Last(); projContext.Load(pEng); projContext.Load(pEng.Resource); projContext.ExecuteQuery(); } DataRow[] rows = ds.Tables[2].Select("resourceuid='" + res_uid + "' and projectuid='" + proj_uid + "'"); ProjectEngagementTimephasedCollection petpc = pEng.GetTimephased(Convert.ToDateTime(r["start_dt"]), Convert.ToDateTime(r["end_dt"]), TimeScale.Days, EngagementContourType.Draft); //works //ProjectEngagementTimephasedCollection petpc = pEng.GetTimephased(Convert.ToDateTime("10/1/2019"), Convert.ToDateTime("10/31/2019"), TimeScale.Months, EngagementContourType.Draft); //ProjectEngagementTimephasedCollection petpc = pEng.GetTimephased(Convert.ToDateTime("10/1/2019"), Convert.ToDateTime("12/31/2019"), TimeScale.Days, EngagementContourType.Draft); projContext.Load(petpc); projContext.ExecuteQuery(); //petpc.GetByStart(Convert.ToDateTime("10/1/2019")).Work = "1"; //petpc.GetByStart(Convert.ToDateTime("10/2/2019")).Work = "2"; //petpc.GetByStart(Convert.ToDateTime("10/3/2019")).Work = "3"; //petpc.GetByStart(Convert.ToDateTime("10/4/2019")).Work = "0"; //petpc[3].Work = "4"; //DateTime dt = petpc[2].Start; //petpc[0].Work = "100h"; //petpc.GetByStart(Convert.ToDateTime("10/1/2019")).Work = "50h"; //draftProj.Engagements.Update(); ProjectEngagementTimephasedPeriod petpP = null; foreach (DataRow row in rows) { petpc.GetByStart(Convert.ToDateTime(row["timebyday"].ToString())).Work = row["allocationwork"].ToString(); //string dt = row["timebyday"].ToString(); //petpP = petpc.GetByStart(Convert.ToDateTime(row["timebyday"])); //projContext.Load(petpP); //projContext.ExecuteQuery(); //petpP.Work = row["allocationwork"].ToString(); //ProjectEngagementTimephasedCollection petpc = pEng.GetTimephased(Convert.ToDateTime(row["timebyday"]), Convert.ToDateTime(row["timebyday"]), TimeScale.Days, EngagementContourType.Draft); //projContext.Load(petpc); //projContext.ExecuteQuery(); //petpc[0].Work = row["allocationwork"].ToString(); //draftProj.Engagements.Update(); } //draftProj.Engagements.Update(); pEng.Status = EngagementStatus.Reproposed; //this is needed draftProj.Engagements.Update(); draftProj.CheckIn(false); //this updates the last TBD engagement in PWA, Approved will remove Eng from PWA QueueJob qJob1 = projContext.Projects.Update(); JobState jobState = projContext.WaitForQueue(qJob1, timeoutSeconds); { //approve proposed request projContext.Load(res.Engagements); projContext.ExecuteQuery(); ResourceEngagement eng = res.Engagements.GetById(pEng.Id.ToString()); projContext.Load(eng); projContext.ExecuteQuery(); //Too many resources: 4205. You cannot load dependent objects for more than 1000 resources. Use a filter to restrict your query eng.Status = EngagementStatus.Approved; res.Engagements.Update(); QueueJob qJob = projContext.Projects.Update(); jobState = projContext.WaitForQueue(qJob, timeoutSeconds); } } }
public Task <PublishedProject> LinkToEnterpriseResource(PublishedProject publishedProject, EnterpriseResource enterpriseResource) { return(LinkToEnterpriseResources(publishedProject, new List <EnterpriseResource>() { enterpriseResource })); }