public void stateComm()
        {
            DataTime = DateTime.Now;
            StateReport stateRESP = new StateReport
            {
                Id          = configGP.TowerID,
                Time        = DataTime,
                Mode        = statusGP.StrgMode,
                State       = statusGP.StrgState,
                AccessState = statusGP.StrgAccState,
                JobId       = recvdataGP.JobID,
                Msg         = "state Check"
            };

            string JsonSerial = JsonConvert.SerializeObject(stateRESP);

            Textbox_Write(JsonSerial, stateURL);
            if (serverRESP != null && serverRESP.Job != null && recvdataGP.JobID != serverRESP.Job.Id)
            {
                recvdataGP.JobID      = serverRESP.Job.Id;
                recvdataGP.UuidID     = serverRESP.Job.Uuid;
                recvdataGP.OperName   = serverRESP.Job.Oper;
                recvdataGP.ViewEnable = true;
                serverRESP.Job        = null;
                OnEventJobState?.Invoke(this, recvdataGP);
            }
        }
Beispiel #2
0
        private Task HandleSuccess(string username, StateReport stateReport, IMessageHandlerContext context)
        {
            var data = stateReport.SerializeMessage();

            return(context.Publish <IStatePlanPromoted>(e =>
            {
                e.Username = username;
                e.Organization = stateReport.Organization;
                e.StateReport = stateReport;
                e.SerializedData = data;
            }));
        }
        public void Handle(CoreProjectionStatusMessage.StateReport message)
        {
            var command = new StateReport {
                Id            = message.ProjectionId.ToString("N"),
                State         = message.State,
                CorrelationId = message.CorrelationId.ToString("N"),
                Position      = message.Position,
                Partition     = message.Partition
            };

            _writer.PublishCommand("$state", command);
        }
        public ReportData GetGeneratedData(int organizationId, ReportingPeriod reportingPeriod)
        {
            var managedOrganizations = _organizationService.GetManagedOrganizations(organizationId);
            var organizations        = managedOrganizations as Organization[] ?? managedOrganizations.ToArray();

            var onlyRecentStateReports = new StateReport[0];
            var allStateReports        = new StateReport[0];

            var onlyRecentZoneReports = _zoneReportService.GetOnlyRecentZoneReports(reportingPeriod, organizations);
            var allZoneReports        = _zoneReportService.GetAllZoneReports(reportingPeriod, organizations);

            var onlyRecentUnitReports = _unitReportService.GetOnlyRecentUnitReports(reportingPeriod, organizations);
            var allUnitReports        = _unitReportService.GetAllUnitReports(reportingPeriod, organizations);

            return(ReportDataCalculator.GetCalculatedReportData(onlyRecentUnitReports, allUnitReports, onlyRecentZoneReports, allZoneReports, onlyRecentStateReports, allStateReports));
        }
