Esempio n. 1
0
        public async Task ConnectAsync(VssConnection jobConnection)
        {
            ArgUtil.NotNull(jobConnection, nameof(jobConnection));

            _connection = jobConnection;
            int attemptCount = 5;

            while (!_connection.HasAuthenticated && attemptCount-- > 0)
            {
                try
                {
                    await _connection.ConnectAsync();

                    break;
                }
                catch (Exception ex) when(attemptCount > 0)
                {
                    Trace.Info($"Catch exception during connect. {attemptCount} attemp left.");
                    Trace.Error(ex);
                }

                await Task.Delay(100);
            }

            _buildHttpClient = _connection.GetClient <Build2.BuildHttpClient>();
        }
Esempio n. 2
0
        public async Task ConnectAsync(VssConnection jobConnection)
        {
            if (HostContext.RunMode == RunMode.Local)
            {
                return;
            }

            _connection = jobConnection;
            int attemptCount = 5;

            while (!_connection.HasAuthenticated && attemptCount-- > 0)
            {
                try
                {
                    await _connection.ConnectAsync();

                    break;
                }
                catch (Exception ex) when(attemptCount > 0)
                {
                    Trace.Info($"Catch exception during connect. {attemptCount} attemp left.");
                    Trace.Error(ex);
                }

                await Task.Delay(100);
            }

            _taskAgentClient = _connection.GetClient <TaskAgentHttpClient>();
            _hasConnection   = true;
        }
Esempio n. 3
0
        private async Task <VssConnection> LocalAsyncImpl(VssCredentials clientCredentials, CancellationToken cancellationToken)
        {
            var connection = new VssConnection(new Uri(Url), clientCredentials);
            await connection.ConnectAsync(cancellationToken);

            return(connection);
        }
        static void Main(string[] args)
        {
            var buildLight = BuildLight.Initialise();

            buildLight.TurnOff();

            var uri    = new Uri(AppConfiguration.Url);
            var client = new VssConnection(uri, new VssBasicCredential(string.Empty, AppConfiguration.PersonalKey));


            try
            {
                client.ConnectAsync()
                .SyncResult();
            }
            catch (WebException)
            {
                Console.WriteLine("could not connect to the Vsts or TFS isntance");
                return;
            }

            var buildClient   = client.GetClient <BuildHttpClient>();
            var projectClient = client.GetClient <ProjectHttpClient>();
            var project       = projectClient.GetProjects().Result
                                .Single(x => x.Name == AppConfiguration.Project);

            try
            {
                while (true)
                {
                    var lastBuildResult = buildClient.GetBuildsAsync(project.Id, AppConfiguration.BuildDefinitions)
                                          .Result
                                          .OrderBy(x => x.FinishTime)
                                          .Last()
                                          .Result;


                    switch (lastBuildResult)
                    {
                    case BuildResult.Succeeded:
                        buildLight.ChangeColourToGreen();
                        break;

                    case BuildResult.PartiallySucceeded:
                        buildLight.ChangeColourToAmber();
                        break;

                    default:
                        buildLight.ChangeColourToRed();
                        break;
                    }
                    Thread.Sleep(2000);
                }
            }
            catch (Exception)
            {
                Console.WriteLine("error occured while trying to get latest build and change build light");
                buildLight.TurnOff();
            }
        }
        private bool ConnectWithCredentials(CredentialsModel credentialsModel)
        {
            _vssConnection = GetVssConnection(credentialsModel);

            try
            {
                _vssConnection.ConnectAsync().SyncResult();
            }
            catch (Exception ex)
            {
                _console.ErrorMessage(ex.Message);
            }

            if (_vssConnection.HasAuthenticated)
            {
                AccountName         = credentialsModel.AccountName;
                Project             = credentialsModel.Project;
                PersonalAccessToken = credentialsModel.PersonalAccessToken;

                _cacheService.CacheConnection(credentialsModel);
                return(true);
            }

            return(false);
        }
