コード例 #1
0
        private void CreateResources()
        {
            EnterpriseResourceType selectedEnterpriseResourceType = EnterpriseResourceType.Work;

            cbxResType.InvokeIfRequired(s => selectedEnterpriseResourceType = (EnterpriseResourceType)cbxResType.SelectedValue);
            for (int resourceCount = 1; resourceCount <= numResources.Value; resourceCount++)
            {
                EnterpriseResourceCreationInformation erCi = new EnterpriseResourceCreationInformation
                {
                    Name         = txtResourceName.Text + resourceCount,
                    IsInactive   = CB_Inactive.Checked,
                    IsGeneric    = CB_Generic.Checked,
                    IsBudget     = CB_Budget.Checked,
                    ResourceType = selectedEnterpriseResourceType
                };
                Log.WriteVerbose(new SourceInfo(), TB_Status, "Creating Resource with name {0}", erCi.Name);
                ProjContext.EnterpriseResources.Add(erCi);
            }
            ProjContext.EnterpriseResources.Update();
            ProjContext.ExecuteQuery();
        }
コード例 #2
0
        public async Task <IEnumerable <EnterpriseResource> > GetAllByTypeAsync(EnterpriseResourceType resourceType)
        {
            IEnumerable <EnterpriseResource> enterpriseResources = new List <EnterpriseResource>();

            try
            {
                var localEnterpriseResources = _projectContext.LoadQuery(_projectContext.EnterpriseResources.Where(p => p.ResourceType == resourceType));
                await _projectContext.ExecuteQueryAsync();

                // Force a new list to avoid returning same list than stored in context
                enterpriseResources = new List <EnterpriseResource>(localEnterpriseResources.ToArray());
            }
            catch (Exception ex)
            {
                // TODO: LOG ERROR!

                throw new CsomClientException($"Unexcepted error getting enterprise resources by type. " +
                                              $"Project context url is {_projectContext.Url}.", ex);
            }

            return(enterpriseResources);
        }