コード例 #1
0
        private static void UpdateTaskCF()

        {
            projectContext.Load(projectContext.Projects);     //Load Projects from PWA
            projectContext.ExecuteQuery();
            projectContext.Load(projectContext.CustomFields); //Load Custom Fields from PWA
            projectContext.ExecuteQuery();

            Guid ProjectGuid     = new Guid("3531cb1f - 51ce - 4a27 - a45a - 590339b99aed");
            Guid TaskGuid        = new Guid("56b0ba40 - da78 - e611 - 80cb - 00155da4672c");
            Guid CustomFieldGuid = new Guid("3c3dfd8b - da78 - e611 - 80cb - 00155da4672c");

            var          project      = projectContext.Projects.GetByGuid(ProjectGuid);
            DraftProject draftProject = project.CheckOut(); //CheckOut Project to make it  editable

            projectContext.Load(draftProject.Tasks);        //Load tasks of Project

            projectContext.ExecuteQuery();

            var taskToEdit       = draftProject.Tasks.First(task => task.Id == TaskGuid);//Get the task to be updated, Here you can also use the property task.Name
            var CustomField      = projectContext.CustomFields.First(CF => CF.Id == CustomFieldGuid);
            var CustomFieldValue = "New Value";

            string internalName = CustomField.InternalName.ToString(); //Get internal name of custom field

            taskToEdit[internalName] = CustomFieldValue;               //Set custom field value
            draftProject.Publish(true);                                //Publish and Check-in the project
            projectContext.ExecuteQuery();
        }
コード例 #2
0
ファイル: update.cs プロジェクト: mortegag/Project_online
        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)
            {
            }
        }
コード例 #3
0
        public void CheckInDraftProject(DraftProject draft)
        {
            QueueJob publishJob = draft.Publish(true);
            JobState result     = projContext.WaitForQueue(publishJob, 3600);

            Console.WriteLine("publish job state is {0}", result);
        }
コード例 #4
0
        internal System.Threading.Tasks.Task PublishAndUpdate(DraftProject draftProject, string projectName)
        {
            if (draftProject == null)
            {
                throw new ArgumentNullException(nameof(draftProject));
            }

            try
            {
                return(System.Threading.Tasks.Task.Run(() => {
                    // https://nearbaseline.com/2014/08/ciconotcheckedout-queue-errors-when-updating-projects-via-jsom/
                    // TODO: Do I need to do update and publish?
                    var queuedJob = draftProject.Publish(false);
                    WaitForQueuedJobToComplete(queuedJob, $"publishing a change in a project with name {projectName}");

                    //queuedJob = _projectContext.Projects.Update();
                    //WaitForQueuedJobToComplete(queuedJob, $"updating a project with name {projectName}");
                }));
            }
            catch (Exception ex)
            {
                // TODO: LOG ERROR!

                throw new CsomClientException($"Unexcepted error publishing and updating draft project. " +
                                              $"draft project id is {draftProject.Id}. " +
                                              $"Project context url is {_projectContext.Url}.", ex);
            }
        }
コード例 #5
0
 public void SetPSAMInProjectName()
 {
     projContext.Load(projContext.Projects);
     projContext.ExecuteQuery();
     foreach (var pubProj in projContext.Projects)
     {
         int planZakazNumber = 0;
         try
         {
             planZakazNumber = Convert.ToInt32(pubProj.Name.Substring(0, 4));
         }
         catch
         {
         }
         string rsamName = "";
         if (planZakazNumber > 0)
         {
             rsamName = GetRSAMName(planZakazNumber).Replace("_", "-");
         }
         if (planZakazNumber > 1156 && rsamName != "" && pubProj.Name.Length == pubProj.Name.Replace("PCAM", "").Length&& GetVipusk(planZakazNumber) == false)
         {
             try
             {
                 DraftProject projectDraft = pubProj.CheckOut();
                 projContext.Load(projectDraft);
                 projContext.ExecuteQuery();
                 projectDraft.Name += "   " + rsamName;
                 Console.WriteLine(projectDraft.Name);
                 QueueJob job = projectDraft.Update();
                 job = projectDraft.Publish(true);
             }
             catch { }
         }
     }
 }
コード例 #6
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);
            }
        }
