Beispiel #1
0
        public async Task Dispatch(DashboardContext context)
        {
            var requestedMetrics = await context.Request.GetFormValuesAsync("metrics[]").ConfigureAwait(false);

            var page = new StubPage();

            page.Assign(context);

            var metrics = DashboardMetrics.GetMetrics().Where(x => requestedMetrics.Contains(x.Name));
            var result  = new Dictionary <string, Metric>();

            foreach (var metric in metrics)
            {
                var value = metric.Func(page);
                result.Add(metric.Name, value);
            }

            var settings = new JsonSerializerSettings
            {
                ContractResolver = new CamelCasePropertyNamesContractResolver(),
                Converters       = new JsonConverter[] { new StringEnumConverter {
                                                             CamelCaseText = true
                                                         } }
            };
            var serialized = JsonConvert.SerializeObject(result, settings);

            context.Response.ContentType = "application/json";
            await context.Response.WriteAsync(serialized).ConfigureAwait(false);
        }
Beispiel #2
0
        public async Task Dispatch(RequestDispatcherContext context)
        {
            var owinContext = new OwinContext(context.OwinEnvironment);
            var form        = await owinContext.ReadFormSafeAsync();

            var requestedMetrics = new HashSet <string>(form.GetValues("metrics[]") ?? new string[0]);

            var page = new StubPage();

            page.Assign(context);

            var metrics = DashboardMetrics.GetMetrics().Where(x => requestedMetrics.Contains(x.Name));
            var result  = new Dictionary <string, Metric>();

            foreach (var metric in metrics)
            {
                var value = metric.Func(page);
                result.Add(metric.Name, value);
            }

            var settings = new JsonSerializerSettings
            {
                ContractResolver = new CamelCasePropertyNamesContractResolver(),
                Converters       = new JsonConverter[] { new StringEnumConverter {
                                                             CamelCaseText = true
                                                         } }
            };
            var serialized = JsonConvert.SerializeObject(result, settings);

            owinContext.Response.ContentType = "application/json";
            await owinContext.Response.WriteAsync(serialized);
        }
Beispiel #3
0
        public async Task Dispatch(RequestDispatcherContext context)
        {
            var owinContext = new OwinContext(context.OwinEnvironment);
            var form = await owinContext.Request.ReadFormAsync();
            var requestedMetrics = new HashSet<string>(form.GetValues("metrics[]") ?? new string[0]);

            var page = new StubPage();
            page.Assign(context);

            var metrics = DashboardMetrics.GetMetrics().Where(x => requestedMetrics.Contains(x.Name));
            var result = new Dictionary<string, Metric>();

            foreach (var metric in metrics)
            {
                var value = metric.Func(page);
                result.Add(metric.Name, value);
            }

            var settings = new JsonSerializerSettings
            {
                ContractResolver = new CamelCasePropertyNamesContractResolver(),
                Converters = new JsonConverter[]{ new StringEnumConverter { CamelCaseText = true } }
            };
            var serialized = JsonConvert.SerializeObject(result, settings);

            owinContext.Response.ContentType = "application/json";
            await owinContext.Response.WriteAsync(serialized);
        }
Beispiel #4
0
        public async Task Dispatch(DashboardContext context)
        {
            var page = new StubPage();

            page.Assign(context);

            var monitor   = context.Monitor;
            var pipelines = monitor.GetMetrics();

            var settings = new JsonSerializerSettings
            {
                ContractResolver = new CamelCasePropertyNamesContractResolver(),
                Converters       = new JsonConverter[] { new StringEnumConverter {
                                                             NamingStrategy = new CamelCaseNamingStrategy()
                                                         } }
            };
            var serialized = JsonConvert.SerializeObject(pipelines, settings);

            context.Response.ContentType = "application/json";
            await context.Response.WriteAsync(serialized);
        }
Beispiel #5
0
        public async Task Dispatch(DashboardContext context)
        {
            var requestedMetrics = await context.Request.GetFormValuesAsync("metrics[]");

            var page = new StubPage();

            page.Assign(context);

            var metrics = DashboardMetrics.GetMetrics().Where(x => requestedMetrics.Contains(x.Name));
            var result  = new Dictionary <string, Metric>();

            foreach (var metric in metrics)
            {
                var value = metric.Func(page);
                result.Add(metric.Name, value);
            }

            var serialized = JsonSerializer.Serialize(result);

            context.Response.ContentType = "application/json";
            await context.Response.WriteAsync(serialized);
        }