Esempio n. 1
0
    public override void Run()
    {
        if (Arguments.Length < 3)
            {
                Console.WriteLine("Usage: tf label <label> <itemSpec>");
                Environment.Exit((int)ExitCode.Failure);
            }

        string labelName = Arguments[0];
        string itemPath = Path.GetFullPath(Arguments[2]);

        // parse arguments
        LabelChildOption childOption = (LabelChildOption) Enum.Parse(typeof(LabelChildOption), OptionChild, true);
        RecursionType rtype = OptionRecursive ? RecursionType.Full : RecursionType.None;
        ItemSpec itemSpec = new ItemSpec(itemPath, rtype);

        VersionControlLabel label = new VersionControlLabel(VersionControlServer, labelName,
                                                                                                                OwnerFromString(OptionOwner), null, OptionComment);

        List<LabelItemSpec> labelItemSpecs = new List<LabelItemSpec>();
        Workspace workspace = GetWorkspaceFromCache();

        labelItemSpecs.Add(new LabelItemSpec(itemSpec, new WorkspaceVersionSpec(workspace), false));

        LabelResult[] results = VersionControlServer.CreateLabel(label, labelItemSpecs.ToArray(),
                                                                                                                         childOption);

        foreach (LabelResult result in results)
            {
                Console.WriteLine("{0} label {1}@{2}", result.Status, result.Label,
                                                    result.Scope);
            }
    }
Esempio n. 2
0
    public void BriefOutput(VersionControlLabel[] labels)
    {
        int maxName = 9, maxOwner = 5;
        foreach (VersionControlLabel label in labels)
            {
                if (label.Name.Length > maxName) maxName = label.Name.Length;

                // domain is stripped on output
                int ownerNameLen = label.OwnerName.Length;
                int slash = label.OwnerName.IndexOf('\\');
                if (-1 != slash) ownerNameLen = label.OwnerName.Length - slash;

                if (ownerNameLen > maxOwner)
                    {
                        maxOwner = ownerNameLen;
                    }
            }

        int maxDate = WindowWidth - maxName - maxOwner - 3;
        if (maxDate < 0) maxDate = 0;

        string line = String.Format("{0} {1} {2}",
                                                                "Label".PadRight(maxName),
                                                                "Owner".PadRight(maxOwner),
                                                                "Date".PadRight(maxDate));
        Console.WriteLine(line);

        line = String.Format("{0} {1} {2}",
                                                 "-".PadRight(maxName, '-'),
                                                 "-".PadRight(maxOwner, '-'),
                                                 "-".PadRight(maxDate, '-'));
        Console.WriteLine(line);

        foreach (VersionControlLabel label in labels)
            {
                string date = label.LastModifiedDate.ToString("d");

                // domain is stripped on output
                string ownerName = label.OwnerName;
                int slash = label.OwnerName.IndexOf('\\');
                if (-1 != slash)
                    {
                        ownerName = label.OwnerName.Substring(slash+1);
                    }

                line = String.Format("{0} {1} {2}",
                                                         label.Name.PadRight(maxName),
                                                         ownerName.PadRight(maxOwner),
                                                         date);
                Console.WriteLine(line);
            }
    }
