public static TfsConfigurationServer GetConfigurationServerAndAuthenticate(Uri tfsUrl)
        {
            TfsConfigurationServer tfsConfigurationServer = TfsConfigurationServerFactory.GetConfigurationServer(tfsUrl);

            tfsConfigurationServer.Authenticate();
            return(tfsConfigurationServer);
        }
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="username">Username on the service.</param>
 /// <param name="password">Password on the service.</param>
 /// <param name="domain">Domain on the service.</param>
 /// <param name="host">Root path of the service.</paparam>
 internal TeamFoundationServerService(String username, String password, String domain, String host)
 {
     _username = username;
     _configurationServer = GetConfigurationServer(username, password, domain, host);
     try
     {
         _configurationServer.Authenticate();
     }
     catch (Exception)
     {
         try
         {
             Uri url = new Uri(host);
             String ip = Dns.GetHostAddresses(url.DnsSafeHost).First().ToString();
             String newHost = url.Scheme + "://" + ip + ":" + url.Port + url.PathAndQuery;
             _configurationServer = GetConfigurationServer(username, password, domain, newHost);
             _configurationServer.Authenticate();
         }
         catch (TeamFoundationServiceUnavailableException)
         {
             //if authentication fail
             return;
         }
     }
 }
示例#3
0
        public IList <KeyValuePair <Guid, String> > GetCollections()
        {
            //ApplicationLogger.Log("Entered into GetCollections() : ");
            var collectionList = new List <KeyValuePair <Guid, String> >();

            try
            {
                _TfsConfigurationServer.Authenticate();

                ReadOnlyCollection <CatalogNode> collectionNodes = _TfsConfigurationServer.CatalogNode.QueryChildren(
                    new[] { CatalogResourceTypes.ProjectCollection },
                    false,
                    CatalogQueryOptions.None);
                foreach (CatalogNode collectionNode in collectionNodes)
                {
                    var collectionId = new Guid(collectionNode.Resource.Properties["InstanceId"]);
                    TfsTeamProjectCollection teamProjectCollection =
                        _TfsConfigurationServer.GetTeamProjectCollection(collectionId);

                    if (teamProjectCollection == null)
                    {
                        continue;
                    }

                    collectionList.Add(new KeyValuePair <Guid, String>(collectionId, teamProjectCollection.Name));
                }
            }
            catch (Exception e)
            {
                //ApplicationLogger.Log(e);
            }

            return(collectionList);
        }
示例#4
0
        public static TfsConfigurationServer AuthenticateToTFSService()
        {
            Uri                  tfsUri    = new Uri(GetConfigValue("$Instance.VSOnlineUri$"));
            string               username  = GetConfigValue("$Instance.Username$");
            string               password  = GetConfigValue("$Instance.Password$");
            NetworkCredential    netCred   = new NetworkCredential(username, password);
            BasicAuthCredential  basicCred = new BasicAuthCredential(netCred);
            TfsClientCredentials tfsCred   = new TfsClientCredentials(basicCred);

            tfsCred.AllowInteractive = false;

            TfsConfigurationServer configurationServer = new TfsConfigurationServer(new Uri(tfsUrl), tfsCred);

            configurationServer.Authenticate();
            return(configurationServer);

            //If you specify a provider, the user will be provided with a prompt to provide non-default credentials
            ICredentialsProvider   provider = new UICredentialsProvider();
            TfsConfigurationServer tfs      = TfsConfigurationServerFactory.GetConfigurationServer(tfsUri, provider);

            try
            {
                //Prompts the user for credentials if they have not already been authenticated
                tfs.EnsureAuthenticated();
            }
            catch (TeamFoundationServerUnauthorizedException)
            {
                //Handle the TeamFoundationServerUnauthorizedException that is thrown when the user clicks 'Cancel'
                //in the authentication prompt or if they are otherwise unable to be successfully authenticated
                tfs = null;
            }

            return(tfs);
        }
        public static TfsConfigurationServer GetConfigurationServerAndAuthenticate(Uri tfsUrl, string domain, string userName, string password)
        {
            TfsConfigurationServer tfsConfigurationServer = TfsConfigurationServerFactory.GetConfigurationServer(tfsUrl);

            tfsConfigurationServer.Credentials = new NetworkCredential(userName, password, domain);
            tfsConfigurationServer.Authenticate();
            return(tfsConfigurationServer);
        }
