public Task <ReportViewModel> Handle(GenerateReportCommand request, CancellationToken cancellationToken)
        {
            return(Task.Run(() =>
            {
                using (OutageAccessProxy outageProxy = _proxyFactory.CreateProxy <OutageAccessProxy, IOutageAccessContract>(EndpointNames.OutageAccessEndpoint))
                {
                    try
                    {
                        _logger.LogInfo("[ReportCommandHandler::GenerateReport] Sending a Generate command to Outage service.");

                        var options = new ReportOptions
                        {
                            Type = (ReportType)request.Options.Type,
                            ElementId = request.Options.ElementId,
                            StartDate = request.Options.StartDate,
                            EndDate = request.Options.EndDate
                        };

                        var report = outageProxy.GenerateReport(options);

                        return new ReportViewModel
                        {
                            Data = report.Data,
                            Type = report.Type
                        };
                    }
                    catch (Exception ex)
                    {
                        _logger.LogError("[ReportCommandHandler::GenerateReport] Failed to generate active outages from Outage service.", ex);
                        throw ex;
                    }
                }
            }, cancellationToken));
        }
Exemple #2
0
        public Task <IEnumerable <ArchivedOutageViewModel> > Handle(GetArchivedOutagesQuery request, CancellationToken cancellationToken)
        {
            return(Task.Run(() =>
            {
                using (OutageAccessProxy outageProxy = _proxyFactory.CreateProxy <OutageAccessProxy, IOutageAccessContract>(EndpointNames.OutageAccessEndpoint))
                {
                    try
                    {
                        _logger.LogInfo("[OutageQueryHandler::GetArchivedOutages] Sending a GET query to Outage service for archived outages.");
                        IEnumerable <ArchivedOutageMessage> archivedOutages = outageProxy.GetArchivedOutages();

                        IEnumerable <ArchivedOutageViewModel> archivedOutageViewModels = _mapper.MapArchivedOutages(archivedOutages);
                        return archivedOutageViewModels;
                    }
                    catch (Exception ex)
                    {
                        _logger.LogError("[OutageQueryHandler::GetArchivedOutages] Failed to GET archived outages from Outage service.", ex);
                        throw ex;
                    }
                }
            }));
        }