Esempio n. 6
0
        internal async Task <bool> InvokeLocalAsync(string projectName, string @event, int workItemId, string ruleFilePath, bool dryRun, SaveMode saveMode)
        {
            if (!File.Exists(ruleFilePath))
            {
                logger.WriteError($"Rule code not found at {ruleFilePath}");
                return(false);
            }

            var devopsLogonData = DevOpsLogon.Load().connection;

            logger.WriteVerbose($"Connecting to Azure DevOps using {devopsLogonData.Mode}...");
            var clientCredentials = default(VssCredentials);

            if (devopsLogonData.Mode == DevOpsTokenType.PAT)
            {
                clientCredentials = new VssBasicCredential(devopsLogonData.Mode.ToString(), devopsLogonData.Token);
            }
            else
            {
                logger.WriteError($"Azure DevOps Token type {devopsLogonData.Mode} not supported!");
                throw new ArgumentOutOfRangeException(nameof(devopsLogonData.Mode));
            }

            string collectionUrl = devopsLogonData.Url;

            using (var devops = new VssConnection(new Uri(collectionUrl), clientCredentials))
            {
                await devops.ConnectAsync();

                logger.WriteInfo($"Connected to Azure DevOps");

                Guid   teamProjectId;
                string teamProjectName;
                using (var projectClient = devops.GetClient <ProjectHttpClient>())
                {
                    logger.WriteVerbose($"Reading Azure DevOps project data...");
                    var project = await projectClient.GetProject(projectName);

                    logger.WriteInfo($"Project {projectName} data read.");
                    teamProjectId   = project.Id;
                    teamProjectName = project.Name;
                }

                using (var witClient = devops.GetClient <WorkItemTrackingHttpClient>())
                {
                    logger.WriteVerbose($"Rule code found at {ruleFilePath}");
                    string[] ruleCode = File.ReadAllLines(ruleFilePath);

                    var engineLogger = new EngineWrapperLogger(logger);
                    var engine       = new Engine.RuleEngine(engineLogger, ruleCode, saveMode);
                    engine.DryRun = dryRun;

                    string result = await engine.ExecuteAsync(collectionUrl, teamProjectId, teamProjectName, devopsLogonData.Token, workItemId, witClient);

                    logger.WriteInfo($"Rule returned '{result}'");

                    return(true);
                }
            }
        }
Esempio n. 7
0
        private static async Task TestWorkItemTypes(string collectionUrl, string devOpsToken, string projectName, CancellationToken cancellationToken)
        {
            var clientCredentials = new VssBasicCredential("", devOpsToken);

            using var devops = new VssConnection(new Uri(collectionUrl), clientCredentials);
            await devops.ConnectAsync(cancellationToken);

            using var workClient = await devops.GetClientAsync <WorkHttpClient>(cancellationToken);

            var processConfiguration = await workClient.GetProcessConfigurationAsync(projectName);

            var backlogWorkItemTypes = new List <CategoryConfiguration>(processConfiguration.PortfolioBacklogs)
            {
                processConfiguration.BugWorkItems,
                processConfiguration.RequirementBacklog,
                processConfiguration.TaskBacklog,
            };

            foreach (var item in backlogWorkItemTypes)
            {
                Console.WriteLine(item.Name);
            }

            devops.Disconnect();
        }
