예제 #1
0
        private static void UpdateProjectCustomField(Guid ProjectId)
        {
            DraftProject projCheckedOut = null;

            try
            {
                Dictionary <string, object> projDict = new Dictionary <string, object>();


                using (ProjectContext projContext = new ProjectContext(PWAUrl))
                {
                    projContext.ExecutingWebRequest += claimsHelper.clientContext_ExecutingWebRequest;

                    var PrjList = projContext.LoadQuery(projContext.Projects.Where(proj => proj.Name == ""));

                    projContext.ExecuteQuery();
                    Guid pGuid = PrjList.First().Id;

                    PublishedProject proj2Edit = PrjList.First();
                    projCheckedOut = proj2Edit.CheckOut().IncludeCustomFields;
                    projContext.Load(projCheckedOut);
                    projContext.ExecuteQuery();

                    var cflist = projContext.LoadQuery(projContext.CustomFields.Where(cf => cf.Name == "Testcol"));
                    projContext.ExecuteQuery();
                    projCheckedOut.SetCustomFieldValue(cflist.FirstOrDefault().InternalName, "Entry_c8f0abff70f5e51180cc00155dd45b0a");

                    QueueJob qJob     = projCheckedOut.Publish(true);
                    JobState jobState = projContext.WaitForQueue(qJob, 70);
                }
            }
            catch (Exception ex)
            {
            }
        }
        public DraftProject CheckOutProject(PublishedProject publishedProject)
        {
            logger.LogAndSendMessage(null, "CheckOutProject",
                                     publishedProject.Id, winServiceIterationUid,
                                     $"CheckOutProject START publishedProject.Id: {publishedProject.Id}",
                                     false, null);
            DraftProject draftProject = publishedProject.CheckOut();

            try
            {
                draftProject = GetDraftProject(draftProject, publishedProject.Id);
            }
            catch (Exception exception)
            {
                logger.LogAndSendMessage(null, "CheckOutProject",
                                         publishedProject.Id, winServiceIterationUid,
                                         $"CheckOutProject publishedProject.Id: {publishedProject.Id}",
                                         false, exception);
                if (draftProject != null)
                {
                    QueueJob job = draftProject.CheckIn(true);
                    JobState jobState;
                    WaitForQueue(job, publishedProject.Id, draftProject, out jobState);
                    draftProject = null;
                }
                //ExecuteQuery();
            }
            logger.LogAndSendMessage(null, "CheckOutProject",
                                     publishedProject.Id, winServiceIterationUid,
                                     $"CheckOutProject END publishedProject.Id: {publishedProject.Id}",
                                     false, null);
            return(draftProject);
        }
        public async Task <DraftProject> CheckOutAsync(PublishedProject publishedProject)
        {
            if (publishedProject == null)
            {
                throw new ArgumentNullException(nameof(publishedProject));
            }

            DraftProject draftProject = null;

            try
            {
                await System.Threading.Tasks.Task.Run(() =>
                {
                    draftProject = publishedProject.CheckOut();
                });
            }
            catch (Exception ex)
            {
                // TODO: LOG ERROR!

                throw new CsomClientException($"Unexcepted error checking out a project. " +
                                              $"project id is {publishedProject.Id}. " +
                                              $"Project context url is {_projectContext.Url}.", ex);
            }

            return(draftProject);
        }
예제 #4
0
        public void RenameTasks()
        {
            DateTime dateTimeControl = new DateTime(2018, 9, 26);
            var      list            = _dbPortal.RenameTasksKBM.ToList();
            var      projCollection  = projContext.LoadQuery(projContext.Projects.Where(d => d.CreatedDate > dateTimeControl));

            projContext.ExecuteQuery();
            foreach (var prj in projCollection)
            {
                PublishedProject project = prj;
                DraftProject     draft   = project.CheckOut();
                projContext.Load(draft, p => p.Tasks);
                projContext.ExecuteQuery();
                if (draft.Tasks.Count > 0)
                {
                    foreach (var task in draft.Tasks.ToList())
                    {
                        foreach (var baseTask in list)
                        {
                            if (baseTask.@base == task.Name)
                            {
                                task.Name = baseTask.@this;
                            }
                        }
                    }
                }
                draft.Update();
                Console.WriteLine(prj.Name);
                JobState jobState = projContext.WaitForQueue(draft.Publish(true), 20);
            }
        }
