/// <summary> /// Clone Bug /// </summary> /// <param name="bugId"></param> /// <param name="targetConnectDomain"></param> /// <param name="targetProductName"></param> public void CloneBug(int bugId, string targetConnectDomain, string targetProductName) { DatastoreItem psItem = null; DatastoreItem psCloneItem = null; ProductStudio.Directory psTargetDirectory = null; Product psTargetProduct = null; Datastore psTargetDataStore = null; try { if (targetConnectDomain != null && targetProductName != null) { psTargetDirectory = new ProductStudio.Directory(); psTargetDirectory.Connect(targetConnectDomain, "", ""); psTargetProduct = psTargetDirectory.GetProductByName(targetProductName); psTargetDataStore = psTargetProduct.Connect("", "", ""); } else { psTargetDataStore = this.psDataStore; } psItem = this.psDataStore.GetDatastoreItem(PsDatastoreItemTypeEnum.psDatastoreItemTypeBugs, bugId, null); psItem.Edit(PsItemEditActionEnum.psDatastoreItemEditActionReadOnly, null, PsApplyRulesMask.psApplyRulesAll); // Clone the item to the targetDataStore psCloneItem = psItem.Clone(psTargetDataStore); // Save the new item psCloneItem.Save(true); } catch (Exception e) { throw new Exception(String.Format("Failed to clone bug {0} to {1} database.", bugId, targetProductName), e); } finally { if (psTargetDirectory != null) { psTargetDirectory.Disconnect(); } } }
/// <summary> /// Update Bug in PS using the PS SDK /// </summary> /// <param name="bugChangeList"></param> /// <param name="bugFieldMappingCollection"></param> /// <param name="updateAction"></param> public void UpdateBug(PSBugChangeList psBugChangeList) { DatastoreItem psItem = null; bool hasInvalidField = false; try { psItem = this.psDataStore.GetDatastoreItem(PsDatastoreItemTypeEnum.psDatastoreItemTypeBugs, psBugChangeList.BugId, null); switch (psBugChangeList.Action) { case PSUpdateAction.Update: psItem.Edit(PsItemEditActionEnum.psDatastoreItemEditActionEdit, null, PsApplyRulesMask.psApplyRulesAll); break; case PSUpdateAction.Resolve: psItem.Edit(PsItemEditActionEnum.psBugEditActionResolve, null, PsApplyRulesMask.psApplyRulesAll); break; case PSUpdateAction.Close: psItem.Edit(PsItemEditActionEnum.psBugEditActionClose, null, PsApplyRulesMask.psApplyRulesAll); break; case PSUpdateAction.Activate: psItem.Edit(PsItemEditActionEnum.psBugEditActionActivate, null, PsApplyRulesMask.psApplyRulesAll); break; } foreach (string psFieldName in psBugChangeList.BugChanges.Keys) { // We need to skip these values as they are auto filled by PS. if (string.Compare(psFieldName, "Closed By", true) == 0 || string.Compare(psFieldName, "Resolved By", true) == 0 || string.Compare(psFieldName, "Changed By", true) == 0) { continue; } Field psField = null; // PendingChangelist doesn't have mapping value in DB because Sync Service doesn't handle it, so we have to map it to a PS value manually. if (string.Compare(psFieldName, BugFields.PendingChangelist.ToString(), true) == 0) { psField = psItem.Fields["ChangelistInfo"]; } else { psField = psItem.Fields[psFieldName]; } if (psField == null) { throw new Exception("Failed to find property [" + psFieldName + "]"); } else if (psField.IsReadOnly) { // We need to do some logging here as we skip some read-only psField when doing update //throw new Exception("Failed to update read-only property [" + psFieldName + "]"); continue; } else { // SLA Date in PS is string, but in SysBugItem is DateTime, there comes is datetime string or null if (string.Compare(psField.Name, "SLA Date", true) == 0) { DateTime slaDate; if (DateTime.TryParse(psBugChangeList.BugChanges[psFieldName].ToString(), out slaDate) == true) { psField.Value = string.Format("{0:MM/dd/yyyy}", slaDate); } else { psField.Value = null; } } // PendingChangelist doesn't have mapping value in DB because Sync Service doesn't handle it, so we have to map it to a PS value manually. else if (string.Compare(psField.Name, "ChangelistInfo", true) == 0) { Dictionary <string, ChangelistInfo> changelistDict = new Dictionary <string, ChangelistInfo>(StringComparer.OrdinalIgnoreCase); string changeListInfos = psField.Value; ChangelistInfo newPendingChangelist = psBugChangeList.BugChanges[psFieldName] as ChangelistInfo; if (string.IsNullOrEmpty(changeListInfos) == false && changeListInfos.Length > 0) { Regex r = new Regex(@"^\s*\d+,.+,.+,.+,.+,.*$"); string[] split = changeListInfos.Split("\r".ToCharArray()); foreach (string s in split) { // 722: Handle changelist with linefeed in description if (r.IsMatch(s.Trim("\n".ToCharArray()))) { ChangelistInfo info = new ChangelistInfo(s.Trim("\n".ToCharArray())); // If the changelist is related and it also ends with $$SEPortal$$, we will discard them, not adding them into the dictionary if (string.Compare(info.Relation, "related", true) == 0 && info.Description.EndsWith("$$SEPortal$$") == true) { continue; } // If the changelist has the same id as the new changelist, we will discard it, not adding it into the dictionary if (newPendingChangelist != null && string.Compare(info.ChangelistId, newPendingChangelist.ChangelistId, true) == 0) { continue; } // Add the changelist to the dictionary if it is not already added if (changelistDict.ContainsKey(info.ChangelistId) == false) { changelistDict.Add(info.ChangelistId, info); } } } } if (newPendingChangelist != null) { changelistDict.Add(newPendingChangelist.ChangelistId, newPendingChangelist); } string pendingChangelistStr = string.Empty; foreach (ChangelistInfo changelistInfo in changelistDict.Values) { if (newPendingChangelist != null && string.Compare(newPendingChangelist.Relation, "Related", true) == 0 && string.Compare(newPendingChangelist.ChangelistId, changelistInfo.ChangelistId, true) == 0) { pendingChangelistStr += changelistInfo.ToString() + " $$SEPortal$$\r"; } else { pendingChangelistStr += changelistInfo.ToString() + "\r"; } } psField.Value = pendingChangelistStr; } else { if (psBugChangeList.BugChanges[psFieldName] != null) { psField.Value = psBugChangeList.BugChanges[psFieldName].ToString(); } else { psField.Value = null; } } } } // Verify that all fields are valid before saving foreach (ProductStudio.Field field in psItem.Fields) { if (field.Validity != PsFieldStatusEnum.psFieldStatusValid) { hasInvalidField = true; throw new Exception("Updating Field (" + field.Name + ") with Value (" + field.Value + ") is invalid. Counld not edit bug " + psBugChangeList.BugId.ToString()); } } // Commit the save if there is no invalid field if (hasInvalidField) { throw new Exception("Invalid Field(s) were found. Could not edit bug " + psBugChangeList.BugId.ToString()); } else { psItem.Save(); } } catch (Exception e) { throw new Exception(String.Format("Failed to update bug {0} in {1} database.", psBugChangeList.BugId, this.productName), e); } }
public Int32 CreateNewBug(string psFieldDefXml) { bool hasInvalidField = false; // Create a new datastore instance DatastoreItemList psDataList = new DatastoreItemList(); psDataList.Datastore = this.psDataStore; // Craete a blank bug psDataList.CreateBlank(PsDatastoreItemTypeEnum.psDatastoreItemTypeBugs); DatastoreItem psDataItem = psDataList.DatastoreItems.Add(null, PsApplyRulesMask.psApplyRulesAll); // Set fields for the new bug Fields psFields = psDataItem.Fields; // New PS Bug Field Description XML file will look like // ======================================================= // <psfieldDef> // <Title> // Title (Ex. RFH: Hotfix for ...) // </Title> // <Tree Path> // Path (Ex. SCCM 2007 SP2) // </Tree Path> // <Issue type> // Issue Type (Ex. RFH / CDCR) // </Issue type> // <Get Help> // Get Help (Ex. Yes / No) // </Get Help> // <Priority> // Priority (Ex. 1, 2, 3, 4) // </Priority> // <Severity> // Severity (Ex. 1, 2, 3, 4) // </Severity> // <SMS Product> // SMS Product (Ex. x86 / x64) // </SMS Product> // <Component> // Component (Ex. component name) // </Component> // <FeatureArea> // Feature Area (Ex. feature area name) // </FeatureArea> // <Open Build> // Open Build (Ex. build version 6487.2000) // </Open Build> // <Language> // Language (Ex. ENU) // </Language> // <How found> // How Found (Ex. Internal) // </How found> // <Source> // Source (Ex. Ad Hoc) // </Source> // <Source ID> // Source ID (ex. Airforce) // </Source ID> // <PSS> // SR Number (ex. SR Number) // </PSS> // <KB Article> // KB Number (ex. KB Number 98765432) // </KB Article> // <Repro Steps> // Repro Steps (ex. Repro Steps) // </Repro Steps> // <Description> // Description (ex. Description) // </Description> // <Related Bugs> // SMS Sustained Engineering:5991 // </Related Bugs> // <QFE Status> // Core Review // </QFE Status> // </psfieldDef> XmlReader xmlReader = XmlReader.Create(new StringReader(psFieldDefXml)); while (xmlReader.Read()) { if (xmlReader.NodeType == XmlNodeType.Element) { if (string.Compare(XmlConvert.DecodeName(xmlReader.Name), "psfieldDef", StringComparison.OrdinalIgnoreCase) == 0) { xmlReader.Read(); // Read psfieldDef } else if (string.Compare(XmlConvert.DecodeName(xmlReader.Name), "Tree Path", StringComparison.OrdinalIgnoreCase) == 0) { xmlReader.ReadStartElement(xmlReader.Name); // Read <Tree Path> psFields["TreeID"].Value = this.GetTreeIDFromTreePath(this.psDataStore.RootNode, xmlReader.Value); xmlReader.Read(); xmlReader.ReadEndElement(); } else if (string.Compare(XmlConvert.DecodeName(xmlReader.Name), "Related Bugs", StringComparison.OrdinalIgnoreCase) == 0) { xmlReader.ReadStartElement(xmlReader.Name); // Read <RelatedBugs> string product = xmlReader.Value.Substring(0, xmlReader.Value.IndexOf(':')); Int32 bugId = 0; Int32.TryParse(xmlReader.Value.Substring(xmlReader.Value.IndexOf(':') + 1), out bugId); ((Bug)psDataItem).AddRelatedLink(bugId, product); xmlReader.Read(); xmlReader.ReadEndElement(); } else if (string.Compare(XmlConvert.DecodeName(xmlReader.Name), "File", StringComparison.OrdinalIgnoreCase) == 0) { xmlReader.ReadStartElement(xmlReader.Name); // Read <File> ((Bug)psDataItem).Files.Add(xmlReader.Value); xmlReader.Read(); xmlReader.ReadEndElement(); } else { string fieldName = XmlConvert.DecodeName(xmlReader.Name); xmlReader.ReadStartElement(xmlReader.Name); // Read Start Element Ex. <Title> psFields[fieldName].Value = xmlReader.Value; xmlReader.Read(); xmlReader.ReadEndElement(); // Read End Element Ex. </Title> } } } // Let's make sure all fields are valid before saving foreach (Field psField in psDataItem.Fields) { if (psField.Validity != PsFieldStatusEnum.psFieldStatusValid) { hasInvalidField = true; throw new Exception("Invalid Field (" + psField.Name + ") with Value (" + psField.Value + "). Counld not new bug!"); } } if (hasInvalidField) { throw (new ApplicationException("Invalid Field(s) were found. Could not create new bug.")); } else { psDataItem.Save(true); return(Convert.ToInt32(psFields["ID"].Value)); } }
private void MakeTestCase(string module, string suite, string testcase) { string key = TestKey(module, suite, testcase); if (m_existing.ContainsKey(key)) { m_existedCount++; return; } // Create a new datastore instance. DatastoreItemList psDataList = new DatastoreItemListClass(); psDataList.Datastore = m_psDataStore; // Create a blank Test Case psDataList.CreateBlank(PsDatastoreItemTypeEnum.psDatastoreItemTypeTestCase); DatastoreItem psDataItem = psDataList.DatastoreItems.Add(null, PsApplyRulesMask.psApplyRulesAll); // Set fields for the Test Case Fields psFields = psDataItem.Fields; psFields["Title"].Value = key; psFields["TreeID"].Value = TreeIDFromPath(m_psDataStore.RootNode, "OS"); // psFields["TCMTreeID"].Value = -200; psFields["Test Status"].Value = "Active"; //psFields["Test Priority"].Value = 2; psFields["Test Module"].Value = module; psFields["Test Suite"].Value = suite; psFields["TestCase"].Value = testcase; // psFields["Test Class"].Value = "Boundary"; // psFields["Test Type"].Value = "Automatic"; // psFields["Frequency"].Value = "Daily"; psFields["Owner"].Value = "Active"; psFields["Description"].Value = "A test case generated from profile " + m_profile; // Let's make sure all fields are valid before saving bool hasInvalidField = false; foreach (Field psField in psDataItem.Fields) { if (psField.Validity != PsFieldStatusEnum.psFieldStatusValid) { hasInvalidField = true; Console.WriteLine("Invalid Field '{0}': {1}", psField.Name, psField.Validity.ToString()); Console.WriteLine("Current Value: '{0}'", psField.Value); Console.WriteLine(); } } if (hasInvalidField) { throw (new ApplicationException("Invalid Field(s) were found. Could not update.")); } else { psDataItem.Save(true); int testCaseID = Convert.ToInt32(psFields["ID"].Value); Console.WriteLine("Test Case #{0} {1} Successfully Created.", testCaseID, key); } m_createdCount++; }