Esempio n. 8
0
        public async Task ConnectAsync(VssConnection jobConnection)
        {
            _connection = jobConnection;
            int attemptCount = 5;

            while (!_connection.HasAuthenticated && attemptCount-- > 0)
            {
                try
                {
                    await _connection.ConnectAsync();

                    break;
                }
                catch (Exception ex) when(attemptCount > 0)
                {
                    Trace.Info($"Catch exception during connect. {attemptCount} attempt left.");
                    Trace.Error(ex);
                }

                await Task.Delay(100);
            }

            _locationClient = _connection.GetClient <LocationHttpClient>();
            _hasConnection  = true;
        }
        public async Task ConnectAsync(VssConnection jobConnection)
        {
            ArgUtil.NotNull(jobConnection, nameof(jobConnection));

            _connection = jobConnection;
            int attemptCount = 5;

            while (!_connection.HasAuthenticated && attemptCount-- > 0)
            {
                try
                {
                    await _connection.ConnectAsync();

                    break;
                }
                catch (SocketException ex)
                {
                    ExceptionsUtil.HandleSocketException(ex, _connection.Uri.ToString(), Trace.Error);
                }
                catch (Exception ex) when(attemptCount > 0)
                {
                    Trace.Info($"Catch exception during connect. {attemptCount} attemp left.");
                    Trace.Error(ex);
                }

                await Task.Delay(100);
            }

            _releaseHttpClient = _connection.GetClient <ReleaseHttpClient>();
        }
Esempio n. 10
0
        private async Task <string> ExecAsyncImpl(IRule rule, WorkItemEventContext eventContext, VssCredentials clientCredentials, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            // TODO improve from https://github.com/Microsoft/vsts-work-item-migrator
            using var devops = new VssConnection(eventContext.CollectionUri, clientCredentials);
            try
            {
                await devops.ConnectAsync(cancellationToken);

                logger.WriteInfo($"Connected to Azure DevOps");
            }
            catch (System.Exception ex)
            {
                logger.WriteError(ex.Message);
                if (ex.InnerException != null)
                {
                    logger.WriteError(ex.InnerException.Message);
                }
                throw ex;
            }
            using var clientsContext = new AzureDevOpsClientsContext(devops);
            var engine = new RuleEngine(logger, configuration.SaveMode, configuration.DryRun);

            var ruleResult = await engine.RunAsync(rule, eventContext.ProjectId, eventContext.WorkItemPayload, eventContext.EventType, clientsContext, cancellationToken);

            logger.WriteInfo(ruleResult);
            return(ruleResult);
        }
Esempio n. 11
0
        public static async Task <VssConnection> GetVssConnectionAsync(Uri uri, string accessToken, DelegatingHandler retryOnTimeoutMessageHandler = null)
        {
            VssConnection connection;

            if (!_vssConnections.TryGetValue(uri, out connection))
            {
                VssClientCredentials cred = GetCredentials(accessToken);

                VssClientHttpRequestSettings settings = VssClientHttpRequestSettings.Default.Clone();

                if (settings.SendTimeout < _minTimeout)
                {
                    settings.SendTimeout = _minTimeout;
                }

                VssHttpMessageHandler innerHandler = new VssHttpMessageHandler(cred, settings);

                DelegatingHandler[] handlers = new DelegatingHandler[]
                {
                    retryOnTimeoutMessageHandler
                };

                connection = new VssConnection(uri, innerHandler, handlers);
                await connection.ConnectAsync().ConfigureAwait(false);

                if (!_vssConnections.TryAdd(uri, connection))
                {
                    // first writer wins. Every caller returned the same instance.
                    connection = _vssConnections[uri];
                }
            }

            return(connection);
        }
Esempio n. 12
0
        public async Task <string> ExecuteAsync(IRule rule, WorkItemEventContext eventContext, CancellationToken cancellationToken)
        {
            logger.WriteVerbose($"Connecting to Azure DevOps using {configuration.DevOpsTokenType}...");
            var clientCredentials = default(VssCredentials);

            if (configuration.DevOpsTokenType == DevOpsTokenType.PAT)
            {
                clientCredentials = new VssBasicCredential(configuration.DevOpsTokenType.ToString(), configuration.DevOpsToken);
            }
            else
            {
                logger.WriteError($"Azure DevOps Token type {configuration.DevOpsTokenType} not supported!");
                throw new ArgumentOutOfRangeException(nameof(configuration.DevOpsTokenType));
            }

            cancellationToken.ThrowIfCancellationRequested();

            // TODO improve from https://github.com/Microsoft/vsts-work-item-migrator
            using (var devops = new VssConnection(eventContext.CollectionUri, clientCredentials))
            {
                await devops.ConnectAsync(cancellationToken);

                logger.WriteInfo($"Connected to Azure DevOps");
                using (var clientsContext = new AzureDevOpsClientsContext(devops))
                {
                    var engine = new RuleEngine(logger, configuration.SaveMode, configuration.DryRun);

                    var ruleResult = await engine.RunAsync(rule, eventContext.ProjectId, eventContext.WorkItemPayload, clientsContext, cancellationToken);

                    logger.WriteInfo(ruleResult);
                    return(ruleResult);
                }
            }
        }
