Пример #1
0
        static ITestManagementTeamProject GetProject(string serverUrl, string project)
        {
            TfsTeamProjectCollection tfs = new TfsTeamProjectCollection(TfsTeamProjectCollection.GetFullyQualifiedUriForName(serverUrl));
            ITestManagementService   tms = tfs.GetService <ITestManagementService>();

            return(tms.GetTeamProject(project));
        }
Пример #2
0
        private static Workspace GetWorkspace(WorkspaceInfo workspaceInfo)
        {
            string tfsName     = workspaceInfo.ServerUri.AbsoluteUri;
            var    credentials = System.Net.CredentialCache.DefaultCredentials; //new System.Net.NetworkCredential(userName, password, domain);
            var    projects    = new TfsTeamProjectCollection(TfsTeamProjectCollection.GetFullyQualifiedUriForName(tfsName), credentials, new UICredentialsProvider());

            return(workspaceInfo.GetWorkspace(projects));
        }
Пример #3
0
        private static IIdentityManagementService GetIdentityManagementService(string address)
        {
            var tfs =
                TfsTeamProjectCollectionFactory.GetTeamProjectCollection(
                    TfsTeamProjectCollection.GetFullyQualifiedUriForName(address));
            var ims = tfs.GetService <IIdentityManagementService>();

            return(ims);
        }
Пример #4
0
 public AuthTfsTeamProjectCollection(ITFS tfs)
 {
     TFS = tfs;
     if (Tfs == null || Tfs.Name != tfs.Context.DomainName)
     {
         Tfs =
             TfsTeamProjectCollectionFactory.GetTeamProjectCollection(
                 TfsTeamProjectCollection.GetFullyQualifiedUriForName(TFS.Context.DomainUri));
     }
 }
Пример #5
0
        public override void Load()
        {
            var teamFoundationServerUrl = ConfigurationManager.AppSettings["TeamFoundationServerUrl"];
            var tfs = new TfsTeamProjectCollection(TfsTeamProjectCollection.GetFullyQualifiedUriForName(teamFoundationServerUrl));

            Bind <IBuildServer>().ToMethod(ctx => tfs.GetService <IBuildServer>());
            Bind <VersionControlServer>().ToMethod(ctx => tfs.GetService <VersionControlServer>());
            Bind <ITestManagementService>().ToMethod(ctx => tfs.GetService <ITestManagementService>());

            Bind <IBuildService>().To <Tfs2010BuildService>().InSingletonScope();
        }
Пример #6
0
        private void ChangeConnection()
        {
            if (!string.IsNullOrEmpty(this.ctx.ActiveConnection))
            {
                var collection = new TfsTeamProjectCollection(TfsTeamProjectCollection.GetFullyQualifiedUriForName(this.ctx.ActiveConnection), new TfsClientCredentials());
                collection.EnsureAuthenticated();

                var view = this.Content as MainView;
                view.InitializeContext(this.ctx);
                view.InitializeRepository(new TfsClientRepository(collection));
            }
        }
Пример #7
0
        /// <summary>
        /// The constructor sets up build service based on server key
        /// </summary>
        /// <param name="tfsserverKey"></param>
        public TFSBuildService(string tfsserverKey)
        {
            var tfs = new TfsTeamProjectCollection(TfsTeamProjectCollection.GetFullyQualifiedUriForName(tfsserverKey));

            this._buildServer           = tfs.GetService <IBuildServer>();
            this._versionControlServer  = tfs.GetService <VersionControlServer>();
            this._testManagementService = tfs.GetService <ITestManagementService>();
            _httpServiceTfs             = tfs.GetService <TswaClientHyperlinkService>();
            var tp = _versionControlServer.GetTeamProject(@"AllWG");

            pathofTeamProject = tp.ServerItem;
        }
        public static SortedDictionary <string, string> GetTestPlans(string collectionName, string projectName)
        {
            tfs  = new TfsTeamProjectCollection(TfsTeamProjectCollection.GetFullyQualifiedUriForName(XML.GetCollectionURL(collectionName)));
            tms  = tfs.GetService <ITestManagementService>();
            proj = tms.GetTeamProject(projectName);
            iTPC = proj.TestPlans.Query("Select * From TestPlan");
            SortedDictionary <string, string> iTP = new SortedDictionary <string, string>();

            foreach (ITestPlan itp in iTPC)
            {
                iTP.Add(itp.Id.ToString(), itp.Name);
            }
            return(iTP);
        }
        public override void ExecuteCommand()
        {
            TfsClientCredentials cred = new TfsClientCredentials(new WindowsCredential(new NetworkCredential(UserName, Password)), true);

            cred.AllowInteractive = true;
            tfs = new TfsTeamProjectCollection(TfsTeamProjectCollection.GetFullyQualifiedUriForName(HostUrl), cred);
            //Get data store that contains all workitems on a particular server
            store = tfs.GetService <WorkItemStore>();
            //Get particular Team Project
            project = store.Projects[ProjectName];
            Console.WriteLine("Connected to project: " + project.Name);
            CreatereportForSupportRequestsByCategory();
            CreatereportForSupportRequestSummary();
        }
