예제 #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);
        }
예제 #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);
        }
예제 #3
0
        /// <summary>
        /// Gets a value indicating whether the specified catalog entry already exists.
        /// </summary>
        /// <param name="entry">The catalog entry.</param>
        /// <returns><c>true</c> if the catalog entry exists. Otherwise <c>false.</c></returns>
        public async Task <bool> CatalogEntryExists(CatalogEntry entry)
        {
            using (IDocumentContextScope scope = this.dataContextScopeFactory.CreateDocumentContextScope(this.connectionStrings.DataAggregationDB))
            {
                IFileDocumentRepository repository = scope.GetRepository <IFileDocumentRepository>();

                return((await repository.GetAsync(entry.ID)) != null);
            }
        }
예제 #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);
            }
        }
예제 #5
0
        /// <summary>
        /// Deletes the specified catalog entry.
        /// </summary>
        /// <param name="entry">The instance of <see cref="CatalogEntry" /> type to delete.</param>
        /// <returns>
        /// The deleted instance of <see cref="CatalogEntry"/> type.
        /// </returns>
        public async Task <CatalogEntry> DeleteCatalogEntry(CatalogEntry entry)
        {
            using (IDocumentContextScope scope = this.dataContextScopeFactory.CreateDocumentContextScope(this.connectionStrings.DataAggregationDB))
            {
                IFileDocumentRepository repository = scope.GetRepository <IFileDocumentRepository>();

                await repository.DeleteAsync(entry.ID);
            }

            return(entry);
        }
예제 #6
0
        /// <summary>
        /// Deletes the specified catalog.
        /// </summary>
        /// <param name="catalog">The instance of <see cref="Catalog" /> type to delete.</param>
        /// <returns>
        /// The deleted instance of <see cref="Catalog"/> type.
        /// </returns>
        public async Task <Catalog> DeleteCatalog(Catalog catalog)
        {
            using (IDocumentContextScope scope = this.dataContextScopeFactory.CreateDocumentContextScope(this.connectionStrings.DataAggregationDB))
            {
                ICatalogDocumentRepository repository = scope.GetRepository <ICatalogDocumentRepository>();

                await repository.DeleteAsync(data => data.Path != null && data.Path.StartsWith(catalog.Path));
            }

            return(catalog);
        }
예제 #7
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));
        }