Esempio n. 13
0
        public virtual async Task SetUp()
        {
            var collectionUrl = Environment.GetEnvironmentVariable("WILINQ_TEST_TPCURL");

            if (string.IsNullOrWhiteSpace(collectionUrl))
            {
                throw new InvalidOperationException("Environment variable 'WILINQ_TEST_TPCURL' is missing");
            }
            var            personnalAccessToken = Environment.GetEnvironmentVariable("WILINQ_TEST_PAT");
            VssCredentials vssCredentials;

            if (string.IsNullOrWhiteSpace(personnalAccessToken))
            {
                vssCredentials = new VssClientCredentials
                {
                    Storage = new VssClientCredentialStorage()
                };
            }
            else
            {
                vssCredentials = new VssBasicCredential(string.Empty, personnalAccessToken);
            }

            var connection = new VssConnection(new Uri(collectionUrl), vssCredentials);

            await connection.ConnectAsync();

            Client = await connection.GetClientAsync <WorkItemTrackingHttpClient>();

            var projectHttpClient = await connection.GetClientAsync <ProjectHttpClient>();

            Project = await projectHttpClient.GetProject("WiLinqTestProject");

            TestSessionId = Guid.NewGuid().ToString();
        }
Esempio n. 14
0
        static void Main(string[] args)
        {
            var vssClientCredentials = new VssClientCredentials();

            vssClientCredentials.Storage = new VssClientCredentialStorage();

            VssConnection connection = new VssConnection(new Uri("https://reeferwatch.visualstudio.com"), vssClientCredentials);

            connection.ConnectAsync().Wait();

            var projectHttpClient = connection.GetClient <ProjectHttpClient>();
            var projects          = projectHttpClient.GetProjects().Result;
            var project           = projects.First();

            var buildHttpClient  = connection.GetClient <BuildHttpClient>();
            var buildDefinitions = buildHttpClient.GetDefinitionsAsync(project.Id).Result;

            System.Console.WriteLine($"{buildDefinitions.Count} builds in {project.Name}");

            foreach (var definitionReference in buildDefinitions)
            {
                var builds = buildHttpClient.GetBuildsAsync(project.Id, new[] { definitionReference.Id }).Result;
                System.Console.WriteLine($"{definitionReference.Name}: {string.Join(",", builds.Take(5).Select(x => x.Result.ToString()))}");
            }

            System.Console.ReadLine();
        }
Esempio n. 15
0
        /// <summary>
        /// Get Vss connection
        /// </summary>
        /// <param name="url">url to TFS instance</param>
        /// <param name="pat">Personal Access Token</param>
        /// <returns></returns>
        private static async Task <VssConnection> GetVssConnectionAsync(string url, string pat)
        {
            var conn = new VssConnection(new Uri(url),
                                         new VssCredentials(new Microsoft.VisualStudio.Services.Common.VssBasicCredential(string.Empty, pat)));
            await conn.ConnectAsync();

            return(conn);
        }
