Exemplo n.º 1
0
        public void Get_Down_Time_Basic()
        {
            // Normal case. Two sequential Downtime.
            var list     = GetSampleStatusHistories();
            var downtime = StatusHistory.GetServiceDowntimeTotal(list);

            Assert.AreEqual(TimeSpan.FromHours(2), downtime);
        }
        public async Task <TimeSpan> GetDowntimeAsync(string teamId)
        {
            var statusHistories = await this.service.GetDocumentsAsync <StatusHistory>(
                (query) =>
            {
                return(query.Where(f => f.TeamId == teamId));
            }
                );

            return(StatusHistory.GetServiceDowntimeTotal(statusHistories));
        }
Exemplo n.º 3
0
        public void Get_Down_Time_Without_Finished()
        {
            var list = new List <StatusHistory>();

            list.AddRange(GetSampleStatusHistories());
            // This data is not finished.
            list.Add(
                GetSampleStatusHistory(
                    "01",
                    new DateTime(2018, 5, 29, 14, 0, 0),
                    DowntimeStatus.Started
                    ));

            var downtime = StatusHistory.GetServiceDowntimeTotal(list, new DateTime(2018, 5, 29, 15, 0, 0));

            Assert.AreEqual(TimeSpan.FromHours(3), downtime);
        }
Exemplo n.º 4
0
        public static async Task <IActionResult> GetTeamsStatus([HttpTrigger(AuthorizationLevel.Function, "get", Route = null)] HttpRequest req, TraceWriter log)
        {
            using (var scope = Container.BeginLifetimeScope())
            {
                try
                {
                    var service = scope.Resolve <DocumentService>();
                    // Get Openhack Start/End time.
                    var openhack = await service.GetDocumentAsync <Openhack>();

                    // Get Team list
                    var teams = await service.GetAllDocumentsAsync <Team>();

                    var list = new List <UptimeReport>();
                    foreach (var team in teams)
                    {
                        var histories = await service.GetDocumentsAsync <StatusHistory>(
                            (query) =>
                        {
                            return(query.Where(f => f.TeamId == team.Id));
                        });

                        var downtime = StatusHistory.GetServiceDowntimeTotal(histories);
                        // TODO implement uptime and uppercent
                        list.Add(
                            new UptimeReport
                        {
                            Name      = team.Name,
                            Uptime    = (int)openhack.GetUpTime(downtime).TotalHours,
                            Uppercent = (int)openhack.GetTotalAvailavility(downtime),
                            Point     = 300 // No logic until now.
                        }
                            );
                    }
                    var result = JsonConvert.SerializeObject(list);
                    return(new OkObjectResult(result));
                } catch (Exception e)
                {
                    log.Error($"Get Team status error: {e.Message}");
                    log.Error(e.StackTrace);
                    return(new BadRequestObjectResult("{'status': 'error', 'message': '{" + e.Message + "'}"));
                }
            }
        }