public IEnumerable <CounterRecord> RequestRecords(DateTime runDate, CounterReport report)
        {
            if (_arguments.JsonRepository != null)
            {
                using (IDirectoryRepository localJsonRepo = RepositoryFactory.CreateDirectoryRepository(_arguments.JsonRepository))
                {
                    List <DirectoryObjectMetadata> jsonFiles = localJsonRepo.ListFiles().ToList();

                    if (jsonFiles.Any(x => x.Name == $"{Name} {runDate:yyyy-MM-dd} {report}.json"))
                    {
                        DirectoryObjectMetadata directoryObjectMetadata = jsonFiles.First(x => x.Name == $"{Name} {runDate:yyyy-MM-dd} {report}.json");
                        using (Stream openFile = localJsonRepo.OpenFile(directoryObjectMetadata.Name))
                        {
                            string jsonString = new StreamReader(openFile).ReadToEnd();
                            foreach (var record in JsonConvert.DeserializeObject <IEnumerable <CounterRecord> >(jsonString))
                            {
                                yield return(record);
                            }
                        }

                        yield break;
                    }
                }
            }

            LogMessage($"Requesting {report.ToString()}");
            var reportItems = GetResponse(runDate, report.ToString());

            if (reportItems == null)
            {
                yield break;
            }

            foreach (IReportItem reportItem in reportItems)
            {
                if (reportItem.ItemDataType == Sushi.DataType.Platform && string.IsNullOrWhiteSpace(reportItem.ItemName))
                {
                    reportItem.ItemName = reportItem.ItemPublisher;
                }

                yield return(new CounterRecord
                {
                    ItemName = reportItem.ItemName,
                    ItemPlatform = reportItem.ItemPlatform,
                    ItemType = Convert(reportItem.ItemDataType),
                    RunDate = runDate,
                    Identifiers = reportItem.ItemIdentifier.Bind(a => a.Select(i => Convert(i, reportItem.ItemPlatform, reportItem.ItemDataType)).Where(i => i != null).ToArray(), new CounterIdentifier[] { }),
                    Metrics = reportItem.ItemPerformance.SelectMany(m => m.Instance).Select(i => new CounterMetric {
                        MetricType = Convert(i.MetricType), MetricValue = Int32.Parse(i.Count)
                    }).ToArray()
                });
            }
        }
Пример #2
0
        public override bool Validate(SushiReport report)
        {
            base.Validate(report);

            if (report.CounterReports.Count < 1)
            {
                // no reports to validate, fail validation and quit
                _errorMessages.Add("No Counter Data found.");
                return(false);
            }

            // for now just expect one counter report
            CounterReport counterReport = report.CounterReports[0];

            foreach (var customerReport in counterReport.CustomerReports)
            {
                foreach (var reportItem in customerReport.ReportItems)
                {
                    foreach (CounterPerformanceItem perfItem in reportItem.PerformanceItems)
                    {
                        foreach (var key in perfItem.Metrics.Keys)
                        {
                            CounterMetric metric = perfItem.Metrics[key];

                            if (!ValidationRule.CheckStartDay(metric.Start))
                            {
                                _isValid = false;
                                _errorMessages.Add(
                                    string.Format(
                                        "Report Item \"{0}\" has a metric start date that is not the first day of the month. The start date given was {1}.",
                                        reportItem.ItemName, metric.Start.ToString("yyyy-M-d")));
                            }

                            if (!ValidationRule.CheckEndDay(metric.End))
                            {
                                _isValid = false;
                                _errorMessages.Add(
                                    string.Format(
                                        "Report Item \"{0}\" has a metric end date that is not the last day of the month. The end date given was {1}.",
                                        reportItem.ItemName, metric.End.ToString("yyyy-M-d")));
                            }

                            switch (report.ReportType)
                            {
                            case CounterReportType.JR1:
                            case CounterReportType.JR2:
                            case CounterReportType.JR3:
                            case CounterReportType.JR4:
                            case CounterReportType.DB1:
                            case CounterReportType.DB2:
                            case CounterReportType.DB3:
                                if (!ValidationRule.CheckDuration(metric.Start, metric.End, 0))
                                {
                                    _isValid = false;
                                    _errorMessages.Add(
                                        string.Format(
                                            "Report Item \"{0}\" has a metric duration of more than 1 month. The given dates were from {1} to {2}.",
                                            reportItem.ItemName, metric.Start.ToString("yyyy-M-d"), metric.End.ToString("yyyy-M-d")));
                                }
                                break;
                            }
                        }
                    }
                }
            }

            return(_isValid);
        }
Пример #3
0
 /// <inheritdoc />
 public IEnumerable <CounterRecord> RequestRecords(DateTime runDate, CounterReport report)
 {
     (string fileName, EmailRecord emailRecord)[] downloadMessages = DownloadMessages().ToArray();