Esempio n. 1
0
        /// <summary>
        /// Apply rules to cards
        /// </summary>
        /// <param name="projectName"></param>
        /// <param name="Json"></param>

        public void ApplyRules(string projectName, string Json)
        {
            //CardStylesPatch.ListofCardStyles cardStyles1 = JsonConvert.DeserializeObject<CardStylesPatch.ListofCardStyles>(File.ReadAllText(""));

            CardStylesPatch.ListofCardStyles cardStyles = JsonConvert.DeserializeObject <CardStylesPatch.ListofCardStyles>(Json);
            if (cardStyles.rules.Message == null)
            {
                cardStyles.rules.Message = "test";
            }

            string teamName = projectName + " Team";

            using (var client = new HttpClient())
            {
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", _credentials);

                // serialize the fields array into a json string
                var patchValue = new StringContent(JsonConvert.SerializeObject(cardStyles), Encoding.UTF8, "application/json"); // mediaType needs to be application/json-patch+json for a patch call
                var method     = new HttpMethod("PATCH");
                // GetBoards getAgileBoards = new GetBoards(_configuration);
                string boardURL = _configuration.UriString + "/" + projectName + "/" + teamName + "/_apis/work/boards/Backlog%20items/cardrulesettings?api-version=" + _configuration.VersionNumber + "-preview";
                //Console.WriteLine("Board URL i s {0}", boardURL);
                var request = new HttpRequestMessage(method, boardURL)
                {
                    Content = patchValue
                };
                var response = client.SendAsync(request).Result;

                if (response.IsSuccessStatusCode)
                {
                    // viewModel = response.Content.ReadAsAsync<GetCardFieldResponse.ListofCards>().Result;
                }
                else
                {
                    var    errorMessage = response.Content.ReadAsStringAsync();
                    string error        = Utility.GeterroMessage(errorMessage.Result.ToString());
                    this.LastFailureMessage = error;
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Apply rules to cards
        /// </summary>
        /// <param name="projectName"></param>
        /// <param name="json"></param>

        public void ApplyRules(string projectName, string json, string boardType, string teamName)
        {
            try
            {
                json = json.Replace("null", "\"\"");
                json = json.Replace("$ProjectName$", projectName);
                CardStylesPatch.ListofCardStyles cardStyles = JsonConvert.DeserializeObject <CardStylesPatch.ListofCardStyles>(json);
                if (cardStyles.rules.Message == null)
                {
                    cardStyles.rules.Message = "test";
                }
                using (var client = GetHttpClient())
                {
                    var    patchValue = new StringContent(JsonConvert.SerializeObject(cardStyles), Encoding.UTF8, "application/json"); // mediaType needs to be application/json-patch+json for a patch call
                    var    method     = new HttpMethod("PATCH");
                    string boardURL   = "https://dev.azure.com/" + Account + "/" + projectName + "/" + teamName + "/_apis/work/boards/" + boardType + "/cardrulesettings?api-version=" + _configuration.VersionNumber;
                    var    request    = new HttpRequestMessage(method, boardURL)
                    {
                        Content = patchValue
                    };
                    var response = client.SendAsync(request).Result;

                    if (response.IsSuccessStatusCode)
                    {
                    }
                    else
                    {
                        var    errorMessage = response.Content.ReadAsStringAsync();
                        string error        = Utility.GeterroMessage(errorMessage.Result.ToString());
                        this.LastFailureMessage = error;
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Debug(DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss") + "\t" + "CreateNewTeam" + "\t" + ex.Message + "\t" + "\n" + ex.StackTrace + "\n");
            }
        }