/// <summary> /// Création d'un label lors de la publication /// </summary> /// <param name="model"></param> private void CreateLabel(CandleModel model, string modelFileName) { if (model == null || modelFileName == null) { return; } try { DTE dte = GetService <DTE>(); string solutionFolder = Path.GetDirectoryName(modelFileName); // Récupère les caractèristiques du workspace contenant le fichier contenant le modèle if (Workstation.Current == null) { throw new Exception("TFS not installed"); } WorkspaceInfo wi = Workstation.Current.GetLocalWorkspaceInfo(solutionFolder); if (wi == null) { LogError("The current solution is not in a Team System workspace"); return; } // Récupèration du server TFS à partir des infos du workspace TeamFoundationServer tfs = TeamFoundationServerFactory.GetServer(wi.ServerUri.AbsoluteUri); // Création d'un label sur la solution VersionControlServer vcs = tfs.GetService(typeof(VersionControlServer)) as VersionControlServer; vcs.NonFatalError += new ExceptionEventHandler(vcs_NonFatalError); // On prend tous les fichiers de la solution ItemSpec itemSpec = new ItemSpec(solutionFolder, RecursionType.Full); LabelItemSpec labelItemSpec = new LabelItemSpec(itemSpec, VersionSpec.Latest, false); string changeSet = "-"; // Calcul du nom du label string labelName = String.Format(labelNameFormat, DateTime.Now, wi.OwnerName, wi.Computer, model.Version, model.Version.Revision, changeSet); // Calcul du commentaire string labelComment = String.Format(labelCommentFormat, DateTime.Now, wi.OwnerName, wi.Computer, model.Version, model.Version.Revision, changeSet); //Checkin if (forceCheckin) { Workspace ws = wi.GetWorkspace(tfs); PendingChange[] pendingChanges = ws.GetPendingChanges(new ItemSpec[] { itemSpec }, false); if (pendingChanges.Length > 0) { changeSet = ws.CheckIn(pendingChanges, labelComment).ToString(); // Mise à jour de l'explorateur de solution (icones) Microsoft.VisualStudio.Shell.ServiceProvider serviceProvider = new Microsoft.VisualStudio.Shell.ServiceProvider((Microsoft.VisualStudio.OLE.Interop.IServiceProvider)dte); IVersionControlProvider versionControlProvider = (IVersionControlProvider)serviceProvider.GetService(typeof(IVersionControlProvider)); if (versionControlProvider != null) { versionControlProvider.RefreshStatus(); } // On intègre le changeset dans le commentaire labelName = String.Format(labelNameFormat, DateTime.Now, wi.OwnerName, wi.Computer, model.Version, model.Version.Revision, changeSet); labelComment = String.Format(labelCommentFormat, DateTime.Now, wi.OwnerName, wi.Computer, model.Version, model.Version.Revision, changeSet); } } string scope; string label; LabelSpec.Parse(labelName, null, false, out label, out scope); VersionControlLabel vcl = new VersionControlLabel(vcs, label, null, scope, labelComment); // Et on applique le label. LabelResult[] results = vcs.CreateLabel(vcl, new LabelItemSpec[] { labelItemSpec }, childOption); } catch (Exception ex) { LogError(ex); nbErrors++; } if (nbErrors > 0 && stopOnError) { throw new PublishingException(); } }