/// <summary> /// The add details for work item. /// </summary> /// <param name="id"> /// The id. /// </param> /// <param name="fieldName"> /// The field name. /// </param> /// <param name="ms"> /// The memory stream. /// </param> public void AddDetailsForWorkItem(int id, string fieldName, MemoryStream ms) { WorkItem workItem = ItemsStore.GetWorkItem(id); string temp = Environment.GetFolderPath(Environment.SpecialFolder.InternetCache) + @"\image.png"; File.WriteAllBytes(temp, ms.ToArray()); var attach = new Attachment(temp); var attachIndex = workItem.Attachments.Add(attach); workItem.Save(); Field itemField = workItem.Fields.Cast <Field>().FirstOrDefault(f => f.Name == fieldName); if (itemField != null) { switch (tfsVersion) { case TfsVersion.Tfs2011: itemField.Value += string.Format(@"<img src='{0}' />", workItem.Attachments[attachIndex].Uri); break; case TfsVersion.Tfs2010: itemField.Value += string.Format("\r({0} : {1})\r", ResourceHelper.GetResourceString("SEE_ATTACHEMENTS"), workItem.Attachments[attachIndex].Name); break; } } workItem.Save(); }
internal Field(Tfs.Field field) : base( ExceptionHandlingDynamicProxyFactory.Create <IRevisionInternal>(new WorkItem(field?.WorkItem)), ExceptionHandlingDynamicProxyFactory.Create <IFieldDefinition>(new FieldDefinition(field?.FieldDefinition))) { NativeField = field ?? throw new ArgumentNullException(nameof(field)); }
/// <summary> /// The add details for work item. /// </summary> /// <param name="id"> /// The id. /// </param> /// <param name="fieldName"> /// The field name. /// </param> /// <param name="bitmapSource"> /// The bitmap source. /// </param> public void AddDetailsForWorkItem(int id, string fieldName, BitmapSource bitmapSource) { WorkItem workItem = ItemsStore.GetWorkItem(id); string temp = Environment.GetFolderPath(Environment.SpecialFolder.InternetCache) + @"\image.png"; using (var ms = new MemoryStream()) { BitmapEncoder enc = new BmpBitmapEncoder(); enc.Frames.Add(BitmapFrame.Create(bitmapSource)); enc.Save(ms); File.WriteAllBytes(temp, ms.ToArray()); } var attach = new Attachment(temp); workItem.Attachments.Add(attach); Field itemField = workItem.Fields.Cast <Field>().FirstOrDefault(f => f.Name == fieldName); if (itemField != null) { itemField.Value += string.Format(@"<img src='{0}' />", attach.Uri); } workItem.Save(); }
private int GetStateCount(WorkItem wi, string fieldName, string fieldValue) { int ret = 0; List <DateTime> stateChangedDates = new List <DateTime>(); foreach (Revision rev in wi.Revisions) { List <Field> fields = rev.Fields.Cast <Field>().ToList(); if (fields.Any(x => x.Name == fieldName && x.Value != null && x.Value.ToString() == fieldValue)) { if (fields.Any(x => x.Name == "State Change Date")) { Field field = fields.First(x => x.Name == "State Change Date"); if (field.Value != null && !stateChangedDates.Contains(Convert.ToDateTime(field.Value.ToString()))) { stateChangedDates.Add(Convert.ToDateTime(field.Value.ToString())); ret += 1; } } } } return(ret); }
public void Sprint1Plan() { TfsTeamProjectCollection tpc = TfsConnect(); // Load tasks from config file XmlDocument xmlInput = new XmlDocument(); xmlInput.Load(InputFile); XmlNodeList tasks = xmlInput.SelectNodes("//plan/task"); // Get PBI work items WorkItemStore store = new WorkItemStore(tpc); Project project = store.Projects[TeamProject]; string wiql = "SELECT [System.Id] FROM WorkItems " + "WHERE [System.TeamProject] = '" + TeamProject + "' AND [System.WorkItemType] ='Product Backlog Item'"; WorkItemCollection collection = store.Query(wiql); // Loop through each PBI int count = 0; for (int i = 0; i < collection.Count; i++) { WorkItem PBI = collection[i]; // Loop through each Task foreach (XmlNode task in tasks) { WorkItem wi = new WorkItem(project.WorkItemTypes["task"]); wi.Title = task["title"].InnerText; wi.IterationPath = @"Fabrikam\Release 1\Sprint 1"; wi.Fields["Microsoft.VSTS.Scheduling.RemainingWork"].Value = Convert.ToInt32(task["remainingwork"].InnerText); ArrayList ValidationResult = wi.Validate(); if (ValidationResult.Count > 0) { Microsoft.TeamFoundation.WorkItemTracking.Client.Field badField = (Microsoft.TeamFoundation.WorkItemTracking.Client.Field)ValidationResult[0]; Console.WriteLine(); Console.WriteLine(" Invalid \"{0}\" value \"{1}\" ({2})", badField.Name, badField.Value, badField.Status); return; } Console.Write("."); wi.Save(); // Save link to parent PBI WorkItemLinkTypeEnd childLink = store.WorkItemLinkTypes.LinkTypeEnds["Parent"]; wi.WorkItemLinks.Add(new WorkItemLink(childLink, PBI.Id)); wi.Save(); count++; } } // Done Console.WriteLine(string.Format(" ({0} tasks added)", count)); }
/// <summary> /// Is step /// </summary> /// <param name="id"></param> /// <param name="fieldName"></param> /// <returns></returns> public bool IsStep(int id, string fieldName) { WorkItem workItem = ItemsStore.GetWorkItem(id); Field fieldSteps = workItem.Fields.Cast <Field>().FirstOrDefault(f => f.Name == "Steps"); if (fieldSteps == null) { fieldSteps = workItem.Fields.Cast <Field>().FirstOrDefault(f => f.Name == "Шаги"); } if (fieldSteps != null && fieldName == fieldSteps.Name) { return(true); } return(false); }
/// <summary> /// Replace details for work item /// </summary> /// <param name="id"></param> /// <param name="fieldName"></param> /// <param name="data"></param> public void ReplaceDetailsForWorkItem(int id, string fieldName, string data) { WorkItem workItem = ItemsStore.GetWorkItem(id); Field itemField = workItem.Fields.Cast <Field>().FirstOrDefault(f => f.Name.Equals(fieldName, StringComparison.InvariantCultureIgnoreCase)); if (fieldName.Equals("system.title", StringComparison.InvariantCultureIgnoreCase)) { itemField = workItem.Fields["System.Title"]; } if (itemField != null) { itemField.Value = null; itemField.Value += data; workItem.Save(); } }
/// <summary> /// The add details for work item. /// </summary> /// <param name="id"> /// The id. /// </param> /// <param name="fieldName"> /// The field name. /// </param> /// <param name="dataObject"> /// The data Object. /// </param> public void AddDetailsForWorkItem(int id, string fieldName, IDataObject dataObject, out bool comment) { //var html = dataObject.GetData(DataFormats.Html).ToString(); string html = ClipboardHelper.Instanse.CopyFromClipboard(); WorkItem workItem = ItemsStore.GetWorkItem(id); string attachmentName = string.Empty; html = html.CleanHeader(); IDictionary <string, string> links = html.GetLinks(); foreach (var link in links) { if (File.Exists(link.Value) && !(new FileInfo(link.Value).Extension == ".thmx" || new FileInfo(link.Value).Extension == ".xml" || new FileInfo(link.Value).Extension == ".mso")) { var attach = new Attachment(link.Value); if (tfsVersion == TfsVersion.Tfs2010) { var attachIndex = workItem.Attachments.Add(attach); workItem.Save(); attachmentName += string.Format("Name={0} Id={1},", workItem.Attachments[attachIndex].Name, workItem.Attachments[attachIndex].Id); string uri = attach.Uri.ToString(); html = html.Replace(link.Key, uri); } else { workItem.Attachments.Add(attach); workItem.Save(); string uri = attach.Uri.ToString(); html = html.Replace(link.Key, uri); } } else { html = html.Replace(link.Key, string.Empty); } } Field itemField = workItem.Fields.Cast <Field>().FirstOrDefault(f => f.Name == fieldName); //Field fieldSteps = workItem.Fields.Cast<Field>().FirstOrDefault(f => f.Id == 10265); Field fieldSteps = workItem.Fields.Cast <Field>().FirstOrDefault(f => f.Name == "Steps"); var fields = workItem.Fields; if (fieldSteps == null) { fieldSteps = workItem.Fields.Cast <Field>().FirstOrDefault(f => f.Name == "Шаги"); //fieldSteps = workItem.Fields.Cast<Field>().FirstOrDefault(f => f.Id == 10032); } comment = false; if (itemField != null) { if (fieldSteps != null && fieldName == fieldSteps.Name) { AddStep(dataObject, workItem, out comment, true); } else { if (tfsVersion == TfsVersion.Tfs2010) { if (itemField.FieldDefinition.FieldType == FieldType.Html) { itemField.Value += html.ClearComments(); } else { string temp = Regex.Replace(dataObject.GetData(DataFormats.Text).ToString(), @"\s+", " "); itemField.Value += "\r" + temp; if (attachmentName != string.Empty) { itemField.Value += string.Format("\r({0}: {1})", Resources.SeeAttachments_Text, attachmentName.TrimEnd(',')); } } } else { itemField.Value += html.ClearComments(); } workItem.Save(); comment = true; } } }
public ActionResult CreateBug(string uri, string teamProjectName, string title, string description, string area, string iteration, string assignee, string reproductionSteps) { #region Temp // Connect to the server and the store, and get the WorkItemType object // for Bug from the team project where the user story will be created. Uri collectionUri = new Uri(uri);//"http://server:port/vdir/DefaultCollection"); TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(collectionUri); WorkItemStore workItemStore = tpc.GetService <WorkItemStore>(); Project teamProject = workItemStore.Projects[teamProjectName]; WorkItemType workItemType = teamProject.WorkItemTypes["Bug"]; // Create the work item. WorkItem newBug = new WorkItem(workItemType); { // The title is generally the only required field that doesn’t have a default value. // You must set it, or you can’t save the work item. If you’re working with another // type of work item, there may be other fields that you’ll have to set. // Create the work item. newBug.Title = title; newBug.Description = description; newBug.AreaPath = area; newBug.IterationPath = iteration; newBug.Fields["Priority"].Value = 2; newBug.Fields["Severity"].Value = "4 - Low"; newBug.Fields["Assigned To"].Value = assignee; newBug.Fields["Repro Steps"].Value = reproductionSteps; }; //// Save the new user story. //newBug.Save(); #endregion var validationResult = newBug.Validate(); if (validationResult.Count == 0) { // Save the new work item. newBug.Save(); return(new ActionResult() { Success = true }); } else { // Establish why it can't be saved var result = new ActionResult() { Success = false, ErrorCodes = new List <string>() }; foreach (var res in validationResult) { Microsoft.TeamFoundation.WorkItemTracking.Client.Field field = res as Microsoft.TeamFoundation.WorkItemTracking.Client.Field; if (field == null) { result.ErrorCodes.Add(res.ToString()); } else { result.ErrorCodes.Add("Error with: {field.Name}"); } } return(result); } }
public void CreatePBIs() { TfsTeamProjectCollection tpc = TfsConnect(); int count = 0; Hashtable workItems = new Hashtable(); // Validate that it's the right kind of team project WorkItemStore store = new WorkItemStore(tpc); Project project = store.Projects[TeamProject]; if (!project.WorkItemTypes.Contains("Product Backlog Item")) { Console.WriteLine("This team project was not created using the Visual Studio Scrum process template."); return; } // Load work items XmlDocument xmlInput = new XmlDocument(); xmlInput.Load(InputFile); XmlNodeList items = xmlInput.SelectNodes("//backlog/item"); foreach (XmlNode item in items) { Console.Write("."); string WIT = item["type"].InnerText.Trim().ToLower(); string title = item["title"].InnerText; string state; if (item["state"] == null) { state = "approved"; } else { state = item["state"].InnerText.ToLower(); } WorkItem wi = new WorkItem(project.WorkItemTypes[WIT]); wi.Title = title; if (item["description"] != null) { wi.Description = item["description"].InnerText; } else { wi.Description = title; } if (item["reprosteps"] != null) { wi.Fields["Microsoft.VSTS.TCM.ReproSteps"].Value = item["reprosteps"].InnerText; } if (item["acceptancecriteria"] != null) { wi.Fields["Microsoft.VSTS.Common.AcceptanceCriteria"].Value = item["acceptancecriteria"].InnerText; } wi.AreaPath = TeamProject + item["area"].InnerText; if (item["iteration"] != null) { wi.IterationPath = TeamProject + item["iteration"].InnerText; } wi.Fields["System.AssignedTo"].Value = ProductOwner; if (state == "approved" || state == "active") { if (item["businessvalue"] != null && item["businessvalue"].InnerText != "") { wi.Fields["Microsoft.VSTS.Common.BusinessValue"].Value = item["businessvalue"].InnerText; } if (item["effort"] != null && item["effort"].InnerText != "") { wi.Fields["Microsoft.VSTS.Scheduling.Effort"].Value = item["effort"].InnerText; } if (item["order"] != null && item["order"].InnerText != "") { wi.Fields["Microsoft.VSTS.Common.BacklogPriority"].Value = item["order"].InnerText; } } ArrayList ValidationResult = wi.Validate(); if (ValidationResult.Count > 0) { Microsoft.TeamFoundation.WorkItemTracking.Client.Field badField = (Microsoft.TeamFoundation.WorkItemTracking.Client.Field)ValidationResult[0]; Console.WriteLine(); Console.WriteLine(" Invalid \"{0}\" value \"{1}\" ({2})", badField.Name, badField.Value, badField.Status); return; } wi.Save(); count++; workItems.Add(wi.Id, wi.Title.Trim().ToLower()); // linked items? if (item["parent"] != null) { string parent = item["parent"].InnerText.Trim().ToLower(); int parentId = 0; foreach (DictionaryEntry candidate in workItems) { if (candidate.Value.ToString() == parent) { parentId = Convert.ToInt32(candidate.Key); } } if (parentId > 0) { // lookup child link type WorkItemLinkTypeEnd childLink = store.WorkItemLinkTypes.LinkTypeEnds["Parent"]; wi.WorkItemLinks.Add(new WorkItemLink(childLink, parentId)); wi.Save(); } } if (state == "approved") { wi.State = "Approved"; wi.Save(); } else if (state == "active") { wi.State = "Active"; wi.Save(); } else if (state == "committed") { wi.State = "Committed"; wi.Save(); } else if (state == "done") { wi.State = "Done"; wi.Save(); } } // Done Console.WriteLine(string.Format(" ({0} PBIs created)", count)); }
internal FieldProxy(Tfs.Field field) { _field = field; }
public FieldWrapper(TFS.Field field) { this.tfsField = field; }