private static AssignmentCreationInformation CreateAssignment(Guid taskGuid, Guid resourceGuid)
 {
     AssignmentCreationInformation assnCi = new AssignmentCreationInformation
     {
         TaskId = taskGuid,
         ResourceId = resourceGuid
     };
     return assnCi;
 }
示例#2
0
        private static AssignmentCreationInformation CreateAssignment(Guid taskGuid, Guid resourceGuid)
        {
            AssignmentCreationInformation assnCi = new AssignmentCreationInformation
            {
                TaskId     = taskGuid,
                ResourceId = resourceGuid
            };

            return(assnCi);
        }
示例#3
0
        private void AddAssignmentToTask(DraftTask task, IEnumerable <EnterpriseResource> resources, int resourceCount, Guid taskId)
        {
            int resourceCountPerTask = RandomHelper.Random(1, resourceCount);

            int[] resourcesIndex = RandomHelper.GetRandomIndex(resourceCountPerTask, resources.Count() - 1);

            for (int i = 0; i < resourcesIndex.Count(); i++)
            {
                AssignmentCreationInformation assignmentInfo = new AssignmentCreationInformation
                {
                    ResourceId = resources.ElementAt(resourcesIndex[i]).Id,
                    TaskId     = taskId
                };
                task.Assignments.Add(assignmentInfo);
            }
        }
示例#4
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);
        }