示例#6
0
        /// <summary>
        /// The get catalog nodes.
        /// </summary>
        /// <param name="uri">
        /// The uri.
        /// </param>
        /// <returns>
        /// The <see cref="List"/>.
        /// </returns>
        private List <CatalogNode> GetCatalogNodes(Uri uri, ICredentials cred, bool anotherUser)
        {
            List <CatalogNode> catalogNodes = null;

            try
            {
                connectUri = uri;
                TfsClientCredentials tfsClientCredentials;
                if (anotherUser)
                {
                    if (connectUri.ToString().Contains(".visualstudio.com"))
                    {
                        tfsClientCredentials = new TfsClientCredentials(false);
                    }
                    else
                    {
                        Microsoft.TeamFoundation.Client.WindowsCredential wcred = new Microsoft.TeamFoundation.Client.WindowsCredential(false);
                        tfsClientCredentials = new TfsClientCredentials(wcred);
                    }
                }
                else
                {
                    if (connectUri.ToString().Contains(".visualstudio.com"))
                    {
                        tfsClientCredentials = new TfsClientCredentials();
                    }
                    else
                    {
                        Microsoft.TeamFoundation.Client.WindowsCredential wcred = new Microsoft.TeamFoundation.Client.WindowsCredential(true);
                        tfsClientCredentials = new TfsClientCredentials(wcred);
                    }
                }

                using (TfsConfigurationServer serverConfig = new TfsConfigurationServer(uri, tfsClientCredentials))
                {
                    serverConfig.Authenticate();
                    serverConfig.EnsureAuthenticated();
                    if (serverConfig.HasAuthenticated)
                    {
                        Credential   = serverConfig.Credentials;
                        catalogNodes = serverConfig.CatalogNode.QueryChildren(new[] { CatalogResourceTypes.ProjectCollection }, false, CatalogQueryOptions.None).OrderBy(f => f.Resource.DisplayName).ToList();
                    }
                }
            }
            catch (TeamFoundationServiceUnavailableException ex)
            {
                MessageBox.Show(ResourceHelper.GetResourceString("MSG_TFS_SERVER_IS_INACCESSIBLE") + "\n" + uri.OriginalString, ResourceHelper.GetResourceString("ERROR_TEXT"), MessageBoxButton.OK, MessageBoxImage.Error);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, ResourceHelper.GetResourceString("ERROR_TEXT"), MessageBoxButton.OK, MessageBoxImage.Error);
                return(catalogNodes);
            }

            return(catalogNodes);
        }
示例#7
0
        public void IntegrationTestUpdateRetentionPolicies()
        {
            TfsConfigurationServer tfsConfigurationServer = TfsConfigurationServerFactory.GetConfigurationServer(new Uri("myTfsUrl"));

            tfsConfigurationServer.Authenticate();
            TeamProjectDtoCollection allTeamProjectCollections = tfsConfigurationServer.GetAllTeamProjectsInAllTeamProjectCollections();

            foreach (TeamProjectDto teamProjectDto in allTeamProjectCollections)
            {
                TfsTeamProjectCollection teamProjectCollection = tfsConfigurationServer.GetTeamProjectCollection(teamProjectDto.CollectionId);
                IBuildServer             buildServer           = teamProjectCollection.GetService <IBuildServer>();
                BuildServerFacade        buildServerFacade     = new BuildServerFacade(buildServer);
                buildServerFacade.UpdateRetentionPolicies(teamProjectDto.DisplayName, 1, 5, 5, 10, "All");
            }
        }
示例#8
0
        public static void UpdateRetentionPolicies(Uri tfsUrl, string teamProjectName, int numberOfStoppedBuildsToKeep, int numberOfFailedBuildsToKeep, int numberOfPartiallySucceededBuildsToKeep, int numberOfSucceededBuildsToKeep, string deleteOptions)
        {
            TfsConfigurationServer tfsConfigurationServer = TfsConfigurationServerFactory.GetConfigurationServer(tfsUrl);

            tfsConfigurationServer.Authenticate();
            TeamProjectDtoCollection allTeamProjectCollections = tfsConfigurationServer.GetAllTeamProjectsInAllTeamProjectCollections();

            foreach (TeamProjectDto teamProjectDto in allTeamProjectCollections)
            {
                if (teamProjectDto.DisplayName == teamProjectName)
                {
                    TfsTeamProjectCollection teamProjectCollection = tfsConfigurationServer.GetTeamProjectCollection(teamProjectDto.CollectionId);
                    IBuildServer             buildServer           = teamProjectCollection.GetService <IBuildServer>();
                    BuildServerFacade        buildServerFacade     = new BuildServerFacade(buildServer);
                    buildServerFacade.UpdateRetentionPolicies(teamProjectDto.DisplayName, numberOfStoppedBuildsToKeep, numberOfFailedBuildsToKeep, numberOfPartiallySucceededBuildsToKeep, numberOfSucceededBuildsToKeep, deleteOptions);
                }
            }
        }
