예제 #1
0
        static async Task <Establishment[]> GetEstablishments(CancellationToken cancellationToken)
        {
            _logger.Info("Downloading establishments...");
            var establishments = await _giasApiClient.DownloadEstablishmentsAsync(cancellationToken);

            _logger.Info($"Downloaded {establishments.Length} establishments");
            return(establishments);
        }
예제 #2
0
        private async Task <PointInTimeEstablishment[]> DownloadEstablishmentsToCacheAsync(DateTime pointInTime, GroupLink[] groupLinks,
                                                                                           CancellationToken cancellationToken)
        {
            _logger.Info("Acquiring establishments file from GIAS...");

            // Download
            var establishments = await _giasApiClient.DownloadEstablishmentsAsync(cancellationToken);

            _logger.Debug($"Downloaded {establishments.Length} establishments from GIAS");

            // Timestamp
            var pointInTimeEstablishments = establishments.Select(establishment => establishment.Clone <PointInTimeEstablishment>()).ToArray();

            foreach (var pointInTimeEstablishment in pointInTimeEstablishments)
            {
                pointInTimeEstablishment.PointInTime = pointInTime;
            }

            // Add links
            foreach (var establishment in pointInTimeEstablishments)
            {
                var establishmentGroupLinks = groupLinks.Where(l => l.Urn == establishment.Urn).ToArray();
                var federationLink          = establishmentGroupLinks.FirstOrDefault(l => l.GroupType == "Federation");
                var trustLink = establishmentGroupLinks.FirstOrDefault(l =>
                                                                       l.GroupType == "Trust" || l.GroupType == "Single-academy trust" || l.GroupType == "Multi-academy trust");

                if (federationLink != null)
                {
                    establishment.Federations = new CodeNamePair
                    {
                        Code = federationLink.Uid.ToString(),
                    };
                    _logger.Debug($"Set Federations to {federationLink.Uid} from links of establishment {establishment.Urn}");
                }

                if (trustLink != null)
                {
                    establishment.Trusts = new CodeNamePair
                    {
                        Code = trustLink.Uid.ToString(),
                    };
                    _logger.Debug($"Set Trusts to {trustLink.Uid} from links of establishment {establishment.Urn}");
                }
            }

            // Store
            await _establishmentRepository.StoreInStagingAsync(pointInTimeEstablishments, cancellationToken);

            _logger.Debug($"Stored {pointInTimeEstablishments.Length} establishments in staging");

            _logger.Info("Finished downloading Establishments to cache");
            return(pointInTimeEstablishments);
        }
예제 #3
0
        static async Task <ManagementGroup[]> GetLocalAuthorities(CancellationToken cancellationToken)
        {
            _logger.Info("Downloading establishments...");
            var establishments = await _giasApiClient.DownloadEstablishmentsAsync(cancellationToken);

            var localAuthorities = establishments
                                   .Select(e => e.LA)
                                   .GroupBy(la => la.Code)
                                   .Select(la => la.First())
                                   .Select(cnp =>
                                           new LocalAuthority
            {
                Code = int.Parse(cnp.Code),
                Name = cnp.DisplayName,
            })
                                   .ToArray();

            _logger.Debug($"Converted {establishments.Length} to {localAuthorities.Length} distinct local authorities");

            return(await MapAsync(localAuthorities, cancellationToken));
        }