示例#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);
        }
        /// <summary>
        /// Converts the instance of <see cref="!:TSource" /> type to the instance of <see cref="!:TTarget" />.
        /// </summary>
        /// <param name="source">The instance of <see cref="!:TSource" />.</param>
        /// <param name="target">The instance of <see cref="!:TTarget" />.</param>
        /// <returns>
        /// The converted instance of <see cref="!:TTarget" />.
        /// </returns>
        public FileDocument Convert(CatalogEntry source, FileDocument 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);
        }
        /// <summary>
        /// Converts the instance of <see cref="!:TSource" /> type to the instance of <see cref="!:TTarget" />.
        /// </summary>
        /// <param name="source">The instance of <see cref="!:TSource" />.</param>
        /// <param name="target">The instance of <see cref="!:TTarget" />.</param>
        /// <returns>
        /// The converted instance of <see cref="!:TTarget" />.
        /// </returns>
        public CatalogEntry Convert(FileDocument source, CatalogEntry target)
        {
            if (target.ID == Guid.Empty)
            {
                target.ID = source.ID;
            }

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

            return(target);
        }