Пример #1
0
        private void LoadResourcesList()
        {
            IEnumerable <EnterpriseResource> resourcesList = ProjContext.LoadQuery(ProjContext.EnterpriseResources.Include(p => p.Name, p => p.Id, p => p.IsCheckedOut));

            ProjContext.ExecuteQuery();

            List <ListViewItem> listViewItems = new List <ListViewItem>();

            foreach (EnterpriseResource res in resourcesList)
            {
                ListViewItem lvi = new ListViewItem(res.Id.ToString());
                lvi.SubItems.Add(res.Name);
                lvi.SubItems.Add(res.IsCheckedOut.ToString());
                lvi.Tag = res;
                Log.WriteVerbose(new SourceInfo(), TB_Status, "Found Resource {0}", res.Name);
                listViewItems.Add(lvi);
            }
            LV_ServerObjects.InvokeIfRequired(s =>
            {
                s.Items.Clear();
                s.Columns.Clear();
                s.Columns.Add(new ColumnHeader {
                    Text = "Id", DisplayIndex = 0, Width = 20
                });
                s.Columns.Add(new ColumnHeader {
                    Text = "Name", DisplayIndex = 0, Width = 20
                });
                s.Columns.Add(new ColumnHeader {
                    Text = "CheckOut", DisplayIndex = 0, Width = 20
                });
                s.Items.AddRange(listViewItems.ToArray());
                s.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
                s.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
            });
        }
        private void LoadProjects()
        {
            CB_ProjectList.InvokeIfRequired(s =>
            {
                s.DataSource = null;
                s.Items.Clear();
            });

            IEnumerable <PublishedProject> projectList =
                ProjContext.LoadQuery(ProjContext.Projects.Include(p => p.Draft.Name, p => p.Draft, p => p.IsCheckedOut));

            ProjContext.ExecuteQuery();
            Dictionary <string, PublishedProject> projList = new Dictionary <string, PublishedProject>
            {
                { "Select a Project", null }
            };

            foreach (PublishedProject project in projectList)
            {
                projList.Add(project.Draft.Name, project);
            }
            CB_ProjectList.InvokeIfRequired(s =>
            {
                CB_ProjectList.SelectedIndexChanged += CB_ProjectList_SelectedIndexChanged;
                CB_ProjectList.DropDownStyle         = ComboBoxStyle.DropDown;
                CB_ProjectList.AutoCompleteMode      = AutoCompleteMode.SuggestAppend;
                CB_ProjectList.AutoCompleteSource    = AutoCompleteSource.ListItems;
                CB_ProjectList.DataSource            = new BindingSource(projList, null);
                CB_ProjectList.DisplayMember         = "Key";
                CB_ProjectList.ValueMember           = "Value";
            });
        }
        private void GetDraftProjectsList()
        {
            LV_Projects.InvokeIfRequired(s => s.Items.Clear());
            IEnumerable <PublishedProject> projectList =
                ProjContext.LoadQuery(ProjContext.Projects.Include(p => p.Draft.Name, p => p.Draft.Id,
                                                                   p => p.IsCheckedOut));

            ProjContext.ExecuteQuery();
            PublishedProject[]  publishedProjects = projectList.ToArray();
            List <ListViewItem> listViewItems     = new List <ListViewItem>();

            foreach (PublishedProject project in publishedProjects)
            {
                ListViewItem lvi = new ListViewItem(project.Draft.Name)
                {
                    Tag = project
                };
                Log.WriteVerbose(new SourceInfo(), "Found Project:{0}", project.Draft.Name);
                listViewItems.Add(lvi);
            }
            LV_Projects.InvokeIfRequired(s =>
            {
                s.Columns[0].Text = $"Projects({publishedProjects.Length})";
                s.Items.AddRange(listViewItems.ToArray());
            });
        }
