コード例 #1
0
        public async Task <IActionResult> Index()
        {
            var allStatuses = await _statusService.CheckAllSystems();

            var isAllOk = allStatuses.All(m => m.Value);
            var isAnyOk = allStatuses.Any(m => m.Value);
            var apiMsg  = new ApiMessage <MessageDto> {
                Status = isAllOk
            };
            var overallStatusMessage = isAllOk
                ? "System is in graceful state."
                : (isAnyOk ? "System is degraded." : "All systems are down.");

            apiMsg.Messages.Push(overallStatusMessage);

            if (isAllOk)
            {
                return(Ok(apiMsg));
            }

            var desertedSystems =
                allStatuses.Where(s => !s.Value).ToList();

            desertedSystems.ForEach(n =>
            {
                apiMsg.Messages.Push($"{n.Key} is in downstate due to maintenance or a critical system fault.");
            });
            return(Ok(apiMsg));
        }