Пример #1
0
 /// <summary>
 ///     The assembly company
 /// </summary>
 /// <param name="context"></param>
 /// <param name="cancellationToken"></param>
 /// <returns></returns>
 public Task <string?> Company(IResolverContext context, CancellationToken cancellationToken)
 {
     return(context.CacheDataLoader <string, string?>(
                (_, _) =>
                Task.FromResult(
                    _rootAssembly.GetCustomAttribute <AssemblyCompanyAttribute>()?.Company
                    ),
                nameof(Company)
                ).LoadAsync(nameof(Company), cancellationToken));
 }
Пример #2
0
 /// <summary>
 ///     The assembly updated date
 /// </summary>
 /// <param name="context"></param>
 /// <param name="cancellationToken"></param>
 /// <returns></returns>
 public Task <Instant?> Updated(IResolverContext context, CancellationToken cancellationToken)
 {
     return(context.CacheDataLoader <string, Instant?>(
                (_, _) =>
     {
         var location = _rootAssembly.Location;
         return Task.FromResult <Instant?>(!string.IsNullOrWhiteSpace(location) ? File.GetLastWriteTimeUtc(location).ToInstant() : null);
     },
                nameof(Updated)
                ).LoadAsync(nameof(Updated), cancellationToken));
 }
Пример #3
0
 /// <summary>
 ///     The assembly version
 /// </summary>
 /// <param name="context"></param>
 /// <param name="cancellationToken"></param>
 /// <returns></returns>
 public Task <string?> Version(IResolverContext context, CancellationToken cancellationToken)
 {
     return(context.CacheDataLoader <string, string?>(
                (_, _) =>
                Task.FromResult <string?>(
                    _rootAssembly.GetCustomAttribute <AssemblyInformationalVersionAttribute>()?.InformationalVersion
                    ?? _rootAssembly.GetCustomAttribute <AssemblyFileVersionAttribute>()?.Version
                    ?? _rootAssembly.GetCustomAttribute <AssemblyVersionAttribute>()?.Version
                    ?? "0.0.0"
                    ),
                nameof(Version)
                ).LoadAsync(nameof(Version), cancellationToken));
 }
Пример #4
0
    /// <summary>
    ///     The assembly metadata
    /// </summary>
    /// <param name="context"></param>
    /// <param name="cancellationToken"></param>
    /// <returns></returns>
    public Task <IDictionary <string, string?> > Metadata(IResolverContext context, CancellationToken cancellationToken)
    {
        return(context
               .CacheDataLoader <string, IDictionary <string, string?> >(
                   (_, _) =>
                   Task.FromResult <IDictionary <string, string?> >(
#pragma warning disable CS8620
                       _rootAssembly.GetCustomAttributes <AssemblyMetadataAttribute>().ToDictionary(z => z.Key, z => z.Value)
#pragma warning restore CS8620
                       ),
                   nameof(Metadata)
                   ).LoadAsync(nameof(Metadata), cancellationToken));
    }
        public async Task <School> GetCurrentSchool(
            [Parent] Student student,
            [Service] IPowerSchoolSchoolService powerSchoolSchoolService,
            IResolverContext context)
        {
            var loader = context.CacheDataLoader <string, PowerSchoolSchool>(
                powerSchoolSchoolService.GetCurrentSchoolForStudent,
                cacheSize: 10000);

            var foundSchool = await loader.LoadAsync(student.StudentNumber,
                                                     new CancellationToken());

            return(foundSchool.ToGraphType());
        }
        public async Task <IEnumerable <SectionEnrollment> > GetSectionEnrollments(
            [Parent] Enrollment thisEnrollment,
            [Service] IPowerSchoolSectionService powerSchoolSectionService,
            [Service] IPowerSchoolSectionEnrollmentService powerSchoolSectionEnrollmentService,
            IResolverContext context)
        {
            var allEnrollments = new List <PowerSchoolSectionEnrollment>();

            var sectionLoader = context.CacheDataLoader <(string, string), IEnumerable <PowerSchoolSection> >(
                powerSchoolSectionService.GetAllBySchoolAndYear,
                cacheSize: 100000);

            var enrollmentLoader = context.CacheDataLoader <PowerSchoolSection, IEnumerable <PowerSchoolSectionEnrollment> >(
                powerSchoolSectionEnrollmentService.GetSectionEnrollments,
                cacheSize: 1000000);


            var currentSchoolYearDate = DateTime.Parse(thisEnrollment.EntryDate ?? throw new InvalidOperationException());

            var foundSections = await sectionLoader.LoadAsync(
                (thisEnrollment.SchoolId, currentSchoolYearDate.Year.ToString()),
                new CancellationToken());

            var powerSchoolSections = foundSections as PowerSchoolSection[] ?? foundSections.ToArray();

            var tasks = new List <Task <IEnumerable <PowerSchoolSectionEnrollment> > >();

            foreach (var powerSchoolSection in powerSchoolSections)
            {
                var task = enrollmentLoader.LoadAsync(powerSchoolSection, new CancellationToken(false));
                tasks.Add(task);

                if (tasks.Count() >= 30)
                {
                    var batch = await _resolveBatch(tasks);

                    allEnrollments.AddRange(batch);
                }
            }

            if (tasks.Any())
            {
                var batch = await _resolveBatch(tasks);

                allEnrollments.AddRange(batch);
            }

            //ToDo: Remove This after the service is implemented
#if !DEBUG
            var studentEnrollments = allEnrollments.Where(x => x.StudentId.ToString().Equals(thisEnrollment.StudentId));
#else
            var studentEnrollments = allEnrollments;
#endif

            return(studentEnrollments.ToGraphType());

            async Task <List <PowerSchoolSectionEnrollment> > _resolveBatch(List <Task <IEnumerable <PowerSchoolSectionEnrollment> > > tasks)
            {
                var result = new List <PowerSchoolSectionEnrollment>();
                var batch  = await Task.WhenAll(tasks);

                foreach (var enrollments in batch)
                {
                    foreach (var enrollment in enrollments)
                    {
                        result.Add(enrollment);
                    }
                }

                return(result);
            }
        }