Пример #4
0
        private void LoadProjectsList()
        {
            LV_Projects.InvokeIfRequired(s =>
            {
                s.Items.Clear();
                s.Columns.Clear();
                s.Columns.Add(new ColumnHeader {
                    Text = "Id", DisplayIndex = 0, Width = 20
                });
                s.Columns.Add(new ColumnHeader {
                    Text = "Name", DisplayIndex = 0, Width = 20
                });
                s.Columns.Add(new ColumnHeader {
                    Text = "Owner", DisplayIndex = 0, Width = 20
                });
                s.Columns.Add(new ColumnHeader {
                    Text = "CheckOut by", DisplayIndex = 0, Width = 20
                });
                s.Columns.Add(new ColumnHeader {
                    Text = "Published Date", DisplayIndex = 0, Width = 20
                });
                s.Columns.Add(new ColumnHeader {
                    Text = "Updated Date", DisplayIndex = 0, Width = 20
                });
                s.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
                s.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
            });

            IEnumerable <PublishedProject> projectList =
                ProjContext.LoadQuery(ProjContext.Projects.Include(p => p.Name, p => p.Id, p => p.IsCheckedOut,
                                                                   p => p.CheckedOutBy.LoginName, p => p.LastPublishedDate, p => p.Owner.LoginName,
                                                                   p => p.Draft.LastSavedDate));

            ProjContext.ExecuteQuery();

            List <ListViewItem> listViewItems = new List <ListViewItem>();

            foreach (PublishedProject proj in projectList)
            {
                ListViewItem lvi = new ListViewItem(proj.Id.ToString());
                lvi.SubItems.Add(proj.Name);
                lvi.SubItems.Add(proj.Owner.LoginName);
                lvi.SubItems.Add(proj.IsCheckedOut ? proj.CheckedOutBy.LoginName : string.Empty);
                lvi.SubItems.Add(proj.LastPublishedDate.ToString(CultureInfo.InvariantCulture));
                lvi.SubItems.Add(proj.Draft.LastSavedDate.ToString(CultureInfo.InvariantCulture));
                lvi.Tag = proj;
                listViewItems.Add(lvi);
            }
            LV_Projects.InvokeIfRequired(s =>
            {
                s.Items.AddRange(listViewItems.ToArray());
                s.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
                s.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
            });
        }
Пример #5
0
        private void LoadCustomFieldsList()
        {
            LV_ServerObjects.InvokeIfRequired(s =>
            {
                s.Items.Clear();
                s.Columns.Clear();
                s.Columns.Add(new ColumnHeader {
                    Text = "Id", DisplayIndex = 0, Width = 20
                });
                s.Columns.Add(new ColumnHeader {
                    Text = "Name", DisplayIndex = 0, Width = 20
                });
                s.Columns.Add(new ColumnHeader {
                    Text = "Type", DisplayIndex = 0, Width = 20
                });
                s.Columns.Add(new ColumnHeader {
                    Text = "Required", DisplayIndex = 0, Width = 20
                });
                s.Columns.Add(new ColumnHeader {
                    Text = "LookupTable", DisplayIndex = 0, Width = 20
                });
                s.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
                s.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
            });

            IEnumerable <CustomField> customFieldList = ProjContext.LoadQuery(ProjContext.CustomFields.Include(r => r.Name, r => r.EntityType.Name, r => r.Id, r => r.IsRequired, r => r.LookupTable.Name));

            ProjContext.ExecuteQuery();
            List <ListViewItem> listViewItems = new List <ListViewItem>();

            foreach (CustomField cf in customFieldList)
            {
                ListViewItem lvi = new ListViewItem(cf.Id.ToString());
                lvi.SubItems.Add(cf.Name);
                lvi.SubItems.Add(cf.EntityType.Name);
                lvi.SubItems.Add(cf.IsRequired.ToString());
                if (cf.LookupTable.ServerObjectIsNull != null && !cf.LookupTable.ServerObjectIsNull.Value)
                {
                    lvi.SubItems.Add(cf.LookupTable.Name);
                }
                lvi.Tag = cf;
                listViewItems.Add(lvi);
            }
            LV_ServerObjects.InvokeIfRequired(s =>
            {
                s.Items.AddRange(listViewItems.ToArray());
                s.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
                s.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
            });
        }
