public async Task Invoke(HttpContext context)
        {
            var request = context.Request;

            if (request.Path == "/" || string.IsNullOrEmpty(request.Path))
            {
                await WriteIndexFile(context);

                return;
            }
            if (request.Path == "/favicon.ico")
            {
                await WriteFileAsync(context, "favicon.ico", "image/x-icon");

                return;
            }
            if (request.Path == "/index.min.js")
            {
                await WriteFileAsync(context, "index.min.js", "application/javascript");

                return;
            }

            if (request.Path == "/version")
            {
                await WriteJson(context, new { version = typeof(DashboardMiddleware).Assembly.GetName().Version.ToString() });

                return;
            }

            if (request.Path == "/DashboardCounters")
            {
                var result = await client.DashboardCounters();
                await WriteJson(context, result.Value);

                return;
            }

            if (request.Path == "/ClusterStats")
            {
                var result = await client.ClusterStats();

                await WriteJson(context, result.Value);

                return;
            }

            if (request.Path == "/Reminders")
            {
                try
                {
                    var result = await client.GetReminders(1, REMINDER_PAGE_SIZE);

                    await WriteJson(context, result.Value);
                }
                catch
                {
                    // if reminders are not configured, the call to the grain will fail
                    await WriteJson(context, new ReminderResponse { Reminders = new ReminderInfo[0], Count = 0 });
                }

                return;
            }

            if (request.Path.StartsWithSegments("/Reminders", out var pageString1) && int.TryParse(pageString1.ToValue(), out var page))
            {
                try
                {
                    var result = await client.GetReminders(page, REMINDER_PAGE_SIZE);

                    await WriteJson(context, result.Value);
                }
                catch
                {
                    // if reminders are not configured, the call to the grain will fail
                    await WriteJson(context, new ReminderResponse { Reminders = new ReminderInfo[0], Count = 0 });
                }

                return;
            }

            if (request.Path.StartsWithSegments("/HistoricalStats", out var remaining))
            {
                var result = await client.HistoricalStats(remaining.ToValue());

                await WriteJson(context, result.Value);

                return;
            }

            if (request.Path.StartsWithSegments("/SiloProperties", out var address1))
            {
                var result = await client.SiloProperties(address1.ToValue());

                await WriteJson(context, result.Value);

                return;
            }

            if (request.Path.StartsWithSegments("/SiloStats", out var address2))
            {
                var result = await client.SiloStats(address2.ToValue());

                await WriteJson(context, result.Value);

                return;
            }

            if (request.Path.StartsWithSegments("/SiloCounters", out var address3))
            {
                var result = await client.GetCounters(address3.ToValue());

                await WriteJson(context, result.Value);

                return;
            }

            if (request.Path.StartsWithSegments("/GrainStats", out var grainName1))
            {
                var result = await client.GrainStats(grainName1.ToValue());

                await WriteJson(context, result.Value);

                return;
            }

            if (request.Path == "/TopGrainMethods")
            {
                var result = await client.TopGrainMethods();

                await WriteJson(context, result.Value);

                return;
            }

            if (request.Path == "/Trace")
            {
                await TraceAsync(context);

                return;
            }

            await next(context);
        }
예제 #2
0
 public async Task <IActionResult> ClusterStats()
 {
     return(Json((await _client.ClusterStats()).Value));
 }