private void AddResourcesToProject()
        {
            PublishedProject publishedProject = null;
            DraftProject     draftProject;

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

            List <EnterpriseResource> resourceList = new List <EnterpriseResource>();

            LV_EnterpiseResources.InvokeIfRequired(s =>
            {
                ListView.SelectedListViewItemCollection selectedItems = s.SelectedItems;
                resourceList.AddRange(selectedItems.Cast <ListViewItem>().Select(selectedItem => (EnterpriseResource)selectedItem.Tag));
            });

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

                resourceList.ToList().ForEach(r =>
                {
                    Log.WriteVerbose(new SourceInfo(), TB_Status, "Adding Resource:{0} to Project:{1}.", r.Name, publishedProject.Draft.Name);
                    draftProject.ProjectResources.AddEnterpriseResource(r);
                });

                QueueJob queueJob = draftProject.Update();
                Log.WriteVerbose(new SourceInfo(), TB_Status, _bgeAddResourcesToProject, "Waiting for the Project Update job to complete.");
                CsomHelper.ExecuteAndWait(queueJob, TB_Status);
            }
            Log.WriteVerbose(new SourceInfo(), TB_Status, _bgeAddResourcesToProject, "Refreshing Project resources.");
            GetDraftTeamForSelectedProject();
        }
Exemplo n.º 2
0
        private void UpdateProjectOwner()
        {
            List <PublishedProject> projectList = new List <PublishedProject>();
            EnterpriseResource      resource    = null;

            LV_Projects.InvokeIfRequired(s =>
            {
                ListView.SelectedListViewItemCollection selectedItems = s.SelectedItems;
                projectList.AddRange(selectedItems.Cast <ListViewItem>().Select(selectedItem => (PublishedProject)selectedItem.Tag));
            });

            LV_EnterpiseResources.InvokeIfRequired(s => resource = (EnterpriseResource)s.SelectedItems[0].Tag);

            if (resource == null)
            {
                Log.WriteWarning(new SourceInfo(), TB_Status, "No enterprise resource selected.");
                return;
            }

            List <QueueJob> jobs = new List <QueueJob>();

            foreach (PublishedProject publishedproject in projectList)
            {
                if (!publishedproject.IsCheckedOut)
                {
                    publishedproject.CheckOut();
                }
                else if (!publishedproject.CheckedOutBy.IsNull() && publishedproject.CheckedOutBy.Title != CsomBase.CurrentResource.User.Title)
                {
                    Log.WriteWarning(new SourceInfo(), TB_Status,
                                     "Project:{0} checked out to a different user:{1}, not changing the owner to {2}.",
                                     publishedproject.Name,
                                     publishedproject.Owner.Title,
                                     resource.User.Title);
                    continue;
                }

                Log.WriteVerbose(new SourceInfo(), TB_Status, "Updating project:{0}, Setting owner to:{1}", publishedproject.Name,
                                 resource.Name);

                publishedproject.Owner = resource.User;
                jobs.Add(publishedproject.Draft.Update());
            }
            Log.WriteVerbose(new SourceInfo(), TB_Status, _bgeProject, "Waiting for the Project Update job to complete.");
            CsomHelper.ExecuteAndWait(jobs, TB_Status);
            Log.WriteVerbose(new SourceInfo(), TB_Status, _bgeProject, "Loading Projects.");
            LoadProjects();
        }
        private void GetEnterpriseResourcesList()
        {
            LV_EnterpiseResources.InvokeIfRequired(s => s.Items.Clear());
            IEnumerable <EnterpriseResource> resourcesList = ProjContext.LoadQuery(ProjContext.EnterpriseResources.Where(r => r.ResourceType == EnterpriseResourceType.Work));

            ProjContext.ExecuteQuery();

            EnterpriseResource[] enterpriseResources = resourcesList.ToArray();
            foreach (EnterpriseResource res in enterpriseResources)
            {
                ListViewItem lvi = new ListViewItem(res.Name)
                {
                    Tag = res
                };
                Log.WriteVerbose(new SourceInfo(), "Found Resource:{0}", res.Name);

                LV_EnterpiseResources.InvokeIfRequired(s => s.Items.Add(lvi));
            }
            LV_EnterpiseResources.InvokeIfRequired(s => s.Columns[0].Text = $"Enterprise Resources({enterpriseResources.Length})");
        }
Exemplo n.º 4
0
        private void LoadEnterpriseResources()
        {
            Log.WriteVerbose(new SourceInfo(), "Loading Enterprise Resources");

            LV_EnterpiseResources.InvokeIfRequired(s => s.Items.Clear());
            IEnumerable <EnterpriseResource> resourcesList = ProjContext.LoadQuery(ProjContext.EnterpriseResources.Include(r => r.Name, r => r.User));

            ProjContext.ExecuteQuery();
            List <ListViewItem> listViewItems = resourcesList.Where(r => !r.User.IsNull()).Select(res =>
            {
                Log.WriteVerbose(new SourceInfo(), TB_Status, "Found Enterprise Resource {0}", res.Name);
                return(new ListViewItem(res.Name)
                {
                    Tag = res
                });
            }).ToList();

            LV_EnterpiseResources.InvokeIfRequired(s =>
            {
                s.Items.AddRange(listViewItems.ToArray());
                s.Columns[0].Text = $"Enterprise Resources({listViewItems.Count})";
            });
        }