Пример #6
0
        private void LoadProjectsList()
        {
            IEnumerable <PublishedProject> projectList =
                ProjContext.LoadQuery(ProjContext.Projects.Include(p => p.Name, p => p.Id, p => p.IsCheckedOut,
                                                                   p => p.Owner.LoginName, p => p.CheckedOutBy.LoginName, p => p.CheckedOutDate));

            ProjContext.ExecuteQuery();

            List <ListViewItem> listViewItems = new List <ListViewItem>();

            foreach (PublishedProject project in projectList)
            {
                ListViewItem lvi = new ListViewItem(project.Name);
                lvi.SubItems.Add(project.IsCheckedOut.ToString());
                lvi.SubItems.Add(project.Owner.LoginName);
                if (project.IsCheckedOut)
                {
                    lvi.SubItems.Add(project.CheckedOutBy.LoginName);
                    lvi.SubItems.Add(project.CheckedOutDate.ToString(CultureInfo.InvariantCulture));
                }
                lvi.Tag = project;
                Log.WriteVerbose(new SourceInfo(), TB_Status, "Found Project {0}", project.Name);
                listViewItems.Add(lvi);
            }
            LV_ServerObjects.InvokeIfRequired(s =>
            {
                s.Items.Clear();
                s.Columns.Clear();
                s.Columns.Add(new ColumnHeader {
                    Text = "Name", DisplayIndex = 0, Width = 20
                });
                s.Columns.Add(new ColumnHeader {
                    Text = "CheckOut", DisplayIndex = 0, Width = 20
                });
                s.Columns.Add(new ColumnHeader {
                    Text = "Owner", DisplayIndex = 0, Width = 30
                });
                s.Columns.Add(new ColumnHeader {
                    Text = "CheckOut By", DisplayIndex = 0, Width = 20
                });
                s.Columns.Add(new ColumnHeader {
                    Text = "CheckOut Date", DisplayIndex = 0, Width = 20
                });
                s.Items.AddRange(listViewItems.ToArray());
                s.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
                s.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
            });
        }
Пример #7
0
        private void LoadResourcesList()
        {
            LV_ServerObjects.InvokeIfRequired(s =>
            {
                s.Items.Clear();
                s.Columns.Clear();
                s.Columns.Add(new ColumnHeader {
                    Text = "Id", DisplayIndex = 0, Width = 20
                });
                s.Columns.Add(new ColumnHeader {
                    Text = "Name", DisplayIndex = 0, Width = 20
                });
                s.Columns.Add(new ColumnHeader {
                    Text = "Active", DisplayIndex = 0, Width = 20
                });
                s.Columns.Add(new ColumnHeader {
                    Text = "CheckOut", DisplayIndex = 0, Width = 20
                });
                s.Columns.Add(new ColumnHeader {
                    Text = "Modified", DisplayIndex = 0, Width = 20
                });
                s.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
                s.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
            });

            IEnumerable <EnterpriseResource> resourcesList = ProjContext.LoadQuery(ProjContext.EnterpriseResources.Include(p => p.Name, p => p.Id, p => p.IsCheckedOut, p => p.Modified, p => p.IsActive));

            ProjContext.ExecuteQuery();
            List <ListViewItem> listViewItems = new List <ListViewItem>();

            foreach (EnterpriseResource res in resourcesList)
            {
                ListViewItem lvi = new ListViewItem(res.Id.ToString());
                lvi.SubItems.Add(res.Name);
                lvi.SubItems.Add(res.IsActive.ToString());
                lvi.SubItems.Add(res.IsCheckedOut.ToString());
                lvi.SubItems.Add(res.Modified.ToString(CultureInfo.InvariantCulture));
                lvi.Tag = res;
                listViewItems.Add(lvi);
            }
            LV_ServerObjects.InvokeIfRequired(s =>
            {
                s.Items.AddRange(listViewItems.ToArray());
                s.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
                s.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
            });
        }
        private void LoadLookupTables()
        {
            IEnumerable <LookupTable> lookupTables1 = ProjContext.LoadQuery(ProjContext.LookupTables);

            ProjContext.ExecuteQuery();
            Dictionary <string, LookupTable> lookupTables = new Dictionary <string, LookupTable> {
                { "Select", null }
            };

            foreach (LookupTable lt in lookupTables1)
            {
                lookupTables.Add(lt.Name, lt);
            }
            CB_LookupTable.InvokeIfRequired(cb =>
            {
                cb.DataSource    = new BindingSource(lookupTables, null);
                cb.DisplayMember = "Key";
                cb.ValueMember   = "Value";
            });
        }
        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})");
        }
