/// <summary> /// Upload the configuration data to the server. Return True if its done with no problem. /// </summary> /// <param name="ServerOperation">ServerOperationManager object</param> /// <param name="log">Custom Logger object</param> public bool Upload_Process(bool isUIRun, ServerOperationManager ServerOperation, Logger log) { try { ServerOperation.datasForFileModification.Clear(); ServerOperation.Archive(isUIRun, CurrentTeamProjectName); PbisConfigSection myPBISection = ConfigurationManager.GetSection("PBICollectionSection") as PbisConfigSection; for (int i = 0; i < myPBISection.Members.Count; i++) { PBI pbi = myPBISection.Members[i]; ServerOperation.Upload(isUIRun, pbi, ServerOperation.AreaPath); } return(true); } catch (Exception ex) { log.Error(ex); log.Flush(); return(false); } }
/// <summary> /// PBI / User Story configuration Creator and Uploader to the Server. /// </summary> /// <param name="isUIRun">logical flag, is it a UI run or Automated run section</param> /// <param name="pbi"> Parameter is a PBI / User Story, what we would like to upload to the server.</param> /// <returns></returns> public bool Upload(bool isUIRun, PBI pbi, string AreaPath) { try { string PBI_AssignedTo = string.Empty; PBIType = conn.TeamProject.WorkItemTypes["User Story"]; TaskType = conn.TeamProject.WorkItemTypes["Task"]; // Create actual PBI / User Story WorkItem TFSpbi = new WorkItem(PBIType); // Set the Title and Tags to the PBI / User Stroy TFSpbi.Title = pbi.Title + RunDatePeriod(); if (isUIRun) { TFSpbi.Fields["Tags"].Value = "Created_By_Person_With_UI" + ";" + "Szakdolgozat" + ";" + "ELTE"; } else { TFSpbi.Fields["Tags"].Value = "Created_By_Program" + ";" + "Szakdolgozat" + ";" + "ELTE"; } //Run a query for check this WorkItem with this title already exist or not Query query = new Query(conn.WorkItemStore, string.Format("SELECT Id FROM WorkItems WHERE System.Title = '{0}' AND System.AreaPath = '{1}' AND (System.State = '{2}' OR System.State = '{3}')", TFSpbi.Title, AreaPath, "Active", "New")); WorkItemCollection workItemCollection = query.RunQuery(); if (workItemCollection.Count == 0) { // WorkItem Parent Query Query queryParent = new Query(conn.WorkItemStore, string.Format("SELECT Id FROM WorkItems WHERE System.Id = '{0}'", pbi.ParentID)); WorkItemCollection workItemCollectionParent = queryParent.RunQuery(); if (workItemCollectionParent.Count == 1) { // Link to the Parent TFSpbi.Links.Add(new RelatedLink(conn.WorkItemStore.WorkItemLinkTypes.LinkTypeEnds["Parent"], int.Parse(pbi.ParentID))); } else { log.Error("There is no Parent!"); log.Flush(); } // PBI / User Story Configuration TFSpbi.Fields["System.AssignedTo"].Value = pbi.AssignedTo; TFSpbi.Fields["System.AreaPath"].Value = AreaPath; TFSpbi.Fields["System.IterationPath"].Value = Iteration; TFSpbi.Fields["Microsoft.VSTS.Common.Risk"].Value = "3 - Low"; string description = "Created Ready To Work User Stroy/PBI Period."; var htmlString = WebUtility.HtmlEncode(description); TFSpbi.Fields["System.Description"].Value = htmlString; // validation check (ready for save) if (TFSpbi.Validate().Count == 0) { TFSpbi.Save(); } // State Change and Validation check before Save again TFSpbi.Fields["State"].Value = "Active"; if (TFSpbi.Validate().Count == 0) { TFSpbi.Save(); } PBI_AssignedTo = pbi.AssignedTo; // file writing init part datasForFileModification.Add(string.Format("{0};{1};{2};{3}", TFSpbi.Id, TFSpbi.Title, PBI_AssignedTo, TFSpbi.State, Environment.NewLine)); // PBI / User Stroy Task Configuration period foreach (ConfigTask task in pbi.Tasks) { ConfigTaskConfigurator(isUIRun, task, TFSpbi); } log.Info("Upload was successful" + " " + TFSpbi.Title); log.Flush(); return(true); } else { log.Error("PBI already exist! Fail to Upload"); log.Flush(); return(false); } } catch (Exception ex) { log.Error(ex); log.Flush(); } return(false); }