Beispiel #5
0
        public static ReportData GetCalculatedReportData(UnitReport[] onlyRecentUnitReports,
                                                         UnitReport[] allUnitReports,
                                                         ZoneReport[] onlyRecentZoneReports       = null,
                                                         ZoneReport[] allZoneReports              = null,
                                                         StateReport[] onlyRecentStateReports     = null,
                                                         StateReport[] allStateReports            = null,
                                                         CentralReport[] onlyRecentCentralReports = null,
                                                         CentralReport[] allCentralReports        = null

                                                         )
        {
            if (onlyRecentUnitReports == null)
            {
                onlyRecentUnitReports = new UnitReport[0];
            }
            if (onlyRecentZoneReports == null)
            {
                onlyRecentZoneReports = new ZoneReport[0];
            }
            if (onlyRecentStateReports == null)
            {
                onlyRecentStateReports = new StateReport[0];
            }
            if (onlyRecentCentralReports == null)
            {
                onlyRecentCentralReports = new CentralReport[0];
            }

            if (allUnitReports == null)
            {
                allUnitReports = new UnitReport[0];
            }
            if (allZoneReports == null)
            {
                allZoneReports = new ZoneReport[0];
            }
            if (allStateReports == null)
            {
                allStateReports = new StateReport[0];
            }
            if (allCentralReports == null)
            {
                allCentralReports = new CentralReport[0];
            }

            return(Calculator.GetCalculatedReportData(onlyRecentUnitReports.Select(o =>
            {
                ReportData r = o;
                return r;
            }).ToArray(),
                                                      allUnitReports.Select(o =>
            {
                ReportData r = o;
                return r;
            }).ToArray(),
                                                      onlyRecentZoneReports.Select(o =>
            {
                ReportData r = o;
                return r;
            }).ToArray(),
                                                      allZoneReports.Select(o =>
            {
                ReportData r = o;
                return r;
            }).ToArray(),
                                                      onlyRecentStateReports.Select(o =>
            {
                ReportData r = o;
                return r;
            }).ToArray(),
                                                      allStateReports.Select(o =>
            {
                ReportData r = o;
                return r;
            }).ToArray(),
                                                      onlyRecentCentralReports.Select(o =>
            {
                ReportData r = o;
                return r;
            }).ToArray(),
                                                      allCentralReports.Select(o =>
            {
                ReportData r = o;
                return r;
            }).ToArray()));
        }
        public async Task Handle_Publishes_ExpectedResult()
        {
            DateTimeDbTestExtensions.SetUtcNowToRandomDate();
            var testParams = Endpoint.ArrangeOnSqlSession(AssemblySetupFixture.EndpointTestContainer,
                                                          s =>
            {
                var username      = DataProvider.Get <string>();
                var organizations = IntegrationTestOrganizationHelper.SetupOrzanizations();
                var central       = organizations.First(o => o.Key == IntegrationTestOrganizationHelper.Central).Value;
                var nswState      = organizations.First(o => o.Key == IntegrationTestOrganizationHelper.NswState).Value;
                var nswZone1      = organizations.First(o => o.Key == IntegrationTestOrganizationHelper.NswZoneOne).Value;
                var lakemba       = organizations.First(o => o.Key == IntegrationTestOrganizationHelper.Lakemba).Value;

                var year1 = 2019;
                var year2 = 2020;

                var period1 = new ReportingPeriod(ReportingFrequency.Monthly, ReportingTerm.One, year1);
                var period2 = new ReportingPeriod(ReportingFrequency.Monthly, ReportingTerm.One, year2);

                var period1ReportingData = new ReportDataBuilder().Build();
                var period2ReportingData = new ReportDataBuilder().Build();

                var period1UnitReport =
                    new UnitReport(DataProvider.Get <string>(), lakemba, period1, period1ReportingData);
                s.Save(period1UnitReport);
                var period2UnitReport =
                    new UnitReport(DataProvider.Get <string>(), lakemba, period2, period2ReportingData);
                s.Save(period2UnitReport);

                var period1ZoneReport =
                    new ZoneReport(DataProvider.Get <string>(), nswZone1, period1, period1ReportingData);
                s.Save(period1ZoneReport);
                var period2ZoneReport =
                    new ZoneReport(DataProvider.Get <string>(), nswZone1, period2, period2ReportingData);
                s.Save(period2ZoneReport);

                var period1StateReport =
                    new StateReport(DataProvider.Get <string>(), nswState, period1, period1ReportingData);
                s.Save(period1StateReport);
                var period2StateReport =
                    new StateReport(DataProvider.Get <string>(), nswState, period2, period2ReportingData);
                s.Save(period2StateReport);

                var period1CentralReport =
                    new CentralReport(DataProvider.Get <string>(), central, period1, period1ReportingData);
                s.Save(period1CentralReport);
                var period2CentralReport =
                    new CentralReport(DataProvider.Get <string>(), central, period2, period2ReportingData);
                s.Save(period2CentralReport);

                var reportIds = new[]
                {
                    period1UnitReport.Id, period2UnitReport.Id, period1ZoneReport.Id, period2ZoneReport.Id,
                    period1StateReport.Id, period2StateReport.Id, period1CentralReport.Id, period2CentralReport.Id,
                };
                var expectedReportData = ReportDataCalculator.GetCalculatedReportData(new[] { period2UnitReport },
                                                                                      new[] { period1UnitReport, period2UnitReport }, new[] { period2ZoneReport },
                                                                                      new[] { period1ZoneReport, period2ZoneReport }, new[] { period2StateReport },
                                                                                      new[] { period1StateReport, period2StateReport }, new[] { period2CentralReport },
                                                                                      new[] { period1CentralReport, period2CentralReport });

                return(new
                {
                    username,
                    expectedReportData,
                    cmd = new ConsolidateReportCommand(reportIds),
                });
            });

            var context = await Endpoint.Act <ConsolidateReportCommandHandler>(AssemblySetupFixture.EndpointTestContainer,
                                                                               (h, ctx) =>
            {
                ctx.SetUsernameOnHeader(testParams.username);
                return(h.Handle(testParams.cmd, ctx));
            });

            var evt = context.ExpectPublish <IConsolidateReportSucceeded>();

            evt.ReportIds.Should().BeEquivalentTo(testParams.cmd.ReportIds);
            evt.ReportData.Should().BeEquivalentTo(testParams.expectedReportData);
            evt.Username.Should().BeEquivalentTo(testParams.username);
        }
        public void GetConsolidatedReportData_Returns_ExpectedReportData()
        {
            DateTimeDbTestExtensions.SetUtcNowToRandomDate();
            var testParams = Endpoint.ArrangeOnSqlSession(AssemblySetupFixture.EndpointTestContainer, s =>
            {
                var organizations = IntegrationTestOrganizationHelper.SetupOrzanizations();
                var central       = organizations.First(o => o.Key == IntegrationTestOrganizationHelper.Central).Value;
                var nswState      = organizations.First(o => o.Key == IntegrationTestOrganizationHelper.NswState).Value;
                var nswZone1      = organizations.First(o => o.Key == IntegrationTestOrganizationHelper.NswZoneOne).Value;
                var lakemba       = organizations.First(o => o.Key == IntegrationTestOrganizationHelper.Lakemba).Value;

                var year1 = 2019;
                var year2 = 2020;

                var period1 = new ReportingPeriod(ReportingFrequency.Monthly, ReportingTerm.One, year1);
                var period2 = new ReportingPeriod(ReportingFrequency.Monthly, ReportingTerm.One, year2);

                var period1ReportingData = new ReportDataBuilder().Build();
                var period2ReportingData = new ReportDataBuilder().Build();

                var period1UnitReport =
                    new UnitReport(DataProvider.Get <string>(), lakemba, period1, period1ReportingData);
                s.Save(period1UnitReport);
                var period2UnitReport =
                    new UnitReport(DataProvider.Get <string>(), lakemba, period2, period2ReportingData);
                s.Save(period2UnitReport);

                var period1ZoneReport =
                    new ZoneReport(DataProvider.Get <string>(), nswZone1, period1, period1ReportingData);
                s.Save(period1ZoneReport);
                var period2ZoneReport =
                    new ZoneReport(DataProvider.Get <string>(), nswZone1, period2, period2ReportingData);
                s.Save(period2ZoneReport);

                var period1StateReport =
                    new StateReport(DataProvider.Get <string>(), nswState, period1, period1ReportingData);
                s.Save(period1StateReport);
                var period2StateReport =
                    new StateReport(DataProvider.Get <string>(), nswState, period2, period2ReportingData);
                s.Save(period2StateReport);

                var period1CentralReport =
                    new CentralReport(DataProvider.Get <string>(), central, period1, period1ReportingData);
                s.Save(period1CentralReport);
                var period2CentralReport =
                    new CentralReport(DataProvider.Get <string>(), central, period2, period2ReportingData);
                s.Save(period2CentralReport);

                var reportIds = new[]
                {
                    period1UnitReport.Id, period2UnitReport.Id, period1ZoneReport.Id, period2ZoneReport.Id,
                    period1StateReport.Id, period2StateReport.Id, period1CentralReport.Id, period2CentralReport.Id,
                };
                var expectedReportData = ReportDataCalculator.GetCalculatedReportData(new[] { period2UnitReport },
                                                                                      new[] { period1UnitReport, period2UnitReport }, new[] { period2ZoneReport },
                                                                                      new[] { period1ZoneReport, period2ZoneReport }, new[] { period2StateReport },
                                                                                      new[] { period1StateReport, period2StateReport }, new[] { period2CentralReport },
                                                                                      new[] { period1CentralReport, period2CentralReport });
                return(new { reportIds, expectedReportData });
            });
            var result = Endpoint.Act(AssemblySetupFixture.EndpointTestContainer,
                                      c => c.GetInstance <ConsolidatedReportService>().GetConsolidatedReportData(testParams.reportIds));

            result.Should().NotBeNull();
            result.Should().BeEquivalentTo(testParams.expectedReportData);
        }