Пример #10
0
        private void LoadLookupTablesList()
        {
            LV_ServerObjects.InvokeIfRequired(s =>
            {
                s.Items.Clear();
                s.Columns.Clear();
                s.Columns.Add(new ColumnHeader {
                    Text = "Id", DisplayIndex = 0, Width = 20
                });
                s.Columns.Add(new ColumnHeader {
                    Text = "Name", DisplayIndex = 0, Width = 20
                });
                s.Columns.Add(new ColumnHeader {
                    Text = "Type", DisplayIndex = 0, Width = 20
                });
                s.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
                s.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
            });

            IEnumerable <LookupTable> lookupFieldList = ProjContext.LoadQuery(ProjContext.LookupTables.Include(r => r.Name, r => r.Id, r => r.FieldType));

            ProjContext.ExecuteQuery();
            List <ListViewItem> listViewItems = new List <ListViewItem>();

            foreach (LookupTable lt in lookupFieldList)
            {
                ListViewItem lvi = new ListViewItem(lt.Id.ToString());
                lvi.SubItems.Add(lt.Name);
                lvi.SubItems.Add(lt.FieldType.ToString());
                lvi.Tag = lt;
                listViewItems.Add(lvi);
            }
            LV_ServerObjects.InvokeIfRequired(s =>
            {
                s.Items.AddRange(listViewItems.ToArray());
                s.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
                s.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
            });
        }
Пример #11
0
        private void LoadCalendarsList()
        {
            LV_ServerObjects.InvokeIfRequired(s =>
            {
                s.Items.Clear();
                s.Columns.Clear();
                s.Columns.Add(new ColumnHeader {
                    Text = "Id", DisplayIndex = 0, Width = 20
                });
                s.Columns.Add(new ColumnHeader {
                    Text = "Name", DisplayIndex = 0, Width = 20
                });
                s.Columns.Add(new ColumnHeader {
                    Text = "Changed Date", DisplayIndex = 0, Width = 20
                });
                s.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
                s.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
            });

            IEnumerable <Calendar> calendarList = ProjContext.LoadQuery(ProjContext.Calendars.Include(r => r.Name, r => r.Id, r => r.Modified));

            ProjContext.ExecuteQuery();
            List <ListViewItem> listViewItems = new List <ListViewItem>();

            foreach (Calendar cal in calendarList)
            {
                ListViewItem lvi = new ListViewItem(cal.Id.ToString());
                lvi.SubItems.Add(cal.Name);
                lvi.SubItems.Add(cal.Modified.ToString(CultureInfo.InvariantCulture));
                lvi.Tag = cal;
                listViewItems.Add(lvi);
            }
            LV_ServerObjects.InvokeIfRequired(s =>
            {
                s.Items.AddRange(listViewItems.ToArray());
                s.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
                s.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
            });
        }
        private void GetDraftTeamForSelectedProject()
        {
            PublishedProject project = null;

            LV_Projects.InvokeIfRequired(s => project = s.SelectedItems[0].Tag as PublishedProject);
            LV_ProjectResources.InvokeIfRequired(s => s.Items.Clear());

            IEnumerable <DraftProjectResource> resourceList = ProjContext.LoadQuery(project.Draft.ProjectResources);

            ProjContext.ExecuteQuery();

            DraftProjectResource[] draftProjectResources = resourceList.ToArray();

            foreach (ListViewItem lvi in draftProjectResources.Select(res => new ListViewItem(res.Name)
            {
                Tag = res
            }))
            {
                LV_ProjectResources.InvokeIfRequired(s => s.Items.Add(lvi));
            }

            LV_ProjectResources.InvokeIfRequired(s => s.Columns[0].Text = $"Project Resources({draftProjectResources.Length})");
        }
Пример #13
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})";
            });
        }
Пример #14
0
        private void LoadProjects()
        {
            Log.WriteVerbose(new SourceInfo(), "Loading projects");

            IEnumerable <PublishedProject> projectList = ProjContext.LoadQuery(ProjContext.Projects.Include(p => p.Name, p => p.Owner, p => p.Id, p => p.Owner.Title, p => p.IsCheckedOut, p => p.CheckedOutBy.Title, p => p.Draft.LastSavedDate, p => p.Draft));

            ProjContext.ExecuteQuery();
            List <ListViewItem> listViewItems = new List <ListViewItem>();

            foreach (PublishedProject project in projectList)
            {
                ListViewItem lvi = new ListViewItem(project.Name);
                lvi.SubItems.Add(project.Owner.Title);
                if (project.CheckedOutBy.IsNull())
                {
                    lvi.SubItems.Add(String.Empty);
                }
                else
                {
                    lvi.SubItems.Add(project.CheckedOutBy.Title);
                }
                lvi.SubItems.Add(project.Draft.LastSavedDate.ToString(CultureInfo.InvariantCulture));

                lvi.Tag = project;
                Log.WriteVerbose(new SourceInfo(), "Found Project:{0}", project.Name);
                listViewItems.Add(lvi);
            }
            LV_Projects.InvokeIfRequired(s =>
            {
                s.Items.Clear();
                s.Items.AddRange(listViewItems.ToArray());
                s.Columns[0].Text = $"Projects({listViewItems.Count})";
                LV_Projects.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
                LV_Projects.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
            });
        }
