public static SortedDictionary <string, string> GetBuilds(string projName, string defName)
        {
            SortedDictionary <string, string> lsBuildsQuery = new SortedDictionary <string, string>();

            try
            {
                IBuildServer buildServer     = (IBuildServer)tfs.GetService(typeof(IBuildServer));
                ILinking     iLinkingService = tfs.GetService <ILinking>(); //can be used later to get build URL link

                //Specify query
                IBuildDetailSpec spec = buildServer.CreateBuildDetailSpec(projName.Trim(), defName.Trim());
                spec.InformationTypes = null;                             // for speed improvement
                spec.MinFinishTime    = DateTime.Now.AddDays(-21);        //to get only builds of last 2 weeks
                //spec.MaxBuildsPerDefinition = 1; //get only one build per build definintion
                spec.QueryOrder   = BuildQueryOrder.FinishTimeDescending; //get the latest build only
                spec.QueryOptions = QueryOptions.All;

                IBuildDetail[]      bDetails  = buildServer.QueryBuilds(spec).Builds;
                List <IBuildDetail> ibDetails = bDetails.OrderBy(x => x.CompilationStatus == BuildPhaseStatus.Succeeded).OrderByDescending(x => x.StartTime).Take(10).ToList();
                foreach (IBuildDetail ibdet in ibDetails)
                {
                    lsBuildsQuery.Add(ibdet.BuildNumber, ibdet.Uri.Port.ToString());
                }
            }
            catch (Exception ex)
            {
                lsBuildsQuery.Add("Please Load the definition first", "-1");
            }
            return(lsBuildsQuery);
        }
示例#2
0
    public override void Run()
    {
        WorkItemStore store     = Driver.TeamFoundationServer.GetService(typeof(WorkItemStore)) as WorkItemStore;
        ILinking      linking   = Driver.TeamFoundationServer.GetService(typeof(ILinking)) as ILinking;
        int           changeSet = 1;

        // Get URI for changeset
        ArtifactId changeSetId = new ArtifactId();

        changeSetId.Tool           = "VersionControl";
        changeSetId.ArtifactType   = "ChangeSet";
        changeSetId.ToolSpecificId = changeSet.ToString();
        string changeSetUri = LinkingUtilities.EncodeUri(changeSetId);

        // Get referencing artifacts for given changeset
        Artifact[] artifacts = linking.GetReferencingArtifacts(new string[] { changeSetUri }, null);

        foreach (Artifact artifact in artifacts)
        {
            Console.WriteLine(artifact.ToString());
            ArtifactId artifactId = LinkingUtilities.DecodeUri(artifact.Uri);
            if (String.Equals(artifactId.Tool, "WorkItemTracking", StringComparison.OrdinalIgnoreCase))
            {
                WorkItem wi = store.GetWorkItem(Convert.ToInt32(artifactId.ToolSpecificId));
                Console.WriteLine(wi);
            }
        }
    }
示例#3
0
        public TfsConnector(string url)
        {
            //var excludedDirs = new[] { "CodeAnalysis", "QA", "_AutomatedBuild" };

            _tfsTeamProjectCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(url, UriKind.Absolute));
            _itemStore       = _tfsTeamProjectCollection.GetService <WorkItemStore>();
            _changesetServer = _tfsTeamProjectCollection.GetService <VersionControlServer>();
            _linkingServer   = _tfsTeamProjectCollection.GetService <ILinking>();
        }
示例#4
0
        public static void List(string[] args)
        {
            if (args.Length < 2)
            {
                Console.WriteLine("Usage: WorkItemHelper.List <URL for TFS> <server path>");
                //Environment.Exit(1);
                return;
            }

            TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(new Uri(args[0]));
            VersionControlServer     vcs = tpc.GetService <VersionControlServer>();

            // Get the changeset artifact URIs for each changeset in the history query
            List <string> changesetArtifactUris = new List <string>();

            foreach (Object obj in vcs.QueryHistory(args[1],                       // path we care about ($/project/whatever)
                                                    VersionSpec.Latest,            // version of that path
                                                    0,                             // deletion ID (0 = not deleted)
                                                    RecursionType.Full,            // entire tree - full recursion
                                                    null,                          // include changesets from all users
                                                    new ChangesetVersionSpec(1),   // start at the beginning of time
                                                    VersionSpec.Latest,            // end at latest
                                                    100,                           // only return these max count rows
                                                    false,                         // we don't want the files changed
                                                    true))                         // do history on the path
            {
                Changeset c = obj as Changeset;
                changesetArtifactUris.Add(c.ArtifactUri.AbsoluteUri);
            }

            // We'll use the linking service to get information about the associated work items
            ILinking   linkingService = tpc.GetService <ILinking>();
            LinkFilter linkFilter     = new LinkFilter();

            linkFilter.FilterType   = FilterType.ToolType;
            linkFilter.FilterValues = new string[1] {
                ToolNames.WorkItemTracking
            };                                                                       // we only want work items

            // Convert the artifact URIs for the work items into strongly-typed objects holding the properties rather than name/value pairs
            Artifact[] artifacts = linkingService.GetReferencingArtifacts(changesetArtifactUris.ToArray(), new LinkFilter[1] {
                linkFilter
            });
            AssociatedWorkItemInfo[] workItemInfos = AssociatedWorkItemInfo.FromArtifacts(artifacts);

            // Here we'll just print the IDs and titles of the work items
            foreach (AssociatedWorkItemInfo workItemInfo in workItemInfos.OrderByDescending(a => a.Id).ToList())
            {
                Console.WriteLine("Id: " + workItemInfo.Id + " Title: " + workItemInfo.Title);
            }
        }
示例#5
0
文件: TFS.cs 项目: Eun/TFSMonkey
        private void Initialize(Uri server, TfsClientCredentials credential)
        {
            _connection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(server);

            if (credential != null)
            {
                _connection.ClientCredentials = credential;
            }

            _connection.EnsureAuthenticated();

            _versionControlServer = _connection.GetService <VersionControlServer>();
            _linkingService       = _connection.GetService <ILinking>();
            Url = server.AbsoluteUri;
        }