Exemplo n.º 1
0
        static void getEngagements()
        {
            string err = "";
            string sql = "exec [MCG_RM_GetPendingUpdates_engagements]";

            DataSet        ds = new DataSet();
            SqlDataAdapter da = new SqlDataAdapter(sql, cn);

            da.Fill(ds);

            resources = projContext.EnterpriseResources;
            projContext.Load(resources);
            projContext.ExecuteQuery();

            testEngagement(ds);

            int x = 0;

            if (ds.Tables[0].Rows.Count > 0)
            {
                foreach (DataRow r in ds.Tables[0].Rows)
                {
                    checkEngagement(r["projectuid"].ToString());

                    //if (x >= 17)
                    {
                        try
                        {
                            createPWAEngagement(r["projectuid"].ToString(), r["resourceuid"].ToString(), r["start_dt"].ToString(), r["end_dt"].ToString(), Convert.ToDouble(r["pct1"].ToString()), 0, "", "");
                        }
                        catch (Exception ex)
                        {
                            err += r["projectuid"].ToString() + "|" + r["resourceuid"].ToString() + "|" + ex.Message + ";";
                        }
                    }
                    x = x + 1;
                }

                draftProj.CheckIn(false);

                QueueJob qJob     = projContext.Projects.Update();
                JobState jobState = projContext.WaitForQueue(qJob, timeoutSeconds);
            }


            //createPWAEngagement("ccb09aba-3b48-e611-80ca-00155d784803", "2faccbc2-7cc0-e511-80e2-00155da47821", "3/8/17", "4/1/17", .5, 0, "project", "_test6"); //mcg dev
            //createPWAEngagement("7b0d8c9a-1f51-e611-80db-00155dac312b", "897dacfa-afba-e511-80f6-00155da88b1b", "4/3/17", "4/5/17", 0, 0, "resplan", "");  //tina
            //createPWAEngagement("102c1cf8-15a1-e611-80ce-00155db08b21", "6C8D9F86-775A-E611-80C6-00155DB0931F", "10/1/16", "1/31/17", 0, 0, "resplan", "Team project forecast");
        }
        public void CheckInProject(DraftProject draftProject, Guid projectGuid)
        {
            if (draftProject == null)
            {
                return;
            }
            QueueJob job;
            JobState jobState;

            logger.LogAndSendMessage(null, "CheckInProject",
                                     projectGuid, winServiceIterationUid,
                                     $"CheckInProject START projectGuid: {projectGuid}",
                                     false, null, CommonConstants.Epm, CommonConstants.Start);

            try
            {
                logger.LogAndSendMessage(null, "CheckInProject CheckIn",
                                         projectGuid, winServiceIterationUid,
                                         $"CheckInProject CheckIn projectGuid: {projectGuid}",
                                         false, null);
                job = draftProject.CheckIn(false);
                if (!WaitForQueue(job, draftProject.Id, draftProject, out jobState))
                {
                    logger.LogAndSendMessage(null, "CheckInProject CheckIn WaitForQueue",
                                             projectGuid, winServiceIterationUid,
                                             $"CheckInProject CheckIn WaitForQueue job failed. Project UID: {projectGuid}; " +
                                             $"jobState: {jobState}",
                                             true, null);
                }
            }
            catch (Exception exception)
            {
                logger.LogAndSendMessage(null, "CheckInProject",
                                         projectGuid, winServiceIterationUid,
                                         $"CheckInProject Exception {projectGuid}",
                                         false, exception);
                logger.LogAndSendMessage(null, "ForceCheckInProject",
                                         projectGuid, winServiceIterationUid,
                                         $"ForceCheckInProject projectGuid: {projectGuid}",
                                         false, null);
                job = draftProject.CheckIn(true);
                WaitForQueue(job, draftProject.Id, draftProject, out jobState);
            }
            logger.LogAndSendMessage(null, "CheckInProject",
                                     projectGuid, winServiceIterationUid,
                                     $"CheckInProject END projectGuid: {projectGuid}",
                                     false, null, CommonConstants.Epm, CommonConstants.End);
        }
        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);
        }
Exemplo n.º 4
0
        public JobState CheckInProjectForce(DraftProject draft)
        {
            //CheckIn
            QueueJob publishJob = draft.CheckIn(true);
            JobState result     = projContext.WaitForQueue(publishJob, 3600);

            return(result);
        }
        public DraftProject CheckOutProject(PublishedProject publishedProject, string systemNames, Guid projectUid)
        {
            DraftProject draftProject = null;

            try
            {
                if (publishedProject.IsCheckedOut)
                {
                    if (isOnline)
                    {
                        if (publishedProject.IsCheckedOut && publishedProject.CheckedOutBy?.Email != null)
                        {
                            EmailSender emailSender = new EmailSender();
                            emailSender.SendNotificationEmail(publishedProject.CheckedOutBy.Email,
                                                              $"Check-in project {publishedProject.Name} request",
                                                              $"Hello, {publishedProject.CheckedOutBy.Title}. This is 60i Administrator. I've found that several tasks in project {publishedProject.Name} should be synchronized with {systemNames}. " +
                                                              "Howerver I need to change some properties of these tasks, but project is checked-out to you. Please check-in it for a little time so I can do neccessary operations.");
                            return(null);
                        }
                    }
                    return(null);
                }
                draftProject = CheckOutProject(publishedProject);
                return(draftProject);
            }
            //catch (PropertyOrFieldNotInitializedException exception)
            //{
            //    logger.LogAndSendMessage($"CheckOutProject ProjectUid: {projectUid}");
            //    logger.LogAndSendMessage(exception);
            //    if (draftProject != null)
            //    {
            //        logger.LogAndSendMessage("ForceCheckInProject");
            //        QueueJob job = draftProject.CheckIn(true);
            //        WaitForQueue(job, projectUid, draftProject);
            //        //ExecuteQuery();
            //    }
            //}
            catch (Exception exception)
            {
                logger.LogAndSendMessage(null, "CheckOutProject",
                                         projectUid, winServiceIterationUid,
                                         $"CheckOutProject ProjectUid: {projectUid}",
                                         false, exception);
                if (draftProject != null)
                {
                    logger.LogAndSendMessage(null, "ForceCheckInProject",
                                             projectUid, winServiceIterationUid,
                                             $"ForceCheckInProject {draftProject.Id}",
                                             false, null);
                    QueueJob job = draftProject.CheckIn(true);
                    JobState jobState;
                    WaitForQueue(job, projectUid, draftProject, out jobState);
                }
            }
            return(null);
        }
Exemplo n.º 6
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);
                }
            }
        }
Exemplo n.º 7
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);
            }
        }
Exemplo n.º 8
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);
                }
            }
        }