Ejemplo n.º 1
0
        public static async Task <string> GetProjectSummary(int vsoId)
        {
            using (WorkItemTrackingHttpClient workItemTrackingHttpClient = GetWorkItemTrackingHttpClient())
            {
                try
                {
                    WorkItem workitem = await workItemTrackingHttpClient.GetWorkItemAsync(vsoId);

                    string projectStatus = $"<b>Description</b>: {workitem.Fields[DescriptionFieldName]}\n\n" +
                                           $"<b>Assigned to</b>: {workitem.Fields["System.AssignedTo"]}\n\n" +
                                           $"<b>Due on</b>: {workitem.Fields["Microsoft.VSTS.Scheduling.TargetDate"]}\n\n" +
                                           $"<b>Current State</b>: {workitem.Fields[StateFieldName]}\n\n";

                    Trace.TraceInformation($"Task successfully fetched task {workitem.Id}");

                    return(projectStatus);
                }
                catch (Exception ex)
                {
                    WebApiConfig.TelemetryClient.TrackException(ex, new Dictionary <string, string>
                    {
                        { "function", "GetProjectSummary" },
                        { "vsoId", vsoId.ToString() }
                    });

                    throw;
                }
            }
        }
        private async Task <WorkItem> CreateChildTask(Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models.WorkItem parentPbi, string title)
        {
            var document = new JsonPatchDocument();

            document.Add(
                new JsonPatchOperation()
            {
                Path      = "/fields/System.Title",
                Operation = Microsoft.VisualStudio.Services.WebApi.Patch.Operation.Add,
                Value     = title
            });

            document.Add(
                new JsonPatchOperation()
            {
                Path      = "/relations/-",
                Operation = Microsoft.VisualStudio.Services.WebApi.Patch.Operation.Add,
                Value     = new
                {
                    rel = "System.LinkTypes.Hierarchy-Reverse",
                    url = parentPbi.Url
                }
                //https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_apis/wit/workItems/297
            });

            return(await witClient.CreateWorkItemAsync(document, projectId, "Task"));
        }
Ejemplo n.º 3
0
        public static async Task CloseProject(int vsoId)
        {
            JsonPatchDocument patchDocument = new JsonPatchDocument
            {
                new JsonPatchOperation()
                {
                    Operation = Operation.Add, Path = "/fields/System.State", Value = "Closed"
                },
            };

            using (WorkItemTrackingHttpClient workItemTrackingHttpClient = GetWorkItemTrackingHttpClient())
            {
                try
                {
                    WorkItem result =
                        await workItemTrackingHttpClient.UpdateWorkItemAsync(patchDocument, vsoId);

                    Trace.TraceInformation($"Task successfully closed: Research task {result.Id}");
                }
                catch (Exception ex)
                {
                    WebApiConfig.TelemetryClient.TrackException(ex, new Dictionary <string, string>
                    {
                        { "function", "CloseProject" },
                        { "vsoId", vsoId.ToString() }
                    });

                    throw;
                }
            }
        }
Ejemplo n.º 4
0
        public static async Task <int> AddTeamsAgentConversationId(
            int researchVsoId,
            string teamsConversationId)
        {
            Uri    uri     = new Uri(Uri);
            string project = Project;

            JsonPatchDocument patchDocument = new JsonPatchDocument
            {
                new JsonPatchOperation()
                {
                    Operation = Operation.Add, Path = "/fields/Custom.TeamsConversationId", Value = teamsConversationId
                },
            };

            using (WorkItemTrackingHttpClient workItemTrackingHttpClient = GetWorkItemTrackingHttpClient())
            {
                try
                {
                    WorkItem result =
                        await workItemTrackingHttpClient.UpdateWorkItemAsync(patchDocument, researchVsoId);

                    Trace.TraceInformation(@"Bug Successfully Created: Research task #{0}", result.Id);

                    return((int)result.Id);
                }
                catch (Exception ex)
                {
                    Trace.TraceError(@"Error creating research task: {0}", ex.InnerException.Message);
                    throw;
                }
            }
        }
Ejemplo n.º 5
0
Archivo: Query.cs Proyecto: xul8tr/Qwiq
 private WorkItem CreateItemEager(Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models.WorkItem workItem)
 {
     return(new WorkItem(
                workItem,
                LookUpWorkItemType(workItem),
                // REVIEW: Delegate allocation from method group
                LinkFunc));
 }
Ejemplo n.º 6
0
Archivo: Query.cs Proyecto: xul8tr/Qwiq
        private WorkItem CreateItemLazy(Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models.WorkItem workItem)
        {
            IWorkItemType WorkItemTypeFactory()
            {
                return(LookUpWorkItemType(workItem));
            }

            return(new WorkItem(workItem, new Lazy <IWorkItemType>(WorkItemTypeFactory), LinkFunc));
        }