Esempio n. 3
0
        public LabelResult[] LabelItem(Workspace workspace, VersionControlLabel label,
                                       LabelItemSpec[] labelSpecs, LabelChildOption children)
        {
            Message msg = new Message(GetWebRequest(new Uri(Url)), "LabelItem");

            msg.Body.WriteElementString("workspaceName", workspace.Name);
            msg.Body.WriteElementString("workspaceOwner", workspace.OwnerName);
            label.ToXml(msg.Body, "label");

            msg.Body.WriteStartElement("labelSpecs");
            foreach (LabelItemSpec labelSpec in labelSpecs)
            {
                labelSpec.ToXml(msg.Body, "LabelItemSpec");
            }
            msg.Body.WriteEndElement();

            msg.Body.WriteElementString("children", children.ToString());

            List <LabelResult> labelResults = new List <LabelResult>();
            List <Failure>     faillist     = new List <Failure>();

            using (HttpWebResponse response = Invoke(msg))
            {
                XmlReader results = msg.ResponseReader(response);

                while (results.Read())
                {
                    if (results.NodeType == XmlNodeType.Element)
                    {
                        switch (results.Name)
                        {
                        case "LabelResult":
                            labelResults.Add(LabelResult.FromXml(this, results));
                            break;

                        case "Failure":
                            faillist.Add(Failure.FromXml(this, results));
                            break;
                        }
                    }
                }
            }

            foreach (Failure failure in faillist)
            {
                versionControlServer.OnNonFatalError(workspace, failure);
            }

            return(labelResults.ToArray());
        }
Esempio n. 4
0
        internal static VersionControlLabel FromXml(Repository repository, XmlReader reader)
        {
            VersionControlLabel label = new VersionControlLabel();
            string elementName        = reader.Name;

            label.lastModifiedDate = DateTime.Parse(reader.GetAttribute("date"));
            label.name             = reader.GetAttribute("name");
            label.ownerName        = reader.GetAttribute("owner");
            label.scope            = reader.GetAttribute("scope");
            label.labelId          = Convert.ToInt32(reader.GetAttribute("lid"));

            List <Item> items = new List <Item>();

            while (reader.Read())
            {
                if (reader.NodeType == XmlNodeType.EndElement && reader.Name == elementName)
                {
                    break;
                }

                if (reader.NodeType == XmlNodeType.Element)
                {
                    switch (reader.Name)
                    {
                    case "Item":
                        items.Add(Item.FromXml(repository, reader));
                        break;

                    case "Comment":
                        label.comment = reader.ReadString();
                        break;
                    }
                }
            }

            label.items = items.ToArray();
            return(label);
        }
        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();
        }
Esempio n. 6
0
        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");

                // Create Label Item Spec.
                ItemSpec itemSpec = new ItemSpec(this.ProjectPath, RecursionType.Full);
                LabelItemSpec[] labelItemSpec = new LabelItemSpec[] {  
                    new LabelItemSpec(itemSpec, this.WorkingVersion, false)
                };

                this.SourceControl.CreateLabel(label, labelItemSpec, LabelChildOption.Replace);
            }
        }
Esempio n. 7
0
    public void DetailedOutput(VersionControlLabel[] labels)
    {
        bool first = true;

        foreach (VersionControlLabel label in labels)
            {
                if (!first)
                    {
                        Console.WriteLine("=".PadRight(WindowWidth, '='));
                    }
                else first = false;

                Console.WriteLine("Label  : " + label.Name);
                Console.WriteLine("Scope  : " + label.Scope);
                Console.WriteLine("Owner  : " + label.OwnerName);
                Console.WriteLine("Date   : " + label.LastModifiedDate.ToString("F"));
                Console.WriteLine("Comment: " + label.Comment);

                Console.WriteLine();
                Console.WriteLine("Changeset Item");
                Console.WriteLine("--------- {0}", new String('-', 70));

                foreach (Item item in label.Items)
                    {
                        Console.WriteLine(item.ChangesetId + "      " + item.ServerItem);
                    }

                Console.WriteLine();
            }
    }
        /// <summary>
        /// Applies the specified label to the specified source path
        /// </summary>
        /// <param name="label">label to apply</param>
        /// <param name="sourcePath">path to apply label to</param>
        public void ApplyLabel(string label, string sourcePath)
        {
            // verify sourcePath
            if (string.IsNullOrEmpty(sourcePath)) throw new ArgumentNullException("sourcePath");
            sourcePath = BuildSourcePath(sourcePath);

            using (var tfs = this.GetTeamProjectCollection())
            {
                var versionControlService = tfs.GetService<VersionControlServer>();

                var versionControlLabel = new VersionControlLabel(versionControlService, label, versionControlService.AuthenticatedUser, sourcePath, "Label applied by BuildMaster");
                versionControlService.CreateLabel(versionControlLabel, new[] { new LabelItemSpec(new ItemSpec(sourcePath, RecursionType.Full), VersionSpec.Latest, false) }, LabelChildOption.Replace);
            }
        }
