示例#1
0
        public async Task <bool> Trigger()
        {
            Console.WriteLine("[ApplicationInsightsIngestion]: Triggering ingestion");
            var client   = new AnalyticsDataSourceClient();
            var settings = new AnalyticsDataSourceIngestionRequestSettings(_configuration);
            var request  = new AnalyticsDataSourceIngestionRequest(settings);

            return(await client.RequestBlobIngestion(request));
        }
        public async Task <bool> RequestBlobIngestion(AnalyticsDataSourceIngestionRequest ingestionRequest)
        {
            var request = WebRequest.CreateHttp(endpoint);

            request.Method      = WebRequestMethods.Http.Post;
            request.ContentType = RequestContentType;
            request.Accept      = RequestAccess;

            string notificationJson = Serialize(ingestionRequest);

            byte[] notificationBytes = GetContentBytes(notificationJson);
            request.ContentLength = notificationBytes.Length;

            Stream requestStream = request.GetRequestStream();

            requestStream.Write(notificationBytes, 0, notificationBytes.Length);
            requestStream.Close();

            try
            {
                using (var response = (HttpWebResponse)await request.GetResponseAsync())
                {
                    return(response.StatusCode == HttpStatusCode.OK);
                }
            }
            catch (WebException e)
            {
                HttpWebResponse httpResponse = e.Response as HttpWebResponse;
                if (httpResponse != null)
                {
                    Console.WriteLine(
                        "Ingestion request failed with status code: {0}. Error: {1}",
                        httpResponse.StatusCode,
                        httpResponse.StatusDescription);
                }
                throw;
            }
        }
 private string Serialize(AnalyticsDataSourceIngestionRequest ingestionRequest)
 {
     return(JsonConvert.SerializeObject(ingestionRequest));
 }