public async Task <WorkItemModel> CreateLinkedWorkitem(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, Priority = "2", Title = title, Severity = "2 - High" }; ListParams.AddRange(GetBugFields(field)); break; default: //Issue,Feature,Task field = new Fields() { AssignedTo = workItem.assignedTo, Description = description, Priority = "2", Title = title, Severity = "2 - High" }; ListParams.AddRange(GetTaskIssueFeatureFields(field)); break; } foreach (var item in ListParams)//there will be one type of witalways { patchDocument.Add( new JsonPatchOperation() { Operation = Microsoft.VisualStudio.Services.WebApi.Patch.Operation.Add, Path = item.Path, Value = item.Value, } ); } if (workItem.parentWit > 0) { /* patchDocument.Add(new Microsoft.VisualStudio.Services.WebApi.Patch.Json.JsonPatchOperation() * { * Operation = Microsoft.VisualStudio.Services.WebApi.Patch.Operation.Add, * Path = "/fields/System.Title", * Value = "childWIT" * });*/ patchDocument.Add(new Microsoft.VisualStudio.Services.WebApi.Patch.Json.JsonPatchOperation() { Operation = Microsoft.VisualStudio.Services.WebApi.Patch.Operation.Add, Path = "/relations/-", Value = new { rel = "System.LinkTypes.Hierarchy-Reverse", url = poolObj.VssConnection.Uri.AbsoluteUri + "/" + workItem.projectname + "/_apis/wit/workItems/" + workItem.parentWit } }); } var workitem = await workItemTrackingClient.CreateWorkItemAsync(patchDocument, workItem.projectid, workItem.type); if (workitem != null) { workItemModel.Id = workitem.Id.Value; workItemModel.url = workitem.Url; } } catch (Exception ex) { } finally { _builderPool.Return(poolObj); } return(workItemModel); }
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); }