Esempio n. 16
0
        async void InitAzureDevOps()
        {
            var    collectionUri = "https://dev.azure.com/chdurham2020/";
            string PAT           = Environment.GetEnvironmentVariable("PAT");

            // Create connection
            _connection = new VssConnection(new Uri(collectionUri), new VssBasicCredential(string.Empty, PAT));
            await _connection.ConnectAsync();
        }
        public override async Task Connect(string personalAccessToken)
        {
            Uri accountUri = new Uri(this.AccountOrOrganization, UriKind.Absolute);

            VssConnection connection = new VssConnection(accountUri, new VssBasicCredential(string.Empty, personalAccessToken));
            await connection.ConnectAsync();

            _witClient = await connection.GetClientAsync <WorkItemTrackingHttpClient>();
        }
Esempio n. 18
0
        internal async Task <string> ExecuteAsync(dynamic data, CancellationToken cancellationToken)
        {
            string collectionUrl = data.resourceContainers.collection.baseUrl;
            string eventType     = data.eventType;
            int    workItemId    = (eventType != "workitem.updated")
                ? data.resource.id
                : data.resource.workItemId;
            Guid   teamProjectId   = data.resourceContainers.project.id;
            string teamProjectName = (eventType != "workitem.updated")
                ? data.resource.fields["System.TeamProject"]
                : data.resource.revision.fields["System.TeamProject"];

            logger.WriteVerbose($"Connecting to Azure DevOps using {configuration.DevOpsTokenType}...");
            var clientCredentials = default(VssCredentials);

            if (configuration.DevOpsTokenType == DevOpsTokenType.PAT)
            {
                clientCredentials = new VssBasicCredential(configuration.DevOpsTokenType.ToString(), configuration.DevOpsToken);
            }
            else
            {
                logger.WriteError($"Azure DevOps Token type {configuration.DevOpsTokenType} not supported!");
                throw new ArgumentOutOfRangeException(nameof(configuration.DevOpsTokenType));
            }

            cancellationToken.ThrowIfCancellationRequested();

            // TODO improve from https://github.com/Microsoft/vsts-work-item-migrator
            using (var devops = new VssConnection(new Uri(collectionUrl), clientCredentials))
            {
                await devops.ConnectAsync(cancellationToken);

                logger.WriteInfo($"Connected to Azure DevOps");
                using (var witClient = devops.GetClient <WorkItemTrackingHttpClient>())
                {
                    string ruleFilePath = Path.Combine(functionDirectory, $"{ruleName}.rule");
                    if (!File.Exists(ruleFilePath))
                    {
                        logger.WriteError($"Rule code not found at {ruleFilePath}");
                        return("Rule file not found!");
                    }

                    logger.WriteVerbose($"Rule code found at {ruleFilePath}");
                    string[] ruleCode;
                    using (var fileStream = File.OpenRead(ruleFilePath))
                    {
                        var reader = new StreamReader(fileStream);
                        ruleCode = await ReadAllLinesAsync(reader);
                    }

                    var engine = new Engine.RuleEngine(logger, ruleCode, configuration.SaveMode, configuration.DryRun);

                    return(await engine.ExecuteAsync(teamProjectId, teamProjectName, workItemId, witClient, cancellationToken));
                }
            }
        }
Esempio n. 19
0
        /// <summary>
        /// Parametrized method which returns http client of TFS
        /// </summary>
        /// <typeparam name="T">Http client type</typeparam>
        /// <param name="orgName">TFS organization name</param>
        /// <param name="PatToken">TFS PAT token</param>
        /// <returns></returns>
        public async static Task <T> GetTFSHttpClient <T>(string orgName, string PatToken) where T : VssHttpClientBase
        {
            var            u          = new Uri($"https://dev.azure.com/" + orgName);
            VssCredentials c          = new VssCredentials(new VssBasicCredential(string.Empty, PatToken));
            var            connection = new VssConnection(u, c);
            // check connection
            await connection.ConnectAsync();

            return(await connection.GetClientAsync <T>());
        }