예제 #5
0
        private DraftProject CheckOutProject(PublishedProject project)
        {
            DraftProject draftProject = null;

            ExcuteJobWithRetries(() =>
            {
                LoggerHelper.Instance.Comment("About to Checkout Project with Name: " + project.Name);
                draftProject = project.CheckOut();
                BaseProjectContext.Load(draftProject);
                BaseProjectContext.ExecuteQuery();
                LoggerHelper.Instance.Comment("Finish Checkout Project with Name: " + project.Name);
            },
                                 "Checkout Project");
            return(draftProject);
        }
        private void BTN_Update_Click(object sender, EventArgs e)
        {
            if (_publishedProject == null)
            {
                return;
            }
            if (!_publishedProject.IsCheckedOut)
            {
                _publishedProject.CheckOut();
            }
            QueueJob job = _publishedProject.Draft.Update();

            CsomHelper.ExecuteAndWait(job, TB_Status);
            LoadProjectInfo();
        }
예제 #7
0
        private int CreateTasksInProject(IGrouping <Guid, ProjectServer_CreateTasks> data)
        {
            try
            {
                using (ProjectContext projectCont1 = new ProjectContext(PwaPath))
                {
                    string nameProject    = _db.PWA_EmpProject.First(d => d.ProjectUID == data.Key).ProjectName;
                    var    projCollection = projectCont1.LoadQuery(projectCont1.Projects.Where(p => p.Name == nameProject));
                    projectCont1.ExecuteQuery();
                    PublishedProject proj2Edit      = projCollection.First();
                    DraftProject     projCheckedOut = proj2Edit.CheckOut();

                    foreach (var taskInList in _db.ProjectServer_CreateTasks.Where(d => d.ProjectUID == data.Key).ToList())
                    {
                        Guid taskId = Guid.NewGuid();
                        Task task   = projCheckedOut.Tasks.Add(new TaskCreationInformation()
                        {
                            Id       = taskId,
                            Name     = taskInList.TaskName,
                            Notes    = "new Task",
                            IsManual = false,
                            Duration = "1d",
                            Start    = DateTime.Now
                        });
                        projCheckedOut.Update();
                        // Create a local resource and assign the task to him
                        projCheckedOut.Update();
                        Guid resourceGuid =
                            (Guid)_db.AspNetUsers.First(d => d.Email == taskInList.Resource).ResourceUID;
                        DraftAssignment assignment = projCheckedOut.Assignments.Add(new AssignmentCreationInformation()
                        {
                            ResourceId = resourceGuid,
                            TaskId     = taskId
                        });
                        projCheckedOut.Update();
                    }

                    projCheckedOut.Publish(true);
                    QueueJob qJob     = projectCont1.Projects.Update();
                    JobState jobState = projectCont1.WaitForQueue(qJob, 20);
                }
                return(1);
            }
            catch
            {
                return(0);
            }
        }
예제 #8
0
 private int ReadAndUpdateProject()
 {
     try
     {
         var tasksList = _db.ProjectServer_UpdateMustStartOn.ToList();
         if (tasksList.Count > 0)
         {
             try
             {
                 foreach (var dataList in tasksList)
                 {
                     ProjectContext context        = new ProjectContext(PwaPath);
                     string         nameProject    = _db.PWA_EmpProject.First(d => d.ProjectUID == dataList.ProjectUID).ProjectName;
                     var            projCollection = context.LoadQuery(context.Projects.Where(p => p.Name == nameProject));
                     context.ExecuteQuery();
                     PublishedProject project = projCollection.First();
                     DraftProject     draft   = project.CheckOut();
                     context.Load(draft, p => p.StartDate,
                                  p => p.Description);
                     string taskName = _db.PWA_EmpTaskAll.First(d => d.TaskUID == dataList.TaskUID).TaskName;
                     context.Load(draft.Tasks, dt => dt.Where(t => t.Name == taskName));
                     context.Load(draft.Assignments, da => da.Where(a => a.Task.Name == taskName));
                     context.ExecuteQuery();
                     DraftTask task = draft.Tasks.First();
                     task.ConstraintType     = ConstraintType.MustStartOn;
                     task.ConstraintStartEnd = dataList.ActualStart;
                     draft.Update();
                     JobState jobState = context.WaitForQueue(draft.Publish(true), 20);
                 }
                 return(1);
             }
             catch
             {
                 return(0);
             }
         }
         else
         {
             return(0);
         }
     }
     catch
     {
         return(0);
     }
 }
예제 #9
0
        public DraftProject GetDraftProject(PublishedProject published)
        {
            DraftProject draft = null;

            try
            {
                if (published.Draft.IsCheckedOut)
                {
                    return(draft);
                }
                draft = published.CheckOut();
            }
            catch (Exception)
            {
                projContext.Load(published, P1 => P1.Draft);
                projContext.ExecuteQuery();
                return(GetDraftProject(published));
            }
            projContext.Load(draft);
            projContext.ExecuteQuery();
            return(draft);
        }
