/// <summary> /// controllo Global List /// </summary> /// <param name="tfs"> /// connessione a TFS /// </param> /// <param name="project"> /// progetto da analizzare /// </param> /// <param name="cis"> /// ci software /// </param> /// <returns> /// true o false in base all'esito /// </returns> public static bool ControlloGlobalList(TfsTeamProjectCollection tfs, string project, string cis) { var store = new WorkItemStore(tfs); var globallists = store.ExportGlobalLists(); XmlNode globalList = globallists.SelectSingleNode("//GLOBALLIST[@name='CIS']"); XmlNodeList xml = globalList.ChildNodes; foreach (XmlNode x in xml) { if (x.Attributes[0].Value.Equals(cis)) { return true; } } return false; }
/// <summary> /// scrittura sulla global list. /// prende l'esistente e aggiunge il nuovo /// </summary> /// <param name="collection"> /// collection a cui collegarsi /// </param> /// <param name="tp"> /// tp per cui scrivere la global list /// </param> public static void ScriviGlobalList(String tfsName, string collection, List<TP> tp) { using (var tfs = new TfsTeamProjectCollection(new Uri(tfsName + collection), Cred)) { try { List<string> cisSoftware = new List<string>(); // Console.WriteLine("Avviato servizio su " + server.Uri.ToString()); // Console.WriteLine("loggato come " + System.Security.Principal.WindowsIdentity.GetCurrent().Name); var store = new WorkItemStore(tfs); // Console.WriteLine("ho creato lo store"); var globallists = store.ExportGlobalLists(); // Console.WriteLine("ho scaricato le global list"); RemoveAllListItem(globallists, "//GLOBALLIST[@name='CIS']"); // Console.WriteLine("ho rimosso i vecchi CIS"); var nuove = AddListItems(globallists, "//GLOBALLIST[@name='CIS']", "LISTITEM", "non disponibile"); foreach (var cis in tp) { if (!cisSoftware.Contains(cis.CISoftware)) { cisSoftware.Add(cis.CISoftware); nuove = AddListItems(globallists, "//GLOBALLIST[@name='CIS']", "LISTITEM", cis.CISoftware); } } // Console.WriteLine("ho creato le nuove global list"); // var xmlFileName = System.IO.Directory.GetCurrentDirectory() + @"\tmp.xml"; // globallists.Save(xmlFileName); store.ImportGlobalLists(globallists.InnerXml); store.RefreshCache(); // Console.WriteLine("ho importato le nuove global list su tfs " + server.Uri.ToString()); // Console.WriteLine("operazione completata"); } catch (Exception ex) { Logger.Error(new LogInfo(System.Reflection.MethodBase.GetCurrentMethod(), "INT", string.Format("errore in scrittura GlobalList: {0}", ex.Message))); throw ex; } } }
/// <summary> /// Gets or creates the global lists document. /// </summary> /// <returns></returns> private XmlDocument GetOrCreateGlobalListsXmlDocument(WorkItemStore workItemStore) { if (workItemStore == null) throw new ArgumentNullException("workItemStore"); XmlDocument xmlDocument = workItemStore.ExportGlobalLists(); if (xmlDocument != null) return xmlDocument; xmlDocument = new XmlDocument(); //Define encoding for non english languages XmlProcessingInstruction xmlProcessingInstruction = xmlDocument.CreateProcessingInstruction(ProcessingInstructionTarget, ProcessingInstructionData); xmlDocument.AppendChild(xmlProcessingInstruction); var globalListsRoot = xmlDocument.CreateElement(GlobalListsPrefix, GlobalListsIdentifier, GlobalListsNamespace); xmlDocument.AppendChild(globalListsRoot); return xmlDocument; }