Ejemplo n.º 1
0
 private ProjectResourceCreationInformation CreateLocalResource(int resourceSuffix)
 {
     ProjectResourceCreationInformation localResourceCi = new ProjectResourceCreationInformation
     {
         Name = txtResName.Text + resourceSuffix,
     };
     return localResourceCi;
 }
Ejemplo n.º 2
0
        ProjectResourceCreationInformation CreateLocalResource(int resourceSuffix)
        {
            ProjectResourceCreationInformation localResourceCi = new ProjectResourceCreationInformation
            {
                Name = txtResName.Text + resourceSuffix,
            };

            return(localResourceCi);
        }
Ejemplo n.º 3
0
        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);
        }