コード例 #1
0
        public void Load(ILoadingContext loadingContext)
        {
            var lookupIds  = loadingContext.ReferenceIds <TReference, TId>();
            var references = _loadReferences(lookupIds);

            loadingContext.AddResults(references, reference => _getReferenceId(reference));
        }
コード例 #2
0
        public Task LoadReferencesAsync(ILoadingContext loadingContext)
        {
            foreach (var referenceIds in loadingContext.ReferenceIds())
            {
                LoadReference(referenceIds.Key, referenceIds.Value, loadingContext);
            }

#if NETSTANDARD
            return(Task.CompletedTask);
#else
            return(Task.FromResult(0));
#endif
        }
コード例 #3
0
        private void LoadImages(ILoadingContext loadingContext)
        {
            var lookupIds  = loadingContext.ReferenceIds <Image, string>();
            var references = lookupIds
                             .Select(id =>
                                     new Image
            {
                Id      = id,
                Credits = id + "-credits",
                Url     = id + "-url"
            }
                                     )
                             .ToList();

            loadingContext.AddResults(
                references,
                reference => reference.Id
                );
        }
コード例 #4
0
        public void Load(ILoadingContext loadingContext)
        {
            var lookupIds  = loadingContext.ReferenceIds <ImageWithRatios, string>();
            var repository = new ImageWithRatioRepository();
            var images     = repository.GetByDeclinaisonUrl(lookupIds);

            var imagesByDeclinaisonUrl = images.SelectMany(
                image => image.Ratios.Select(declinaison => new
            {
                DeclinaisonUrl = declinaison.Url,
                Image          = image
            })
                )
                                         .ToDictionary(
                imageByDeclinaisonUrl => imageByDeclinaisonUrl.DeclinaisonUrl,
                imageByDeclinaisonUrl => imageByDeclinaisonUrl.Image);

            loadingContext.AddResults(imagesByDeclinaisonUrl);
        }
コード例 #5
0
        private void LoadBlogPosts(ILoadingContext loadingContext)
        {
            var lookupIds  = loadingContext.ReferenceIds <BlogPost, int>();
            var references = lookupIds
                             .Select(id =>
                                     new BlogPost
            {
                Id     = id,
                Author = new Author
                {
                    Name    = "author-name-" + id,
                    Email   = "author-email-" + id,
                    ImageId = "id-" + (id + 500)
                },
                MultimediaContentRef = new MultimediaContentReference
                {
                    Type = id % 2 == 0
                                ? "image"
                                : "media",
                    Id = id % 2 == 0
                                ? "id-" + id
                                : (object)id
                },
                TagIds = new List <int>
                {
                    88 + id,
                    89 + id
                },
                Title = "Title-" + id
            }
                                     )
                             .ToList();

            loadingContext.AddResults(
                references,
                reference => reference.Id
                );
        }