protected override void ExecuteTask() { VersionControlLabel label = new VersionControlLabel(this.ServerConnection.SourceControl, this.LabelName, this.ServerConnection.SourceControl.AuthenticatedUser, this.Scope, this.Comment); RecursionType TypeOfRecursion = GetRecustiveOption(); ItemSpec itemSpec = new ItemSpec(this.ItemSpec, TypeOfRecursion); LabelItemSpec[] labelItemSpec = new LabelItemSpec[] { new LabelItemSpec(itemSpec, this.VersionSpec.GetVersionSpec(), false) }; this.ServerConnection.SourceControl.CreateLabel(label, labelItemSpec, LabelChildOption.Replace); }
public void LabelSourceControl(IIntegrationResult result) { if (ApplyLabel && result.Succeeded) { Log.Debug(String.Format("Applying label \"{0}\"", result.Label)); VersionControlLabel Label = new VersionControlLabel(this.SourceControl, result.Label, _SourceControl.AuthenticatedUser, this.ProjectPath, "Labeled by CruiseControl.NET"); Changeset Set = this.ChangesetQueue.GetCurrentIntegrationSet(); LabelItemSpec[] LabelSpec = new LabelItemSpec[] { new LabelItemSpec(new ItemSpec(this.ProjectPath, RecursionType.Full), new ChangesetVersionSpec(Set.ChangesetId), false) }; this.SourceControl.CreateLabel(Label, LabelSpec, LabelChildOption.Replace); } this.ChangesetQueue.EndIntegration(); }
private void PerformLabel(SourceProject project, IIntegrationResult result) { if (project.ApplyLabel) { Log.Debug(String.Format("Applying label \"{0}\" on project \"{1}\"", result.Label, project.ProjectPath)); string comment = result.StartTime.ToString() + " on " + project.ProjectPath; VersionControlLabel vcLabel = new VersionControlLabel( this.SourceControl, result.Label, this.SourceControl.AuthorizedUser, project.ProjectPath, comment); // Create Label Item Spec. ItemSpec itemSpec = new ItemSpec(project.ProjectPath, RecursionType.Full); LabelItemSpec[] labelItemSpec = new LabelItemSpec[] { new LabelItemSpec(itemSpec, new DateVersionSpec(result.StartTime), false) }; this.SourceControl.CreateLabel(vcLabel, labelItemSpec, LabelChildOption.Replace); } }
/// <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(); } }