public ImageDocument(DocumentMetaData metaData, Config config)
        {
            MetaData    = metaData;
            DisplayName = MetaData.DisplayName;

            var extensions = MetaData.Type.GetFileExtensions();

            Pages = Directory.EnumerateFiles(MetaData.DirectoryAbsolutePath, "*.*", SearchOption.TopDirectoryOnly)
                    .Where(x => extensions.Contains(Path.GetExtension(x).ToLower()))
                    .OrderBy(x => x, LogicalStringComparer.Instance)
                    .ToArray();
            var thumbnailDirectory = Path.Combine(config.ThumbnailDirectory, MetaData.Id.ToString());

            LargeThumbnailAbsolutePath = Path.Combine(thumbnailDirectory, "large.png");
            SmallThumbnailAbsolutePath = Path.Combine(thumbnailDirectory, "small.png");
            metaData.PageSize          = Pages.Length;
        }
Beispiel #2
0
        /// <summary>
        /// ファイルからメタデータを読み込む
        /// </summary>
        /// <param name="absolutePath"></param>
        /// <param name="documentMetaData"></param>
        /// <returns></returns>
        private bool TryGetDocumentMetaData(string absolutePath, out DocumentMetaData documentMetaData)
        {
            _logger.WriteLine($"load document meta data file {absolutePath}");
            var metaDataFilePath = Path.Combine(absolutePath, "meta.yml");

            if (File.Exists(metaDataFilePath))
            {
                documentMetaData = YamlSerializeHelper.LoadFromFile <DocumentMetaData>(metaDataFilePath);
                documentMetaData.LatestSavedAbsolutePath = metaDataFilePath;
                documentMetaData.ProjectAbsolutePath     = _config.Project;
                documentMetaData.DirectoryAbsolutePath   = absolutePath;

                return(true);
            }

            _logger.WriteLine($"not found meta data file {absolutePath}");
            var title = Directory.EnumerateFiles(absolutePath)
                        .OrderBy(x => x, LogicalStringComparer.Instance)
                        .FirstOrDefault(x =>
            {
                var ex   = Path.GetExtension(x).ToLower();
                var type = DocumentTypeHelper.FileExtensionToType(ex);
                return(type == DocumentType.Img);
            });

            if (string.IsNullOrEmpty(title))
            {
                documentMetaData = default;
                return(false);
            }

            documentMetaData = new DocumentMetaData()
            {
                DisplayName             = Path.GetFileNameWithoutExtension(absolutePath),
                Type                    = DocumentTypeHelper.FileExtensionToType(Path.GetExtension(title).ToLower()),
                IsEdited                = true,
                LatestSavedAbsolutePath = metaDataFilePath,
                ProjectAbsolutePath     = _config.Project,
                DirectoryAbsolutePath   = absolutePath,
            };
            _logger.WriteLine($"created meta data {absolutePath}");
            return(true);
        }