Beispiel #1
0
        private async Task <byte[]> GetDocumentFromWireServerAsync()
        {
            using (var client = new HttpClient())
            {
                using (HttpResponseMessage responseMessage = await client.GetAsync(zeroSdkUri).ConfigureAwait(false))
                {
                    if (!responseMessage.IsSuccessStatusCode)
                    {
                        string message =
                            "Get document failed with HTTP status code {0}{1}Response message: {2}".ToString(
                                responseMessage.StatusCode, Environment.NewLine, responseMessage.ToJson());
                        traceWriteConditionalWarning("{0}", message);

                        if (responseMessage.StatusCode == HttpStatusCode.GatewayTimeout ||
                            responseMessage.StatusCode == HttpStatusCode.RequestTimeout)
                        {
                            throw new TimeoutException(message);
                        }

                        if (responseMessage.StatusCode == HttpStatusCode.NoContent)
                        {
                            traceWriteConditionalWarning("Get document returned no content which is unexpected, returning null.");
                            return(null);
                        }

                        throw new ManagementException(message);
                    }

                    byte[] payload = await responseMessage.Content.ReadAsByteArrayAsync().ConfigureAwait(false);

                    if (payload == null)
                    {
                        const string message = "Get document failed to get payload";

                        traceWriteConditionalWarning(message);
                        throw new ManagementException(message);
                    }

                    traceType.WriteNoise("Get document response stream payload obtained. Bytes: {0}", payload.Length);

                    return(payload);
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Escalates the impact category based on the impact to a particular resource type.
        /// </summary>
        /// <param name="oldCategory">The current impact category.</param>
        /// <param name="resourceType">The resource type name.</param>
        /// <param name="impact">The impact to the given resource.</param>
        /// <returns>The new impact category.</returns>
        private ImpactCategory ApplyResourceImpact(
            ImpactCategory oldCategory,
            string resourceType,
            Impact impact)
        {
            ImpactCategory newCategory = TranslateResourceImpactToCategory(resourceType, impact);

            newCategory = EscalateImpactCategory(oldCategory, newCategory);

            if (oldCategory != newCategory)
            {
                tracer.WriteNoise(
                    "Overall impact changed from {0} to {1} due to resource impact {2}={3}",
                    oldCategory,
                    newCategory,
                    resourceType,
                    impact);
            }

            return(newCategory);
        }