コード例 #1
0
        /// <summary>
        /// Get the label details.
        /// </summary>
        protected override void InternalExecute()
        {
            var label = this.Label.Get(this.ActivityContext);
            var vcs   = this.VersionControlServer.Get(this.ActivityContext);

            VersionControlLabel vclabel = null;

            if (!string.IsNullOrEmpty(label))
            {
                string str;
                string str2;
                LabelSpec.Parse(label, null, false, out str, out str2);

                if (!string.IsNullOrEmpty(str))
                {
                    var labels = vcs.QueryLabels(str, str2, null, true);
                    if (labels.Length > 0)
                    {
                        vclabel = labels[0];
                    }
                }
            }

            this.VersionControlLabel.Set(this.ActivityContext, vclabel);
        }
コード例 #2
0
        public VersionSpec GetVersionSpec()
        {
            switch (this.VersionSpecType)
            {
            case VersionSpecType.Changeset:
                return(new ChangesetVersionSpec(this.VersionSpecString));

            case VersionSpecType.Date:
                return(new DateVersionSpec(DateTime.Parse(this.VersionSpecString)));

            case VersionSpecType.Label:
                String Label;
                String Scope;
                LabelSpec.Parse(this.VersionSpecString, null, false, out Label, out Scope);
                return(new LabelVersionSpec(Label, Scope));

            case VersionSpecType.Latest:
                return(VersionSpec.Latest);
            }
            return(null);
        }
コード例 #3
0
        /// <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();
            }
        }