예제 #10
0
 private int UpdateTasksInProject(IGrouping <Guid, ProjectServer_UpdateTasks> data)
 {
     try
     {
         using (ProjectContext projectCont1 = new ProjectContext(PwaPath))
         {
             string nameProject    = _db.PWA_EmpProject.First(d => d.ProjectUID == data.Key).ProjectName;
             var    projCollection = projectCont1.LoadQuery(projectCont1.Projects.Where(p => p.Name == nameProject));
             projectCont1.ExecuteQuery();
             PublishedProject proj2Edit      = projCollection.First();
             DraftProject     projCheckedOut = proj2Edit.CheckOut();
             projectCont1.Load(projCheckedOut.Tasks);
             projectCont1.ExecuteQuery();
             DraftTaskCollection catskill = projCheckedOut.Tasks;
             foreach (DraftTask task in catskill)
             {
                 try
                 {
                     if (task.Name != null && task.Id == _db.ProjectServer_UpdateTasks.First(d => d.taskUID == task.Id).taskUID)
                     {
                         ProjectServer_UpdateTasks projectServer_UpdateTasks = _db.ProjectServer_UpdateTasks.First(d => d.taskUID == task.Id);
                         var nk = projectServer_UpdateTasks.nk;
                         if (nk != null)
                         {
                             int time = (int)nk;
                             projectCont1.Load(task.CustomFields);
                             projectCont1.ExecuteQuery();
                             foreach (CustomField cus in task.CustomFields)
                             {
                                 if (cus.Name == "НК")
                                 {
                                     string intname = cus.InternalName;
                                     task[intname] = time;
                                 }
                             }
                             if (task.PercentComplete == 0)
                             {
                                 task.Work = time + "ч";
                             }
                             else
                             {
                                 int factWork = Convert.ToInt32(task.Work.Substring(0, task.Work.Length - 1)) - Convert.ToInt32(task.RemainingWork.Substring(0, task.RemainingWork.Length - 1));
                                 if (factWork < time)
                                 {
                                     task.Work = time - factWork + "ч";
                                 }
                             }
                             QueueJob qJob1     = projCheckedOut.Update();
                             JobState jobState1 = projectCont1.WaitForQueue(qJob1, 10);
                         }
                         else
                         {
                             ProjectServer_UpdateTasks pTask = _db.ProjectServer_UpdateTasks.First(d => d.taskUID == task.Id);
                             if (pTask.percentComplited != null)
                             {
                                 task.PercentComplete = (int)pTask.percentComplited;
                             }
                             if (pTask.finishDate != null)
                             {
                                 task.Finish = (DateTime)pTask.finishDate;
                             }
                             if (task.IsMilestone == true)
                             {
                                 task.Start = (DateTime)pTask.finishDate;
                             }
                             QueueJob qJob1     = projCheckedOut.Update();
                             JobState jobState1 = projectCont1.WaitForQueue(qJob1, 10);
                         }
                     }
                 }
                 catch
                 {
                 }
             }
             projCheckedOut.Publish(true);
             QueueJob qJob     = projectCont1.Projects.Update();
             JobState jobState = projectCont1.WaitForQueue(qJob, 20);
         }
         return(1);
     }
     catch
     {
         return(0);
     }
 }
예제 #11
0
        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);
                }
            }
        }
예제 #12
0
        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;
        }
예제 #13
0
        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);
            }
        }
예제 #14
0
        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);
                }
            }
        }
        private void RemoveResources()
        {
            PublishedProject            publishedProject = null;
            DraftProject                draftProject;
            List <DraftProjectResource> draftProjectResourceresList = new List <DraftProjectResource>();

            LV_Projects.InvokeIfRequired(s => publishedProject = (PublishedProject)s.SelectedItems[0].Tag);

            LV_ProjectResources.InvokeIfRequired(s =>
            {
                ListView.SelectedListViewItemCollection selectedItems = s.SelectedItems;
                draftProjectResourceresList.AddRange(selectedItems.Cast <ListViewItem>().Select(selectedItem => (DraftProjectResource)selectedItem.Tag));
            });

            if (draftProjectResourceresList.Any())
            {
                draftProject = publishedProject.IsCheckedOut ? publishedProject.Draft : publishedProject.CheckOut();

                draftProjectResourceresList.ForEach(r =>
                {
                    Log.WriteVerbose(new SourceInfo(), TB_Status, "Removing Resource:{0} from Project:{1}.", r.Name, publishedProject.Draft.Name);
                    draftProject.ProjectResources.Remove(r);
                });
                QueueJob queueJob = draftProject.Update();
                Log.WriteVerbose(new SourceInfo(), TB_Status, _bgeRemoveProjectResources, "Waiting for the Project Update job to complete.");
                CsomHelper.ExecuteAndWait(queueJob, TB_Status);
            }
            Log.WriteVerbose(new SourceInfo(), TB_Status, _bgeRemoveProjectResources, "Refreshing Project resources.");
            GetDraftTeamForSelectedProject();
        }