示例#9
0
 public void Init()
 {
     try
     {
         Configuration = new Config();
         Configuration.Init();
         TfsUri = new Uri(Configuration.ServerUrl);                                                     //new Uri(@"http://localhost:8088/tfs/");
         var credentials = new NetworkCredential(Configuration.TfsUserName, Configuration.TfsPassword); //new NetworkCredential("milestone\\lay", "Nors1975!");
         ConfigurationServer             = TfsConfigurationServerFactory.GetConfigurationServer(TfsUri);
         ConfigurationServer.Credentials = credentials;
         ConfigurationServer.Authenticate();
         //               _topLevelStatsTimer = new Timer(PrintTopLevelStats, null, 0, 30*1000);
     }
     catch (Exception e)
     {
         e.Error();
         throw;
     }
 }
示例#10
0
        public bool CanConnect(Uri tfsUri)
        {
            Guard.NotNull(tfsUri);

            bool canConnect;
            using (var server = new TfsConfigurationServer(tfsUri))
            {
                try
                {
                    server.Authenticate();
                    canConnect = server.HasAuthenticated;
                }
                catch (Exception)
                {
                    canConnect = false;
                }
            }

            return canConnect;
        }
示例#11
0
        public bool CanConnect(Uri tfsUri)
        {
            Guard.NotNull(tfsUri);

            bool canConnect;

            using (var server = new TfsConfigurationServer(tfsUri))
            {
                try
                {
                    server.Authenticate();
                    canConnect = server.HasAuthenticated;
                }
                catch (Exception)
                {
                    canConnect = false;
                }
            }

            return(canConnect);
        }
示例#12
0
        /// <summary>
        /// 接続
        /// </summary>
        /// <returns>処理結果</returns>
        public bool Connect()
        {
            bool result = false;

            try
            {
                // 認証
                var nc = new NetworkCredential(this.UserName, this.Password);
                var configurationServer = new TfsConfigurationServer(new Uri(this.Url), nc);
                configurationServer.Authenticate();

                if (configurationServer.HasAuthenticated)
                {
                    // VSC接続
                    var configurationServerNode = configurationServer.CatalogNode;

                    var tpcNodes =
                        configurationServerNode.QueryChildren(
                            new[] { CatalogResourceTypes.ProjectCollection },
                            false,
                            CatalogQueryOptions.None);

                    foreach (var tpcNode in tpcNodes)
                    {
                        var tpcId = new Guid(tpcNode.Resource.Properties["InstanceId"]);
                        var tpc   = configurationServer.GetTeamProjectCollection(tpcId);
                        this._vcs = tpc.GetService <VersionControlServer>();
                    }
                }

                result = configurationServer.HasAuthenticated;
            }
            catch (Exception)
            {
                result = false;
            }

            return(result);
        }
示例#13
0
        public IEnumerable<Node> GetTfsProjects(TfsConnection conn)
        {
            var cols = new List<Node>();
            var configServer = new TfsConfigurationServer(
                new Uri(conn.TfsUrl),
                new NetworkCredential(conn.Username, conn.Password, conn.Domain));
            configServer.Authenticate();

            var catalog = configServer.CatalogNode;
            var tpcNodes = catalog.QueryChildren(
                new Guid[] { CatalogResourceTypes.ProjectCollection },
                false, CatalogQueryOptions.None);

            foreach (var tpcNode in tpcNodes)
            {
                Node nd = new Node();

                Guid tpcId = new Guid(tpcNode.Resource.Properties["InstanceId"]);
                nd.Properties.Add(new Item("guid", tpcId.ToString()));
                nd.Name = tpcNode.Resource.DisplayName;
                cols.Add(nd);
                var tpc = configServer.GetTeamProjectCollection(tpcId);

                // Get catalog of tp = 'Team Projects' for the tpc = 'Team Project Collection'
                var tpNodes = tpcNode.QueryChildren(
                          new Guid[] { CatalogResourceTypes.TeamProject },
                          false, CatalogQueryOptions.None);

                foreach (var p in tpNodes)
                {
                    var ndProj = new Node();
                    ndProj.Name = p.Resource.DisplayName;
                    nd.Children.Add(ndProj);
                }
            }

            return cols;

            /*
            WorkItemStore workItemStore = (WorkItemStore)collection.GetService(typeof(WorkItemStore));
            string qry = "SELECT [Title] From WorkItems Where [Work Item Type] = 'Bug' " +
                " AND [Iteration Path] = 'AML_Module\\Release 3\\Sprint 4' AND [Team Project]='AML_Module'";

            var res = workItemStore.Query(qry);
            foreach (var wi in res)
            {
                string s = wi.ToString();
            }*/
        }
