Beispiel #1
0
        public async Task <Gallery> GetRandom(int itemsInGallery)
        {
            Gallery gallery;
            var     searchResponse = await _client.SearchAsync <GalleryPictureDTO>(s => s
                                                                                   .Query(q => q
                                                                                          .FunctionScore(f => f
                                                                                                         .Functions(fx => fx
                                                                                                                    .RandomScore(rng => rng.Seed(DateTime.Now.Millisecond))
                                                                                                                    )
                                                                                                         )
                                                                                          )
                                                                                   .Size(itemsInGallery)
                                                                                   .Index(_indexName)
                                                                                   );

            gallery = Gallery.Create($"random-{Guid.NewGuid()}".Substring(0, 15).ToLower(), itemsInGallery);
            foreach (var pic in searchResponse.Documents)
            {
                gallery.AddGalleryItem(
                    galleryItemId: pic.Id,
                    indexGlobal: pic.GlobalSortOrder,
                    name: pic.Name,
                    appPath: pic.AppPath
                    );
            }

            return(gallery);
        }
Beispiel #2
0
        public async Task <IEnumerable <Gallery> > GetAll()
        {
            var request = new HttpRequestMessage(HttpMethod.Get, "galleries");

            var response = await _client.SendAsync(request);

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

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

                List <Gallery> list = new List <Gallery>();
                foreach (var i in data)
                {
                    list.Add(Gallery.Create(i.Id, i.ImageCount, galleryName: i.GalleryName));
                }

                return(list);
            }
            else
            {
                throw new Exception($"The API returned a {response.StatusCode} status code.");
            }
        }
Beispiel #3
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.");
            }
        }
        public async Task <GalleryResponse> Get(string id, int itemIndexStart, int numberOfItems)
        {
            // TODO: Use GalleryDescriptor for this?
            Gallery aggregate = Gallery.Create(id, numberOfItems, itemIndexStart);

            aggregate = await _galleryRepository.FillEmptyGalleryWithItems(aggregate);

            return(_mapper.Map <GalleryResponse>(aggregate));
        }
Beispiel #5
0
        public async Task <List <Gallery> > GetAll()
        {
            var list = new List <Gallery>()
            {
                Gallery.Create("gallery1", 7),
                Gallery.Create("subGal1", 5),
                Gallery.Create("subGal2", 4),
                Gallery.Create("subGal3", 5),
            };

            return(list);
        }
Beispiel #6
0
        public async Task <List <Gallery> > GetAll()
        {
            try
            {
                var aggregationResponse = await _client.SearchAsync <GalleryDTO>(s => s
                                                                                 .Aggregations(a => a
                                                                                               .Terms("my_agg", st => st
                                                                                                      .Field(f => f.FolderId.Suffix("keyword")) // "keyword" is an ElasticSearch data-type: https://www.elastic.co/guide/en/elasticsearch/client/net-api/current/multi-fields.html
                                                                                                      .Size(800)
                                                                                                      )
                                                                                               )
                                                                                 .Index(_indexName)
                                                                                 );

                var list = new List <Gallery>();
                foreach (var bucket in aggregationResponse.Aggregations.Terms("my_agg").Buckets)
                {
                    var singleGallerySearchResponse = await _client.SearchAsync <GalleryDTO>(s => s
                                                                                             .Query(q => q
                                                                                                    .Match(m => m
                                                                                                           .Field(f => f.FolderId.Suffix("keyword"))
                                                                                                           .Query(bucket.Key)
                                                                                                           )
                                                                                                    )
                                                                                             .Size(1)
                                                                                             .Index(_indexName)
                                                                                             );

                    var gallery = singleGallerySearchResponse.Documents.FirstOrDefault();

                    list.Add(
                        Gallery.Create(
                            bucket.Key,
                            Convert.ToInt32(bucket.DocCount),
                            galleryName: gallery.FolderName)
                        );
                }

                return(list);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #7
0
        public async Task <Gallery> GetRandom(int itemsInGallery)
        {
            if (itemsInGallery > 21)
            {
                itemsInGallery = 21;
            }

            var aggregate = Gallery.Create($"random-{Guid.NewGuid()}".Substring(0, 15).ToLower(), 1);

            var allData = new MockData().GetAll().ToList();

            allData.ShuffleList();

            var galleryItems = allData.Take(itemsInGallery);

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

            return(aggregate);
        }
Beispiel #8
0
        public async Task <Gallery> GenerateGallery()
        {
            if (_galleryDescriptor.TagFilter == null)
            {
                throw new ArgumentException("Descriptor object is not valid - TagFilter is null");
            }

            var gallery = Gallery.Create(Guid.NewGuid().ToString(), _galleryDescriptor.NumberOfItems);

            int counter = 0;

            while (gallery.GalleryItems.Count < _galleryDescriptor.NumberOfItems && counter < MAX_ITERATIONS)
            {
                var items = await GenerateGalleryItems();

                foreach (var item in items)
                {
                    if (gallery.GalleryItems.Count == _galleryDescriptor.NumberOfItems)
                    {
                        break;
                    }

                    gallery.AddGalleryItem(
                        galleryItemId: item.Id,
                        indexGlobal: item.Index,
                        name: item.Name,
                        appPath: item.AppPath,
                        tags: item.Tags
                        );
                }

                counter++;
            }

            return(gallery);
        }
Beispiel #9
0
 private Gallery BuildInteface()
 {
     return(Gallery.Create(this.Id, this.Uid, this.Title, this.UserId, this.CreatedDate, this.CategoryId));
 }