Пример #1
0
        public async Task <WorkItemModel> CreateWorkitem(CreateWorkItem workItem)
        {
            WorkItemModel        workItemModel = new WorkItemModel();
            DevOpsConnectionPool poolObj       = _builderPool.Get();

            try
            {
                List <Params> ListParams = new List <Params>();
                //VssCredentials creds = new VssBasicCredential(string.Empty, personalaccesstoken);
                //VssConnection connection = new VssConnection(new Uri(c_collectionUri), creds);
                //ProjectHttpClient projectClient = connection.GetClient<ProjectHttpClient>();

                var workItemTrackingClient = poolObj.VssConnection.GetClient <WorkItemTrackingHttpClient>();

                JsonPatchDocument patchDocument = new JsonPatchDocument();
                Fields            field         = null;

                string title       = $"error deploying solution {workItem.crmsolutioname} in {workItem.crmorgurl}";
                string bugtest     = $"error deploying solution {workItem.crmsolutioname} in {workItem.crmorgurl}. \n see attachment file for full error log.";
                string description = $"error deploying solution {workItem.crmsolutioname} in {workItem.crmorgurl}. \n see attachment file for full error log.";

                switch (workItem.type.ToLower())
                {
                case "bug":
                    field = new Fields()
                    {
                        AssignedTo = workItem.assignedTo,
                        BugText    = bugtest, //workItem.bugtest,
                        Priority   = "2",
                        Title      = title,   //workItem.title,
                        Severity   = "2 - High"
                    };
                    ListParams.AddRange(GetBugFields(field));
                    break;

                default:    //Issue,Feature,Task
                    field = new Fields()
                    {
                        AssignedTo  = workItem.assignedTo,
                        Description = description,    //workItem.description,
                        Priority    = "2",
                        Title       = title,
                        Severity    = "2 - High"
                    };
                    ListParams.AddRange(GetTaskIssueFeatureFields(field));
                    break;
                }

                foreach (var item in ListParams)
                {
                    patchDocument.Add(
                        new JsonPatchOperation()
                    {
                        Operation = Microsoft.VisualStudio.Services.WebApi.Patch.Operation.Add,
                        Path      = item.Path,
                        Value     = item.Value,
                    }
                        );
                }

                var workitem = await workItemTrackingClient.CreateWorkItemAsync(patchDocument, workItem.projectid, workItem.type);

                if (workitem != null)
                {
                    workItemModel.Id  = workitem.Id.Value;
                    workItemModel.url = workitem.Url;
                }
            }
            catch (Exception)
            {
            }
            finally
            {
                _builderPool.Return(poolObj);
            }
            return(workItemModel);
        }