Esempio n. 1
0
        public Task <AmazonWebServiceResponse> SendAsync(TelemetryRequest request)
        {
            var options = new InvokeOptions();

            options.RequestMarshaller    = TelemetryRequestMarshaller.Instance;
            options.ResponseUnmarshaller = TelemetryResponseUnmarshaller.Instance;
            return(InvokeAsync <AmazonWebServiceResponse>(request, options, CancellationToken.None));
        }
        private static async Task <bool> PutLogData
        (
            string logName,
            string logData,
            string profile,
            TelemetryConfiguration telemetryConfiguration,
            ITelemetryClient client
        )
        {
            try
            {
                dynamic requestMetadata = new JObject();
                requestMetadata.version     = "1.0";
                requestMetadata.service     = telemetryConfiguration.ServiceName;
                requestMetadata.token       = "12345678";
                requestMetadata.description = telemetryConfiguration.Description;

                dynamic log = new JObject();
                log.timestamp = DateTime.Now.ToString();
                log.logName   = logName;
                var logDataInBytes = System.Text.Encoding.UTF8.GetBytes(logData);
                log.logData = System.Convert.ToBase64String(logDataInBytes);

                dynamic body = new JObject();
                body.requestMetadata = requestMetadata;
                body.log             = log;

                var requestContent = new StringContent(body.ToString(Formatting.None), Encoding.UTF8, "application/json");

                var contentString = await requestContent.ReadAsStringAsync();

                var telemetryRequest  = new TelemetryRequest(telemetryConfiguration.ServiceName, contentString);
                var telemetryResponse = await client.SendAsync(telemetryRequest);

                if (telemetryResponse.HttpStatusCode != HttpStatusCode.OK)
                {
                    Log.Logger.Error("Http response failed with status code: " + telemetryResponse.HttpStatusCode.ToString());
                }

                return(telemetryResponse.HttpStatusCode == HttpStatusCode.OK);
            }
            catch (Exception ex)
            {
                Log.Logger.Error(ex.Message);
                return(false);
            }
        }