Пример #10
0
    static void Main(string[] args)
    {
        string collection            = @"http://ictfs2015:8080/tfs/DefaultCollection";
        TfsTeamProjectCollection tfs = new TfsTeamProjectCollection(TfsTeamProjectCollection.GetFullyQualifiedUriForName(collection));

        tfs.EnsureAuthenticated();
        VersionControlServer vcs = tfs.GetService <VersionControlServer>();

        TeamProject[] teamProjects = vcs.GetAllTeamProjects(true);

        foreach (TeamProject proj in teamProjects)
        {
            System.Console.WriteLine(string.Format("Team Project: {0}", proj.Name));
        }
        System.Console.ReadLine();
    }
Пример #11
0
        private static TfsTeamProjectCollection GetTfsTeamProjectCollection(string server, string creds, string personalAccessToken)
        {
            var uri = TfsTeamProjectCollection.GetFullyQualifiedUriForName(server);

            if (creds == null)
            {
                Logger.Info("using personalAccessToken");
                return(personalAccessToken == null
                    ? new TfsTeamProjectCollection(uri, new VssClientCredentials())
                    : new TfsTeamProjectCollection(uri, new VssBasicCredential(string.Empty, personalAccessToken)));
            }

            Logger.Info("using creds");
            var credsLocal  = Regex.Match(creds, SyncUtil.CredsPatternDomain).Groups;
            var networkCred = new NetworkCredential(credsLocal[1].Value, credsLocal[2].Value, credsLocal[3].Value);
            var windowsCred = new WindowsCredential(networkCred);

            return(new TfsTeamProjectCollection(uri, new VssClientCredentials(windowsCred, CredentialPromptType.DoNotPrompt)));
        }
Пример #12
0
        public static TfsTeamProjectCollection CreateTfsCollection(string tfsName)
        {
            //This function may be a bit slow and runs on the UI thread, so would deserve optimization if many people are using it.
            //Works for VS 2017+, with assemblies from VS 15. Does not work when compiling the VSIX from VS 2015 (will cause an exception saying the assembly could not be found).
            Uri fullyQualifiedUriForName = TfsTeamProjectCollection.GetFullyQualifiedUriForName(tfsName);

            if (Resolvers.IdeHelper.VsMajorVersion < 17)
            {
                var vssCredentials           = VssClientCredentials.LoadCachedCredentials(fullyQualifiedUriForName, false, Microsoft.VisualStudio.Services.Common.CredentialPromptType.DoNotPrompt);
                var tfsTeamProjectCollection = new TfsTeamProjectCollection(fullyQualifiedUriForName, vssCredentials);
                return(tfsTeamProjectCollection);
            }
            //Only works with VS2022+
            var vssCredentials2           = new VssClientCredentials(useDefaultCredentials: true);
            var tfsTeamProjectCollection2 = new TfsTeamProjectCollection(fullyQualifiedUriForName, vssCredentials2);

            tfsTeamProjectCollection2.Authenticate(); //Will only prompt user to authenticate once normally.
            return(tfsTeamProjectCollection2);
        }