Ejemplo n.º 7
0
 public WorkItem(azure.WorkItem azureWI, int duration)
 {
     Id = azureWI.Id ?? -1;
     azureWI.Fields.TryGetValue <string>("System.WorkItemType", out var tmpWiType);
     WiType = tmpWiType;
     azureWI.Fields.TryGetValue <string>("System.Title", out var tmpTitle);
     Title    = tmpTitle;
     Duration = duration;
 }
 string TryGetFieldContent(WorkItem workItem, string fieldName, string defaultText)
 {
     if (workItem.Fields.ContainsKey(fieldName))
     {
         return((string)workItem.Fields[fieldName]);
     }
     else
     {
         return(defaultText);
     }
 }
Ejemplo n.º 9
0
 private void CreateWorkItemLinkToParentInAzure(WorkItem parent, WorkItem child, Guid projectId)
 {
     try
     {
         var linkFromParentToChild = child.GetParentLinkPatch();
         UpdateWorkItem(linkFromParentToChild, projectId, parent.Id.Value, false, false);
     }
     catch (Exception e)
     {
         Logger.Error($"{GetType()} Failed saving workitem relation from '{parent.Id}' to '{child.Id}'{Environment.NewLine}\t{e.Message}");
     }
 }
Ejemplo n.º 10
0
 public WorkItem(
     Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models.WorkItem item,
     Lazy <IWorkItemType> wit,
     Func <string, IWorkItemLinkType> linkFunc)
     : base(wit)
 {
     Contract.Requires(item != null);
     Contract.Requires(wit != null);
     Contract.Requires(linkFunc != null);
     _item     = item ?? throw new ArgumentNullException(nameof(item));
     _linkFunc = linkFunc ?? throw new ArgumentNullException(nameof(linkFunc));
     Url       = _item.Url;
 }
