Beispiel #1
0
        /// <summary>
        /// Returns a list of ofsted inspection details
        /// </summary>
        /// <returns>A set of inspection details giving website, ukrpn, date ofsted results published, and effectiveness rating</returns>
        public InspectionOutcomesResponse GetOfstedInspectionOutcomes()
        {
            _logger.Info("Start: gathering of Ofsted details");
            var getFirstMatchingLink = GetFirstMatchingLink();

            _logger.Debug($"First Link retrieved {getFirstMatchingLink}");
            var firstLinkUrl = BuildFullLinkFromRelativeFirstLink(getFirstMatchingLink);

            _logger.Debug($"First link built: '{firstLinkUrl}'");
            var result = _getInspectionsService.GetInspectionsDetail(firstLinkUrl);

            _logger.Info("End: All Ofsted details returned");
            return(result);
        }
        private InspectionsStatusCode ProcessLineIntoDetailsAsDetailOrError(ExcelWorksheet keyWorksheet,
                                                                            SpreadsheetDetails spreadsheetDetails,
                                                                            int lineNumber,
                                                                            ICollection <InspectionOutcome> inspections, ICollection <InspectionError> errorSet)
        {
            var error = new InspectionError {
                LineNumber = lineNumber
            };

            var ukprn = ProcessUkprnForError(Convert.ToString(keyWorksheet.Cells[lineNumber, spreadsheetDetails.UkPrnColumn].Value), error);
            var url   = _processExcelFormulaToLink.GetLinkFromFormula(
                keyWorksheet.Cells[lineNumber, spreadsheetDetails.WebLinkColumn].Formula,
                keyWorksheet.Cells[lineNumber, spreadsheetDetails.WebLinkColumn].Text);
            var overallEffectiveness = ProcessOverallEffectivenessForError(Convert.ToString(keyWorksheet.Cells[lineNumber, spreadsheetDetails.OverallEffectivenessColumn]?.Value), error);
            var datePublished        = ProcessDatePublishedForError(keyWorksheet.Cells[lineNumber, spreadsheetDetails.DatePublishedColumn], error);

            if (ukprn != null && overallEffectiveness != null && datePublished != null)
            {
                AddInspectionData((int)ukprn, url, datePublished, (OverallEffectiveness)overallEffectiveness,
                                  inspections);
                _logger.Debug($"Details processed successfully for line {lineNumber}: {ukprn}, {url}, {error.DatePublished}, {overallEffectiveness}");
                return(InspectionsStatusCode.Success);
            }

            error.Website = url ?? string.Empty;

            errorSet.Add(error);
            _logger.Warn($"Details processed unsuccessfully for line {error.LineNumber}: '{error.Ukprn}', '{error.Website}', '{error.DatePublished}', '{error.OverallEffectiveness}'");
            return(InspectionsStatusCode.ProcessedWithErrors);
        }
Beispiel #3
0
        public InspectionOutcomesResponse GetInspectionsDetail(string firstLinkUrl)
        {
            InspectionOutcomesResponse inspectionOutcomesResponse;

            try
            {
                _logger.Debug("Opening web client");

                var webClient = _webClientFactory.Create();

                using (var client = webClient)
                {
                    _logger.Debug("Opening memory stream");
                    using (var stream =
                               new MemoryStream(client.DownloadData(new Uri(firstLinkUrl))))
                    {
                        _logger.Debug("Opened memory stream");

                        using (var package = new ExcelPackage(stream))
                        {
                            _logger.Debug("Opened excel package");
                            inspectionOutcomesResponse = _getOfstedDetailsFromExcelPackageService.ExtractOfstedInspections(package);
                        }
                        _logger.Debug("Closed excel package");
                    }
                    _logger.Debug("Closed memory stream");
                }
                _logger.Debug($"Closed web client");
            }
            catch (UriFormatException ex)
            {
                var message   = $"Error whilst trying to read url: [{firstLinkUrl}]";
                var exception = new UrlReadingException(message, ex);
                _logger.Error(message, exception);
                throw exception;
            }
            catch (COMException ex)
            {
                var message   = $"Error whilst trying to read excel details from url: [{firstLinkUrl}], message: [{ex.Message}]";
                var exception = new UrlReadingException(message, ex);
                _logger.Error(message, exception);
                throw exception;
            }
            catch (Exception ex)
            {
                var message   = $"Error whilst trying to read excel details";
                var exception = new UrlReadingException(message, ex);
                _logger.Error(message, exception);
                throw exception;
            }

            return(inspectionOutcomesResponse);
        }