Example #1
0
        /// <summary>
        /// Creates the specified catalog entry.
        /// </summary>
        /// <param name="stream">The stream of <see cref="CatalogEntryStream" /> type to create the entry from.</param>
        /// <returns>The newly created instance of <see cref="CatalogEntry" /> type.</returns>
        public async Task <CatalogEntry> CreateCatalogEntry(CatalogEntryStream stream)
        {
            CatalogEntry entry = stream.Entry;

            FileDocument fileDocument = await this.mapper.MapNewAsync <CatalogEntry, FileDocument>(entry);

            CatalogDocument catalogDocument = null;

            using (IDocumentContextScope scope = this.dataContextScopeFactory.CreateDocumentContextScope(this.connectionStrings.DataAggregationDB))
            {
                IFileDocumentRepository fileRepository = scope.GetRepository <IFileDocumentRepository>();
                fileDocument = await fileRepository.SaveAsync(fileDocument);

                if ((entry.Catalog?.ID).HasValue)
                {
                    ICatalogDocumentRepository catalogRepository = scope.GetRepository <ICatalogDocumentRepository>();
                    catalogDocument = await catalogRepository.GetAsync(entry.Catalog.ID);
                }
            }

            entry = await this.mapper.MapAsync(fileDocument, entry);

            entry.Catalog = await this.mapper.MapAsync(catalogDocument, entry.Catalog);

            return(entry);
        }
Example #2
0
        /// <summary>
        /// Updates the specified catalog.
        /// </summary>
        /// <param name="catalog">The instance of <see cref="Catalog" /> type to update.</param>
        /// <returns>The updated instance of <see cref="Catalog"/> type.</returns>
        public async Task <Catalog> UpdateCatalog(Catalog catalog)
        {
            CatalogDocument catalogDocument       = null;
            CatalogDocument parentCatalogDocument = null;

            using (IDocumentContextScope scope = this.dataContextScopeFactory.CreateDocumentContextScope(this.connectionStrings.DataAggregationDB))
            {
                ICatalogDocumentRepository repository = scope.GetRepository <ICatalogDocumentRepository>();

                catalogDocument = await repository.GetAsync(catalog.ID);

                catalogDocument = await this.mapper.MapAsync(catalog, catalogDocument);

                if (catalogDocument.IsChanged)
                {
                    catalogDocument = await repository.SaveAsync(catalogDocument);
                }

                if ((catalog.Parent?.ID).HasValue)
                {
                    parentCatalogDocument = await repository.GetAsync(catalog.Parent.ID);
                }
            }

            catalog = await this.mapper.MapAsync(catalogDocument, catalog);

            catalog.Parent = await this.mapper.MapAsync(parentCatalogDocument, catalog.Parent);

            return(catalog);
        }
Example #3
0
        /// <summary>
        /// Converts the instance of <see cref="CatalogRoot" /> type to the instance of <see cref="CatalogDocument" />.
        /// </summary>
        /// <param name="source">The instance of <see cref="CatalogRoot" />.</param>
        /// <param name="target">The instance of <see cref="CatalogDocument" />.</param>
        /// <returns>
        /// The converted instance of <see cref="CatalogDocument" />.
        /// </returns>
        public CatalogDocument Convert(CatalogRoot source, CatalogDocument target)
        {
            target.ID   = source.ID;
            target.Path = string.IsNullOrWhiteSpace(source.Path) ? target.Path : source.Path;
            target.Size = source.Size.HasValue ? source.Size.Value : target.Size;

            return(target);
        }
Example #4
0
        /// <summary>
        /// Gets a value indicating whether the specified storage already exists.
        /// </summary>
        /// <param name="storage">The storage.</param>
        /// <returns><c>true</c> if the storage exists. Otherwise <c>false.</c></returns>
        public async Task <bool> StorageExists(Storage storage)
        {
            using (IDocumentContextScope scope = this.dataContextScopeFactory.CreateDocumentContextScope(this.connectionStrings.DataAggregationDB))
            {
                ICatalogDocumentRepository repository      = scope.GetRepository <ICatalogDocumentRepository>();
                CatalogDocument            catalogDocument = await repository.GetAsync(storage.ID);

                return(catalogDocument != null);
            }
        }
Example #5
0
        /// <summary>
        /// Converts the instance of <see cref="CatalogDocument" /> type to the instance of <see cref="CatalogRoot" />.
        /// </summary>
        /// <param name="source">The instance of <see cref="CatalogDocument" />.</param>
        /// <param name="target">The instance of <see cref="CatalogRoot" />.</param>
        /// <returns>
        /// The converted instance of <see cref="CatalogRoot" />.
        /// </returns>
        public CatalogRoot Convert(CatalogDocument source, CatalogRoot target)
        {
            if (target.ID == Guid.Empty)
            {
                target.ID = source.ID;
            }

            target.Path = source.Path;
            target.Size = source.Size;

            return(target);
        }
Example #6
0
        /// <summary>
        /// Gets storage by initial instance set.
        /// </summary>
        /// <param name="storage">The initial storage set.</param>
        /// <returns>The instance of <see cref="Storage"/> type.</returns>
        public async Task <Storage> GetStorage(Storage storage)
        {
            CatalogDocument catalogDocument = null;

            using (IDocumentContextScope scope = this.dataContextScopeFactory.CreateDocumentContextScope(this.connectionStrings.DataAggregationDB))
            {
                ICatalogDocumentRepository repository = scope.GetRepository <ICatalogDocumentRepository>();
                catalogDocument = await repository.GetAsync(storage.ID);
            }

            return(await this.mapper.MapAsync(catalogDocument, storage));
        }