Ejemplo n.º 11
0
 public WorkItem(
     [NotNull] Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models.WorkItem item,
     [NotNull] IWorkItemType wit,
     [NotNull] Func <string, IWorkItemLinkType> linkFunc)
     : base(wit)
 {
     Contract.Requires(item != null);
     Contract.Requires(wit != null);
     Contract.Requires(linkFunc != null);
     _item     = item ?? throw new ArgumentNullException(nameof(item));
     _linkFunc = linkFunc ?? throw new ArgumentNullException(nameof(linkFunc));
     Url       = _item.Url;
     _uri      = new Uri(_item.Url, UriKind.Absolute);
 }
        private static Activity DisplayVSOBug(Activity activity, WorkItem workItem)
        {
            var wiState  = workItem.Fields["System.State"].ToString();
            var title    = $"#{workItem.Id}: {workItem.Fields["System.Title"]}";
            var subTitle = $"• Priority: {workItem.Fields["Microsoft.VSTS.Common.Priority"]}\r• State: {wiState}\r • Assigned To {workItem.Fields.GetValueOrDefault("System.AssignedTo") ?? "Not yet assigned"}\r";
            var url      = $"{CollectionUri}/OneClip/_workItems?triage=true&_a=edit&id={workItem.Id}";

            var reply = activity.CreateReply();

            reply.Recipient   = activity.From;
            reply.Type        = ActivityTypes.Message;
            reply.TextFormat  = "markdown";
            reply.Attachments = new List <Attachment>
            {
                CreateCard(title, subTitle, "bug.png", url).ToAttachment()
            };

            return(reply);
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Initialize a wrapper object from a AzDO WorkItem
        /// </summary>
        /// <param name="workItem">Azure DevOps WorkItem</param>
        internal void Initialize(WitModel workItem)
        {
            if (workItem == null)
            {
                throw new ArgumentNullException(nameof(workItem));
            }

            if (this.witModel != null &&
                this.witModel.Id != workItem.Id)
            {
                throw new ArgumentException("WorkItem Id mismatch", nameof(workItem));
            }

            if (!object.ReferenceEquals(workItem, this.witModel))
            {
                this.witModel = workItem;
            }

            this.ResetToInitialState();
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Execute a WIQL query to return a list of bugs using the .NET client library
        /// </summary>
        /// <returns>List of Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models.WorkItem</returns>
        public static async Task <string> GetProjectStatus(int vsoId)
        {
            try
            {
                using (WorkItemTrackingHttpClient workItemTrackingHttpClient = GetWorkItemTrackingHttpClient())
                {
                    WorkItem workitem = await workItemTrackingHttpClient.GetWorkItemAsync(vsoId);

                    return(workitem.Fields[StateFieldName].ToString());
                }
            }
            catch (Exception e)
            {
                WebApiConfig.TelemetryClient.TrackException(e, new Dictionary <string, string>
                {
                    { "function", "GetProjectStatus" },
                    { "vsoId", vsoId.ToString() }
                });

                throw;
            }
        }
Ejemplo n.º 15
0
Archivo: Query.cs Proyecto: xul8tr/Qwiq
        private IWorkItemType LookUpWorkItemType([NotNull] Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models.WorkItem workItem)
        {
            if (!workItem.Fields.TryGetValue(CoreFieldRefNames.TeamProject, out object tp))
            {
                throw new InvalidOperationException($"Field '{CoreFieldRefNames.TeamProject}' is required.");
            }
            if (!workItem.Fields.TryGetValue(CoreFieldRefNames.WorkItemType, out object wit))
            {
                throw new InvalidOperationException($"Field '{CoreFieldRefNames.WorkItemType}' is required.");
            }

            var tps  = tp as string;
            var wits = wit as string;

            if (string.IsNullOrWhiteSpace(tps))
            {
                throw new InvalidOperationException(
                          $"Value for field '{CoreFieldRefNames.TeamProject}' cannot be null or empty.");
            }
            if (string.IsNullOrWhiteSpace(wits))
            {
                throw new InvalidOperationException(
                          $"Value for field '{CoreFieldRefNames.WorkItemType}' cannot be null or empty.");
            }

            if (!_workItemStore.Projects.Contains(tps))
            {
                throw new InvalidOperationException($"No project for specified value '{tps}'.");
            }
            var proj = _workItemStore.Projects[tps];

            if (!proj.WorkItemTypes.Contains(wits))
            {
                throw new InvalidOperationException($"No work item type for specified value '{wits}'.");
            }
            return(proj.WorkItemTypes[wits]);
        }
        private void AddWorkItemRow(Table iterationTable, WorkItem workItem)
        {
            Row currentRow;

            try
            {
                currentRow = iterationTable.Rows.Add();
                currentRow.Range.Font.Size = 7;
                currentRow.Range.Font.Bold = 0;
                currentRow.Cells[1].Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphLeft;
                currentRow.Cells[2].Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphLeft;
                currentRow.Cells[3].Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;
                currentRow.Cells[4].Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphLeft;
                currentRow.Cells[1].Range.Text = TryGetFieldContent(workItem, $"System.{nameof(CoreField.Title)}", "Kein Titel definiert.");
                currentRow.Cells[2].Range.Text = TryGetFieldContent(workItem, $"System.{nameof(CoreField.AssignedTo)}", "Team effort.");
                currentRow.Cells[3].Range.Text = TryGetFieldContent(workItem, $"System.{nameof(CoreField.WorkItemType)}", "Allgemein.");
                TryInsertHtmlAtRange(currentRow.Cells[4].Range, TryGetFieldContent(workItem, $"System.{nameof(CoreField.Description)}", "<p>Keine nähere Beschreibung hinterlegt.</p>"));
                currentRow.Cells[1].Range.Font.Bold = 1;
                currentRow.Cells[4].Range.Font.Size = 7;
            }
            catch (Exception ex)
            {
            }
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Creates a TFS Work Item
        /// </summary>
        /// <param name="item">TFS Item with fields filled out.</param>
        /// <returns>The created Work Item</returns>
        public TFS_API.WorkItem CreateWorkItem(TFS_Item item)
        {
            JsonPatchDocument          patchDocument = GeneratePatchDocument(item);
            VssConnection              connection    = new VssConnection(_uri, _credentials);
            WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient <WorkItemTrackingHttpClient>();

            try
            {
                string workItemType = item.WorkItemType == Enums.WorkItemType.UserStory ? "User Story" : item.WorkItemType.ToString();

                TFS_API.WorkItem result = workItemTrackingHttpClient.CreateWorkItemAsync(patchDocument, _project, workItemType).Result;
                Console.WriteLine($"{item.WorkItemType} Successfully Created: {item.WorkItemType} #{0}", result.Id);
                return(result);
            }
            catch (AggregateException ex)
            {
                Console.WriteLine($"Error creating {item.WorkItemType}: {ex.InnerException.Message}");
                return(null);
            }
            catch (Exception)
            {
                throw;
            }
        }
Ejemplo n.º 18
0
        public static async Task <string> GetAgentConversationIdForVso(int vsoId)
        {
            using (WorkItemTrackingHttpClient workItemTrackingHttpClient = VsoHelper.GetWorkItemTrackingHttpClient())
            {
                try
                {
                    WorkItem workitem = await workItemTrackingHttpClient.GetWorkItemAsync(vsoId);

                    return((string)(workitem.Fields.TryGetValue(AgentConversationIdFieldName, out object conversationId)
                        ? conversationId
                        : ""));
                }
                catch (Exception ex)
                {
                    WebApiConfig.TelemetryClient.TrackException(ex, new Dictionary <string, string>
                    {
                        { "function", "GetAgentConversationIdForVso" },
                        { "vsoId", vsoId.ToString() },
                    });

                    throw;
                }
            }
        }