Пример #1
0
        /// <inheritdoc />
        public async Task <string> CreateAgileBoard(AgileSettings agileSettings)
        {
            if (agileSettings == null)
            {
                throw new ArgumentNullException(nameof(agileSettings));
            }

            var stringContent = new StringContent(JsonConvert.SerializeObject(agileSettings));

            stringContent.Headers.ContentType = new MediaTypeHeaderValue(Constants.HttpContentTypes.ApplicationJson);

            var client = await _connection.GetAuthenticatedHttpClient();

            var response = await client.PostAsync("rest/admin/agile", stringContent);

            if (response.StatusCode == HttpStatusCode.BadRequest)
            {
                // Try reading the error message
                var responseJson = JObject.Parse(await response.Content.ReadAsStringAsync());
                if (responseJson["value"] != null)
                {
                    throw new YouTrackErrorException(responseJson["value"].Value <string>());
                }

                throw new YouTrackErrorException(Strings.Exception_UnknownError);
            }

            response.EnsureSuccessStatusCode();

            // Extract work item id from Location header response
            const string marker         = "admin/agile/";
            var          locationHeader = response.Headers.Location.ToString();

            return(locationHeader.Substring(locationHeader.IndexOf(marker, StringComparison.OrdinalIgnoreCase) + marker.Length));
        }
Пример #2
0
        /// <inheritdoc />
        public async Task UpdateAgileBoard(string agileBoardId, AgileSettings agileSettings)
        {
            if (agileSettings == null)
            {
                throw new ArgumentNullException(nameof(agileSettings));
            }

            // Ensure no null values or empty collections are sent
            if (agileSettings.Projects?.Count == 0)
            {
                agileSettings.Projects = null;
            }
            if (agileSettings.Sprints?.Count == 0)
            {
                agileSettings.Sprints = null;
            }

            var stringContent = new StringContent(JsonConvert.SerializeObject(agileSettings,
                                                                              new JsonSerializerSettings
            {
                NullValueHandling = NullValueHandling.Ignore
            }));

            stringContent.Headers.ContentType = new MediaTypeHeaderValue(Constants.HttpContentTypes.ApplicationJson);

            var client = await _connection.GetAuthenticatedHttpClient();

            var response = await client.PutAsync($"rest/admin/agile/{agileBoardId}", stringContent);

            if (response.StatusCode == HttpStatusCode.BadRequest)
            {
                // Try reading the error message
                var responseJson = JObject.Parse(await response.Content.ReadAsStringAsync());
                if (responseJson["value"] != null)
                {
                    throw new YouTrackErrorException(responseJson["value"].Value <string>());
                }
                else
                {
                    throw new YouTrackErrorException(Strings.Exception_UnknownError);
                }
            }

            response.EnsureSuccessStatusCode();
        }