Esempio n. 1
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 TfsWrapper(string server, ...)
 {
     try
     {
         Uri serverUri = new Uri(server + "/tfs");
         ICredentialsProvider credentials = new UICredentialsProvider();
         tpc = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(serverUri, credentials);
         tpc.EnsureAuthenticated();
         versionControl = tpc.GetService<VersionControlServer>();
     }
 }
 private void Authenticate(string tfsUrl)
 {
     try
     {
         var credentials = new UICredentialsProvider();
         m_tpc = new TfsTeamProjectCollection(new Uri(tfsUrl), credentials);
         m_tpc.EnsureAuthenticated();
     }
     catch
     {
         m_tpc = null;
         throw;
     }
 }
Esempio n. 4
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)
                {
                    tfsClientCredentials = new TfsClientCredentials(false);
                    ICredentialsProvider provider = new UICredentialsProvider();
                    WindowsCredential    wcred    = new WindowsCredential(cred, provider);
                    tfsClientCredentials.Windows = wcred;
                    //Credential = tfsClientCredentials;
                }
                else
                {
                    tfsClientCredentials = new TfsClientCredentials(true);
                    ICredentialsProvider provider = new UICredentialsProvider();
                    WindowsCredential    wcred    = new WindowsCredential(cred, provider);
                    tfsClientCredentials.Windows = wcred;
                }

                using (TfsConfigurationServer serverConfig = new TfsConfigurationServer(uri, tfsClientCredentials))
                {
                    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);
        }
Esempio n. 5
0
        private static Workspace GetWorkspace(Uri tfsName, string localPath)
        {
            ICredentialsProvider fallbackCredentialsProvider = new UICredentialsProvider();

            Workspace[] workspaceArray;
            try {
                var projectCollection    = GetTeamProjectCollection(tfsName, fallbackCredentialsProvider);
                var versionControlServer = projectCollection.GetService <VersionControlServer>();
                workspaceArray = versionControlServer.QueryWorkspaces(null, versionControlServer.AuthorizedUser, Environment.MachineName);
            } catch (TeamFoundationServiceUnavailableException ex) {
                _log.Info(ex, "TFS is not available");
                workspaceArray = null;
            } catch (TeamFoundationServerUnauthorizedException ex) {
                fallbackCredentialsProvider.GetCredentials(tfsName, null);
                var projectCollection    = GetTeamProjectCollection(tfsName, fallbackCredentialsProvider);
                var versionControlServer = projectCollection.GetService <VersionControlServer>();
                workspaceArray = versionControlServer.QueryWorkspaces(null, versionControlServer.AuthorizedUser, Environment.MachineName);
            } catch (Exception ex) {
                _log.Error(ex, "Querying workspaces failed");
                throw;
            }

            if (workspaceArray == null || workspaceArray.Length == 0)
            {
                return(null);
            }

            if (workspaceArray.Length == 1)
            {
                return(workspaceArray[0]);
            }

            foreach (var workspace in workspaceArray)
            {
                foreach (var workingFolder in workspace.Folders)
                {
                    if (!workingFolder.IsCloaked && workspace.IsLocalPathMapped(localPath) && localPath.StartsWith(workingFolder.LocalItem, true, CultureInfo.InvariantCulture))
                    {
                        return(workspace);
                    }
                }
            }

            return(null);
        }
Esempio n. 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)
                {
                    
                    tfsClientCredentials = new TfsClientCredentials(false);
                    ICredentialsProvider provider = new UICredentialsProvider();
                    WindowsCredential wcred = new WindowsCredential(cred, provider);
                    tfsClientCredentials.Windows = wcred;
                    //Credential = tfsClientCredentials;
                }
                else
                {
                    tfsClientCredentials = new TfsClientCredentials(true);
                    ICredentialsProvider provider = new UICredentialsProvider();
                    WindowsCredential wcred = new WindowsCredential(cred, provider);
                    tfsClientCredentials.Windows = wcred;
                }

                using (TfsConfigurationServer serverConfig = new TfsConfigurationServer(uri, tfsClientCredentials))
                {
                    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;
        }
