Example #1
0
        private IEnumerable <MonitoringDataPoint> CreateSampleFromContext(HttpListenerContext context)
        {
            try
            {
                var request     = context.Request;
                var response    = context.Response;
                var content     = request.GetContent();
                var requestData = new MemoryStream(Encoding.UTF8.GetBytes(content ?? string.Empty));

                Trace.WriteLine("=>");
                Trace.WriteLine("Item received: " + content);
                Trace.WriteLine("<=");

                if (request.Url.LocalPath == "/QuickPulseService.svc/ping")
                {
                    response.AddHeader("x-ms-qps-subscribed", true.ToString());
                }
                else if (request.Url.LocalPath == "/QuickPulseService.svc/post")
                {
                    return(TelemetryItemFactory.CreateQuickPulseSamples(requestData));
                }

                return(new MonitoringDataPoint[0]);
            }
            finally
            {
                context.Response.Close();
            }
        }
Example #2
0
        private IEnumerable <MonitoringDataPoint> CreateSampleFromContext(HttpListenerContext context)
        {
            try
            {
                var    request          = context.Request;
                var    content          = request.GetContent();
                var    requestData      = new MemoryStream(Encoding.UTF8.GetBytes(content ?? string.Empty));
                string requestLocalPath = request.Url.LocalPath;

                Trace.WriteLine("=>");
                Trace.WriteLine("Item received: " + content);
                Trace.WriteLine("<=");

                var response = context.Response;

                if (requestLocalPath == "/QuickPulseService.svc/ping")
                {
                    response.AddHeader("x-ms-qps-subscribed", true.ToString());
                    response.AddHeader("x-ms-qps-configuration-etag", "Etag1");
                    this.WriteCollectionConfiguration(response.OutputStream);
                }
                else if (requestLocalPath == "/QuickPulseService.svc/post")
                {
                    var dataPoints = TelemetryItemFactory.CreateQuickPulseSamples(requestData);

                    response.AddHeader("x-ms-qps-subscribed", true.ToString());
                    response.AddHeader("x-ms-qps-configuration-etag", "Etag1");
                    this.WriteCollectionConfiguration(response.OutputStream);

                    return(dataPoints);
                }
            }
            catch (HttpListenerException)
            {
                // client disconnected
            }
            finally
            {
                try
                {
                    context.Response.Close();
                }
                catch (HttpListenerException)
                {
                    // client disconnected
                }
            }

            return(new MonitoringDataPoint[0]);
        }