Пример #15
0
        private void DataGridViewClick(object sender, EventArgs e)
        {
            DataGridView dgv = sender as DataGridView;

            var currentCell = dgv?.CurrentCell;

            if (currentCell == null || currentCell.ReadOnly)
            {
                return;
            }

            if (currentCell.OwningColumn.ValueType == typeof(DateTime))
            {
                Rectangle oRectangle = dgv.GetCellDisplayRectangle(currentCell.ColumnIndex, currentCell.RowIndex, true);
                _dateTimePicker = new DateTimePicker
                {
                    Format   = DateTimePickerFormat.Short,
                    Size     = new Size(oRectangle.Width, oRectangle.Height),
                    Location = new Point(oRectangle.X, oRectangle.Y)
                };
                if (currentCell.FormattedValue.ToString() != string.Empty)
                {
                    _dateTimePicker.Value = (DateTime)currentCell.Value;
                }
                _dateTimePicker.CloseUp     += DateTimePickerCloseUp;
                _dateTimePicker.TextChanged += DateTimePickerOnTextChange;
                dgv.Controls.Add(_dateTimePicker);
                _dateTimePicker.Visible = true;
            }
            else if (currentCell.OwningColumn.ValueType.IsEnum)
            {
                var enumToDictionary = ParseTypeToDictionary(currentCell.OwningColumn.ValueType);
                DataGridViewComboBoxCell dgComboCell = new DataGridViewComboBoxCell
                {
                    DisplayStyle  = DataGridViewComboBoxDisplayStyle.Nothing,
                    DataSource    = new BindingSource(enumToDictionary, null),
                    DisplayMember = "Value",
                    ValueMember   = "Key"
                };
                dgv[currentCell.ColumnIndex, currentCell.RowIndex].ValueType = dgComboCell.ValueType;
                dgv[currentCell.ColumnIndex, currentCell.RowIndex]           = dgComboCell;
            }
            else if (currentCell.OwningColumn.ValueType.IsSubclassOf(typeof(ClientObject)))
            {
                if (currentCell.OwningColumn.ValueType.Name.Contains("Calendar"))
                {
                    if (_calendars == null)
                    {
                        _calendars = ProjContext.LoadQuery(ProjContext.Calendars);
                        ProjContext.ExecuteQuery();
                    }
                    Dictionary <string, Calendar> blah = _calendars.ToDictionary(er => er.Name, er => er);
                    _dgvComboCell = new DataGridViewComboBoxCell
                    {
                        DataSource    = new BindingSource(blah, null),
                        DisplayMember = "Key",
                        ValueMember   = "Value",
                        ValueType     = typeof(Calendar)
                    };
                    dgv[currentCell.ColumnIndex, currentCell.RowIndex] = _dgvComboCell;
                }
                else if (currentCell.OwningColumn.ValueType.Name.Contains("User"))
                {
                    if (_enterpriseResources == null)
                    {
                        _enterpriseResources = ProjContext.LoadQuery(ProjContext.EnterpriseResources.Include(p => p.User));
                        ProjContext.ExecuteQuery();
                    }

                    Dictionary <string, User> blah =
                        _enterpriseResources.Where(resource => !resource.User.IsNull())
                        .ToDictionary(resource => resource.User.Title, resource => resource.User);

                    _dgvComboCell = new DataGridViewComboBoxCell
                    {
                        DisplayMember = "Key",
                        ValueMember   = "Value",
                        ValueType     = typeof(User),
                        DataSource    = new BindingSource(blah, null)
                    };
                    dgv[currentCell.ColumnIndex, currentCell.RowIndex] = _dgvComboCell;
                }
            }
        }
Пример #16
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);
        }