コード例 #7
0
 private void PublishProject(DraftProject project)
 {
     ExcuteJobWithRetries(() =>
     {
         LoggerHelper.Instance.Comment("About to Pubilsh Project with Name: " + project.Name);
         QueueJob job = project.Publish(true);
         BaseProjectContext.ExecuteQuery();
         LoggerHelper.Instance.Comment("Finish Pubilsh Project with Name: " + project.Name);
     }, "Publish Project");
 }
        public void PublishProject(DraftProject draftProject, List <StagingDTO> affectedStagings)
        {
            if (draftProject == null)
            {
                return;
            }
            JobState state = JobState.Unknown;

            logger.LogAndSendMessage(null, "PublishProject",
                                     draftProject.Id, winServiceIterationUid,
                                     $"PublishProject START projectGuid: {draftProject.Id}",
                                     false, null, CommonConstants.Epm, CommonConstants.Start);
            try
            {
                QueueJob job = draftProject.Publish(false);
                WaitForQueue(job, draftProject.Id, draftProject, out state);
                logger.LogAndSendMessage(null, "PublishProject Publish WaitForQueue",
                                         draftProject.Id, winServiceIterationUid,
                                         $"PublishProject Publish WaitForQueue {draftProject.Id}",
                                         false, null);
                if (state == JobState.Success)
                {
                    if (affectedStagings != null)
                    {
                        foreach (StagingDTO affectedStaging in affectedStagings)
                        {
                            affectedStaging.RecordStateGeneral = RecordStateConst.Published;
                        }
                    }
                }
                else
                {
                    logger.LogAndSendMessage(null, "PublishProject Publish WaitForQueue",
                                             draftProject.Id, winServiceIterationUid,
                                             $"PublishProject Publish WaitForQueue job failed. Project UID: {draftProject.Id}; jobState: {state}",
                                             true, null);
                }
            }
            catch (Exception exception)
            {
                logger.LogAndSendMessage(null, "PublishProject",
                                         draftProject.Id, winServiceIterationUid,
                                         $"PublishProject {draftProject.Id} JobState: {state}",
                                         false, exception);
            }
            logger.LogAndSendMessage(null, "PublishProject",
                                     draftProject.Id, winServiceIterationUid,
                                     $"PublishProject END projectGuid: {draftProject.Id}",
                                     false, null, CommonConstants.Epm, CommonConstants.End);
        }
コード例 #9
0
        public void UpdateCriticalDateClose()
        {
            NetworkCredential cred = new NetworkCredential();

            cred.Domain             = "KATEK";
            cred.UserName           = "******";
            cred.Password           = "******";
            projContext.Credentials = cred;
            projContext.Load(projContext.Projects);
            projContext.Load(projContext.CustomFields);
            projContext.ExecuteQuery();
            foreach (var pubProj in projContext.Projects)
            {
                int planZakazNumber = 0;
                try
                {
                    planZakazNumber = Convert.ToInt32(pubProj.Name.Substring(0, 4));
                }
                catch
                {
                }
                if (planZakazNumber != 0 && planZakazNumber > 1734)
                {
                    try
                    {
                        Console.WriteLine("Update: {0}", planZakazNumber);
                        PZ_PlanZakaz pZ_PlanZakaz = _dbPortal.PZ_PlanZakaz.First(d => d.PlanZakaz == planZakazNumber);
                        if (pZ_PlanZakaz.dataOtgruzkiBP > DateTime.Now)
                        {
                            DateTime     criticalDateClose = _dbPortal.PZ_PlanZakaz.First(d => d.PlanZakaz == planZakazNumber).DateSupply;
                            DraftProject projectDraft      = pubProj.CheckOut();
                            projContext.Load(projectDraft);
                            projContext.Load(projectDraft.CustomFields);
                            projContext.ExecuteQuery();
                            CustomField cField = projContext.CustomFields.First(c => c.Name == "CriticalDateClose");
                            projectDraft[cField.InternalName] = criticalDateClose;
                            projectDraft.Update();
                            QueueJob job = projectDraft.Update();
                            job = projectDraft.Publish(true);
                            projContext.ExecuteQuery();
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }
            }
        }
コード例 #10
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);
            }
        }
コード例 #11
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);
     }
 }
コード例 #12
0
        public JobState PublishAndCheckInProject(DraftProject draft)
        {
            QueueJob publishJob = null;
            JobState result     = JobState.Failed;

            // Update
            publishJob = draft.Update();
            result     = projContext.WaitForQueue(publishJob, 3600);

            // Publish
            publishJob = draft.Publish(true);
            result     = projContext.WaitForQueue(publishJob, 3600);

            ; result = this.CheckInProjectForce(draft);

            Console.WriteLine("publish job state is {0}", result);
            return(result);
        }
