public WorkItem CreateWorkItem(string pProjectName, string pWorkItemType, Dictionary <String, String> pFields, string pParentUrl) { JsonPatchDocument _patchDocument = new JsonPatchDocument(); foreach (var _key in pFields.Keys) { _patchDocument.Add(new JsonPatchOperation() { Operation = Operation.Add, Path = "/fields/" + _key, Value = pFields[_key] }); } _patchDocument.Add( new JsonPatchOperation() { Operation = Operation.Add, Path = "/relations/-", Value = new { rel = TFFields.LinkParent.RefName, url = pParentUrl, attributes = new { comment = "From service" } } } ); return(WitClient.CreateWorkItemAsync(_patchDocument, pProjectName, pWorkItemType).Result); }
public Task <LuisResult> QueryAsync(Uri uri, CancellationToken token) { var client = new WitClient(_witToken); var message = client.GetMessage(_text); return(Task.FromResult( new LuisResult( _text, message?.entities .Where(e => e.Key != "intent") .SelectMany(e => e.Value.Select( en => new EntityRecommendation(entity: en.value.ToString(), type: e.Key, score: en.confidence)) ).ToList() ?? Enumerable.Empty <EntityRecommendation>().ToList(), intents: message?.entities .Where(e => e.Key == "intent") .Select(e => { var entity = e.Value.FirstOrDefault(); return new IntentRecommendation(entity.value.ToString(), entity.confidence); }).ToList() ?? Enumerable.Empty <IntentRecommendation>().ToList() ) )); }
public void WitClient_GetMessage_Test() { WitClient client = new WitClient(Properties.Settings.Default.WitToken); Message message = client.GetMessage("hello"); Assert.IsNull(message.error); }
public WorkItemClassificationNode CreateIteration(string TeamProjectName, string IterationName, DateTime StartDate, DateTime FinishDate, string ParentIteration = "") { var project = ProjectClient.GetProject(TeamProjectName).Result; WorkItemClassificationNode newIteration = new WorkItemClassificationNode(); newIteration.Name = IterationName; newIteration.StructureType = TreeNodeStructureType.Iteration; if (StartDate != DateTime.MinValue && FinishDate != DateTime.MinValue) { newIteration.Attributes = new Dictionary <string, object>(); newIteration.Attributes.Add("startDate", StartDate); newIteration.Attributes.Add("finishDate", FinishDate); } var result = WitClient.CreateOrUpdateClassificationNodeAsync(newIteration, project.Id, TreeStructureGroup.Iterations).Result; if (ParentIteration != "") { result = MoveIteration(TeamProjectName, result, ParentIteration); } return(result); }
/// <summary> /// Finds the parent hierarchy. /// </summary> /// <param name="workItem">The work item.</param> /// <param name="parents">The parents.</param> /// <autogeneratedoc/> private async Task FindParentHierarchy(WorkItem workItem, List <string> parents) { var parentRelType = (parentRelationType ?? await GetParentRelationType()).ReferenceName; var parentIds = GetLinkedWorkItemIds(workItem, parentRelType); if (!parentIds.Any()) { return; } var wis = await WitClient.GetWorkItemsAsync(parentIds, null, null, WorkItemExpand.All); var parent = wis .Where( p => p.Fields.ContainsKey(WorkItemFieldType.Title) && p.Fields.ContainsKey(WorkItemFieldType.WorkItemType) && !string.IsNullOrWhiteSpace(p.Fields[WorkItemFieldType.WorkItemType] as string) && (p.Fields[WorkItemFieldType.WorkItemType] as string == WorkItemType.Epic || p.Fields[WorkItemFieldType.WorkItemType] as string == WorkItemType.Feature)) .FirstOrDefault(); if (parent != null) { parents.Add((string)parent.Fields[WorkItemFieldType.Title]); await FindParentHierarchy(parent, parents); } }
public void AddComment() { // Get a work item WorkItem wi = WitClient.GetWorkItemAsync(this.WorkItemsAdded.First()).Result; // Get the current last comment of the work item WorkItemComments comments = WitClient.GetCommentsAsync(wi.Id.Value).Result; var originalCommentCount = comments.Count; // Create a JSON patch document with an entry updating System.History JsonPatchDocument patchDocument = new JsonPatchDocument { new JsonPatchOperation() { Operation = Operation.Add, Path = "/fields/System.History", Value = "Added a comment" } }; // Update the work item with the patch document var result = WitClient.UpdateWorkItemAsync(patchDocument, wi.Id.Value).Result; // Get the current last comment of the work item var updatedComments = WitClient.GetCommentsAsync(result.Id.Value).Result; var updatedCommentCount = updatedComments.Count; // Show that the current last comment is different than the original last comment Console.WriteLine($"There were {originalCommentCount} comments"); Console.WriteLine($"There are now {updatedCommentCount} comments"); Console.WriteLine(); }
public void GetWorkItemCategory() { WorkItemTypeCategory workItemCategory = WitClient.GetWorkItemTypeCategoryAsync(TeamProject.Id, DefaultCategoryReferenceName).Result; Console.WriteLine($"Category with reference name: '{DefaultCategoryReferenceName}' in Project: '{TeamProject.Name}' has name: '{workItemCategory.Name}' and {workItemCategory.WorkItemTypes.Count()} work item types"); Console.WriteLine(); }
public void AddHyperLink() { string hyperlinkToAdd = "https://www.microsoft.com"; JsonPatchDocument patchDocument = new JsonPatchDocument { new JsonPatchOperation() { Operation = Operation.Add, Path = "/relations/-", Value = new { rel = "HyperLink", url = hyperlinkToAdd, attributes = new { comment = "Microsoft" } } } }; WorkItem wi = WitClient.GetWorkItemAsync(this.WorkItemsAdded.First()).Result; var relations = wi.Relations?.Where(r => r.Rel == "Hyperlink") ?? new List <WorkItemRelation>(); var previousRelationsCount = relations.Count(); var result = WitClient.UpdateWorkItemAsync(patchDocument, wi.Id.Value).Result; var newHyperlinks = result.Relations?.Where(r => r.Rel == "Hyperlink"); var newHyperlinksCount = newHyperlinks.Count(); Console.WriteLine($"Updated Existing Work Item: '{wi.Id}'. Had {previousRelationsCount} hyperlinks, now has {newHyperlinksCount}"); Console.WriteLine(); }
public void CreateWorkItem() { JsonPatchDocument patchDocument = new JsonPatchDocument { new JsonPatchOperation() { Operation = Operation.Add, Path = "/fields/System.Title", Value = "Work Item Created Using REST Client" }, new JsonPatchOperation() { Operation = Operation.Add, Path = "/fields/System.AssignedTo", Value = Connection.AuthorizedIdentity.DisplayName } }; try { WorkItem wi = WitClient.CreateWorkItemAsync(patchDocument, TeamProject.Name, DefaultWorkItemType.Name).Result; WorkItemsAdded.Add(wi.Id.Value); Console.WriteLine($"Created a work item with id: '{wi.Id}' and title: '{wi.Fields["System.Title"]}'"); } catch (AggregateException ex) { Console.WriteLine("Error creating workitem: '{0}'", ex.InnerException.Message); } finally { Console.WriteLine(); } }
public void GetWorkItem() { WorkItem wi = WitClient.GetWorkItemAsync(WorkItemsAdded.First()).Result; Console.WriteLine($"Opened a work item with id: '{wi.Id}' and title: '{wi.Fields["System.Title"]}'"); Console.WriteLine(); }
public void GetWorkItems() { JsonPatchDocument patchDocument = new JsonPatchDocument { new JsonPatchOperation() { Operation = Operation.Add, Path = "/fields/System.Title", Value = "2nd Work Item Created Using REST Client" } }; WorkItem wi = WitClient.CreateWorkItemAsync(patchDocument, TeamProject.Name, DefaultWorkItemType.Name).Result; WorkItemsAdded.Add(wi.Id.Value); // GetWorkItemsAsync can only return 200 items at a time, so only take the first 200 of the work items list. // Larger lists will require batching calls to GetWorkItemsAsync until the list is processed. List <WorkItem> workItems = WitClient.GetWorkItemsAsync(WorkItemsAdded.Take(200)).Result; foreach (var workItem in workItems) { Console.WriteLine($"{workItem.Id}: '{workItem.Fields["System.Title"]}'"); } Console.WriteLine(); }
public JarvisServer(IJarvisInput input, IJarvisOutput output) { _handlers = new Dictionary <string, Func <JarvisIntent, JarvisResponse> >(); _input = input; _output = output; _wit = new WitClient("ONEX5ZGJ7MST6WCRTDXTE5AO6K3RLZVA"); }
public WorkItemQueryResult GetWorkItemListWithWIQL(string pWiql, string pProjectName) { Wiql _wiql = new Wiql(); _wiql.Query = pWiql; return(WitClient.QueryByWiqlAsync(_wiql, pProjectName).Result); }
public void GetWorkItemType() { var workItemTypeName = DefaultWorkItemType.Name; var workItemType = WitClient.GetWorkItemTypeAsync(TeamProject.Id, workItemTypeName).Result; Console.WriteLine($"Obtained work item type '{workItemTypeName}', description: '{workItemType.Description}' using REST."); Console.WriteLine(); }
public WorkItemClassificationNode MoveIteration(string TeamProjectName, string IterationName, string ParentIteration) { WorkItemClassificationNode iteration = WitClient.GetClassificationNodeAsync( TeamProjectName, TreeStructureGroup.Iterations, IterationName, 4).Result; return(MoveIteration(TeamProjectName, iteration, ParentIteration)); }
public RESTClientScenarios(string collectionUri, string project) { Connection = new VssConnection(new Uri(collectionUri), new VssClientCredentials()); WitClient = Connection.GetClient <WorkItemTrackingHttpClient>(); ProjectClient = Connection.GetClient <ProjectHttpClient>(); TeamProject = ProjectClient.GetProject(project).Result; WorkItemsAdded = new HashSet <int>(); DefaultWorkItemTypeCategory = WitClient.GetWorkItemTypeCategoryAsync(TeamProject.Id, DefaultCategoryReferenceName).Result; DefaultWorkItemType = DefaultWorkItemTypeCategory.DefaultWorkItemType; }
public Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models.WorkItem GetWorkItem(int Id) { try { return(WitClient.GetWorkItemAsync(Id).Result); } catch { return(null); } }
public void GetWorkItemTypes() { var types = WitClient.GetWorkItemTypesAsync(TeamProject.Id).Result; var typesCount = types.Count; Console.WriteLine($"Project: '{TeamProject.Name}' has the following {typesCount} types:"); foreach (var type in types) { Console.WriteLine($"Name: '{type.Name}' - Description: '{type.Description}'"); } Console.WriteLine(); }
public void GetWorkItemCategories() { List <WorkItemTypeCategory> workItemCategories = WitClient.GetWorkItemTypeCategoriesAsync(TeamProject.Id).Result; var categoriesCount = workItemCategories.Count; Console.WriteLine($"Project: '{TeamProject.Name}' has the following {categoriesCount} categories:"); foreach (WorkItemTypeCategory workItemTypeCategory in workItemCategories) { Console.WriteLine(workItemTypeCategory.Name); } Console.WriteLine(); }
public void GetWorkItemTypeFields() { var workItemTypeName = DefaultWorkItemType.Name; var workItemTypeFields = WitClient.GetWorkItemTypeFieldsWithReferencesAsync(TeamProject.Id, workItemTypeName).Result; Console.WriteLine($"Obtained all the work item type fields for '{workItemTypeName}' on project: '{TeamProject.Name}' using REST."); foreach (WorkItemTypeFieldWithReferences wiTypeField in workItemTypeFields) { Console.WriteLine($"Field '{wiTypeField.Name}'"); } Console.WriteLine(); }
public void AddAttachment() { // Create a file to attach with sample text var filePath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); using (FileStream fstream = File.Create(filePath)) { using (StreamWriter swriter = new StreamWriter(fstream)) { swriter.Write("Sample attachment text"); } } // Upload attachment AttachmentReference attachment = WitClient.CreateAttachmentAsync(filePath).Result; Console.WriteLine("Attachment created"); Console.WriteLine($"ID: {attachment.Id}"); Console.WriteLine($"URL: '{attachment.Url}'"); Console.WriteLine(); // Get an existing work item and add the attachment to it WorkItem wi = WitClient.GetWorkItemAsync(this.WorkItemsAdded.First()).Result; JsonPatchDocument attachmentPatchDocument = new JsonPatchDocument { new JsonPatchOperation() { Operation = Operation.Add, Path = "/relations/-", Value = new { rel = "AttachedFile", url = attachment.Url, attributes = new { comment = "Attached a file" } } } }; var attachments = wi.Relations?.Where(r => r.Rel == "AttachedFile") ?? new List <WorkItemRelation>(); var previousAttachmentsCount = attachments.Count(); var result = WitClient.UpdateWorkItemAsync(attachmentPatchDocument, wi.Id.Value).Result; var newAttachments = result.Relations?.Where(r => r.Rel == "AttachedFile"); var newAttachmentsCount = newAttachments.Count(); Console.WriteLine($"Updated Existing Work Item: '{wi.Id}'. Had {previousAttachmentsCount} attachments, now has {newAttachmentsCount}"); Console.WriteLine(); }
/// <summary> /// Adds the effort values. /// </summary> /// <param name="record">The record.</param> /// <param name="workItem">The work item.</param> /// <returns>Task.</returns> /// <exception cref="VssResourceNotFoundException">Query not found : " + queryName.</exception> private async Task AddEffortValues(List <object?> record, WorkItem workItem) { var childRelType = (childRelationType ?? await GetChildRelationType()).ReferenceName; var fieldNames = GetTaskFieldReferenceNames(); var linkedWi = GetLinkedWorkItemIds(workItem, childRelType); if (linkedWi.Count > 0) { var wis = await WitClient.GetWorkItemsAsync(linkedWi, null, null, WorkItemExpand.Fields); var tasks = wis .Where(p => p.Fields.ContainsKey(WorkItemFieldType.Activity) && p.Fields.ContainsKey(WorkItemFieldType.WorkItemType) && p.Fields[WorkItemFieldType.WorkItemType] as string == WorkItemType.Task) .Select(p => new Effort { Activity = p.Fields[WorkItemFieldType.Activity] as string ?? string.Empty, OriginalEstimate = p.Fields.ContainsKey(WorkItemFieldType.OriginalEstimate) ? p.Fields[WorkItemFieldType.OriginalEstimate] as double? ?? 0 : 0, RemainingWork = p.Fields.ContainsKey(WorkItemFieldType.RemainingWork) ? p.Fields[WorkItemFieldType.RemainingWork] as double? ?? 0 : 0, CompletedWork = p.Fields.ContainsKey(WorkItemFieldType.CompletedWork) ? p.Fields[WorkItemFieldType.CompletedWork] as double? ?? 0 : 0, }) .GroupBy(p => p.Activity) .Select(p => new Effort { Activity = p.Key, OriginalEstimate = p.Sum(q => q.OriginalEstimate), RemainingWork = p.Sum(q => q.RemainingWork), CompletedWork = p.Sum(q => q.CompletedWork), }) .ToList(); record.AddRange(new object[] { tasks.Sum(p => p.OriginalEstimate), tasks.Sum(p => p.RemainingWork), tasks.Sum(p => p.CompletedWork) }); foreach (var activity in (activityCollection ?? await GetOrderedActivityList()).Activities) { var query = tasks.Where(p => p.Activity == activity); if (query.Any()) { var effort = query.Single(); record.AddRange(new object[] { effort.OriginalEstimate, effort.RemainingWork, effort.CompletedWork }); } else { record.AddRange(new object[] { 0, 0, 0 }); } } } else { record.AddRange(new object[] { 0, 0, 0 }); foreach (var activity in (activityCollection ?? await GetOrderedActivityList()).Activities) { record.AddRange(new object[] { 0, 0, 0 }); } } }
public WorkItem GetWorkItem(string pUrl) { int _id = GetWIIDFromUrl(pUrl); if (_id > 0) { return(WitClient.GetWorkItemAsync(_id, expand: WorkItemExpand.Relations).Result); } else { return(null); } }
public void GetWorkItemTypeField() { var workItemTypeName = DefaultWorkItemType.Name; var workItemTypeFieldName = "System.Title"; var workItemTypeField = WitClient.GetWorkItemTypeFieldWithReferencesAsync(TeamProject.Id, workItemTypeName, workItemTypeFieldName).Result; Console.WriteLine($"Obtained work item type field information for '{workItemTypeFieldName}' on project: '{TeamProject.Name}' using REST."); Console.WriteLine($"Name: '{workItemTypeField.Name}'"); Console.WriteLine($"Reference Name: '{workItemTypeField.ReferenceName}'"); Console.WriteLine($"Always Required: '{workItemTypeField.AlwaysRequired}'"); Console.WriteLine($"Help Text: '{workItemTypeField.HelpText}'"); Console.WriteLine(); }
public WorkItem UpdateWorkItem(int pId, Dictionary <string, string> pFields) { JsonPatchDocument _patchDocument = new JsonPatchDocument(); foreach (var _key in pFields.Keys) { _patchDocument.Add(new JsonPatchOperation() { Operation = Operation.Add, Path = "/fields/" + _key, Value = pFields[_key] }); } return(WitClient.UpdateWorkItemAsync(_patchDocument, pId).Result); }
public void ValidateWorkItem() { try { // Create new work item var createPatchDocument = new JsonPatchDocument { new JsonPatchOperation() { Operation = Operation.Add, Path = "/fields/System.History", Value = "Modify system history" } }; // Set validateOnly param to true and attempt to create a work item with an incomplete patch document (missing required title field). var validateOnCreateWI = WitClient.CreateWorkItemAsync(createPatchDocument, TeamProject.Name, DefaultWorkItemType.Name, true).Result; } catch (AggregateException ex) { Console.WriteLine(ex.InnerException.Message); Console.WriteLine(); } // Update existing work item try { var wi = WitClient.GetWorkItemAsync(WorkItemsAdded.First()).Result; var updatePatchDocument = new JsonPatchDocument { new JsonPatchOperation() { Operation = Operation.Add, Path = "/fields/System.AreaPath", Value = "Invalid area path" } }; // Set validateOnly param to true and attempt to update a work item with an invalid field entry. var validateOnUpdateWI = WitClient.UpdateWorkItemAsync(updatePatchDocument, wi.Id.Value, true).Result; } catch (AggregateException ex) { Console.WriteLine(ex.InnerException.Message); Console.WriteLine(); } Console.WriteLine(); }
public Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models.WorkItem CreateWorkItem(string ProjectName, string WorkItemTypeName, Dictionary <string, object> Fields) { JsonPatchDocument patchDocument = new JsonPatchDocument(); foreach (var key in Fields.Keys) { patchDocument.Add(new JsonPatchOperation() { Operation = Operation.Add, Path = "/fields/" + key, Value = Fields[key] }); } return(WitClient.CreateWorkItemAsync(patchDocument, ProjectName, WorkItemTypeName).Result); }
public Task <Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models.WorkItem> UpdateWorkItem(int WIId, Dictionary <string, object> Fields) { JsonPatchDocument patchDocument = new JsonPatchDocument(); foreach (var key in Fields.Keys) { patchDocument.Add(new JsonPatchOperation() { Operation = Operation.Add, Path = "/fields/" + key, Value = Fields[key] }); } return(WitClient.UpdateWorkItemAsync(patchDocument, WIId)); }
public IList <string> GetIntentsFromMessage(string fromId, string text) { if (Client == null) { Client = new WitClient(ConnectionStrings["WitAiKey"].ConnectionString); } try { return(Client.Converse(fromId, text)?.entities["intent"].Select(x => x.value.ToString()).ToList()); } catch (KeyNotFoundException ex) { return(new List <string>()); } }
/// <summary> /// POST: api/Messages /// Receive a message from a user and reply to it /// </summary> public async Task <HttpResponseMessage> Post([FromBody] Activity activity) { if (activity.Type == ActivityTypes.Message) { ConnectorClient connector = new ConnectorClient(new Uri(activity.ServiceUrl)); var wit = new WitClient("G6AM4AHSKKP4EQYJ35ZWJ723H5DDHTAX"); var msg = wit.Converse(activity.From.Id, activity.Text); var intent = string.Empty; double conf = 0; if (msg.entities["intent"] != null) { foreach (var z in msg.entities["intent"]) { if (z.confidence > conf) { conf = z.confidence; intent = z.value.ToString(); } } } var doc = XDocument.Load(System.Web.HttpContext.Current.Request.MapPath("~/Responses.xml")); var r = (from x in doc.Descendants("Response") where x.Attribute("intent").Value == intent select x).FirstOrDefault(); string res = "Я вас не понимаю..."; if (r != null) { var arr = (from x in r.Descendants("Text") select x.Value).ToArray(); if (arr != null && arr.Length > 0) { var rnd = new Random(); res = arr[rnd.Next(0, arr.Length)]; } } Activity reply = activity.CreateReply(res); await connector.Conversations.ReplyToActivityAsync(reply); } else { HandleSystemMessage(activity); } var response = Request.CreateResponse(HttpStatusCode.OK); return(response); }