Esempio n. 9
0
        internal static VersionControlLabel FromXml(Repository repository, XmlReader reader)
        {
            VersionControlLabel label = new VersionControlLabel();
            string elementName = reader.Name;

            label.lastModifiedDate = DateTime.Parse(reader.GetAttribute("date"));
            label.name = reader.GetAttribute("name");
            label.ownerName = reader.GetAttribute("owner");
            label.scope = reader.GetAttribute("scope");
            label.labelId = Convert.ToInt32(reader.GetAttribute("lid"));

             			List<Item> items = new List<Item>();
            while (reader.Read())
                {
                    if (reader.NodeType == XmlNodeType.EndElement && reader.Name == elementName)
                        break;

                    if (reader.NodeType == XmlNodeType.Element)
                        {
                            switch (reader.Name)
                                {
                                case "Item":
                                    items.Add(Item.FromXml(repository, reader));
                                    break;
                                case "Comment":
                                    label.comment = reader.ReadString();
                                    break;
                                }
                        }
                }

            label.items = items.ToArray();
            return label;
        }
Esempio n. 10
0
        public LabelResult[] CreateLabel(VersionControlLabel label,
																			LabelItemSpec[] labelSpecs,
																			LabelChildOption childOption)
        {
            Workspace workspace = GetWorkspace(labelSpecs[0].ItemSpec.Item);
            return repository.LabelItem(workspace, label, labelSpecs, childOption);
        }
Esempio n. 11
0
        public LabelResult[] LabelItem(Workspace workspace, VersionControlLabel label, 
																	 LabelItemSpec[] labelSpecs, LabelChildOption children)
        {
            Message msg = new Message(GetWebRequest (new Uri(Url)), "LabelItem");

            msg.Body.WriteElementString("workspaceName", workspace.Name);
            msg.Body.WriteElementString("workspaceOwner", workspace.OwnerName);
            label.ToXml(msg.Body, "label");

            msg.Body.WriteStartElement("labelSpecs");
            foreach (LabelItemSpec labelSpec in labelSpecs)
                {
                    labelSpec.ToXml(msg.Body, "LabelItemSpec");
                }
            msg.Body.WriteEndElement();

            msg.Body.WriteElementString("children", children.ToString());

            List<LabelResult> labelResults = new List<LabelResult>();
            List<Failure> faillist = new List<Failure>();

            using (HttpWebResponse response = Invoke(msg))
                {
                    XmlReader results = msg.ResponseReader(response);

                    while (results.Read())
                        {
                            if (results.NodeType == XmlNodeType.Element)
                                {
                                    switch (results.Name)
                                        {
                                        case "LabelResult":
                                            labelResults.Add(LabelResult.FromXml(this, results));
                                            break;
                                        case "Failure":
                                            faillist.Add(Failure.FromXml(this, results));
                                            break;
                                        }
                                }
                        }
                }

            foreach (Failure failure in faillist)
                {
                    versionControlServer.OnNonFatalError(workspace, failure);
                }

            return labelResults.ToArray();
        }
Esempio n. 12
0
        private void ApplyLabel(TfsSourceControlContext context, string label)
        {
            using (var tfs = this.GetTeamProjectCollection())
            {
                var versionControlService = tfs.GetService<VersionControlServer>();

                var versionControlLabel = new VersionControlLabel(versionControlService, label, versionControlService.AuthorizedUser, context.SourcePath, "Label applied by BuildMaster");
                versionControlService.CreateLabel(versionControlLabel, new[] { new LabelItemSpec(new ItemSpec(context.SourcePath, RecursionType.Full), VersionSpec.Latest, false) }, LabelChildOption.Replace);
            }
        }