Esempio n. 20
0
        internal async Task <string> Execute(string aggregatorVersion, dynamic data)
        {
            if (string.IsNullOrEmpty(aggregatorVersion))
            {
                aggregatorVersion = "0.1";
            }

            string collectionUrl = data.resourceContainers.collection.baseUrl;
            int    workItemId    = data.resource.id;

            string vstsTokenType = config["Aggregator_VstsTokenType"];
            string vstsToken     = config["Aggregator_VstsToken"];

            logger.WriteVerbose($"Connecting to VSTS using {vstsTokenType}...");
            var clientCredentials = default(VssCredentials);

            if (string.Compare(vstsTokenType, "PAT", true) == 0)
            {
                clientCredentials = new VssBasicCredential(vstsTokenType, vstsToken);
            }
            else
            {
                logger.WriteError($"VSTS Token type {vstsTokenType} not supported!");
                throw new ArgumentOutOfRangeException(nameof(vstsTokenType));
            }
            var vsts = new VssConnection(new Uri(collectionUrl), clientCredentials);
            await vsts.ConnectAsync();

            logger.WriteInfo($"Connected to VSTS");
            var witClient = vsts.GetClient <WorkItemTrackingHttpClient>();
            var self      = await witClient.GetWorkItemAsync(workItemId, expand : WorkItemExpand.All);

            logger.WriteInfo($"Self retrieved");

            string ruleFilePath = Path.Combine(functionDirectory, $"{ruleName}.rule");

            if (!File.Exists(ruleFilePath))
            {
                logger.WriteError($"Rule code not found at {ruleFilePath}");
                return("Rule file not found!");
            }

            logger.WriteVerbose($"Rule code found at {ruleFilePath}");
            string ruleCode = File.ReadAllText(ruleFilePath);

            logger.WriteVerbose($"Executing Rule...");
            var globals = new Globals {
                self = self
            };
            var result = await CSharpScript.EvaluateAsync <string>(ruleCode, globals : globals);

            logger.WriteVerbose($"Rule returned {result}");
            return(result);
        }
Esempio n. 21
0
        public async Task ConnectAsync(VssConnection agentConnection)
        {
            _connection = agentConnection;
            if (!_connection.HasAuthenticated)
            {
                await _connection.ConnectAsync();
            }

            _taskAgentClient = _connection.GetClient <TaskAgentHttpClient>();
            _hasConnection   = true;
        }
Esempio n. 22
0
        public async Task ConnectAsync(VssConnection agentConnection)
        {
            _connection = agentConnection;
            if (!_connection.HasAuthenticated)
            {
                await _connection.ConnectAsync();
            }

            _taskAgentClient = _connection.GetClient<TaskAgentHttpClient>();
            _hasConnection = true;
        }
Esempio n. 23
0
        public override async Task Connect(Uri projectUri, string personalAccessToken)
        {
            _projectName = projectUri.GetProjectName();
            string accountUriString = projectUri.GetAccountUriString();

            Uri accountUri = new Uri(accountUriString, UriKind.Absolute);

            VssConnection connection = new VssConnection(accountUri, new VssBasicCredential(string.Empty, personalAccessToken));
            await connection.ConnectAsync();

            _witClient = await connection.GetClientAsync <WorkItemTrackingHttpClient>();
        }
        public AzureDevOpsClient(string organizationName)
        {
            organizationName = organizationName.Trim();
            Endpoint         = new Uri(@"https://dev.azure.com/" + organizationName + "/");
            var creds = new VssClientCredentials(new WindowsCredential(false), new VssFederatedCredential(true), CredentialPromptType.PromptIfNeeded);

            azureDevopsConnection = new VssConnection(Endpoint, creds);
            azureDevopsConnection.ConnectAsync().Wait();

            buildClient   = azureDevopsConnection.GetClient <BuildHttpClient>();
            projectClient = azureDevopsConnection.GetClient <ProjectHttpClient>();
        }
