Beispiel #1
0
        private string UpdateWorkItem(UpdateWorkItemRequest request)
        {
            var updateResult = _tfsCrudManager.UpdateWorkItem(request);

            if (updateResult == null)
            {
                _lastChangedWorkItems.FailureCount++;
            }
            else
            {
                _lastChangedWorkItems.SuccessCount++;
            }
            return(updateResult);
        }
Beispiel #2
0
        public string UpdateWorkItem(UpdateWorkItemRequest request)
        {
            try
            {
                using (WebClient client = new WebClient())
                {
                    client.UseDefaultCredentials = true;
                    client.Headers.Add("Content-Type", "application/json-patch+json");
                    client.Encoding = Encoding.UTF8;

                    var    operations = new List <object>();
                    string opValue    = null;
                    string columnName = string.Empty;

                    if (request.State != Constants.Tfs.State.None)
                    {
                        opValue = "replace";
                        operations.Add(new
                        {
                            op    = opValue,
                            path  = "/fields/System.State",
                            value = request.State.GetDescription()
                        });
                    }
                    if (request.Title != null)
                    {
                        columnName = "System.Title";
                        opValue    = request.ExistingFields[columnName] == null ? "add" : "replace";
                        operations.Add(new
                        {
                            op    = opValue,
                            path  = $"/fields/{columnName}",
                            value = request.Title
                        });
                    }
                    if (request.Tags != null)
                    {
                        columnName = "System.Tags";
                        opValue    = request.ExistingFields[columnName] == null ? "add" : "replace";
                        operations.Add(new
                        {
                            op    = opValue,
                            path  = $"/fields/{columnName}",
                            value = request.Tags
                        });
                    }
                    if (request.AssignedTo != null)
                    {
                        columnName = "System.AssignedTo";
                        opValue    = request.ExistingFields[columnName] == null ? "add" : "replace";
                        operations.Add(
                            new
                        {
                            op    = opValue,
                            path  = $"/fields/{columnName}",
                            value = request.AssignedTo
                        }
                            );
                    }
                    if (request.Comment != null)
                    {
                        opValue = "add";
                        operations.Add(
                            new
                        {
                            op    = opValue,
                            path  = "/fields/System.History",
                            value = request.Comment
                        }
                            );
                    }
                    var serializedData = JsonConvert.SerializeObject(operations);
                    var url            = string.Format(_getSetWorkItemUrlFormat, request.WorkItemId);
                    _logger.Trace($"Sending followind data to url [PATCH][{url}]: {serializedData}");
                    var responseBody = client.UploadString(url, "PATCH", serializedData);
                    return(responseBody);
                }
            }
            catch (Exception ex)
            {
                _logger.Log(LogLevel.Error, $"Error updating work item #{request.WorkItemId}: {ex}");
            }
            return(null);
        }