protected virtual void PopulateCopy(CopyArgs args, MetadataTreeNode copy) { copy.EnsureNotNull(nameof(copy)); // var copyMetadataElement = default(IMetadataTreeElement); var copyChildrenBuffer = new List <IMetadataTreeNode>(); var copyInclusionsBuffer = new List <IMetadataTreeNodeInclusion>(); try { var copyChildren = copy.ReadDA(ref copy._children); foreach (var childOfThis in Children) { copyChildrenBuffer.Add(childOfThis.CreateCopy(readOnlyState: null)); copyChildren.AddComponent(copyChildrenBuffer[copyChildrenBuffer.Count - 1]); } // var copyInclusions = copy.ReadDA(ref copy._inclusions); foreach (var inclusionOfThis in Inclusions) { copyInclusionsBuffer.Add(inclusionOfThis.CreateCopy(readOnlyState: null)); copyInclusions.AddComponent(copyInclusionsBuffer[copyInclusionsBuffer.Count - 1]); } // copyMetadataElement = MetadataElement?.CreateCopy(readOnlyState: null); var copyMetadataElementLink = new Link <IMetadataTreeNode, IMetadataTreeElement>(copy, copyMetadataElement); copy.SetMetadataElement(copyMetadataElementLink); // } catch (Exception firstException) { DisposeManyDeep(firstException, copyMetadataElement, copyInclusionsBuffer, copyChildrenBuffer); throw; } }
// 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>()); }