예제 #1
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();
        }
예제 #2
0
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         _connection.Disconnect();
     }
 }
예제 #3
0
 private void CloseConnection()
 {
     if (_vssConnection != null && _vssConnection.HasAuthenticated)
     {
         _vssConnection.Disconnect();
     }
 }
 public void Dispose()
 {
     witClient.Dispose();
     connection.Disconnect();
     witClient  = null;
     connection = null;
 }
예제 #5
0
 /// <summary>
 /// Disconnects from AzureDevOps, resets AzureDevOps instance
 /// </summary>
 /// <returns></returns>
 internal void Disconnect()
 {
     lock (myLock)
     {
         try
         {
             _baseServerConnection?.Disconnect();
         }
         catch (ArgumentNullException) { }
         this.UserProfile = null;
     }
 }
예제 #6
0
 /// <summary>
 /// Implements <see cref="IDevOpsIntegration.Disconnect()"/>
 /// </summary>
 public void Disconnect()
 {
     lock (_lockObject)
     {
         try
         {
             _baseServerConnection?.Disconnect();
         }
         catch (ArgumentNullException) { }
         this.UserProfile = null;
     }
 }
예제 #7
0
        public void Disconnect()
        {
            _url = null;
            _availableProjects = null;

            if (_client != null)
            {
                _client.Dispose();
                _client = null;
            }

            if (_connection != null)
            {
                _connection.Disconnect();
                _connection.Dispose();
                _connection = null;
            }

            Disconnected?.Invoke(this);
        }
예제 #8
0
        private static async Task TestRetry(string collectionUrl, string devOpsToken, int worktItemId, CancellationToken cancellationToken)
        {
            // see https://docs.microsoft.com/en-us/azure/devops/integrate/concepts/rate-limits#api-client-experience
            int MaxRetries = 3;
            var policy     = Policy
                             .Handle <HttpRequestException>()
                             // https://github.com/App-vNext/Polly/wiki/Retry#retryafter-when-the-response-specifies-how-long-to-wait
                             .OrResult <HttpResponseMessage>(r => r.StatusCode == (HttpStatusCode)429)
                             .WaitAndRetryAsync(
                retryCount: MaxRetries,
                sleepDurationProvider: (retryCount, response, context) => {
                return(response.Result?.Headers.RetryAfter.Delta.Value
                       ?? TimeSpan.FromSeconds(30 * retryCount));
            },
                onRetryAsync: async(response, timespan, retryCount, context) => {
                await Console.Out.WriteLineAsync($"{Environment.NewLine}Waiting {timespan} before retrying (attemp #{retryCount}/{MaxRetries})...");
            }
                );
            var handler = new PolicyHttpMessageHandler(policy);

            var clientCredentials = new VssBasicCredential("", devOpsToken);
            var vssHandler        = new VssHttpMessageHandler(clientCredentials, VssClientHttpRequestSettings.Default.Clone());

            using var devops = new VssConnection(new Uri(collectionUrl), vssHandler, new DelegatingHandler[] { handler });
            await devops.ConnectAsync(cancellationToken);

            using var witClient = await devops.GetClientAsync <WorkItemTrackingHttpClient>(cancellationToken);

            for (int i = 0; i < 10; i++)
            {
                _ = await witClient.GetWorkItemAsync(worktItemId);

                Console.Write('+');
            }

            devops.Disconnect();
        }