Пример #13
0
        public static TfsTeamProjectCollection CreateTfsCollection(string tfsName)
        {
            //Works for VS 2017+, with assemblies from VS 15. Does not work with VS 2015 (will cause an exception saying the assembly could not be found).
            Uri fullyQualifiedUriForName = TfsTeamProjectCollection.GetFullyQualifiedUriForName(tfsName);
            var vssCredentials           = Microsoft.VisualStudio.Services.Client.VssClientCredentials.LoadCachedCredentials(fullyQualifiedUriForName, false, Microsoft.VisualStudio.Services.Common.CredentialPromptType.DoNotPrompt);
            var tfsTeamProjectCollection = new TfsTeamProjectCollection(fullyQualifiedUriForName, vssCredentials);

            return(tfsTeamProjectCollection);

            //Works for VS 2015, with assemblies from VS 14, but to be compatible with VS 2017+, we'd need to:
            //1. Add the following in AssemblyInfo.cs to redirect the assembly with newer versions:
            //  [assembly: ProvideBindingRedirection(AssemblyName = "Microsoft.TeamFoundation.Client", NewVersion = "15.0.0.0", OldVersionLowerBound = "14.0.0.0", OldVersionUpperBound = "15.0.0.0")]
            //2. Mark the assembly as CopyLocal = true, otherwise it won't compile, saying the file could not be found. This would cause the whole extension to gain around 1 MB.
            //I have not tested if it would actually work for VS 2017+ (it would still require the newer assembly is retro-compatible with the one from V14).

            /*Uri fullyQualifiedUriForName = TfsTeamProjectCollection.GetFullyQualifiedUriForName(tfsName);
             * var vssCredentials = TfsClientCredentials.LoadCachedCredentials(fullyQualifiedUriForName, false, allowInteractive: false);
             * var tfsTeamProjectCollection = new TfsTeamProjectCollection(fullyQualifiedUriForName, vssCredentials);
             * return tfsTeamProjectCollection;*/
        }
Пример #14
0
        private void SetupServer()
        {
            var tfs = new TfsTeamProjectCollection(TfsTeamProjectCollection.GetFullyQualifiedUriForName(tfsServer));

            this.Store = tfs.GetService <WorkItemStore>();
        }
        static void Main(string[] args)
        {
            //Collection URL.
            string serverurl = "http://tfs-2015:8080/tfs/tfsdemo";
            //Workspace name.
            string workspaceName = "Checkin";
            //ID of Work Item that need to be associated.
            int workItemIdLink = 9;
            //Comment for check-in
            string checkinComment = "DemoCheckin";
            //Local path of the file
            var localPath = new DirectoryInfo("C:\\Users\\zhawan2\\Documents\\Workspaces\\ProjectForTest2015TFS");
            var file      = Path.Combine(localPath.FullName, "test.txt");

            try
            {
                TfsTeamProjectCollection tfsCollect     = new TfsTeamProjectCollection(TfsTeamProjectCollection.GetFullyQualifiedUriForName(serverurl));
                WorkItemStore            WIStore        = tfsCollect.GetService <WorkItemStore>();
                VersionControlServer     versionControl = tfsCollect.GetService <VersionControlServer>();
                string    user         = versionControl.AuthorizedUser;
                Workspace workSpace    = versionControl.GetWorkspace(workspaceName, user);
                WorkItem  workItem     = WIStore.GetWorkItem(workItemIdLink);
                var       WIChecInInfo = new[]
                {
                    new WorkItemCheckinInfo(workItem, WorkItemCheckinAction.Associate)
                };
                workSpace.PendEdit(file);
                int changesetNo = workSpace.CheckIn(workSpace.GetPendingChanges(), checkinComment, null, WIChecInInfo, null);
                if (changesetNo > 0)
                {
                    Console.Write("Checkin succeeded, changeset is: " + changesetNo + "\n");
                    //validate work item
                    ArrayList invalidFields = workItem.Validate();
                    if (invalidFields.Count > 0)
                    {
                        foreach (Field field in invalidFields)
                        {
                            string fieldStatus = field.Status.ToString();

                            Console.WriteLine("check-in succeeded, but associating work item failed \n" + fieldStatus);
                        }
                    }
                    else
                    {
                        Console.WriteLine("no validate error \n");
                    }
                }
                else
                {
                    Console.Write("no pending changes, please press Enter to exit \n");
                }
                Console.ReadLine();
            }
            catch (Exception ex)
            {
                var dir = new DirectoryInfo(Path.Combine(Path.GetTempPath(), "logs"));
                if (!dir.Exists)
                {
                    dir.Create();
                }
                var logFile = Path.Combine(dir.FullName, "log-" + DateTime.Now.ToString("yyyyMMdd-hhmmss") + ".txt");
                using (var stream = File.CreateText(logFile))
                {
                    stream.Write("Time: {0}; Exception: {1}", DateTime.Now, ex.Message + "\n" + ex.StackTrace);
                }
                Console.Write("Exception: " + ex.Message + "\n" + ex.StackTrace);
                Console.ReadLine();
            }
        }