Ejemplo n.º 1
0
        private WorkItem UpdateExisitingWorkItem(WorkItem wi, ExceptionEntity exception)
        {
            //string comment, string changeSet, WorkItem wi, string username
            // wi.Open();
            //if (wi.Links == null)
            //{
            //    ServiceLog.Warning($"Links is null for work item {wi.Id}. Work Item  will not be updated");
            //    return wi;
            //}

            if (IsWorkItemFixed(wi))
            {
                ServiceLog.Information($"Workitem {wi.Id} is fixed, update incident count, add comment ");
                UpdateCommentAndRefCount(exception.Comment, wi, exception.Username);
                return(wi);
            }

            if (IsWorkItemClosedButNotFixed(wi))
            {
                ServiceLog.Information(
                    $"Workitem {wi.Id} is closed but not fixed, update incident count, add comment, reopen ");
                UpdateCommentAndRefCount(exception.Comment, wi, exception.Username);
                wi.State("Approved");
                return(wi);
            }

            //If not limit reached increment count, and append comment.
            if (!IsLimitReached(wi))
            {
                ServiceLog.Information($"Updating existing Workitem {wi.Id}");
                UpdateCommentAndRefCount(exception.Comment, wi, exception.Username);
                UpdateBuildVersion(exception.Version, wi);
                UpdateApplication(exception.ApplicationName, wi);
            }
            else
            {
                ServiceLog.Information($"Workitem {wi.Id} is fixed, or has reached max # refCount ");
                //Set to null so we don't update as the workitem is either resolved
                //or max refcounts have been reached.
                wi = null;
            }

            return(wi);
        }
Ejemplo n.º 2
0
        public void RegisterException(ExceptionEntity exceptionEntity)
        {
            WorkItem wi        = null;
            WorkItem linkedWi  = null;
            var      workItems = new ExceptionWorkItemCollection(exceptionEntity, this.ApplicationInfo);

            if (!workItems.HasOpenWorkItems)
            {
                if (workItems.HasWorkItemsWithHigherChangeset)
                {
                    wi = workItems.GetWorkItemWithHigherChangeset();
                    // If not Open and new exception has higher version, we should create new wi with link to the old one
                    if (HasHigherVersion(exceptionEntity.Version, wi))
                    {
                        linkedWi = wi;
                        wi       = null;
                    }
                }
                else
                {
                    wi = workItems.GetLatestNotOpenWorkItem();
                }
            }
            else
            {
                wi = workItems.OpenWorkItems.FirstOrDefault();
                if (wi != null && HasLowerVersion(exceptionEntity.Version, wi))
                {
                    ServiceLog.Information(
                        $"Exception with newer version already exists with ID={wi.Id}. Coming exception will be dropped.");
                    return;
                }
            }

            if (wi == null)
            {
                var json = CreateNewException(exceptionEntity, this.ApplicationInfo);
                SendException(json.Json, ExceptionWorkItemType);
                return;
            }
            else
            {
                wi = UpdateExisitingWorkItem(wi, exceptionEntity);
            }

            if (wi == null)
            {
                return;
            }

            var errors = wi.Validate();

            if (!errors.Any())
            {
                ServiceLog.Error($"Could not create a workitem but no errors found in it  {wi.Id}");
            }
            else
            {
                var errorString = new StringBuilder();
                foreach (var f in errors)
                {
                    errorString.AppendLine($"Error: {f}");
                }
                ServiceLog.Warning("Workitem failed validation: " + errorString);

                //LARS: should throw exception when exception is not valid:
                throw new ArgumentException("TFSException contains invalid fields: " + errorString);
            }
        }