示例#14
0
        private void Test()
        {
            TfsConfigurationServer configServer = new TfsConfigurationServer(
                new Uri("https://cmr.wkglobal.com:8088/tfs"),
                new NetworkCredential("Shafqat.Ahmed", "Hello123", "NA"));
            configServer.Authenticate();

            var catalog = configServer.CatalogNode;
            var tpcNodes = catalog.QueryChildren(
                new Guid[] { CatalogResourceTypes.ProjectCollection },
                false, CatalogQueryOptions.None);

            TfsTeamProjectCollection collection = null;
            foreach (var tpcNode in tpcNodes)
            {
                Guid tpcId = new Guid(tpcNode.Resource.Properties["InstanceId"]);
                var tpc = configServer.GetTeamProjectCollection(tpcId);

                // Get catalog of tp = 'Team Projects' for the tpc = 'Team Project Collection'
                var tpNodes = tpcNode.QueryChildren(
                          new Guid[] { CatalogResourceTypes.TeamProject },
                          false, CatalogQueryOptions.None);

                foreach (var p in tpNodes)
                {
                    if (p.Resource.DisplayName == "AML_Module")
                    {
                        collection = tpc;
                    }
                }
            }

            WorkItemStore workItemStore = (WorkItemStore) collection.GetService(typeof(WorkItemStore));
            string qry = "SELECT [Title] From WorkItems Where [Work Item Type] = 'Bug' "  +
                " AND [Iteration Path] = 'AML_Module\\Release 3\\Sprint 4' AND [Team Project]='AML_Module'";

            var res = workItemStore.Query (qry);
            foreach ( var wi in res)
            {
                string s = wi.ToString();
            }
        }
示例#15
0
        private void QueryTFSButton_Click(object sender, RoutedEventArgs e)
        {
            string tfsUrl = this.TFSUrlComboBox.SelectedItem.ToString();

            // Be sure to enable the alternate credentials as noted in the above blog
            NetworkCredential netCred = new NetworkCredential(
                this.userNameTextBox.Text,
                this.passwordTextBox.Text);
            BasicAuthCredential  basicCred = new BasicAuthCredential(netCred);
            TfsClientCredentials tfsCred   = new TfsClientCredentials(basicCred);

            tfsCred.AllowInteractive = false;

            // Depending on how you connect to TFS, you will need to construct the URL differently

            // TfsTeamProjectCollection requires a collection to be specified
            // As of 1/27/15, TFS Online only supports the /DefaultCollection
            TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(
                new Uri(tfsUrl + "/DefaultCollection"),
                tfsCred);

            tpc.Authenticate();

            // TfsConfigurationServer requires just the base URL, wihtout the collection specified
            // Also note, that TFS Online requires HTTPS://
            TfsConfigurationServer configurationServer = new TfsConfigurationServer(new Uri(tfsUrl), tfsCred);

            configurationServer.Authenticate();

            // Get the catalog of team project collections
            ReadOnlyCollection <CatalogNode> collectionNodes = configurationServer.CatalogNode.QueryChildren(
                new[] { CatalogResourceTypes.ProjectCollection },
                false, CatalogQueryOptions.None);

            // List the team project collections
            foreach (CatalogNode collectionNode in collectionNodes)
            {
                // Use the InstanceId property to get the team project collection
                Guid collectionId = new Guid(collectionNode.Resource.Properties["InstanceId"]);
                TfsTeamProjectCollection teamProjectCollection = configurationServer.GetTeamProjectCollection(collectionId);

                // Print the name of the team project collection
                Console.WriteLine("Collection: " + teamProjectCollection.Name);
                this.NodesListBox.Items.Add("Collection: " + teamProjectCollection.Name);

                // Get a catalog of team projects for the collection
                ReadOnlyCollection <CatalogNode> projectNodes = collectionNode.QueryChildren(
                    new[] { CatalogResourceTypes.TeamProject },
                    false, CatalogQueryOptions.None);


                // In Visual Studio 2015 Preview the TFS binaries are no longer GAC'd
                // One of the binaries is a native dll that must be available for PInvoke for the managed libraries
                // If you have VS 2013 installed side by side, this won't be an issue as they are GACd in VS 2013
                // If you have a pure VS 2015 environment, for now, you'll need to copy the 32 and 64 bit binararies to your bin directory
                // Error: Unable to load DLL 'Microsoft.WITDataStore32.dll'
                var foo = teamProjectCollection.GetService(typeof(WorkItemStore));

                // List the team projects in the collection
                foreach (CatalogNode projectNode in projectNodes)
                {
                    Console.WriteLine(" Team Project: " + projectNode.Resource.DisplayName);
                    this.NodesListBox.Items.Add(" Team Project: " + projectNode.Resource.DisplayName);
                }
            }
        }