Esempio n. 7
0
        public static void Run(string[] args)
        {
            Console.WriteLine("Nusbio initialization");
            var serialNumber = Nusbio.Detect();

            if (serialNumber == null) // Detect the first Nusbio available
            {
                Console.WriteLine("Nusbio not detected");
                return;
            }

            // How do I get the Visual Studio Online credentials cached in the registry? http://stackoverflow.com/questions/20809207/how-do-i-get-the-visual-studio-online-credentials-cached-in-the-registry
            //https://gist.github.com/ctaggart/8164083

            //var netCred = new NetworkCredential("*****@*****.**", "Resforever123!");
            //BasicAuthCredential basicCred = new BasicAuthCredential(netCred);
            //TfsClientCredentials credential = new TfsClientCredentials(basicCred);
            //credential.AllowInteractive = false;
            //string TFSServerPath = "https://fredericaltorres.visualstudio.com/defaultcollection";

            //using (var tfs = new TfsTeamProjectCollection(new Uri(TFSServerPath), credential))
            //{
            //    tfs.Authenticate();
            //    tfs.EnsureAuthenticated();
            //}

            // https://fredericaltorres.visualstudio.com/DefaultCollection/P1/_dashboards

            var collectionUri      = new Uri("https://fredericaltorres.visualstudio.com:443/defaultcollection");
            var credentialProvider = new UICredentialsProvider();
            var tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(collectionUri, new UICredentialsProvider());

            tfs.EnsureAuthenticated();


            var versionControl = tfs.GetService <VersionControlServer>();
            var p1TeamProject  = versionControl.GetTeamProject("P1");
            var bs             = tfs.GetService <IBuildServer>();

            Console.WriteLine("Build ServerVersion:{0}", bs.BuildServerVersion);
            var allBuildDetails = bs.GetBuildQualities("P1");
            var buildController = bs.GetBuildController("");

            Console.WriteLine("Build Controller:{0}", buildController.Name);

            var projectName         = "P1";
            var projectPath         = "$/P1";
            var buildDefinitionName = "MainBuildDef";

            var builds0 = bs.QueryBuilds("P1", buildDefinitionName);

            var teamProjects = versionControl.GetAllTeamProjects(true);
            var p1Project    = teamProjects[0];

            foreach (TeamProject proj in teamProjects)
            {
                Console.WriteLine("Query build for project {0}", proj.Name);
                var builds = bs.QueryBuilds(proj.Name);
                foreach (IBuildDetail build in builds)
                {
                    var result = string.Format("Build {0}/{3} {4} - current status {1} - as of {2}", build.BuildDefinition.Name, build.Status.ToString(), build.FinishTime, build.LabelName, Environment.NewLine);
                    System.Console.WriteLine(result);
                }
            }

            var buildDefinition = bs.GetBuildDefinition(projectName, buildDefinitionName);
            var buildRequest    = buildDefinition.CreateBuildRequest();
            var queuedBuild     = bs.QueueBuild(buildRequest);
            var queuedBuildId   = queuedBuild.Id;


            using (var nusbio = new Nusbio(serialNumber))
            {
                Console.WriteLine("LCD i2c Initialization");
                var timeOut = new TimeOut(1000);
                Cls(nusbio);
                ConsoleEx.WriteLine(0, 10, string.Format("TFS Instance ID {0}, DisplayName:{1}, User:{2}",
                                                         tfs.InstanceId,
                                                         tfs.DisplayName,
                                                         versionControl.AuthenticatedUser
                                                         ), ConsoleColor.Cyan);

                nusbio[NusbioGpio.Gpio2].AsLed.SetBlinkMode(1000, 1);

                while (nusbio.Loop())
                {
                    if (Console.KeyAvailable)
                    {
                        var k = Console.ReadKey(true).Key;
                        if (k == ConsoleKey.Q)
                        {
                            nusbio.ExitLoop();
                        }
                        Cls(nusbio);
                    }
                }
            }
            Console.Clear();
        }