Exemplo n.º 1
0
        public async Task ProcessGalleryAsync(IImageSettings imageImageSettings)
        {
            Task <Photo[]> sourceTask = PhotoMetadataRepository.LoadEmptyRepositoryAsync(baseFolder: this._settings.RootFolder, logging: this._logging);
            Task <Photo[]> targetTask = PhotoMetadataRepository.LoadRepositoryAsync(baseFolder: this._settings.DatabaseOutputFolder, logging: this._logging);

            Photo[][] results = await Task.WhenAll(sourceTask, targetTask);

            Photo[] source = results[0];
            Photo[] target = results[1];

            await this.ProcessAsync(source : source, target : target, imageImageSettings : imageImageSettings);
        }
Exemplo n.º 2
0
        private async Task ProcessOneFileAsync(Photo sourcePhoto, Photo targetPhoto, bool rebuild, bool rebuildMetadata, string url, string shortUrl, IImageSettings imageImageSettings)
        {
            this._logging.LogInformation(rebuild ? $"Rebuild: {sourcePhoto.UrlSafePath}" : $"Build: {sourcePhoto.UrlSafePath}");

            await targetPhoto.UpdateFileHashesAsync(sourcePhoto : sourcePhoto, settings : this._settings);

            bool buildMetadata = targetPhoto == null || rebuild || rebuildMetadata || targetPhoto.Metadata == null;

            if (buildMetadata)
            {
                sourcePhoto.Metadata = MetadataExtraction.ExtractMetadata(sourcePhoto: sourcePhoto, settings: this._settings);
            }
            else
            {
                sourcePhoto.Metadata = targetPhoto.Metadata;
            }

            bool buildImages = targetPhoto == null || rebuild || !targetPhoto.ImageSizes.HasAny();

            List <string> filesCreated = new();

            if (buildImages)
            {
                this._logging.LogInformation(message: "Build images:");
                DateTime creationDate = MetadataHelpers.ExtractCreationDate(sourcePhoto.Metadata);

                try
                {
                    IReadOnlyList <ImageSize> sizes = await this._imageExtraction.BuildImagesAsync(sourcePhoto : sourcePhoto,
                                                                                                   filesCreated : filesCreated,
                                                                                                   creationDate : creationDate,
                                                                                                   url : url,
                                                                                                   shortUrl : shortUrl,
                                                                                                   imageSettings : imageImageSettings);

                    sourcePhoto.ImageSizes = sizes.ToList();
                }
                catch (Exception exception)
                {
                    this._logging.LogInformation($" Failed to load image: {sourcePhoto.UrlSafePath}: {exception.Message}");

                    throw;
                }
            }
            else
            {
                this._logging.LogInformation(message: "Not building images");
                sourcePhoto.ImageSizes = targetPhoto.ImageSizes;
            }

            sourcePhoto.Version = Constants.CURRENT_METADATA_VERSION;

            if (targetPhoto != null)
            {
                targetPhoto.UpdateTargetWithSourceProperties(sourcePhoto);
                targetPhoto.Version = Constants.CURRENT_METADATA_VERSION;

                if (buildImages)
                {
                    //?
                }

                await PhotoMetadataRepository.StoreAsync(photo : targetPhoto, databaseOutputFolder : this._settings.DatabaseOutputFolder);
            }
            else
            {
                await PhotoMetadataRepository.StoreAsync(photo : sourcePhoto, databaseOutputFolder : this._settings.DatabaseOutputFolder);
            }
        }