コード例 #1
0
        public async Task <Gallery> Get(string id, int itemIndexStart, int numberOfItems)
        {
            var request = new HttpRequestMessage(HttpMethod.Get, $"galleries/{id}?itemIndexStart={itemIndexStart}&numberOfItems={numberOfItems}");

            var response = await _client.SendAsync(request);

            if (response.IsSuccessStatusCode)
            {
                using var responseStream = await response.Content.ReadAsStreamAsync();

                var data = await JsonSerializer.DeserializeAsync <GalleryDTO>(responseStream);

                Gallery gallery = Gallery.Create(data.Id, data.ImageCount, galleryName: data.GalleryName);
                foreach (var item in data.GalleryPictures)
                {
                    gallery.AddGalleryItem(
                        galleryItemId: item.Id,
                        mediaType: item.MediaType,
                        appPath: item.AppPath,
                        indexGlobal: item.IndexGlobal
                        );
                }

                return(gallery);
            }
            else
            {
                throw new Exception($"The API returned a {response.StatusCode} status code.");
            }
        }
コード例 #2
0
        private Gallery AddItemsHelper(Gallery aggregate)
        {
            var galleryItems = new MockData().GetAll().Where(d => d.FolderId == aggregate.Id && d.FolderSortOrder >= aggregate.GalleryItemIndexStart);

            foreach (var item in galleryItems)
            {
                aggregate.AddGalleryItem(item.Id, item.GlobalSortOrder, item.Name, item.AppPath);
            }

            return(aggregate);
        }
コード例 #3
0
        public async Task <Gallery> FillEmptyGalleryWithItems(Gallery gallery)
        {
            if (gallery.GalleryItems.Count != 0)
            {
                throw new ArgumentException("The gallery must be empty, meaning it has no items.");
            }

            var searchResponse = await _client.SearchAsync <GalleryPictureDTO>(s => s
                                                                               .Query(q => q
                                                                                      .Match(m => m
                                                                                             .Field(f => f.FolderId)
                                                                                             .Query(gallery.Id)
                                                                                             ) && q
                                                                                      .Range(r => r
                                                                                             .Field(f => f.FolderSortOrder)
                                                                                             .GreaterThanOrEquals(gallery.GalleryItemIndexStart)
                                                                                             .LessThan(gallery.GalleryItemIndexStart + gallery.NumberOfItems)
                                                                                             )
                                                                                      )
                                                                               .Size(gallery.NumberOfItems)
                                                                               .Index(_indexName)
                                                                               );

            string galleryname = searchResponse.Documents?.FirstOrDefault()?.FolderName ?? "Unknown";

            gallery.SetGalleryName(galleryname);

            foreach (var dto in searchResponse.Documents)
            {
                gallery.AddGalleryItem(
                    galleryItemId: dto.Id,
                    indexGlobal: dto.GlobalSortOrder,
                    name: dto.Name,
                    appPath: dto.AppPath
                    );
            }

            return(gallery);
        }