コード例 #13
0
        /// <sumary>
        /// Funcion que permite actualizar las tareas en Project Server
        /// </summary>
        /// <param gui="String">Identificar Grafico Unico de proyecto de Project Server </param>
        /// <param fi="Date"> Fecha Inicial de Tarea</param>
        /// <param ff="Date"> Fecha Final de Tarea</param>
        /// <param porcent="Int"> Valor numerico de porcentaje de progreso de la tarea</param>
        private void UddateTask(string gui, string fi, string ff, int porcent)
        {
            using (ProjectCont1)
            {
                Guid ProjectGuid    = new Guid(gui);
                var  projCollection = ProjectCont1.LoadQuery(
                    ProjectCont1.Projects
                    .Where(p => p.Id == ProjectGuid));
                ProjectCont1.ExecuteQuery();

                if (projCollection != null)
                {
                    csom.PublishedProject proj2Edit  = projCollection.First();
                    DraftProject          draft2Edit = proj2Edit.CheckOut();
                    ProjectCont1.Load(draft2Edit);
                    ProjectCont1.Load(draft2Edit.Tasks);
                    ProjectCont1.ExecuteQuery();

                    var tareas = draft2Edit.Tasks;
                    foreach (DraftTask tsk in tareas)
                    {
                        tsk.Start           = Convert.ToDateTime(fi);
                        tsk.Finish          = Convert.ToDateTime(ff);
                        tsk.PercentComplete = porcent;
                    }

                    draft2Edit.Publish(true);
                    csom.QueueJob qJob     = ProjectCont1.Projects.Update();
                    csom.JobState jobState = ProjectCont1.WaitForQueue(qJob, 200);

                    qJob     = ProjectCont1.Projects.Update();
                    jobState = ProjectCont1.WaitForQueue(qJob, 20);

                    if (jobState == JobState.Success)
                    {
                        coleccion_vacia = false;
                    }
                }
                else
                {
                    coleccion_vacia = true;
                }
            }
        }
コード例 #14
0
ファイル: RKD.cs プロジェクト: YuraMelnikov/Portal
        public void UpdateTasksInProject()
        {
            ProjectContext projContext    = new ProjectContext("http://tpserver/pwa/");
            var            projCollection = projContext.LoadQuery(projContext.Projects.Where(p => p.Name == "Test"));

            projContext.ExecuteQuery();
            foreach (PublishedProject pubProj in projCollection)
            {
                DraftProject            projCheckedOut = pubProj.CheckOut();
                TaskCreationInformation newTask        = new TaskCreationInformation();
                newTask.Name     = "Тестовая задача Андрея";
                newTask.IsManual = false;
                newTask.Duration = "3d";
                newTask.Start    = DateTime.Today;
                projCheckedOut.Tasks.Add(newTask);
                projCheckedOut.StartDate = DateTime.Now.AddYears(1);
                projCheckedOut.Publish(true);
                QueueJob qJob     = projContext.Projects.Update();
                JobState jobState = projContext.WaitForQueue(qJob, 10);
            }
        }
コード例 #15
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);
     }
 }
コード例 #16
0
        private void Modify()
        {
            string g = "";

            using (ProjectCont1)
            {
                ProjectCont1.Load(ProjectCont1.Projects, c => c.IncludeWithDefaultProperties(pr => pr.CustomFields,
                                                                                             prop => prop.IncludeCustomFields, pr => pr.IncludeCustomFields.CustomFields));
                ProjectCont1.ExecuteQuery();



                foreach (PublishedProject item in ProjectCont1.Projects)
                {
                    if (item.Name == "PROYECTO TEST MOISES")
                    {
                        foreach (var customfield in item.IncludeCustomFields.FieldValues)
                        {
                            string k = customfield.Key;

                            if (k == "Custom_b18d6d025dcee911b08f00155db46231")
                            {
                                var lookup = ProjectCont1.LoadQuery(ProjectCont1.LookupTables.Where(x => x.Name == "Lineas de Acción"));
                                ProjectCont1.ExecuteQuery();
                                string lookuptypeCustomFieldValue = string.Empty;

                                DraftProject draft2Edit = item.CheckOut();
                                var          projECFs   = item.IncludeCustomFields.CustomFields;
                                foreach (CustomField cf in projECFs)
                                {
                                    if (k == cf.InternalName.ToString())
                                    {
                                        draft2Edit.SetCustomFieldValue(cf.InternalName, "Entry_b3eae594becde911b08000155db84c31");
                                    }
                                }


                                var publishJob = draft2Edit.Publish(true);



                                foreach (LookupTable tb in lookup)
                                {
                                    ProjectCont1.Load(tb.Entries);
                                    ProjectCont1.ExecuteQuery();

                                    foreach (LookupEntry en in tb.Entries)
                                    {
                                        for (int i = 0; i < ((string[])(customfield.Value)).Count(); i++)
                                        {
                                            string cmp = ((string[])(customfield.Value))[i].ToString();
                                            string ent = en.Id.ToString().Replace("-", "");

                                            if (cmp != "Entry_" + ent)
                                            {
                                                lookuptypeCustomFieldValue = en.FullValue;
                                                escribir_log(lookuptypeCustomFieldValue + "," + cmp + "," + ent, "," + cmp + "," + ent);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }