Example #1
0
        public async Task <ObservableCollection <CatalogItem> > FilterAsync(int catalogBrandId, int catalogTypeId)
        {
            UriBuilder builder = new UriBuilder(GlobalSetting.Instance.CatalogEndpoint);

            builder.Path = $"api/v1/catalog/items/type/{catalogTypeId}/brand/{catalogBrandId}";
            string uri = builder.ToString();

            CatalogRoot catalog = await _requestProvider.GetAsync <CatalogRoot>(uri);

            return(catalog?.Data?.ToObservableCollection() ?? new ObservableCollection <CatalogItem>());
        }
Example #2
0
        /// <summary>
        /// Validates <see cref="Catalog.Parent.Path" /> or <see cref="CatalogEntry.Catalog.Path"/> value not to be empty.
        /// </summary>
        /// <param name="parent">The parent catalog which path should be validated.</param>
        /// <exception cref="ArgumentException">The parent catalog path is empty.</exception>
        /// <exception cref="DirectoryNotFoundException">The parent catalog does not exist by specified path.</exception>
        private static void ValidateParentPath(CatalogRoot parent)
        {
            if (string.IsNullOrWhiteSpace(parent?.Path))
            {
                throw new ArgumentException("The parent catalog path is empty.");
            }

            if (!Directory.Exists(parent.Path))
            {
                throw new DirectoryNotFoundException("The parent catalog does not exist by specified path.");
            }
        }
Example #3
0
        public async Task <ObservableCollection <CatalogItem> > GetCatalogAsync()
        {
            CatalogRoot catalog = await catalogApi.GetCatalogAsync();

            if (catalog?.Data != null)
            {
                return(new ObservableCollection <CatalogItem>(catalog.Data));
            }
            else
            {
                return(new ObservableCollection <CatalogItem>());
            }
        }
Example #4
0
        public async Task <ObservableCollection <CatalogItem> > FilterAsync(int catalogBrandId, int catalogTypeId)
        {
            CatalogRoot catalog = await catalogApi.GetAsyncBy(catalogTypeId, catalogBrandId);

            if (catalog?.Data != null)
            {
                return(new ObservableCollection <CatalogItem>(catalog.Data));
            }
            else
            {
                return(new ObservableCollection <CatalogItem>());
            }
        }
        protected void ImportEntries(CatalogRoot root, CatalogContent catalogContent)
        {
            EntryImporter entryImporter = ServiceLocator.Current.GetInstance <EntryImporter>();

            var defaultContentType = _typeRepository.Load(root.defaults.defaultEntryType);

            entryImporter.DefaultContentType = defaultContentType;
            _log.Debug("Default content type: {0}", defaultContentType != null ? defaultContentType.FullName : "None");

            entryImporter.RootCatalog = catalogContent;
            entryImporter.Defaults    = root.defaults;

            entryImporter.Import(root.entries);
        }
Example #6
0
        public async Task <ObservableCollection <CatalogItem> > FilterAsync(int catalogBrandId, int catalogTypeId)
        {
            var uri = UriHelper.CombineUri(GlobalSetting.Instance.GatewayShoppingEndpoint, $"{ApiUrlBase}/items/type/{catalogTypeId}/brand/{catalogBrandId}");

            CatalogRoot catalog = await _requestProvider.GetAsync <CatalogRoot>(uri);

            if (catalog?.Data != null)
            {
                return(catalog?.Data.ToObservableCollection());
            }
            else
            {
                return(new ObservableCollection <CatalogItem>());
            }
        }
Example #7
0
        public async Task <ObservableCollection <CatalogItem> > FilterAsync(string productfilter)
        {
            var uri = UriHelper.CombineUri(GlobalSetting.Instance.GatewayCatalogEndpoint, $"{ApiUrlBase}/items/productfilter/{productfilter}");

            CatalogRoot catalog = await _requestProvider.GetAsync <CatalogRoot>(uri);

            if (catalog?.Data != null)
            {
                return(catalog?.Data.OrderBy(x => x.Price).ToObservableCollection());
            }
            else
            {
                return(new ObservableCollection <CatalogItem>());
            }
        }
Example #8
0
        public async Task <ObservableCollection <CatalogItem> > GetCatalogAsync()
        {
            var uri = UriHelper.CombineUri(GlobalSetting.Instance.GatewayShoppingEndpoint, $"{ApiUrlBase}/items");

            CatalogRoot catalog = await _requestProvider.GetAsync <CatalogRoot>(uri);

            if (catalog?.Data != null)
            {
                _fixUriService.FixCatalogItemPictureUri(catalog?.Data);
                return(catalog?.Data.ToObservableCollection());
            }
            else
            {
                return(new ObservableCollection <CatalogItem>());
            }
        }
Example #9
0
        ///<summary> Обновление панели с тегами при изменении их в элементе каталога. </summary>
        private void TagSrcChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            TagPanel.Children.Clear();

            var tagArray = (DataContext as AbstractEntry).GetTagList();

            Array.Sort(tagArray);

            foreach (var tag in tagArray)
            {
                var newTag = new TagPlate();
                newTag.TagLabel.Text     = tag;
                newTag.TagLabel.Fill     = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                newTag.TagBrd.Background = CatalogRoot.GetTagColor(tag);
                TagPanel.Children.Add(newTag);
            }
        }
        public async Task <ObservableCollection <CatalogItem> > FilterAsync(int catalogBrandId, int catalogTypeId)
        {
            UriBuilder builder = new UriBuilder(GlobalSetting.Instance.BaseEndpoint);

            builder.Path = $"{ApiUrlBase}/items/type/{catalogTypeId}/brand/{catalogBrandId}";
            string uri = builder.ToString();

            CatalogRoot catalog = await _requestProvider.GetAsync <CatalogRoot>(uri);

            if (catalog?.Data != null)
            {
                return(catalog?.Data.ToObservableCollection());
            }
            else
            {
                return(new ObservableCollection <CatalogItem>());
            }
        }
Example #11
0
        public async Task <ObservableCollection <CatalogItem> > GetCatalogAsync()
        {
            UriBuilder builder = new UriBuilder(GlobalSetting.Instance.CatalogEndpoint);

            builder.Path = "api/v1/catalog/items";
            string uri = builder.ToString();

            CatalogRoot catalog = await _requestProvider.GetAsync <CatalogRoot>(uri);

            if (catalog?.Data != null)
            {
                ServicesHelper.FixCatalogItemPictureUrl(catalog.Data);
                return(catalog.Data.ToObservableCollection <CatalogItem>());
            }
            else
            {
                return(new ObservableCollection <CatalogItem>());
            }
        }
        public async Task <ObservableCollection <CatalogItem> > FilterAsync(int catalogBrandId, int catalogTypeId, byte[] image)
        {
            UriBuilder builder = new UriBuilder(GlobalSetting.Instance.GatewayShoppingEndpoint);

            builder.Path = $"{ApiAIUrlBase}/items";

            const int page = 0;
            const int take = 12;

            var tags = Enumerable.Empty <string>();

            if (image != null)
            {
                tags = await imageClassifier.ClassifyImage(image);

                if (tags == null || !tags.Any())
                {
                    return(new ObservableCollection <CatalogItem>());
                }
            }


            var brandQs = catalogBrandId == 0 ? String.Empty : $"&catalogBrandId={catalogBrandId}";
            var typeQs  = catalogTypeId == 0 ? String.Empty : $"&catalogTypeId={catalogTypeId}";
            var tagsQs  = (tags != null && tags.Any()) ? $"&tags={String.Join(",", tags)}" : String.Empty;

            builder.Query = $"?pageIndex={page}&pageSize={take}{brandQs}{typeQs}{tagsQs}";

            string uri = builder.ToString();

            CatalogRoot catalog = await _requestProvider.GetAsync <CatalogRoot>(uri);

            if (catalog?.Data != null)
            {
                return(catalog?.Data.ToObservableCollection());
            }
            else
            {
                return(new ObservableCollection <CatalogItem>());
            }
        }
        /// <summary>
        /// Gets the list of catalog entries located in specified catalog.
        /// </summary>
        /// <param name="catalog">The catalog of <see cref="CatalogRoot"/> type.</param>
        /// <param name="offset">The offset index.</param>
        /// <param name="limit">The number of records to return.</param>
        /// <returns>
        /// The list of instances of <see cref="CatalogEntry" /> type.
        /// </returns>
        public async Task <IPaginable <CatalogEntry> > GetCatalogEntries(CatalogRoot catalog, int offset = 0, int limit = 20)
        {
            if (limit == 0)
            {
                return(await Task.FromResult(new PagedList <CatalogEntry>()
                {
                    Offset = offset,
                    Limit = limit
                }));
            }

            IEnumerable <FileContract> data = null;
            int count = 0;

            FileContract contract = new FileContract()
            {
                DirectoryID = catalog.ID
            };

            using (IDbContextScope scope = this.dataContextScopeFactory.CreateDbContextScope(this.connectionStrings.DataStorageDB, false))
            {
                IFileRepository fileRepository = scope.GetRepository <IFileRepository>();

                await Task.WhenAll(
                    Task.Run(async() => data  = await fileRepository.FindAsync(contract, offset, limit)),
                    Task.Run(async() => count = await fileRepository.GetCountAsync(contract)));
            }

            IPaginable <CatalogEntry> result = (await this.mapper.MapNewAsync <FileContract, CatalogEntry>(data)).Select(entry =>
            {
                entry.Catalog = (Catalog)catalog;

                return(entry);
            }).AsPaginable();

            result.Offset     = offset;
            result.Limit      = limit;
            result.TotalCount = count;

            return(result);
        }
        /// <summary>
        /// Gets the list of catalogs located in specified parent catalog.
        /// </summary>
        /// <param name="parent">The parent catalog of <see cref="CatalogRoot"/> type.</param>
        /// <param name="offset">The offset index.</param>
        /// <param name="limit">The number of records to return.</param>
        /// <returns>
        /// The list of instances of <see cref="Catalog" /> type.
        /// </returns>
        public async Task <IPaginable <Catalog> > GetCatalogs(CatalogRoot parent, int offset = 0, int limit = 20)
        {
            if (limit == 0)
            {
                return(await Task.FromResult(new PagedList <Catalog>()
                {
                    Offset = offset,
                    Limit = limit
                }));
            }

            IEnumerable <CatalogContract> data = null;
            int count = 0;

            CatalogContract contract = new CatalogContract()
            {
                ParentID = parent?.ID
            };

            using (IDbContextScope scope = this.dataContextScopeFactory.CreateDbContextScope(this.connectionStrings.DataStorageDB, false))
            {
                ICatalogRepository catalogRepository = scope.GetRepository <ICatalogRepository>();

                await Task.WhenAll(
                    Task.Run(async() => data  = await catalogRepository.FindAsync(contract, offset, limit)),
                    Task.Run(async() => count = await catalogRepository.GetCountAsync(contract)));
            }

            IPaginable <Catalog> result = (await this.mapper.MapNewAsync <CatalogContract, Catalog>(data)).Select(catalog =>
            {
                catalog.Parent = (Catalog)parent;

                return(catalog);
            }).AsPaginable();

            result.Offset     = offset;
            result.Limit      = limit;
            result.TotalCount = count;

            return(result);
        }
        public void ImportCatalogFromJsonFile(string appDataRelativePath)
        {
            _log.Debug("Starting import");
            string      path = HttpContext.Current.Server.MapPath("~/App_Data/" + appDataRelativePath);
            CatalogRoot root = ReadDataFromFile(path);

            // Verify content
            var catalogContent = GetCatalogFromName(root.catalog);

            if (catalogContent == null)
            {
                throw new ArgumentNullException("Cannot find catalog with name: " + root.catalog);
            }

            _log.Debug("Importing to catalog {0}", catalogContent.Name);

            // Import Nodes
            ImportNodes(root, catalogContent);

            // Import Entries
            ImportEntries(root, catalogContent);
        }
Example #16
0
 /// <summary>
 /// Gets the list of catalog entries located in specified catalog.
 /// </summary>
 /// <param name="catalog">The catalog of <see cref="CatalogRoot"/> type.</param>
 /// <param name="offset">The offset index.</param>
 /// <param name="limit">The number of records to return.</param>
 /// <returns>
 /// The list of instances of <see cref="CatalogEntry" /> type.
 /// </returns>
 public async Task <IPaginable <CatalogEntry> > GetCatalogEntries(CatalogRoot catalog, int offset = 0, int limit = 20)
 {
     return(await Task.FromException <IPaginable <CatalogEntry> >(new NotSupportedException()));
 }