Esempio n. 25
0
        public async Task ConnectAsync(VssConnection agentConnection)
        {
            ArgUtil.NotNull(agentConnection, nameof(agentConnection));
            _connection = agentConnection;
            if (!_connection.HasAuthenticated)
            {
                await _connection.ConnectAsync();
            }

            _environmentsHttpClient = _connection.GetClient <EnvironmentsHttpClient>();
            _hasConnection          = true;
        }
Esempio n. 26
0
        public void Connect(string serverName)
        {
            // Interactively ask the user for credentials, caching them so the user isn't constantly prompted
            VssCredentials creds = new VssClientCredentials();

            creds.Storage = new VssClientCredentialStorage();

            // Connect to Azure DevOps Services
            _connection = new VssConnection(new Uri(serverName), creds);
            _connection.ConnectAsync().SyncResult();

            Debug.WriteLine("Has authenticaed: " + _connection.HasAuthenticated);
        }
Esempio n. 27
0
 /// <summary>
 /// Connects to the AzureDevOps server at the given url (e.g. https://myaccount.visualstudio.com)
 ///     If prompt is true, then we may prompt if needed - otherwise, we turn prompting off on credentials
 /// </summary>
 /// <param name="url">AzureDevOps URL to connect to</param>
 /// <param name="prompt">whether user should see any login prompts if needed</param>
 /// <returns></returns>
 internal Task ConnectToAzureDevOpsAccount(Uri url, CredentialPromptType prompt = CredentialPromptType.PromptIfNeeded)
 {
     lock (myLock)
     {
         // reset connection state
         Disconnect();
         var credentials = new VssClientCredentials(false);
         credentials.Storage    = new VssClientCredentialStorage();
         credentials.PromptType = prompt;
         _baseServerConnection  = new VssConnection(url, credentials);
         return(_baseServerConnection.ConnectAsync());
     }
 }
Esempio n. 28
0
        public async Task <bool> ConnectAsync()
        {
            try
            {
                _Conn = new VssConnection(new Uri(UserSetting.TFSCollectionUri), new VssAadCredential(UserSetting.TFSUsername, UserSetting.TFSPassword));
                await _Conn.ConnectAsync();

                return(true);
            }
            catch
            {
                return(false);
            }
        }
Esempio n. 29
0
        protected override ITeamProjectCollection ConnectToTfsCollection(Uri endpoint, VssCredentials credentials)
        {
            var tfsServer = new VssConnection(endpoint, credentials);

            tfsServer.Settings.BypassProxyOnLocal = true;
            tfsServer.Settings.CompressionEnabled = true;

            tfsServer.ConnectAsync(VssConnectMode.Automatic).GetAwaiter().GetResult();
            if (!tfsServer.HasAuthenticated)
            {
                throw new InvalidOperationException("Could not connect.");
            }
            return(tfsServer.AsProxy());
        }
Esempio n. 30
0
        static void Main(string[] args)
        {
            var url = new Uri("https://jacanotest123.visualstudio.com");

            var connection = new VssConnection(url, new VssClientCredentials());

            //var connection = new VssConnection(url, new VssBasicCredential("pat", "t77dabkbus5eu77bnvya6k4garoy3kxgyqn4jogktlmqslththea"));

            connection.ConnectAsync().SyncResult();

            TfvcHttpClient tfvcClient = connection.GetClient <TfvcHttpClient>();

            IEnumerable <TfvcBranch> branches = tfvcClient.GetBranchesAsync(includeParent: true, includeChildren: true).Result;
        }
Esempio n. 31
0
        public async Task ConnectAsyncWithNetworkCredentials(
            string accountUri,
            NetworkCredential credential)
        {
            Uri uri = new Uri(accountUri);

            var creds = new VssClientCredentials(new WindowsCredential(credential));

            _vssConnection = new VssConnection(uri, creds);
            await _vssConnection.ConnectAsync().ConfigureAwait(false);

            _tfsCollection = new TfsTeamProjectCollection(uri, creds);
            _tfsCollection.EnsureAuthenticated();
            InitBaseServices();
        }