Exemple #1
0
        // TODO: Put strings into the resources.
        //
        IEnumerable <IMetadataTreeNode> P_LoadNodes(IMetadataLoadContext loadCtx, DirectoryInfo directory, IMetadataTreeNode parentNode = default, bool continuation = default)
        {
            loadCtx.EnsureNotNull(nameof(loadCtx));
            directory.EnsureNotNull(nameof(directory));
            //
            loadCtx.ThrowIfCancellationRequested();
            var buffer             = continuation ? null : new List <IMetadataTreeNode>();
            var fileNameAndNodeMap = new Dictionary <string, IMetadataTreeNode>(FileSystemAccessUtilities.DefaultPathComparer);
            //
            var files = directory.GetFiles(searchPattern: "*", searchOption: SearchOption.TopDirectoryOnly);

            for (var i = 0; i < files.Length; i++)
            {
                loadCtx.ThrowIfCancellationRequested();
                var file = files[i];
                if (ShouldIncludeFile(context: loadCtx, file: file, mediaType: out var fileFormatMediaType))
                {
                    var metadataElement =
                        new MetadataFileInclusionTreeElement()
                    {
                        LocationUri         = new Uri(uriString: $"{UriUtilities.UriSchemeFile}://{file.FullName}", uriKind: UriKind.Absolute),
                        FormatMediaTypeName = fileFormatMediaType
                    };
                    var node = new MetadataTreeNode(parent: parentNode, caption: file.Name, metadataElement: metadataElement);
                    buffer?.Add(node);
                    fileNameAndNodeMap.Add(Path.GetFileNameWithoutExtension(file.Name), node);
                }
            }
            //
            var subdirectories = directory.GetDirectories(searchPattern: "*", searchOption: SearchOption.TopDirectoryOnly);

            for (var i = 0; i < subdirectories.Length; i++)
            {
                loadCtx.ThrowIfCancellationRequested();
                var subdirectory = subdirectories[i];
                if (!fileNameAndNodeMap.TryGetValue(subdirectory.Name, out var subdirectoryParentNode))
                {
                    MetadataName name;
                    try {
                        name = (MetadataName)subdirectory.Name;
                    }
                    catch (Exception exception) {
                        throw new EonException(message: $"Directory name can't be converted to metadata name (type '{typeof(MetadataName)}').{Environment.NewLine}\tDirectory:{subdirectory.FmtStr().GNLI2()}", innerException: exception);
                    }
                    var metadataElement = new EmbeddedMetadataTreeElement(embeddedMetadata: new Namespace(name: name), ownsEmbeddedMetadata: true);
                    var node            = new MetadataTreeNode(parent: parentNode, caption: metadataElement.EmbeddedMetadata.Name, metadataElement: metadataElement);
                    buffer?.Add(node);
                    subdirectoryParentNode = node;
                }
                //
                P_LoadNodes(loadCtx: loadCtx, directory: subdirectory, parentNode: subdirectoryParentNode, continuation: true);
            }
            //
            return(buffer ?? Enumerable.Empty <IMetadataTreeNode>());
        }
Exemple #2
0
        /// <summary>
        /// Вызывается при копировании объекта.
        /// <para>Выполняет заполнение копии объекта <paramref name="copy"/>.</para>
        /// </summary>
        /// <param name="args">Параметры копирования.</param>
        /// <param name="copy">Копия объекта.</param>
        protected virtual void PopulateCopy(CopyArgs args, EmbeddedMetadataTreeElement copy)
        {
            copy.EnsureNotNull(nameof(copy));
            //
            var originalEmbeddedMetadata = EmbeddedMetadata;
            var copyEmbeddedMetadata     = default(IMetadata);

            try {
                copy.WriteDA(
                    ref _embeddedMetadata,
                    originalEmbeddedMetadata == null ? null : (copyEmbeddedMetadata = originalEmbeddedMetadata.CreateCopy(readOnlyState: null)).ToValueHolder(true));
            }
            catch (Exception firstException) {
                DisposeMany(firstException, copyEmbeddedMetadata);
                throw;
            }
        }