예제 #9
0
        public void GetTFSTickets()
        {
            Uri           orgUrl = new Uri("https://dev.azure.com/DCTTFS/");
            String        personalAccessToken = "ndzzurgegqnpmjwrqhwji2c5exr7wffx4bzjhuccdfprfsdjuydq";
            VssConnection connection          = new VssConnection(orgUrl, new VssBasicCredential(string.Empty, personalAccessToken));

            WorkItemTrackingHttpClient witClient = connection.GetClient <WorkItemTrackingHttpClient>();

            Wiql wiql = new Wiql();

            wiql.Query = "SELECT [System.Id],[System.Title],[System.State],[Custom._Severity],[Custom._Module],[System.Description],[System.IterationPath],[Custom.Stream] FROM workitems where [System.State] = 'New'";

            WorkItemQueryResult tasks = witClient.QueryByWiqlAsync(wiql).Result;

            IEnumerable <WorkItemReference> tasksRefs;

            tasksRefs = tasks.WorkItems.OrderBy(x => x.Id);

            List <WorkItem> tasksList = witClient.GetWorkItemsAsync(tasksRefs.Select(wir => wir.Id)).Result;

            tickets = new List <Ticket>();


            foreach (var task in tasksList)
            {
                tickets.Add(new Ticket
                {
                    ID          = task.Id,
                    Title       = task.Fields["System.Title"].ToString(),
                    State       = task.Fields["System.State"].ToString(),
                    Description = "NA",
                    Severity    = task.Fields["Custom._Severity"].ToString(),
                    Module      = task.Fields["Custom._Module"].ToString(),
                    Sprint      = task.Fields["System.IterationPath"].ToString().Split('\\')[1],
                    Stream      = task.Fields["Custom.Stream"].ToString()
                });
            }


            using (SqlConnection conn = new SqlConnection())
            {
                conn.ConnectionString = "server = tcp:hatch.database.windows.net,1433; initial catalog = acrf; persist security info = false; user id = dct; password = Duck@1234; multipleactiveresultsets = false; encrypt = true; trustservercertificate = false; connection timeout = 30;";
                // using the code here...


                conn.Open();
                //SqlCommand cmd = conn.CreateCommand();
                //SqlTransaction transaction;
                //transaction = conn.BeginTransaction();
                //cmd.Transaction = transaction;
                //cmd.Connection = conn;
                try
                {
                    foreach (var task in tasksList)
                    {
                        string sqlstr = "InsertTFSTickets";
                        //sqlstr = "insert into tbl_employee(empid,managerempid,profile,projectid,password,createdby,createdon) values (@empid,@createdby,@createdon)";
                        //sqlstr = "insert into TFSTicketsData(ID,Title,Description,State,Severity,Module) values (@ID,@Title,@Description,@State,@Severity,@Module)";
                        //sqlstr = "insert into tbl_employee(empid,managerempid,profile,projectid,password,status,experties,stream) values (@empid,@managerempid,@profile,@projectid,@password,@status,@experties,@stream)";


                        SqlCommand cmd = new SqlCommand(sqlstr, conn);
                        cmd.CommandType = System.Data.CommandType.StoredProcedure;
                        cmd.Parameters.Clear();
                        cmd.Parameters.AddWithValue("@ID", task.Id);
                        cmd.Parameters.AddWithValue("@Title", task.Fields["System.Title"].ToString());
                        cmd.Parameters.AddWithValue("@Description", "NA");
                        cmd.Parameters.AddWithValue("@State", task.Fields["System.State"].ToString());
                        cmd.Parameters.AddWithValue("@Severity", task.Fields["Custom._Severity"].ToString());
                        cmd.Parameters.AddWithValue("@Module", task.Fields["Custom._Module"].ToString());
                        cmd.Parameters.AddWithValue("@Sprint", task.Fields["System.IterationPath"].ToString().Split('\\')[1].Replace(" ", "").ToLower());
                        cmd.Parameters.AddWithValue("@Stream", task.Fields["Custom.Stream"].ToString());
                        cmd.ExecuteNonQuery();
                    }

                    //transaction.Commit();
                    conn.Close();
                    //result = "employee added successfully!";
                }
                catch (Exception ex)
                {
                    //transaction.Rollback();
                    conn.Close();
                    //global.errorhandlerclass.logerror(ex);
                    //result = ex.message;
                }
            }

            connection.Disconnect();
        }
 public void Dispose()
 {
     _connection.Disconnect();
 }
        public void Dispose()
        {
            _client?.Dispose();

            _connection?.Disconnect();
        }
 public static void Logoff()
 {
     connection.Disconnect();
     _witClient = null;
 }