diff --git a/.ci/check-core.yml b/.ci/check-core.yml index d9ed04f..f1dbb2d 100644 --- a/.ci/check-core.yml +++ b/.ci/check-core.yml @@ -12,10 +12,10 @@ pool: vmImage: 'vs2017-win2016' variables: - solution: '**/Filing_Toolkit.sln' + solution: '**/File_Toolkit.sln' buildPlatform: 'Any CPU' buildConfiguration: 'Release' - projectName: 'Filing_Toolkit' + projectName: 'File_Toolkit' steps: - checkout: self diff --git a/.ci/check-installer.yml b/.ci/check-installer.yml index 302d33d..07fab79 100644 --- a/.ci/check-installer.yml +++ b/.ci/check-installer.yml @@ -12,10 +12,10 @@ pool: vmImage: 'vs2017-win2016' variables: - solution: '**/Filing_Toolkit.sln' + solution: '**/File_Toolkit.sln' buildPlatform: 'Any CPU' buildConfiguration: 'Release' - projectName: 'Filing_Toolkit' + projectName: 'File_Toolkit' steps: - checkout: self diff --git a/.ci/run-compliance-tests.yml b/.ci/run-compliance-tests.yml index e54a691..cd99ca5 100644 --- a/.ci/run-compliance-tests.yml +++ b/.ci/run-compliance-tests.yml @@ -12,10 +12,10 @@ pool: vmImage: 'vs2017-win2016' variables: - solution: '**/Filing_Toolkit.sln' + solution: '**/File_Toolkit.sln' buildPlatform: 'Any CPU' buildConfiguration: 'Release' - projectName: 'Filing_Toolkit' + projectName: 'File_Toolkit' steps: - checkout: self diff --git a/.ci/testSettings.runsettings b/.ci/testSettings.runsettings index d7b2133..c564bfb 100644 --- a/.ci/testSettings.runsettings +++ b/.ci/testSettings.runsettings @@ -44,7 +44,7 @@ - + diff --git a/Filing_Adapter/AdapterActions/Execute.cs b/File_Adapter/AdapterActions/Execute.cs similarity index 96% rename from Filing_Adapter/AdapterActions/Execute.cs rename to File_Adapter/AdapterActions/Execute.cs index d60f2fa..b243892 100644 --- a/Filing_Adapter/AdapterActions/Execute.cs +++ b/File_Adapter/AdapterActions/Execute.cs @@ -20,11 +20,11 @@ * along with this code. If not, see . */ -using BH.Engine.Adapters.Filing; +using BH.Engine.Adapters.File; using BH.Engine.Reflection; using BH.oM.Adapter; using BH.oM.Data.Requests; -using BH.oM.Adapters.Filing; +using BH.oM.Adapters.File; using System; using System.Collections; using System.Collections.Generic; @@ -37,9 +37,9 @@ using BH.oM.Reflection; using BH.oM.Reflection.Attributes; -namespace BH.Adapter.Filing +namespace BH.Adapter.File { - public partial class FilingAdapter + public partial class FileAdapter { /***************************************************/ /**** Methods *****/ @@ -52,7 +52,7 @@ public override oM.Reflection.Output, bool> Execute(IExecuteCommand if (command == null) return new Output, bool>(); - oM.Adapters.Filing.ExecuteConfig executeConfig = actionConfig as oM.Adapters.Filing.ExecuteConfig ?? new ExecuteConfig(); + oM.Adapters.File.ExecuteConfig executeConfig = actionConfig as oM.Adapters.File.ExecuteConfig ?? new ExecuteConfig(); if (m_Execute_enableWarning && !executeConfig.DisableWarnings) { diff --git a/File_Adapter/AdapterActions/Pull.cs b/File_Adapter/AdapterActions/Pull.cs new file mode 100644 index 0000000..78868dd --- /dev/null +++ b/File_Adapter/AdapterActions/Pull.cs @@ -0,0 +1,95 @@ +/* + * This file is part of the Buildings and Habitats object Model (BHoM) + * Copyright (c) 2015 - 2020, the respective contributors. All rights reserved. + * + * Each contributor holds copyright over their respective contributions. + * The project versioning (Git) records all such contribution source information. + * + * + * The BHoM is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3.0 of the License, or + * (at your option) any later version. + * + * The BHoM is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this code. If not, see . + */ + +using BH.Engine.Adapters.File; +using BH.Engine.Reflection; +using BH.oM.Adapter; +using BH.oM.Data.Requests; +using BH.oM.Adapters.File; +using System; +using System.Collections; +using System.Collections.Generic; +using System.IO; +using System.IO.Abstractions; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using BH.Engine.Base; + +namespace BH.Adapter.File +{ + public partial class FileAdapter + { + /***************************************************/ + /**** Methods *****/ + /***************************************************/ + + public override bool SetupPullRequest(object request, out IRequest pullRequest) + { + pullRequest = request as IRequest; + + // If there is no input request, but a target filepath was specified through the Adapter constructor, use that. + if (!string.IsNullOrWhiteSpace(m_defaultFilePath) && (request == null || request is Type)) + { + if (request is Type) + { + pullRequest = new FileContentRequest() { File = m_defaultFilePath, Types = new List() { request as Type } }; + BH.Engine.Reflection.Compute.RecordNote($"Type interpreted as new {nameof(FileContentRequest)} targeting the Adapter targetLocation: `{m_defaultFilePath}` and filtering per type `{(request as Type).Name}`."); + } + else if (request is IEnumerable) + { + pullRequest = new FileContentRequest() { File = m_defaultFilePath, Types = (request as IEnumerable).ToList() }; + BH.Engine.Reflection.Compute.RecordNote($"Type interpreted as new {nameof(FileContentRequest)} targeting the Adapter targetLocation: `{m_defaultFilePath}` and filtering per types: {String.Join(", ",(request as IEnumerable).Select(t => t.Name))}."); + } + else + { + pullRequest = new FileContentRequest() { File = m_defaultFilePath }; + BH.Engine.Reflection.Compute.RecordNote($"Pulling file contents from the Adapter targetLocation: `{m_defaultFilePath}`."); + } + + return true; + } + + if (request == null && string.IsNullOrWhiteSpace(m_defaultFilePath)) + { + BH.Engine.Reflection.Compute.RecordError($"Please specify a valid Request, or create the {nameof(FileAdapter)} with the constructor that takes inputs to specify a target Location."); + return false; + } + + if ((request as IRequest) != null && !string.IsNullOrWhiteSpace(m_defaultFilePath)) + { + BH.Engine.Reflection.Compute.RecordWarning($"Both request and targetLocation have been specified. Requests take precedence. Pulling as specified by the input `{request.GetType().Name}`."); + return true; + } + + return base.SetupPullRequest(request, out pullRequest); + } + + public override IEnumerable Pull(IRequest request, PullType pullType = PullType.AdapterDefault, ActionConfig actionConfig = null) + { + return Read(request as dynamic, actionConfig as PullConfig ?? new PullConfig()); + } + + /***************************************************/ + + } +} diff --git a/File_Adapter/AdapterActions/Push.cs b/File_Adapter/AdapterActions/Push.cs new file mode 100644 index 0000000..8631171 --- /dev/null +++ b/File_Adapter/AdapterActions/Push.cs @@ -0,0 +1,171 @@ +/* + * This file is part of the Buildings and Habitats object Model (BHoM) + * Copyright (c) 2015 - 2020, the respective contributors. All rights reserved. + * + * Each contributor holds copyright over their respective contributions. + * The project versioning (Git) records all such contribution source information. + * + * + * The BHoM is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3.0 of the License, or + * (at your option) any later version. + * + * The BHoM is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this code. If not, see . + */ + +using BH.Engine.Adapters.File; +using BH.Engine.Reflection; +using BH.oM.Adapter; +using BH.oM.Data.Requests; +using BH.oM.Adapters.File; +using System; +using System.Collections; +using System.Collections.Generic; +using System.IO; +using System.IO.Abstractions; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using BH.Engine.Base; +using BH.oM.Base; + +namespace BH.Adapter.File +{ + public partial class FileAdapter + { + /***************************************************/ + /**** Methods *****/ + /***************************************************/ + + public override bool SetupPushType(PushType pushType, out PushType pt) + { + pt = pushType; + + if (pushType == PushType.AdapterDefault) + pt = m_AdapterSettings.DefaultPushType; + + if (pushType == PushType.FullPush) + { + BH.Engine.Reflection.Compute.RecordError($"The specified {nameof(PushType)} {nameof(PushType.FullPush)} is not supported."); + return false; + } + + return true; + } + + public override bool SetupPushConfig(ActionConfig actionConfig, out ActionConfig pushConfig) + { + PushConfig pushCfg = actionConfig as PushConfig ?? new PushConfig(); + pushConfig = pushCfg; + + if (pushCfg.BeautifyJson && pushCfg.UseDatasetSerialization) + { + BH.Engine.Reflection.Compute.RecordError($"Input `{nameof(PushConfig.BeautifyJson)}` and `{nameof(PushConfig.UseDatasetSerialization)}` cannot be both set to True."); + return false; + } + + return true; + } + + public override List Push(IEnumerable objects, string tag = "", PushType pushType = PushType.AdapterDefault, ActionConfig actionConfig = null) + { + PushConfig pushConfig = actionConfig as PushConfig; + + if (string.IsNullOrWhiteSpace(m_defaultFilePath)) // = if we are about to push multiple files/directories + if (pushType == PushType.DeleteThenCreate && m_Push_enableDeleteWarning && !pushConfig.DisableWarnings ) + { + BH.Engine.Reflection.Compute.RecordWarning($"You have selected the {nameof(PushType)} {nameof(PushType.DeleteThenCreate)}." + + $"\nThis has the potential of deleting files and folders with their contents." + + $"\nMake sure that you know what you are doing. This warning will not be repeated." + + $"\nRe-enable the component to continue."); + + m_Push_enableDeleteWarning = false; + + return new List(); + } + + List createdFiles = new List(); + + List filesOrDirs = objects.OfType().Select(fd => fd.GetShallowClone() as IResource).ToList(); + List remainder = objects.Where(o => !(o is IResource)).ToList(); + + if (remainder.Any()) + { + if (filesOrDirs.Any()) + { + BH.Engine.Reflection.Compute.RecordError($"Input objects are both of type `{nameof(BH.oM.Adapters.File.File)}`/`{nameof(BH.oM.Adapters.File.Directory)}` and generic objects." + + $"\nIn order to push them:" + + $"\n\t- for the `{nameof(BH.oM.Adapters.File.File)}`/`{nameof(BH.oM.Adapters.File.Directory)}` objects, use a Push using a {nameof(FileAdapter)} with no targetLocation input;"+ + $"\n\t- for the generic objects, use a Push using a {nameof(FileAdapter)} that specifies a targetLocation."); + return null; + } + else if (string.IsNullOrWhiteSpace(m_defaultFilePath)) + { + BH.Engine.Reflection.Compute.RecordError($"To Push objects that are not of type `{nameof(BH.oM.Adapters.File.File)}` or `{nameof(BH.oM.Adapters.File.Directory)}`," + + $"\nyou need to specify a target Location by creating the {nameof(FileAdapter)} through the constructor with inputs."); + return null; + } + } + + if (m_defaultFilePath != null) + { + if (filesOrDirs.Any()) + BH.Engine.Reflection.Compute.RecordWarning($"A `targetLocation` has been specified in the File_Adapter constructor." + + $"\nObjects of type `{nameof(BH.oM.Adapters.File.File)}` or `{nameof(BH.oM.Adapters.File.Directory)}` will be appended to the file at `targetLocation`." + + $"\nIf you want to target multiple files, you need create the {nameof(FileAdapter)} through the constructor without inputs."); + } + + foreach (IResource fileOrDir in filesOrDirs) + { + if (fileOrDir == null) + continue; + + if (fileOrDir is IFile) + { + string extension = Path.GetExtension(fileOrDir.IFullPath()); + + if (string.IsNullOrWhiteSpace(extension)) + { + BH.Engine.Reflection.Compute.RecordNote($"File {fileOrDir.IFullPath()} has no extension specified. Defaults to JSON."); + extension = ".json"; + fileOrDir.Name += extension; + } + + if (extension != ".json") + { + BH.Engine.Reflection.Compute.RecordWarning($"Cannot create File {fileOrDir.IFullPath()}. Currently only JSON extension is supported."); + continue; + } + } + + IResource created = Create(fileOrDir as dynamic, pushType, pushConfig); + createdFiles.Add(created); + } + + if (remainder.Any()) + { + string defaultDirectory = Path.GetDirectoryName(m_defaultFilePath); + string defaultFileName = Path.GetFileName(m_defaultFilePath); + + FSFile file = CreateFSFile(defaultDirectory, defaultFileName, remainder); + + IResource created = Create(file, pushType, pushConfig); + + if (created != null) + createdFiles.Add(created); + } + + return createdFiles.OfType().ToList(); + } + + /***************************************************/ + + } +} diff --git a/Filing_Adapter/AdapterActions/Remove.cs b/File_Adapter/AdapterActions/Remove.cs similarity index 93% rename from Filing_Adapter/AdapterActions/Remove.cs rename to File_Adapter/AdapterActions/Remove.cs index 8501368..c06629a 100644 --- a/Filing_Adapter/AdapterActions/Remove.cs +++ b/File_Adapter/AdapterActions/Remove.cs @@ -20,11 +20,11 @@ * along with this code. If not, see . */ -using BH.Engine.Adapters.Filing; +using BH.Engine.Adapters.File; using BH.Engine.Reflection; using BH.oM.Adapter; using BH.oM.Data.Requests; -using BH.oM.Adapters.Filing; +using BH.oM.Adapters.File; using System; using System.Collections; using System.Collections.Generic; @@ -35,9 +35,9 @@ using System.Threading.Tasks; using BH.Engine.Base; -namespace BH.Adapter.Filing +namespace BH.Adapter.File { - public partial class FilingAdapter + public partial class FileAdapter { /***************************************************/ /**** Methods *****/ @@ -52,7 +52,7 @@ public override int Remove(IRequest request, ActionConfig actionConfig = null) return 0; } - oM.Adapters.Filing.RemoveConfig removeConfig = actionConfig as oM.Adapters.Filing.RemoveConfig ?? new RemoveConfig(); + oM.Adapters.File.RemoveConfig removeConfig = actionConfig as oM.Adapters.File.RemoveConfig ?? new RemoveConfig(); if (m_Remove_enableDeleteWarning && !removeConfig.DisableWarnings) { diff --git a/Filing_Adapter/CRUD/Create/Create.cs b/File_Adapter/CRUD/Create/Create.cs similarity index 77% rename from Filing_Adapter/CRUD/Create/Create.cs rename to File_Adapter/CRUD/Create/Create.cs index bb43a43..59818f3 100644 --- a/Filing_Adapter/CRUD/Create/Create.cs +++ b/File_Adapter/CRUD/Create/Create.cs @@ -21,48 +21,42 @@ */ using BH.oM.Base; -using MongoDB.Bson.Serialization; using System; using System.Collections.Generic; using System.IO; using System.Linq; using BH.Engine.Serialiser; using BH.oM.Adapter; -using BH.Engine.Adapters.Filing; -using BH.oM.Adapters.Filing; +using BH.Engine.Adapters.File; +using BH.oM.Adapters.File; -namespace BH.Adapter.Filing +namespace BH.Adapter.File { - public partial class FilingAdapter : BHoMAdapter + public partial class FileAdapter : BHoMAdapter { /***************************************************/ /**** Public Methods ****/ /***************************************************/ - public static IFSContainer Create(ILocatableResource resource, PushType pushType, PushConfig pushConfig) + public IFSContainer Create(ILocatableResource resource, PushType pushType, PushConfig pushConfig) { if (resource == null) - return null; + return null; IFSContainer fileOrDir = resource.ToFiling(); - return Create(fileOrDir, pushType, pushConfig); + return Create(fileOrDir, pushType, pushConfig); } /***************************************************/ - public static IFSContainer Create(IFSContainer fileOrDir, PushType pushType, PushConfig pushConfig) + public IFSContainer Create(IFSContainer fileOrDir, PushType pushType, PushConfig pushConfig) { pushConfig = pushConfig ?? new PushConfig(); if (fileOrDir == null) return null; - string extension = Path.GetExtension(fileOrDir.IFullPath()); - - if (extension == ".json") - return CreateJson((FSFile)fileOrDir, pushType, pushConfig) as IFSContainer; - - if (extension == ".bson") + if (fileOrDir is IFile) return CreateJson((FSFile)fileOrDir, pushType, pushConfig) as IFSContainer; if (fileOrDir is IDirectory) diff --git a/Filing_Adapter/CRUD/Create/CreateDirectory.cs b/File_Adapter/CRUD/Create/CreateDirectory.cs similarity index 91% rename from Filing_Adapter/CRUD/Create/CreateDirectory.cs rename to File_Adapter/CRUD/Create/CreateDirectory.cs index 55eeb8e..152e67d 100644 --- a/Filing_Adapter/CRUD/Create/CreateDirectory.cs +++ b/File_Adapter/CRUD/Create/CreateDirectory.cs @@ -28,25 +28,24 @@ using System.Linq; using BH.Engine.Serialiser; using BH.oM.Adapter; -using BH.Engine.Adapters.Filing; -using BH.oM.Adapters.Filing; +using BH.Engine.Adapters.File; +using BH.oM.Adapters.File; using BH.Engine.Base; -namespace BH.Adapter.Filing +namespace BH.Adapter.File { - public partial class FilingAdapter : BHoMAdapter + public partial class FileAdapter : BHoMAdapter { /***************************************************/ /**** Public Methods ****/ /***************************************************/ - public static IFSContainer CreateDirectory(FSDirectory dir, PushType pushType, PushConfig pushConfig) + public IFSContainer CreateDirectory(FSDirectory dir, PushType pushType, PushConfig pushConfig) { - List createdDirs = new List(); + List createdDirs = new List(); bool clearfile = pushType == PushType.DeleteThenCreate ? true : false; - string dirFullPath = dir.IFullPath(); bool existed = System.IO.Directory.Exists(dirFullPath); @@ -99,7 +98,7 @@ public static IFSContainer CreateDirectory(FSDirectory dir, PushType pushType, P } else { - BH.Engine.Reflection.Compute.RecordWarning($"The specified Pushtype of {pushType.ToString()} is not supported for {nameof(BH.oM.Adapters.Filing.FSDirectory)} objects."); + BH.Engine.Reflection.Compute.RecordWarning($"The specified Pushtype of {pushType.ToString()} is not supported for {nameof(BH.oM.Adapters.File.FSDirectory)} objects."); directoryCreated = false; } } @@ -111,7 +110,7 @@ public static IFSContainer CreateDirectory(FSDirectory dir, PushType pushType, P if (directoryCreated || existed) { System.IO.DirectoryInfo dirInfo = new System.IO.DirectoryInfo(dirFullPath); - oM.Adapters.Filing.FSDirectory createdDir = dirInfo.ToFiling(); + oM.Adapters.File.FSDirectory createdDir = dirInfo.ToFiling(); return createdDir; } diff --git a/File_Adapter/CRUD/Create/CreateJson.cs b/File_Adapter/CRUD/Create/CreateJson.cs new file mode 100644 index 0000000..aa3b9ba --- /dev/null +++ b/File_Adapter/CRUD/Create/CreateJson.cs @@ -0,0 +1,301 @@ +/* + * This file is part of the Buildings and Habitats object Model (BHoM) + * Copyright (c) 2015 - 2020, the respective contributors. All rights reserved. + * + * Each contributor holds copyright over their respective contributions. + * The project versioning (Git) records all such contribution source information. + * + * + * The BHoM is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3.0 of the License, or + * (at your option) any later version. + * + * The BHoM is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this code. If not, see . + */ + +using BH.oM.Base; +using MongoDB.Bson.Serialization; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using BH.Engine.Serialiser; +using BH.oM.Adapter; +using BH.Engine.Adapters.File; +using BH.oM.Adapters.File; +using System.Text.Json; +using BH.Engine.Diffing; +using BH.oM.Diffing; + +namespace BH.Adapter.File +{ + public partial class FileAdapter : BHoMAdapter + { + /***************************************************/ + /**** Public Methods ****/ + /***************************************************/ + + public FSFile CreateJson(FSFile file, PushType pushType, PushConfig pushConfig) + { + string fullPath = file.IFullPath(); + bool fileExisted = System.IO.File.Exists(fullPath); + + // Put together all of the file content. + List allLines = new List(); + string json = ""; + + // Process file content, only if there is any. + if (file.Content != null && file.Content.Count != 0) + { + if (!pushConfig.UseDatasetSerialization) + { + allLines.AddRange(file.Content.Where(c => c != null).Select(obj => obj.ToJson() + ",")); + + // Remove the trailing comma if there is only one element. + allLines[allLines.Count - 1] = allLines[allLines.Count - 1].Remove(allLines[allLines.Count - 1].Length - 1); + + // Join all between square brackets to make a valid JSON array. + json = String.Join(Environment.NewLine, allLines); + json = "[" + json + "]"; + } + else + { + // Use the non-JSON compliant "Dataset" serialization style. + // This is a newline-separated concatenation of individual JSON-serialized objects. + allLines.AddRange(file.Content.Where(c => c != null).Select(obj => obj.ToJson())); + json = String.Join(Environment.NewLine, allLines); + } + + if (pushConfig.BeautifyJson) + json = BeautifyJson(json); + } + + bool filecreated = true; + try + { + // Clarify if we are considering the Push in terms of content or of Files. + if (string.IsNullOrWhiteSpace(m_defaultFilePath)) // We are talking about Files/Directories. + { + if (pushType == PushType.DeleteThenCreate) + { + if (fileExisted) + System.IO.File.Delete(fullPath); + + WriteJsonFile(fullPath, json, true); + } + else if (pushType == PushType.UpdateOnly) + { + // Overwrite existing file. + if (fileExisted) + WriteJsonFile(fullPath, json, true); + else + BH.Engine.Reflection.Compute.RecordNote($"File {fullPath} was not updated as no file existed at that location."); + } + else if (pushType == PushType.UpdateOrCreateOnly) + { + // Overwrite existing file. If it doesn't exist, create it. + WriteJsonFile(fullPath, json, true); + } + else if (pushType == PushType.CreateOnly || pushType == PushType.CreateNonExisting) + { + // Create only if file didn't exist. Do not touch existing ones. + if (!fileExisted) + WriteJsonFile(fullPath, json, true); + else + BH.Engine.Reflection.Compute.RecordNote($"File {fullPath} was not created as it existed already (Pushtype {pushType.ToString()} was specified)."); + } + else + { + BH.Engine.Reflection.Compute.RecordWarning($"The specified Pushtype of {pushType.ToString()} is not supported for .json files."); + filecreated = false; + } + } + else // We are talking about File content. + { + if (pushType == PushType.DeleteThenCreate) + { + BH.Engine.Reflection.Compute.RecordNote($"Replacing entire content of file `{fullPath}`."); + + // Replace all content. + WriteJsonFile(fullPath, json, true); + } + else if (pushType == PushType.CreateOnly || pushType == PushType.CreateNonExisting || pushType == PushType.UpdateOnly || pushType == PushType.UpdateOrCreateOnly) + { + // Should be refactored to cover distinct use cases for CreateNonExisting, UpdateOnly, UpdateOrCreateOnly + if (fileExisted) + BH.Engine.Reflection.Compute.RecordNote($"Appending content to file `{fullPath}`."); + + WriteJsonFile(fullPath, json, false); + } + else if (pushType == PushType.CreateNonExisting) + { + // Currently captured by CreateOnly. + + // The following ideally should be the default behaviour of the IDiffing method. + + //IEnumerable allReadContent = ReadContent(fullPath); + //IEnumerable bHoMObjects_read = allReadContent.OfType(); + //IEnumerable genericObjs_read = allReadContent.Except(bHoMObjects_read); + + //IEnumerable readBhomObjects_hashAssigned = BH.Engine.Diffing.Modify.SetHashFragment(bHoMObjects_read); + + //IEnumerable bHoMObjects_create = file.Content.OfType(); + //IEnumerable genericObjs_create = file.Content.Except(bHoMObjects_create); + + //Diff diffGeneric = BH.Engine.Diffing.Compute.DiffGenericObjects(genericObjs_read, genericObjs_create, null, true); + + // Then combine the two diffs in one. + // For old objects (= already in file) do not create. + // Create only those that are "new". + } + else if (pushType == PushType.UpdateOnly || pushType == PushType.UpdateOrCreateOnly) + { + // Currently captured by CreateOnly. See above. + + // For old objects (= already in file) Update Them. + // For those who are "new": create them only if `UpdateOrCreateOnly` is used. + } + else + { + BH.Engine.Reflection.Compute.RecordWarning($"The specified Pushtype of {pushType.ToString()} is not supported for .json files."); + filecreated = false; + } + } + } + catch (Exception e) + { + BH.Engine.Reflection.Compute.RecordError(e.Message); + } + + if (filecreated) + { + System.IO.FileInfo fileinfo = new System.IO.FileInfo(fullPath); + oM.Adapters.File.FSFile createdFile = fileinfo.ToFiling(); + createdFile.Content = file.Content; + + return createdFile; + } + + BH.Engine.Reflection.Compute.RecordError($"Could not create {file.ToString()}"); + return null; + } + + /***************************************************/ + + public static void WriteJsonFile(string fullPath, string json, bool replaceContent, bool createParentDirectories = true) + { + if (createParentDirectories) + { + System.IO.FileInfo file = new System.IO.FileInfo(fullPath); + file.Directory.Create(); // If the directory already exists, this method does nothing. + } + + // Treat the "empty input text" case. + if (string.IsNullOrWhiteSpace(json)) + { + if (replaceContent) + System.IO.File.WriteAllText(fullPath, json); // still write the file + else + System.IO.File.AppendAllText(fullPath, json); // still append empty text (modifying the file) + + return; + } + + // If replaceContent is true, or file doesn't exist, or file exists but is empty, then replace all content. + if (replaceContent || !System.IO.File.Exists(fullPath) || !System.IO.File.ReadAllText(fullPath).Any()) + System.IO.File.WriteAllText(fullPath, json); + else + { + // We are appending to an existing, non-empty JSON file. + // This operation is valid only if the existing json file is a JSON array, and if the text to be appended is a JSON array too. + + // Process the text to be appended + string inputJson = json; + if (inputJson.First() == '[' && inputJson.Last() == ']') + { + // The input text is a JSON array. Remove square brackets. + inputJson = inputJson.Remove(inputJson.Count() - 1).Remove(0, 1); + + // Read the Json file + string existingJson = System.IO.File.ReadAllText(fullPath); + if (existingJson.First() != '[' || existingJson.Last() != ']') + { + BH.Engine.Reflection.Compute.RecordError("Invalid operation: attempted to append content to an existing JSON that was not a valid JSON array."); + return; + } + + // Replace last ']' with a comma + string toBeCreated = existingJson.Remove(existingJson.Count() - 1) + ","; + + // Append content and close square brackets. + toBeCreated += "\n" + inputJson + "]"; + + System.IO.File.WriteAllText(fullPath, toBeCreated); + + return; + } + + + string[] asd = new string[] { "" }; + if (!string.IsNullOrWhiteSpace(json) && json.Contains("\r\n")) + asd = json.Split(new[] { "\r\n" }, StringSplitOptions.None); + + if (asd.Count() > 0 && json.FirstOrDefault() == '{' && json.LastOrDefault() == '}') + { + // The input text is a "bhom dataset" json. + + // Read the Json file + string existingJson = System.IO.File.ReadAllText(fullPath); + if (existingJson.First() != '{' || existingJson.Last() != '}') + { + BH.Engine.Reflection.Compute.RecordError("Invalid operation: attempted to append 'BHoM-Dataset' text to an existing .json file that was not a 'BHoM-Dataset' file."); + return; + } + + System.IO.File.AppendAllText(fullPath, Environment.NewLine + json); + } + } + } + + /***************************************************/ + /**** Private Methods ****/ + /***************************************************/ + + private static string BeautifyJson(string jsonString) + { + if (string.IsNullOrWhiteSpace(jsonString)) + return jsonString; + + JsonDocument doc = JsonDocument.Parse( + jsonString, + new JsonDocumentOptions + { + AllowTrailingCommas = true + } + ); + MemoryStream memoryStream = new MemoryStream(); + using ( + var utf8JsonWriter = new Utf8JsonWriter( + memoryStream, + new JsonWriterOptions + { + Indented = true + } + ) + ) + { + doc.WriteTo(utf8JsonWriter); + } + return new System.Text.UTF8Encoding() + .GetString(memoryStream.ToArray()); + } + } +} + diff --git a/Filing_Adapter/CRUD/Delete/Delete.cs b/File_Adapter/CRUD/Delete/Delete.cs similarity index 94% rename from Filing_Adapter/CRUD/Delete/Delete.cs rename to File_Adapter/CRUD/Delete/Delete.cs index 07ea953..c71e377 100644 --- a/Filing_Adapter/CRUD/Delete/Delete.cs +++ b/File_Adapter/CRUD/Delete/Delete.cs @@ -23,16 +23,16 @@ using BH.oM.Adapter; using BH.oM.Base; using BH.oM.Data.Requests; -using BH.oM.Adapters.Filing; +using BH.oM.Adapters.File; using System; using System.Collections.Generic; using System.IO; using System.Linq; -using BH.Engine.Adapters.Filing; +using BH.Engine.Adapters.File; -namespace BH.Adapter.Filing +namespace BH.Adapter.File { - public partial class FilingAdapter : BHoMAdapter + public partial class FileAdapter : BHoMAdapter { /***************************************************/ /**** Public Methods ****/ @@ -47,11 +47,11 @@ public static int Delete(RemoveRequest rr, RemoveConfig removeConfig) foreach (string fullPath in rr.ToRemove) { - BH.oM.Adapters.Filing.FSDirectory dir = null; + BH.oM.Adapters.File.FSDirectory dir = null; if (fullPath.IsExistingDir()) dir = ReadDirectory(fullPath); - BH.oM.Adapters.Filing.FSFile file = null; + BH.oM.Adapters.File.FSFile file = null; if (fullPath.IsExistingFile()) file = ReadFile(fullPath); diff --git a/Filing_Adapter/CRUD/Read/Read.cs b/File_Adapter/CRUD/Read/Read.cs similarity index 74% rename from Filing_Adapter/CRUD/Read/Read.cs rename to File_Adapter/CRUD/Read/Read.cs index 5f315da..cb503e7 100644 --- a/Filing_Adapter/CRUD/Read/Read.cs +++ b/File_Adapter/CRUD/Read/Read.cs @@ -20,19 +20,20 @@ * along with this code. If not, see . */ -using BH.Engine.Adapters.Filing; +using BH.Engine.Adapters.File; using BH.oM.Adapter; using BH.oM.Base; -using BH.oM.Adapters.Filing; +using BH.oM.Adapters.File; using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; +using System.Management.Automation; -namespace BH.Adapter.Filing +namespace BH.Adapter.File { - public partial class FilingAdapter : BHoMAdapter + public partial class FileAdapter : BHoMAdapter { /***************************************************/ /**** Public Methods ****/ @@ -40,34 +41,41 @@ public partial class FilingAdapter : BHoMAdapter public IEnumerable Read(FileDirRequest fdr, PullConfig pullConfig) { + // Copy for immutability in UI + FileDirRequest fdrCopy = BH.Engine.Base.Query.ShallowClone(fdr); + // Recursively walk the directories to retrieve File and Directory Info. List output = new List(); List files = new List(); List dirs = new List(); + WildcardPattern wildcardPattern = null; + if (!Modify.ProcessFileDirRequest(fdrCopy, out wildcardPattern)) + return null; + int retrievedFiles = 0, retrievedDirs = 0; - WalkDirectories(files, dirs, fdr, ref retrievedFiles, ref retrievedDirs, pullConfig.IncludeHiddenFiles, pullConfig.IncludeSystemFiles); + WalkDirectories(files, dirs, fdrCopy, ref retrievedFiles, ref retrievedDirs, pullConfig.IncludeHiddenFiles, pullConfig.IncludeSystemFiles, wildcardPattern); output.AddRange(dirs); output.AddRange(files); // If a sort order is applied, sort separately files and dirs, // then return the maxItems of each of those. - if (fdr.SortOrder != SortOrder.Default) + if (fdrCopy.SortOrder != SortOrder.Default) { - output = Query.SortOrder(output, fdr.SortOrder); + output = Query.SortOrder(output, fdrCopy.SortOrder); - files = output.OfType().Take(fdr.MaxFiles == -1 ? output.Count : fdr.MaxFiles).ToList(); - dirs = output.OfType().Take(fdr.MaxDirectories == -1 ? output.Count : fdr.MaxDirectories).ToList(); + files = output.OfType().Take(fdrCopy.MaxFiles == -1 ? output.Count : fdrCopy.MaxFiles).ToList(); + dirs = output.OfType().Take(fdrCopy.MaxDirectories == -1 ? output.Count : fdrCopy.MaxDirectories).ToList(); } - if (fdr.IncludeFileContents) + if (fdrCopy.IncludeFileContents) files.ForEach(f => ReadAndAddContent(f)); output = new List(); - if (fdr.SortOrder != SortOrder.Default && fdr.SortOrder != SortOrder.ByName) + if (fdrCopy.SortOrder != SortOrder.Default && fdrCopy.SortOrder != SortOrder.ByName) { output.AddRange(files); output.AddRange(dirs); diff --git a/Filing_Adapter/CRUD/Read/ReadFile.cs b/File_Adapter/CRUD/Read/ReadFile.cs similarity index 84% rename from Filing_Adapter/CRUD/Read/ReadFile.cs rename to File_Adapter/CRUD/Read/ReadFile.cs index 01b54fa..5fcf95a 100644 --- a/Filing_Adapter/CRUD/Read/ReadFile.cs +++ b/File_Adapter/CRUD/Read/ReadFile.cs @@ -27,18 +27,18 @@ using System.Linq; using BH.Engine.Serialiser; using BH.oM.Adapter; -using BH.Engine.Adapters.Filing; -using BH.oM.Adapters.Filing; +using BH.Engine.Adapters.File; +using BH.oM.Adapters.File; -namespace BH.Adapter.Filing +namespace BH.Adapter.File { - public partial class FilingAdapter + public partial class FileAdapter { /***************************************************/ /**** Public Methods ****/ /***************************************************/ - public static oM.Adapters.Filing.FSFile ReadFile(FileRequest fr, PullConfig pc) + public static oM.Adapters.File.FSFile ReadFile(FileRequest fr, PullConfig pc) { string fullPath = fr.Location.IFullPath(); @@ -47,7 +47,7 @@ public static oM.Adapters.Filing.FSFile ReadFile(FileRequest fr, PullConfig pc) /***************************************************/ - public static oM.Adapters.Filing.FSFile ReadFile(string fullPath, bool inclFileContent = false, bool inclHidFiles = false, bool inclSysFiles = false) + public static oM.Adapters.File.FSFile ReadFile(string fullPath, bool inclFileContent = false, bool inclHidFiles = false, bool inclSysFiles = false) { // Perform the "Read" = get the System.FileInfo, which will be the basis for our oM.Adapters.Filing.File FileInfo fi = new FileInfo(fullPath); @@ -64,7 +64,7 @@ public static oM.Adapters.Filing.FSFile ReadFile(string fullPath, bool inclFileC return null; // Convert the FileInfo to our oM.Adapters.Filing.File - oM.Adapters.Filing.FSFile file = fi.ToFiling(); + oM.Adapters.File.FSFile file = fi.ToFiling(); // Add author data if possible AddAuthor(file); @@ -78,7 +78,7 @@ public static oM.Adapters.Filing.FSFile ReadFile(string fullPath, bool inclFileC /***************************************************/ - public static oM.Adapters.Filing.FSDirectory ReadDirectory(string fullPath, bool inclHidDirs = false, bool inclSysDirs = false, bool includeFolderContent = false) + public static oM.Adapters.File.FSDirectory ReadDirectory(string fullPath, bool inclHidDirs = false, bool inclSysDirs = false, bool includeFolderContent = false) { // Perform the "Read" = get the System.DirectoryInfo, which will be the basis for our oM.Adapters.Filing.Directory DirectoryInfo di = new DirectoryInfo(fullPath); @@ -95,7 +95,7 @@ public static oM.Adapters.Filing.FSDirectory ReadDirectory(string fullPath, bool return null; // Convert the FileInfo to our oM.Adapters.Filing.File - oM.Adapters.Filing.FSDirectory dir = di.ToFiling(); + oM.Adapters.File.FSDirectory dir = di.ToFiling(); // Add author data if possible AddAuthor(dir); diff --git a/Filing_Adapter/CRUD/Read/ReadFileContent.cs b/File_Adapter/CRUD/Read/ReadFileContent.cs similarity index 66% rename from Filing_Adapter/CRUD/Read/ReadFileContent.cs rename to File_Adapter/CRUD/Read/ReadFileContent.cs index abb5858..57caa7e 100644 --- a/Filing_Adapter/CRUD/Read/ReadFileContent.cs +++ b/File_Adapter/CRUD/Read/ReadFileContent.cs @@ -30,17 +30,17 @@ using System.Collections.Generic; using System.IO; using System.Linq; -using BH.oM.Adapters.Filing; -using BH.Engine.Adapters.Filing; +using BH.oM.Adapters.File; +using BH.Engine.Adapters.File; -namespace BH.Adapter.Filing +namespace BH.Adapter.File { /***************************************************/ /**** Public Methods ****/ /***************************************************/ - public partial class FilingAdapter : BHoMAdapter + public partial class FileAdapter : BHoMAdapter { public IEnumerable Read(FileContentRequest fcr, PullConfig pullConfig) { @@ -48,7 +48,7 @@ public IEnumerable Read(FileContentRequest fcr, PullConfig pullConfig) string fileFullPath = fcr.File.IFullPath(); - oM.Adapters.Filing.FSFile readFile = ReadFile(fileFullPath, true, pullConfig.IncludeHiddenFiles, pullConfig.IncludeSystemFiles); + oM.Adapters.File.FSFile readFile = ReadFile(fileFullPath, true, pullConfig.IncludeHiddenFiles, pullConfig.IncludeSystemFiles); if (readFile == null) return output; @@ -74,10 +74,8 @@ public static IEnumerable ReadContent(string fileFullPath) if (extension == ".json") retrievedObjects.AddRange(RetrieveJsonContent(fileFullPath)); - else if (extension == ".bson") - retrievedObjects.AddRange(RetrieveBsonContent(fileFullPath)); else - BH.Engine.Reflection.Compute.RecordWarning($"Only JSON and BSON file formats are currently supported by the {typeof(FilingAdapter).Name}."); + BH.Engine.Reflection.Compute.RecordNote($"Cannot read content of {fileFullPath}. Only JSON format is currently supported by the {typeof(FileAdapter).Name}."); return retrievedObjects; } @@ -117,42 +115,32 @@ public static IEnumerable RetrieveJsonContent(string fileFullPath) { if (line2FirstChar != default(char) && line2FirstChar == '{' && line2LastChar != default(char) && line2LastChar == '}') - // Assume it's a BHoM Dataset Json. Not proper Json. - isDatasetJson = true; + // Assume it's a BHoM Dataset Json. Not proper Json. + isDatasetJson = true; } - //try - //{ - // System.Text.Json.JsonDocument.Parse(jsonText); - // properJson = true; - //} - //catch - //{ - // // The object was not a proper JSON. It *might* be our "BHoM-Dataset" JSON. - // properJson = false; - //} - - // The problem of directly doing the following without prior validating the json - // is that it would expose an unrelevant Error message to the UI. + if (!isDatasetJson) - converted = BH.Engine.Serialiser.Convert.FromJson(jsonText); + if (!FromJson(jsonText, out converted)) + { + Engine.Reflection.Compute.RecordWarning($"The content of file `{fileFullPath}` is not a supported json format."); + return result; + } if (isDatasetJson || converted == null) { // Try to read the file as a "BHoM-Dataset json" - converted = jsonLines.Select(x => Engine.Serialiser.Convert.FromJson(x)).Where(x => x != null); - } - - // If there is a single CustomObject with no name, assume it was automatically generated by the BHoM Engine deserialization. - CustomObject cObj = (converted as CustomObject); - if (cObj != null && cObj.Name == "" && cObj.CustomData.Count > 0) - { - converted = cObj.CustomData.Values; - - // A nested list may come from the fact that the Engine Deserialiser misinterprets the JSON array []. - var list = (converted as ICollection)?.OfType()?.ToList(); - if (list != null && list.Count == 1) - converted = list.FirstOrDefault(); + List deserialised = new List(); + for (int i = 0; i < jsonLines.Count(); i++) + { + object readObj = null; + if (FromJson(jsonLines[i], out readObj)) + deserialised.Add(readObj); + else + Engine.Reflection.Compute.RecordWarning($"Could not deserialise line {i} of the Dataset file {fileFullPath}."); + } + + converted = deserialised; } if (typeof(IEnumerable).IsAssignableFrom(converted.GetType())) @@ -165,23 +153,44 @@ public static IEnumerable RetrieveJsonContent(string fileFullPath) /***************************************************/ - public static IEnumerable RetrieveBsonContent(string filePath) + public static bool FromJson(string json, out object result) { - FileStream mongoReadStream = System.IO.File.OpenRead(filePath); - var reader = new BsonBinaryReader(mongoReadStream); - List readBson = BsonSerializer.Deserialize(reader, typeof(object)) as List; - IEnumerable output = new List(); + result = null; + + if (json == "") + return false; - try + if (json.StartsWith("{")) { - output = readBson.Select(x => BsonSerializer.Deserialize(x, typeof(object))); + BsonDocument document; + if (BsonDocument.TryParse(json, out document)) + { + result = BH.Engine.Serialiser.Convert.FromBson(document); + return true; + } + else + { + return false; + } } - catch + + if (json.StartsWith("[")) { - BH.Engine.Reflection.Compute.RecordWarning($"Could not read content from Bson file `{filePath}`."); + BsonArray array = MongoDB.Bson.Serialization.BsonSerializer.Deserialize(json); + + try + { + result = array.Select(b => b.IsBsonDocument ? BH.Engine.Serialiser.Convert.FromBson(b.AsBsonDocument) : BH.Engine.Serialiser.Convert.FromJson(b.ToString())).ToList(); + return true; + } + catch + { + return false; + } } - return output; + return false; } } } + diff --git a/File_Adapter/FileAdapter.cs b/File_Adapter/FileAdapter.cs new file mode 100644 index 0000000..f8c3da3 --- /dev/null +++ b/File_Adapter/FileAdapter.cs @@ -0,0 +1,134 @@ +/* + * This file is part of the Buildings and Habitats object Model (BHoM) + * Copyright (c) 2015 - 2020, the respective contributors. All rights reserved. + * + * Each contributor holds copyright over their respective contributions. + * The project versioning (Git) records all such contribution source information. + * + * + * The BHoM is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3.0 of the License, or + * (at your option) any later version. + * + * The BHoM is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this code. If not, see . + */ + +using BH.Adapter; +using BH.Engine.Reflection; +using BH.oM.Base; +using BH.oM.Data.Requests; +using BH.oM.Reflection.Attributes; +using System.Collections.Generic; +using System.ComponentModel; +using System.IO; +using System.IO.Abstractions; +using System.Linq; + +namespace BH.Adapter.File +{ + public partial class FileAdapter : BHoMAdapter + { + /***************************************************/ + /**** Constructors ****/ + /***************************************************/ + + [Description("Initialises the File_Adapter without a target location. Allows to target multiple files. Target file locations will have to be specified in the Adapter Action.")] + public FileAdapter() + { + // By default, if they exist already, the files to be created are wiped out and then re-created. + this.m_AdapterSettings.DefaultPushType = oM.Adapter.PushType.UpdateOrCreateOnly; + } + + [Description("Initialises the File_Adapter with a target location.")] + [Input("defaultFilepath", "Default filePath, including file extension. " + + "\nWhen Pushing, this is used for pushing objects that are not BHoM `File` or `Directory`." + + "\nWhen Pulling, if no request is specified, a FileContentRequest is automatically generated with this location." + + "\nBy default this is `C:\\temp\\Filing_Adapter-objects.json`.")] + [PreviousVersion("4.0", "BH.Adapter.Filing.FilingAdapter(System.String)")] + public FileAdapter(string targetLocation) + { + Init(targetLocation); + } + + [PreviousVersion("4.0", "BH.Adapter.FileAdapter.FileAdapter(System.String, System.String)")] + public FileAdapter(string folder, string fileName) + { + if (folder?.Count() > 2 && folder?.ElementAt(1) != ':') + folder = Path.Combine(@"C:\ProgramData\BHoM\DataSets", folder); + + string location = Path.Combine(folder, fileName); + + Init(location); + } + + /***************************************************/ + /**** Private Fields ****/ + /***************************************************/ + + private bool m_Push_enableDeleteWarning = true; + private bool m_Remove_enableDeleteWarning = true; + private bool m_Remove_enableDeleteAlert = true; + private bool m_Execute_enableWarning = true; + private string m_defaultFilePath = null; + + + /***************************************************/ + /**** Private Methods ****/ + /***************************************************/ + + // Initialisation method for when the File Adapter is instantiated with a location. + private bool Init(string location) + { + if (string.IsNullOrWhiteSpace(location)) + { + BH.Engine.Reflection.Compute.RecordError("Please specifiy a valid target location."); + return true; + } + + m_defaultFilePath = location; + + if (!ProcessExtension(ref m_defaultFilePath)) + return false; + + BH.Engine.Reflection.Compute.RecordNote($"The adapter will always target the input location `{location}`." + + $"\nTo target multiple Files, use the {this.GetType().Name} constructor with no input."); + + // By default, the objects are appendend to the file if it exists already. + this.m_AdapterSettings.DefaultPushType = oM.Adapter.PushType.CreateOnly; + + return true; + } + + /***************************************************/ + + // Checks on the file extension. + private bool ProcessExtension(ref string filePath) + { + string ext = Path.GetExtension(filePath); + + if (!Path.HasExtension(m_defaultFilePath)) + { + Engine.Reflection.Compute.RecordNote($"No extension specified in the FileName input. Defaulting to .json."); + ext = ".json"; + filePath += ext; + } + + if (ext != ".json") + { + Engine.Reflection.Compute.RecordError($"File_Adapter currently supports only .json extension type.\nSpecified file extension is `{ext}`."); + return false; + } + + return true; + } + + /***************************************************/ + } +} diff --git a/Filing_Adapter/Filing_Adapter.csproj b/File_Adapter/File_Adapter.csproj similarity index 90% rename from Filing_Adapter/Filing_Adapter.csproj rename to File_Adapter/File_Adapter.csproj index 9d7c53e..1540a05 100644 --- a/Filing_Adapter/Filing_Adapter.csproj +++ b/File_Adapter/File_Adapter.csproj @@ -7,8 +7,8 @@ {9FF48041-B1F9-4C39-9629-9DF1E0B48C97} Library Properties - BH.Adapter.Filing - Filing_Adapter + BH.Adapter.File + File_Adapter v4.6.1 512 @@ -58,6 +58,12 @@ C:\ProgramData\BHoM\Assemblies\Data_oM.dll False + + C:\ProgramData\BHoM\Assemblies\Diffing_Engine.dll + + + C:\ProgramData\BHoM\Assemblies\Diffing_oM.dll + ..\packages\Microsoft.Bcl.AsyncInterfaces.1.1.0\lib\net461\Microsoft.Bcl.AsyncInterfaces.dll False @@ -67,6 +73,9 @@ ..\packages\MongoDB.Bson.2.7.2\lib\net45\MongoDB.Bson.dll False + + ..\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll + C:\ProgramData\BHoM\Assemblies\Reflection_Engine.dll False @@ -123,6 +132,7 @@ + @@ -134,7 +144,6 @@ - @@ -145,26 +154,26 @@ - + + - + {d0b2a7e0-1d68-42a6-b699-8bb648d50932} - Filing_Engine + File_Engine False - + {d344dcf0-788d-4e0a-8596-70199a080619} - Filing_oM + File_oM False - xcopy "$(TargetDir)$(TargetFileName)" "C:\ProgramData\BHoM\Assemblies" /Y diff --git a/Filing_Adapter/Methods/AddExtraData.cs b/File_Adapter/Methods/AddExtraData.cs similarity index 88% rename from Filing_Adapter/Methods/AddExtraData.cs rename to File_Adapter/Methods/AddExtraData.cs index f24afd9..6cc17f0 100644 --- a/Filing_Adapter/Methods/AddExtraData.cs +++ b/File_Adapter/Methods/AddExtraData.cs @@ -27,18 +27,18 @@ using System.Linq; using BH.Engine.Serialiser; using BH.oM.Adapter; -using BH.Engine.Adapters.Filing; -using BH.oM.Adapters.Filing; +using BH.Engine.Adapters.File; +using BH.oM.Adapters.File; -namespace BH.Adapter.Filing +namespace BH.Adapter.File { - public partial class FilingAdapter + public partial class FileAdapter { /***************************************************/ /**** Private Methods ****/ /***************************************************/ - private static void AddAuthor(oM.Adapters.Filing.IFSContainer retrievedFile) + private static void AddAuthor(oM.Adapters.File.IFSContainer retrievedFile) { string fullPath = retrievedFile.IFullPath(); @@ -61,7 +61,7 @@ private static void AddAuthor(oM.Adapters.Filing.IFSContainer retrievedFile) /***************************************************/ - private static void ReadAndAddContent(oM.Adapters.Filing.FSFile retrievedFile) + private static void ReadAndAddContent(oM.Adapters.File.FSFile retrievedFile) { string fullPath = retrievedFile.IFullPath(); @@ -71,7 +71,7 @@ private static void ReadAndAddContent(oM.Adapters.Filing.FSFile retrievedFile) /***************************************************/ - private static void AddContent(oM.Adapters.Filing.FSDirectory retrievedDir) + private static void AddContent(oM.Adapters.File.FSDirectory retrievedDir) { string fullPath = retrievedDir.IFullPath(); diff --git a/Filing_Adapter/Methods/CreateFSDirectory.cs b/File_Adapter/Methods/CreateFSDirectory.cs similarity index 90% rename from Filing_Adapter/Methods/CreateFSDirectory.cs rename to File_Adapter/Methods/CreateFSDirectory.cs index 48c5d05..1abf05d 100644 --- a/Filing_Adapter/Methods/CreateFSDirectory.cs +++ b/File_Adapter/Methods/CreateFSDirectory.cs @@ -28,11 +28,11 @@ using System.Text; using System.Threading.Tasks; using System.IO; -using BH.oM.Adapters.Filing; +using BH.oM.Adapters.File; using System.ComponentModel; using BH.oM.Reflection.Attributes; -namespace BH.Engine.Adapters.Filing +namespace BH.Engine.Adapters.File { public static partial class Create { @@ -44,7 +44,7 @@ public static partial class Create [Input("directoryName", "Name of the directory.")] [Input("content", "The content of the file.")] [Description("Creates a oM.Adapters.Filing.File object.")] - public static oM.Adapters.Filing.FSDirectory FSDirectory(string dirFullPath) + public static oM.Adapters.File.FSDirectory FSDirectory(string dirFullPath) { if (Path.HasExtension(dirFullPath)) { @@ -60,7 +60,7 @@ public static oM.Adapters.Filing.FSDirectory FSDirectory(string dirFullPath) [Input("directoryName", "Name of the directory.")] [Input("content", "The content of the file.")] [Description("Creates a oM.Adapters.Filing.File object.")] - public static oM.Adapters.Filing.FSDirectory FSDirectory(oM.Adapters.Filing.FSDirectory parentDirectory, string directoryName) + public static oM.Adapters.File.FSDirectory FSDirectory(oM.Adapters.File.FSDirectory parentDirectory, string directoryName) { if (Path.HasExtension(directoryName)) { @@ -68,7 +68,7 @@ public static oM.Adapters.Filing.FSDirectory FSDirectory(oM.Adapters.Filing.FSDi return null; } - return new oM.Adapters.Filing.FSDirectory() + return new oM.Adapters.File.FSDirectory() { ParentDirectory = parentDirectory, Name = directoryName, diff --git a/Filing_Adapter/Methods/CreateFSFile.cs b/File_Adapter/Methods/CreateFSFile.cs similarity index 94% rename from Filing_Adapter/Methods/CreateFSFile.cs rename to File_Adapter/Methods/CreateFSFile.cs index 7ad361a..ad2378a 100644 --- a/Filing_Adapter/Methods/CreateFSFile.cs +++ b/File_Adapter/Methods/CreateFSFile.cs @@ -28,13 +28,13 @@ using System.Text; using System.Threading.Tasks; using System.IO; -using BH.oM.Adapters.Filing; +using BH.oM.Adapters.File; using System.ComponentModel; using BH.oM.Reflection.Attributes; -namespace BH.Adapter.Filing +namespace BH.Adapter.File { - public partial class FilingAdapter + public partial class FileAdapter { /*******************************************/ /**** Methods ****/ @@ -52,7 +52,7 @@ public static FSFile CreateFSFile(FSDirectory parentDirectory, string fullFileNa return null; } - return new oM.Adapters.Filing.FSFile() + return new oM.Adapters.File.FSFile() { ParentDirectory = parentDirectory, Name = fullFileName, diff --git a/Filing_Adapter/Methods/WalkDirectories.cs b/File_Adapter/Methods/WalkDirectories.cs similarity index 74% rename from Filing_Adapter/Methods/WalkDirectories.cs rename to File_Adapter/Methods/WalkDirectories.cs index 60ed43d..a963303 100644 --- a/Filing_Adapter/Methods/WalkDirectories.cs +++ b/File_Adapter/Methods/WalkDirectories.cs @@ -26,17 +26,18 @@ using System.IO; using System.Linq; using BH.oM.Adapter; -using BH.Engine.Adapters.Filing; -using BH.oM.Adapters.Filing; +using BH.Engine.Adapters.File; +using BH.oM.Adapters.File; using System.Text.RegularExpressions; +using System.Management.Automation; -namespace BH.Adapter.Filing +namespace BH.Adapter.File { - public partial class FilingAdapter + public partial class FileAdapter { private void WalkDirectories(List files, List dirs, FileDirRequest fdr, ref int filesCount, ref int dirsCount, - bool inclHidFiles = false, bool inclSysFiles = false) + bool inclHidFiles = false, bool inclSysFiles = false, WildcardPattern wildcardPattern = null) { // Recursion stop condition. if (fdr.MaxNesting == 0) @@ -49,21 +50,22 @@ private void WalkDirectories(List files, List dirs, FileDir return; } - Regex regex = null; - bool hasRegex = Query.TryGetRegexFromPath(fdr.Location, out regex); - bool pointsToSingleFile = Path.HasExtension(fdr.Location) && !hasRegex; - System.IO.DirectoryInfo selectedDir = new System.IO.DirectoryInfo(fdr.Location.IFullPath()); System.IO.DirectoryInfo[] dirArray = new System.IO.DirectoryInfo[] { }; - if (!Path.HasExtension(selectedDir.FullName)) // If the location points to a directory, populate the list of folders there. + // Check if the location points to a single file. + // To point to a single file, the location must not be a wildcard (therefore wildcardPattern must be null) + // and it must have an extension. + bool isSingleFile = Path.HasExtension(selectedDir.FullName) && wildcardPattern == null; + + if (!isSingleFile) // If the location points to a directory, populate the list of folders there. dirArray = selectedDir.GetDirectories(); - else // if the location points to a file, the selected directory is its parent. + else // if the location points to a single file, the selected directory is its parent. selectedDir = new System.IO.DirectoryInfo(Path.GetDirectoryName(selectedDir.FullName)); foreach (System.IO.DirectoryInfo di in dirArray) { - oM.Adapters.Filing.FSDirectory bhomDir = ReadDirectory(di.FullName, inclHidFiles, inclSysFiles); + oM.Adapters.File.FSDirectory bhomDir = ReadDirectory(di.FullName, inclHidFiles, inclSysFiles); if (bhomDir == null) continue; @@ -72,7 +74,8 @@ private void WalkDirectories(List files, List dirs, FileDir if (fdr.Exclusions != null && fdr.Exclusions.Contains(bhomDir)) continue; - if (fdr.IncludeDirectories) + if (fdr.IncludeDirectories && wildcardPattern == null) + { if (fdr.SortOrder != SortOrder.Default || !MaxItemsReached(fdr.MaxDirectories, dirsCount)) { // The limit in number of item retrieved in WalkDirectories applies only if there is no sortOrder applied. @@ -82,32 +85,37 @@ private void WalkDirectories(List files, List dirs, FileDir if (fdr.Exclusions != null && fdr.Exclusions.Contains(bhomDir)) continue; - // Check Regex matches - if (!regex?.IsMatch(bhomDir.Name) ?? false) - continue; + // Check Wildcard matches - DISABLED: only allow wildcards in filename. Too complicated otherwise. + //if (!wildcardPattern?.IsMatch(bhomDir.Name) ?? false) + // continue; dirs.Add(bhomDir); dirsCount += 1; } + } + // Recurse if requested, and if the limits are not exceeded. - if (fdr.SearchSubdirectories == true && MaxItemsReached(fdr.MaxFiles, filesCount, fdr.MaxDirectories, dirsCount)) + if (fdr.SearchSubdirectories == true && !MaxItemsReached(fdr.MaxFiles, filesCount, fdr.MaxDirectories, dirsCount)) { FileDirRequest fdrRecurse = BH.Engine.Base.Query.ShallowClone(fdr); fdrRecurse.Location = bhomDir.IFullPath(); fdrRecurse.MaxNesting -= 1; - WalkDirectories(files, dirs, fdrRecurse, ref filesCount, ref dirsCount, inclHidFiles, inclSysFiles); + WalkDirectories(files, dirs, fdrRecurse, ref filesCount, ref dirsCount, inclHidFiles, inclSysFiles, wildcardPattern); } } if (fdr.IncludeFiles) { - System.IO.FileInfo[] fileInfos = new System.IO.FileInfo[] { }; + System.IO.FileInfo[] fileInfos = new System.IO.FileInfo[1]; try { - fileInfos = selectedDir.GetFiles("*.*"); + if (isSingleFile) + fileInfos[0] = new FileInfo(fdr.Location.IFullPath()); + else + fileInfos = selectedDir.GetFiles("*.*"); } // This is thrown if one of the files requires permissions greater than the application provides. catch (UnauthorizedAccessException e) @@ -127,23 +135,14 @@ private void WalkDirectories(List files, List dirs, FileDir if (fdr.Exclusions != null && fdr.Exclusions.Contains(fi.ToFiling())) continue; - // If the path points to a single file, continue only if fileName matches the specified name - if (pointsToSingleFile && fi.Name != Path.GetFileName(fdr.Location)) - continue; - - // Check Regex matches - if (!regex?.IsMatch(fi.Name) ?? false) - continue; - - // If the path was erroneously recognised as a regex that matches, - // check that at least the retrieved filename contains the location's filename. - if (regex == null && !fi.Name.Contains(Path.GetFileName(fdr.Location))) + // Check Wildcard matches + if (!wildcardPattern?.IsMatch(fi.Name) ?? false) continue; // When reading the file, do not retrieve content. // Content must be retrieved after WalkDirectories has run. // This is because additional filtering might be done later. - oM.Adapters.Filing.FSFile omFile = ReadFile(fi.FullName, false, inclHidFiles, inclSysFiles); + oM.Adapters.File.FSFile omFile = ReadFile(fi.FullName, false, inclHidFiles, inclSysFiles); if (omFile != null) { @@ -166,7 +165,7 @@ private bool MaxItemsReached(int maxItems, int retrievedItemsCount) private bool MaxItemsReached(int maxFiles, int retrievedFilesCount, int maxDirs, int retrivedDirsCount) { - return !MaxItemsReached(maxFiles, retrievedFilesCount) && !MaxItemsReached(maxDirs, retrivedDirsCount); + return MaxItemsReached(maxFiles, retrievedFilesCount) || MaxItemsReached(maxDirs, retrivedDirsCount); } } } diff --git a/Filing_Adapter/Properties/AssemblyInfo.cs b/File_Adapter/Properties/AssemblyInfo.cs similarity index 100% rename from Filing_Adapter/Properties/AssemblyInfo.cs rename to File_Adapter/Properties/AssemblyInfo.cs diff --git a/File_Adapter/Versioning_40.json b/File_Adapter/Versioning_40.json new file mode 100644 index 0000000..fbf09a8 --- /dev/null +++ b/File_Adapter/Versioning_40.json @@ -0,0 +1,19 @@ +{ + "Namespace": { + "ToNew": { + "BH.Adapter.FileAdapter": "BH.Adapter.File", + "BH.Adapter.Filing": "BH.Adapter.File" + }, + "ToOld": { + "BH.Adapter.File": "BH.Adapter.FileAdapter" + } + }, + "Type": { + "ToNew": { + "BH.Adapter.FileAdapter.FileAdapter": "BH.Adapter.File.FileAdapter" + }, + "ToOld": { + "BH.Adapter.File.FileAdapter": "BH.Adapter.FileAdapter.FileAdapter" + } + } +} diff --git a/Filing_Adapter/app.config b/File_Adapter/app.config similarity index 100% rename from Filing_Adapter/app.config rename to File_Adapter/app.config diff --git a/Filing_Adapter/packages.config b/File_Adapter/packages.config similarity index 93% rename from Filing_Adapter/packages.config rename to File_Adapter/packages.config index 2cc9040..95e03c2 100644 --- a/Filing_Adapter/packages.config +++ b/File_Adapter/packages.config @@ -3,6 +3,7 @@ + diff --git a/Filing_Engine/Compute/CreateFolders.cs b/File_Engine/Compute/CreateFolders.cs similarity index 93% rename from Filing_Engine/Compute/CreateFolders.cs rename to File_Engine/Compute/CreateFolders.cs index 00f4e6b..7a6395c 100644 --- a/Filing_Engine/Compute/CreateFolders.cs +++ b/File_Engine/Compute/CreateFolders.cs @@ -28,12 +28,12 @@ using System.Text; using System.Threading.Tasks; -namespace BH.Engine.Adapters.Filing +namespace BH.Engine.Adapters.File { public static partial class Compute { [Description("Creates Directories and subdirectories for the specified path, if they do not exist. " + - "E.g. `C:\folder2\folder1` will create both folder2 and folder1 if they do not exist.")] + "E.g. `C:\\folder2\\folder1` will create both folder2 and folder1 if they do not exist.")] public static void CreateFolders(string parentFolder, bool active = false) { if (active) diff --git a/Filing_Engine/Compute/DirectorySize.cs b/File_Engine/Compute/DirectorySize.cs similarity index 95% rename from Filing_Engine/Compute/DirectorySize.cs rename to File_Engine/Compute/DirectorySize.cs index f9e3cdb..c72aa68 100644 --- a/Filing_Engine/Compute/DirectorySize.cs +++ b/File_Engine/Compute/DirectorySize.cs @@ -28,12 +28,12 @@ using System.Text; using System.Threading.Tasks; -namespace BH.Engine.Adapters.Filing +namespace BH.Engine.Adapters.File { public static partial class Compute { [Description("Returns the size of the directory. The calculation might take some time.")] - public static long DirectorySize(BH.oM.Adapters.Filing.FSDirectory directory) + public static long DirectorySize(BH.oM.Adapters.File.FSDirectory directory) { return DirectorySize(directory.FromFiling()); } diff --git a/File_Engine/Compute/NewFilenameIfExists.cs b/File_Engine/Compute/NewFilenameIfExists.cs new file mode 100644 index 0000000..0d5f5e6 --- /dev/null +++ b/File_Engine/Compute/NewFilenameIfExists.cs @@ -0,0 +1,70 @@ +/* + * This file is part of the Buildings and Habitats object Model (BHoM) + * Copyright (c) 2015 - 2020, the respective contributors. All rights reserved. + * + * Each contributor holds copyright over their respective contributions. + * The project versioning (Git) records all such contribution source information. + * + * + * The BHoM is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3.0 of the License, or + * (at your option) any later version. + * + * The BHoM is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this code. If not, see . + */ + +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BH.Engine.Adapters.File +{ + public static partial class Compute + { + [Description("If the targetPath points to a file that exists, return the same filepath with appended `- Copy (i)`, " + + "where `i` is the first index pointing to a non existing file.")] + public static string NewFilenameIfExists(string targetPath) + { + int i = 0; + do + { + string copyFileName = Path.GetFileNameWithoutExtension(targetPath); + + string copyStr = $" - Copy"; + + if (copyFileName.Substring(copyFileName.Length - copyStr.Length - 4).Contains($" - Copy (")) + { + copyFileName = copyFileName.Remove(copyFileName.Length - copyStr.Length - 4) + $" - Copy ({i})"; + } + + if (copyFileName.EndsWith(copyStr)) + copyFileName = copyFileName.Replace(copyStr, $" - Copy ({i})"); + + if (copyFileName.EndsWith(" - Copy (0)")) + copyFileName.Replace(" - Copy (0)", copyStr); + + if (!copyFileName.Substring(copyFileName.Length - copyStr.Length - 4).Contains($" - Copy")) + { + copyFileName += $" - Copy"; + } + + targetPath = Path.Combine(Path.GetDirectoryName(targetPath), copyFileName + Path.GetExtension(targetPath)); + i++; + } + while (System.IO.File.Exists(targetPath)); + + return targetPath; + } + } +} diff --git a/Filing_Engine/Convert/FromFiling/FSDirectory.cs b/File_Engine/Convert/FromFiling/FSDirectory.cs similarity index 95% rename from Filing_Engine/Convert/FromFiling/FSDirectory.cs rename to File_Engine/Convert/FromFiling/FSDirectory.cs index 4961c97..08235f0 100644 --- a/Filing_Engine/Convert/FromFiling/FSDirectory.cs +++ b/File_Engine/Convert/FromFiling/FSDirectory.cs @@ -20,7 +20,7 @@ * along with this code. If not, see . */ -using BH.oM.Adapters.Filing; +using BH.oM.Adapters.File; using BH.oM.Reflection.Attributes; using System; using System.Collections.Generic; @@ -30,7 +30,7 @@ using System.Text; using System.Threading.Tasks; -namespace BH.Engine.Adapters.Filing +namespace BH.Engine.Adapters.File { public static partial class Convert { @@ -40,7 +40,7 @@ public static partial class Convert [Description("Converts the provided Directory into a System.IO.DirectoryInfo." + "\nAny `Content` property is lost in this conversion.")] - public static DirectoryInfo FromFiling(this oM.Adapters.Filing.FSDirectory directory) + public static DirectoryInfo FromFiling(this oM.Adapters.File.FSDirectory directory) { return new DirectoryInfo(directory.IFullPath()); } diff --git a/Filing_Engine/Convert/FromFiling/FSFile.cs b/File_Engine/Convert/FromFiling/FSFile.cs similarity index 93% rename from Filing_Engine/Convert/FromFiling/FSFile.cs rename to File_Engine/Convert/FromFiling/FSFile.cs index 5a77577..a5be40b 100644 --- a/Filing_Engine/Convert/FromFiling/FSFile.cs +++ b/File_Engine/Convert/FromFiling/FSFile.cs @@ -20,7 +20,7 @@ * along with this code. If not, see . */ -using BH.oM.Adapters.Filing; +using BH.oM.Adapters.File; using BH.oM.Reflection.Attributes; using System; using System.Collections.Generic; @@ -30,7 +30,7 @@ using System.Text; using System.Threading.Tasks; -namespace BH.Engine.Adapters.Filing +namespace BH.Engine.Adapters.File { public static partial class Convert { @@ -40,7 +40,7 @@ public static partial class Convert [Description("Converts the provided File into a System.IO.FileInfo." + "\nAny `Content` property is lost in this conversion.")] - public static FileInfo FromFiling(this oM.Adapters.Filing.FSFile file) + public static FileInfo FromFiling(this oM.Adapters.File.FSFile file) { return new FileInfo(file.IFullPath()); } diff --git a/Filing_Engine/Convert/ToFileRequest.cs b/File_Engine/Convert/ToFileRequest.cs similarity index 93% rename from Filing_Engine/Convert/ToFileRequest.cs rename to File_Engine/Convert/ToFileRequest.cs index f338136..2c73482 100644 --- a/Filing_Engine/Convert/ToFileRequest.cs +++ b/File_Engine/Convert/ToFileRequest.cs @@ -20,7 +20,7 @@ * along with this code. If not, see . */ -using BH.oM.Adapters.Filing; +using BH.oM.Adapters.File; using BH.oM.Reflection.Attributes; using System; using System.Collections.Generic; @@ -30,7 +30,7 @@ using System.Text; using System.Threading.Tasks; -namespace BH.Engine.Adapters.Filing +namespace BH.Engine.Adapters.File { public static partial class Convert { @@ -38,7 +38,7 @@ public static partial class Convert /*** Methods ***/ /***************************************************/ - public static oM.Adapters.Filing.FileRequest ToFileRequest(this FileDirRequest fdr) + public static oM.Adapters.File.FileRequest ToFileRequest(this FileDirRequest fdr) { return new FileRequest() { diff --git a/Filing_Engine/Convert/ToFiling/FSDirectory.cs b/File_Engine/Convert/ToFiling/FSDirectory.cs similarity index 91% rename from Filing_Engine/Convert/ToFiling/FSDirectory.cs rename to File_Engine/Convert/ToFiling/FSDirectory.cs index 4efc065..df9dac8 100644 --- a/Filing_Engine/Convert/ToFiling/FSDirectory.cs +++ b/File_Engine/Convert/ToFiling/FSDirectory.cs @@ -20,7 +20,7 @@ * along with this code. If not, see . */ -using BH.oM.Adapters.Filing; +using BH.oM.Adapters.File; using BH.oM.Reflection.Attributes; using System; using System.Collections.Generic; @@ -30,7 +30,7 @@ using System.Text; using System.Threading.Tasks; -namespace BH.Engine.Adapters.Filing +namespace BH.Engine.Adapters.File { public static partial class Convert { @@ -40,11 +40,11 @@ public static partial class Convert [Description("Converts the provided DirectoryInfo into a BH.oM.Adapters.Filing.Directory." + "\nTo populate its `Content` property you need to pull the Directory.")] - public static oM.Adapters.Filing.FSDirectory ToFiling(this DirectoryInfo di) + public static oM.Adapters.File.FSDirectory ToFiling(this DirectoryInfo di) { if (di == null) return null; - oM.Adapters.Filing.FSDirectory bd = new oM.Adapters.Filing.FSDirectory(); + oM.Adapters.File.FSDirectory bd = new oM.Adapters.File.FSDirectory(); bd.ParentDirectory = di.Parent.ToFiling(); bd.Name = di.Name; diff --git a/Filing_Engine/Convert/ToFiling/FSFile.cs b/File_Engine/Convert/ToFiling/FSFile.cs similarity index 92% rename from Filing_Engine/Convert/ToFiling/FSFile.cs rename to File_Engine/Convert/ToFiling/FSFile.cs index 0ef4ea1..79d2557 100644 --- a/Filing_Engine/Convert/ToFiling/FSFile.cs +++ b/File_Engine/Convert/ToFiling/FSFile.cs @@ -20,7 +20,7 @@ * along with this code. If not, see . */ -using BH.oM.Adapters.Filing; +using BH.oM.Adapters.File; using BH.oM.Reflection.Attributes; using System; using System.Collections.Generic; @@ -30,7 +30,7 @@ using System.Text; using System.Threading.Tasks; -namespace BH.Engine.Adapters.Filing +namespace BH.Engine.Adapters.File { public static partial class Convert { @@ -40,11 +40,11 @@ public static partial class Convert [Description("Converts the provided FileInfo into a BH.oM.Adapters.Filing.File." + "\nTo populate its `Content` property you need to pull the file.")] - public static oM.Adapters.Filing.FSFile ToFiling(this FileInfo fi) + public static oM.Adapters.File.FSFile ToFiling(this FileInfo fi) { if (fi == null) return null; - oM.Adapters.Filing.FSFile bf = new oM.Adapters.Filing.FSFile(); + oM.Adapters.File.FSFile bf = new oM.Adapters.File.FSFile(); bf.ParentDirectory = fi.Directory.ToFiling(); bf.Name = fi.Name; diff --git a/Filing_Engine/Convert/ToFiling/IContainer.cs b/File_Engine/Convert/ToFiling/IContainer.cs similarity index 86% rename from Filing_Engine/Convert/ToFiling/IContainer.cs rename to File_Engine/Convert/ToFiling/IContainer.cs index ea867ba..8298567 100644 --- a/Filing_Engine/Convert/ToFiling/IContainer.cs +++ b/File_Engine/Convert/ToFiling/IContainer.cs @@ -20,7 +20,7 @@ * along with this code. If not, see . */ -using BH.oM.Adapters.Filing; +using BH.oM.Adapters.File; using BH.oM.Reflection.Attributes; using System; using System.Collections.Generic; @@ -30,13 +30,13 @@ using System.Text; using System.Threading.Tasks; -namespace BH.Engine.Adapters.Filing +namespace BH.Engine.Adapters.File { public static partial class Convert { - public static oM.Adapters.Filing.IFSContainer ToFiling(this oM.Adapters.Filing.IContainer iContainer) + public static oM.Adapters.File.IFSContainer ToFiling(this oM.Adapters.File.IContainer iContainer) { - oM.Adapters.Filing.IFSContainer fscont = (iContainer as ILocatableResource).ToFiling(); + oM.Adapters.File.IFSContainer fscont = (iContainer as ILocatableResource).ToFiling(); fscont.Content = iContainer.Content; diff --git a/Filing_Engine/Convert/ToFiling/ILocatableResource.cs b/File_Engine/Convert/ToFiling/ILocatableResource.cs similarity index 94% rename from Filing_Engine/Convert/ToFiling/ILocatableResource.cs rename to File_Engine/Convert/ToFiling/ILocatableResource.cs index 788254d..84d5d13 100644 --- a/Filing_Engine/Convert/ToFiling/ILocatableResource.cs +++ b/File_Engine/Convert/ToFiling/ILocatableResource.cs @@ -20,7 +20,7 @@ * along with this code. If not, see . */ -using BH.oM.Adapters.Filing; +using BH.oM.Adapters.File; using BH.oM.Reflection.Attributes; using System; using System.Collections.Generic; @@ -30,12 +30,12 @@ using System.Text; using System.Threading.Tasks; -namespace BH.Engine.Adapters.Filing +namespace BH.Engine.Adapters.File { public static partial class Convert { [Description("Attempts conversion of a generic Resource to a File-system Resource.")] - public static oM.Adapters.Filing.IFSContainer ToFiling(this ILocatableResource iLocRes) + public static oM.Adapters.File.IFSContainer ToFiling(this ILocatableResource iLocRes) { try { diff --git a/Filing_Engine/Create/FileDirRequest.cs b/File_Engine/Create/FileDirRequest.cs similarity index 97% rename from Filing_Engine/Create/FileDirRequest.cs rename to File_Engine/Create/FileDirRequest.cs index 11302c2..75a491c 100644 --- a/Filing_Engine/Create/FileDirRequest.cs +++ b/File_Engine/Create/FileDirRequest.cs @@ -29,10 +29,10 @@ using System.Text; using System.Threading.Tasks; using System.IO; -using BH.oM.Adapters.Filing; +using BH.oM.Adapters.File; using System.ComponentModel; -namespace BH.Engine.Adapters.Filing +namespace BH.Engine.Adapters.File { public static partial class Create { diff --git a/Filing_Engine/Filing_Engine.csproj b/File_Engine/File_Engine.csproj similarity index 92% rename from Filing_Engine/Filing_Engine.csproj rename to File_Engine/File_Engine.csproj index de5d379..0928cfe 100644 --- a/Filing_Engine/Filing_Engine.csproj +++ b/File_Engine/File_Engine.csproj @@ -7,8 +7,8 @@ {D0B2A7E0-1D68-42A6-B699-8BB648D50932} Library Properties - BH.Engine.Adapters.Filing - Filing_Engine + BH.Engine.Adapters.File + File_Engine v4.6.1 512 @@ -62,6 +62,7 @@ + @@ -69,6 +70,7 @@ + @@ -86,6 +88,7 @@ + @@ -101,13 +104,15 @@ - + {d344dcf0-788d-4e0a-8596-70199a080619} - Filing_oM + File_oM False - + + + diff --git a/Filing_Engine/Modify/AddContent.cs b/File_Engine/Modify/AddContent.cs similarity index 97% rename from Filing_Engine/Modify/AddContent.cs rename to File_Engine/Modify/AddContent.cs index 9d09e0e..8d7ed7d 100644 --- a/Filing_Engine/Modify/AddContent.cs +++ b/File_Engine/Modify/AddContent.cs @@ -20,7 +20,7 @@ * along with this code. If not, see . */ -using BH.oM.Adapters.Filing; +using BH.oM.Adapters.File; using BH.oM.Reflection.Attributes; using System; using System.Collections.Generic; @@ -31,7 +31,7 @@ using BH.Engine.Base; using BH.Engine.Reflection; -namespace BH.Engine.Adapters.Filing +namespace BH.Engine.Adapters.File { public static partial class Modify { diff --git a/Filing_Engine/Modify/ChangeDirectory.cs b/File_Engine/Modify/ChangeDirectory.cs similarity index 94% rename from Filing_Engine/Modify/ChangeDirectory.cs rename to File_Engine/Modify/ChangeDirectory.cs index 275a787..7480f40 100644 --- a/Filing_Engine/Modify/ChangeDirectory.cs +++ b/File_Engine/Modify/ChangeDirectory.cs @@ -20,7 +20,7 @@ * along with this code. If not, see . */ -using BH.oM.Adapters.Filing; +using BH.oM.Adapters.File; using BH.oM.Reflection.Attributes; using System; using System.Collections.Generic; @@ -29,7 +29,7 @@ using System.Text; using System.Threading.Tasks; -namespace BH.Engine.Adapters.Filing +namespace BH.Engine.Adapters.File { public static partial class Modify { @@ -41,7 +41,7 @@ public static partial class Modify [Input("file", "The file (or directory) to move.")] [Input("to", "The new parent Directory.")] [Output("The moved file object.")] - public static IFSContainer ChangeDirectory(this oM.Adapters.Filing.IFSContainer fileOrDir, oM.Adapters.Filing.FSDirectory to) + public static IFSContainer ChangeDirectory(this oM.Adapters.File.IFSContainer fileOrDir, oM.Adapters.File.FSDirectory to) { fileOrDir = BH.Engine.Base.Query.ShallowClone(fileOrDir); fileOrDir.ParentDirectory = to; diff --git a/Filing_Engine/Modify/NormalisePath.cs b/File_Engine/Modify/NormalisePath.cs similarity index 97% rename from Filing_Engine/Modify/NormalisePath.cs rename to File_Engine/Modify/NormalisePath.cs index ec2519f..d394f6f 100644 --- a/Filing_Engine/Modify/NormalisePath.cs +++ b/File_Engine/Modify/NormalisePath.cs @@ -20,7 +20,7 @@ * along with this code. If not, see . */ -using BH.oM.Adapters.Filing; +using BH.oM.Adapters.File; using BH.oM.Reflection.Attributes; using System; using System.Collections.Generic; @@ -30,7 +30,7 @@ using System.Text; using System.Threading.Tasks; -namespace BH.Engine.Adapters.Filing +namespace BH.Engine.Adapters.File { public static partial class Modify { diff --git a/File_Engine/Modify/ProcessFileDirRequest.cs b/File_Engine/Modify/ProcessFileDirRequest.cs new file mode 100644 index 0000000..8fd1401 --- /dev/null +++ b/File_Engine/Modify/ProcessFileDirRequest.cs @@ -0,0 +1,81 @@ +/* + * This file is part of the Buildings and Habitats object Model (BHoM) + * Copyright (c) 2015 - 2020, the respective contributors. All rights reserved. + * + * Each contributor holds copyright over their respective contributions. + * The project versioning (Git) records all such contribution source information. + * + * + * The BHoM is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3.0 of the License, or + * (at your option) any later version. + * + * The BHoM is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this code. If not, see . + */ + +using BH.oM.Adapters.File; +using BH.oM.Reflection.Attributes; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.IO; +using System.Linq; +using System.Management.Automation; +using System.Text; +using System.Threading.Tasks; + +namespace BH.Engine.Adapters.File +{ + public static partial class Modify + { + /***************************************************/ + /*** Methods ***/ + /***************************************************/ + + [Description("Get the contents of the file as a string, reading from its location.")] + [Input("file", "The file to get the contents of.")] + [Input("encoding", "The encoding to use to decode the data. If null (default) discovery will be attempted; defaults to UTF-8 if it can't be discovered.")] + [Output("The contents of the file.")] + public static bool ProcessFileDirRequest(this FileDirRequest fdr, out WildcardPattern wildcardPattern) + { + wildcardPattern = null; + + if (WildcardPattern.ContainsWildcardCharacters(fdr.Location)) + { + if (WildcardPattern.ContainsWildcardCharacters(fdr.Location)) + { + string allButLastSegment = fdr.Location.Remove(fdr.Location.Count() - Path.GetFileName(fdr.Location).Count()); + if (WildcardPattern.ContainsWildcardCharacters(allButLastSegment)) + { + BH.Engine.Reflection.Compute.RecordError("Wildcards are only allowed in the last segment of the path."); + return false; + } + else + wildcardPattern = new WildcardPattern(Path.GetFileName(fdr.Location)); + } + + if (fdr.IncludeDirectories) + { + BH.Engine.Reflection.Compute.RecordWarning($"The usage of Wildcards is limited to file retrievals: " + + $"\ncannot have `{nameof(FileDirRequest)}.{nameof(fdr.IncludeDirectories)}` set to true while a Wildcard is specified in the path." + + $"\nDefaulting `{nameof(fdr.IncludeDirectories)}` to false and continuing."); + fdr.IncludeDirectories = false; + } + + if (fdr.IncludeFileContents) + BH.Engine.Reflection.Compute.RecordNote($"Note that `{nameof(fdr.IncludeFileContents)}` works only for BHoM-serialized JSON files."); + } + + return true; + } + + /***************************************************/ + } +} diff --git a/Filing_Engine/Modify/RelativiseUserPath.cs b/File_Engine/Modify/RelativiseUserPath.cs similarity index 98% rename from Filing_Engine/Modify/RelativiseUserPath.cs rename to File_Engine/Modify/RelativiseUserPath.cs index b0846b2..79257c7 100644 --- a/Filing_Engine/Modify/RelativiseUserPath.cs +++ b/File_Engine/Modify/RelativiseUserPath.cs @@ -20,7 +20,7 @@ * along with this code. If not, see . */ -using BH.oM.Adapters.Filing; +using BH.oM.Adapters.File; using BH.oM.Reflection.Attributes; using System; using System.Collections.Generic; @@ -32,7 +32,7 @@ using BH.Engine.Reflection; using System.IO; -namespace BH.Engine.Adapters.Filing +namespace BH.Engine.Adapters.File { public static partial class Modify { diff --git a/Filing_Engine/Modify/RemoveContent.cs b/File_Engine/Modify/RemoveContent.cs similarity index 97% rename from Filing_Engine/Modify/RemoveContent.cs rename to File_Engine/Modify/RemoveContent.cs index 5bda24c..703b8cc 100644 --- a/Filing_Engine/Modify/RemoveContent.cs +++ b/File_Engine/Modify/RemoveContent.cs @@ -20,7 +20,7 @@ * along with this code. If not, see . */ -using BH.oM.Adapters.Filing; +using BH.oM.Adapters.File; using BH.oM.Reflection.Attributes; using System; using System.Collections.Generic; @@ -31,7 +31,7 @@ using BH.Engine.Base; using BH.Engine.Reflection; -namespace BH.Engine.Adapters.Filing +namespace BH.Engine.Adapters.File { public static partial class Modify { diff --git a/Filing_Engine/Modify/Rename.cs b/File_Engine/Modify/Rename.cs similarity index 93% rename from Filing_Engine/Modify/Rename.cs rename to File_Engine/Modify/Rename.cs index a5d8561..c66de34 100644 --- a/Filing_Engine/Modify/Rename.cs +++ b/File_Engine/Modify/Rename.cs @@ -20,7 +20,7 @@ * along with this code. If not, see . */ -using BH.oM.Adapters.Filing; +using BH.oM.Adapters.File; using BH.oM.Reflection.Attributes; using System; using System.Collections.Generic; @@ -29,7 +29,7 @@ using System.Text; using System.Threading.Tasks; -namespace BH.Engine.Adapters.Filing +namespace BH.Engine.Adapters.File { public static partial class Modify { @@ -41,7 +41,7 @@ public static partial class Modify [Input("file", "The file (or directory) to rename.")] [Input("name", "The new name.")] [Output("The moved file object.")] - public static IFSContainer IRename(this oM.Adapters.Filing.IFSContainer fileOrDir, string name) + public static IFSContainer IRename(this oM.Adapters.File.IFSContainer fileOrDir, string name) { fileOrDir = BH.Engine.Base.Query.ShallowClone(fileOrDir); return Rename(fileOrDir as dynamic, name); diff --git a/Filing_Engine/Objects/EqualityComparers/PathComparer.cs b/File_Engine/Objects/EqualityComparers/PathComparer.cs similarity index 96% rename from Filing_Engine/Objects/EqualityComparers/PathComparer.cs rename to File_Engine/Objects/EqualityComparers/PathComparer.cs index d4ff258..de2f402 100644 --- a/Filing_Engine/Objects/EqualityComparers/PathComparer.cs +++ b/File_Engine/Objects/EqualityComparers/PathComparer.cs @@ -20,14 +20,14 @@ * along with this code. If not, see . */ -using BH.oM.Adapters.Filing; +using BH.oM.Adapters.File; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -namespace BH.Engine.Adapters.Filing +namespace BH.Engine.Adapters.File { public class PathComparer : IEqualityComparer { diff --git a/Filing_Engine/Properties/AssemblyInfo.cs b/File_Engine/Properties/AssemblyInfo.cs similarity index 100% rename from Filing_Engine/Properties/AssemblyInfo.cs rename to File_Engine/Properties/AssemblyInfo.cs diff --git a/Filing_Engine/Query/Contents.cs b/File_Engine/Query/Contents.cs similarity index 98% rename from Filing_Engine/Query/Contents.cs rename to File_Engine/Query/Contents.cs index 1eaefab..dd48df4 100644 --- a/Filing_Engine/Query/Contents.cs +++ b/File_Engine/Query/Contents.cs @@ -20,7 +20,7 @@ * along with this code. If not, see . */ -using BH.oM.Adapters.Filing; +using BH.oM.Adapters.File; using BH.oM.Reflection.Attributes; using System; using System.Collections.Generic; @@ -29,7 +29,7 @@ using System.Text; using System.Threading.Tasks; -namespace BH.Engine.Adapters.Filing +namespace BH.Engine.Adapters.File { public static partial class Query { diff --git a/Filing_Engine/Query/Encoding.cs b/File_Engine/Query/Encoding.cs similarity index 98% rename from Filing_Engine/Query/Encoding.cs rename to File_Engine/Query/Encoding.cs index fd42a7e..d4dcec0 100644 --- a/Filing_Engine/Query/Encoding.cs +++ b/File_Engine/Query/Encoding.cs @@ -20,7 +20,7 @@ * along with this code. If not, see . */ -using BH.oM.Adapters.Filing; +using BH.oM.Adapters.File; using BH.oM.Reflection.Attributes; using System; using System.Collections.Generic; @@ -29,7 +29,7 @@ using System.Text; using System.Threading.Tasks; -namespace BH.Engine.Adapters.Filing +namespace BH.Engine.Adapters.File { public static partial class Query { diff --git a/Filing_Engine/Query/FullPath.cs b/File_Engine/Query/FullPath.cs similarity index 78% rename from Filing_Engine/Query/FullPath.cs rename to File_Engine/Query/FullPath.cs index daf402c..18de5e2 100644 --- a/Filing_Engine/Query/FullPath.cs +++ b/File_Engine/Query/FullPath.cs @@ -21,7 +21,7 @@ */ using BH.oM.Base; -using BH.oM.Adapters.Filing; +using BH.oM.Adapters.File; using BH.oM.Reflection.Attributes; using System; using System.Collections.Generic; @@ -31,7 +31,7 @@ using System.Text; using System.Threading.Tasks; -namespace BH.Engine.Adapters.Filing +namespace BH.Engine.Adapters.File { public static partial class Query { @@ -39,7 +39,8 @@ public static partial class Query /*** Methods ***/ /***************************************************/ - [Description("Get the full path.")] + [Description("Get the full path. " + + "If the input is a string path containing wildcard symbols, return only the upper portion of the path that doesn't have any.")] public static string IFullPath(this object obj) { return obj != null ? FullPath(obj as dynamic) ?? "" : ""; @@ -66,7 +67,15 @@ private static string FullPath(this ILocatableResource fdr) if (fdr?.Location == null) return null; - return Path.Combine(fdr.Location, string.IsNullOrWhiteSpace(fdr.Name) ? "" : fdr.Name); + string location = Path.Combine(fdr.Location, string.IsNullOrWhiteSpace(fdr.Name) ? "" : fdr.Name); + + if (location.Contains("/") && location.Contains("\\")) + { + // If the location has inconsistent separators, assume the format of local windows FileSystem. + location = location.Replace("/", "\\"); + } + + return location; } private static string FullPath(this string path) @@ -74,33 +83,26 @@ private static string FullPath(this string path) if (string.IsNullOrWhiteSpace(path)) return null; + path = path.Replace("/", "\\"); + FileInfo fi = null; DirectoryInfo di = null; - try + if (System.Management.Automation.WildcardPattern.ContainsWildcardCharacters(path)) { - // If using a Regex, this will throw an Exception. No other way to check for proper name. - di = new DirectoryInfo(path); - } - catch (ArgumentException e) - { - if (e.Message.Contains("Illegal characters")) - { - // If the illegal characters are in the filename, we're most probably using a Regex there. - // Extract only up to the parent directory. - path = path.Replace("/", "\\"); - path = string.Join("\\",path.Split('\\').Take(path.Split('\\').Length - 1)); - - di = new DirectoryInfo(path); - } + // If path contains wildcard chars, return only up to the parent folder that doesn't have any. + string allButLastSegment = path.Remove(path.Count() - Path.GetFileName(path).Count()); + return FullPath(allButLastSegment); } + di = new DirectoryInfo(path); + if (di?.Exists ?? false) return di.FullName; if (di != null && !di.Exists && !string.IsNullOrWhiteSpace(Path.GetFileName(path))) { - // If the full path does not exist but there is a FileName, we might be using a Regex in the FileName. + // If the full path does not exist but there is a FileName, we might be using a Wildcard in the FileName. // Extract only the directory part. di = new DirectoryInfo(Path.GetDirectoryName(path)); } @@ -119,7 +121,7 @@ private static string FullPath(this string path) if (fi?.Exists ?? false) return fi.FullName; - // If the following is true, we assume we're using a Regex. + // If the following is true, we assume we're using a Wildcard. if (!fi?.Exists ?? false && di != null && di.Exists) return di.FullName; @@ -134,7 +136,5 @@ private static string FullPath(object fileOrDir) } /***************************************************/ - - } } diff --git a/Filing_Engine/Query/IsAcyclic.cs b/File_Engine/Query/IsAcyclic.cs similarity index 97% rename from Filing_Engine/Query/IsAcyclic.cs rename to File_Engine/Query/IsAcyclic.cs index e052594..686a01f 100644 --- a/Filing_Engine/Query/IsAcyclic.cs +++ b/File_Engine/Query/IsAcyclic.cs @@ -20,7 +20,7 @@ * along with this code. If not, see . */ -using BH.oM.Adapters.Filing; +using BH.oM.Adapters.File; using BH.oM.Reflection.Attributes; using System; using System.Collections.Generic; @@ -29,7 +29,7 @@ using System.Text; using System.Threading.Tasks; -namespace BH.Engine.Adapters.Filing +namespace BH.Engine.Adapters.File { public static partial class Query { diff --git a/Filing_Engine/Query/IsExistingDir.cs b/File_Engine/Query/IsExistingDir.cs similarity index 97% rename from Filing_Engine/Query/IsExistingDir.cs rename to File_Engine/Query/IsExistingDir.cs index 5306096..7fc9969 100644 --- a/Filing_Engine/Query/IsExistingDir.cs +++ b/File_Engine/Query/IsExistingDir.cs @@ -20,7 +20,7 @@ * along with this code. If not, see . */ -using BH.oM.Adapters.Filing; +using BH.oM.Adapters.File; using BH.oM.Reflection.Attributes; using System; using System.Collections.Generic; @@ -30,7 +30,7 @@ using System.Text; using System.Threading.Tasks; -namespace BH.Engine.Adapters.Filing +namespace BH.Engine.Adapters.File { public static partial class Query { diff --git a/Filing_Engine/Query/IsExistingFile.cs b/File_Engine/Query/IsExistingFile.cs similarity index 97% rename from Filing_Engine/Query/IsExistingFile.cs rename to File_Engine/Query/IsExistingFile.cs index d332b26..431423d 100644 --- a/Filing_Engine/Query/IsExistingFile.cs +++ b/File_Engine/Query/IsExistingFile.cs @@ -20,7 +20,7 @@ * along with this code. If not, see . */ -using BH.oM.Adapters.Filing; +using BH.oM.Adapters.File; using BH.oM.Reflection.Attributes; using System; using System.Collections.Generic; @@ -30,7 +30,7 @@ using System.Text; using System.Threading.Tasks; -namespace BH.Engine.Adapters.Filing +namespace BH.Engine.Adapters.File { public static partial class Query { diff --git a/Filing_Engine/Query/NestingDepth.cs b/File_Engine/Query/NestingDepth.cs similarity index 94% rename from Filing_Engine/Query/NestingDepth.cs rename to File_Engine/Query/NestingDepth.cs index da23d8d..39916f1 100644 --- a/Filing_Engine/Query/NestingDepth.cs +++ b/File_Engine/Query/NestingDepth.cs @@ -20,7 +20,7 @@ * along with this code. If not, see . */ -using BH.oM.Adapters.Filing; +using BH.oM.Adapters.File; using BH.oM.Reflection.Attributes; using System; using System.Collections.Generic; @@ -29,7 +29,7 @@ using System.Text; using System.Threading.Tasks; -namespace BH.Engine.Adapters.Filing +namespace BH.Engine.Adapters.File { public static partial class Query { @@ -38,7 +38,7 @@ public static partial class Query /***************************************************/ [Description("Get the nesting depth of the input File or Directory, which is the total number of parent folders.")] - public static int NestingDepth(oM.Adapters.Filing.IFSInfo fileOrDir) + public static int NestingDepth(oM.Adapters.File.IFSInfo fileOrDir) { int count = 0; while (fileOrDir.ParentDirectory != null) diff --git a/Filing_Engine/Query/PathCombine.cs b/File_Engine/Query/PathCombine.cs similarity index 97% rename from Filing_Engine/Query/PathCombine.cs rename to File_Engine/Query/PathCombine.cs index f499164..85bd94a 100644 --- a/Filing_Engine/Query/PathCombine.cs +++ b/File_Engine/Query/PathCombine.cs @@ -21,7 +21,7 @@ */ using BH.oM.Base; -using BH.oM.Adapters.Filing; +using BH.oM.Adapters.File; using BH.oM.Reflection.Attributes; using System; using System.Collections.Generic; @@ -31,7 +31,7 @@ using System.Text; using System.Threading.Tasks; -namespace BH.Engine.Adapters.Filing +namespace BH.Engine.Adapters.File { public static partial class Query { diff --git a/Filing_Engine/Query/SortOrder.cs b/File_Engine/Query/SortOrder.cs similarity index 87% rename from Filing_Engine/Query/SortOrder.cs rename to File_Engine/Query/SortOrder.cs index 9e81b1a..f0840a1 100644 --- a/Filing_Engine/Query/SortOrder.cs +++ b/File_Engine/Query/SortOrder.cs @@ -20,7 +20,7 @@ * along with this code. If not, see . */ -using BH.oM.Adapters.Filing; +using BH.oM.Adapters.File; using BH.oM.Reflection.Attributes; using System; using System.Collections.Generic; @@ -29,7 +29,7 @@ using System.Text; using System.Threading.Tasks; -namespace BH.Engine.Adapters.Filing +namespace BH.Engine.Adapters.File { public static partial class Query { @@ -42,16 +42,16 @@ public static List SortOrder(this List resources, SortOrder so { IEnumerable output = resources.ToList(); - if (sortOrder == BH.oM.Adapters.Filing.SortOrder.ByName) + if (sortOrder == BH.oM.Adapters.File.SortOrder.ByName) output = output.OrderBy(x => x.Name); - if (sortOrder == BH.oM.Adapters.Filing.SortOrder.BySize) + if (sortOrder == BH.oM.Adapters.File.SortOrder.BySize) output = output.OrderBy(x => x.Size).Reverse(); - if (sortOrder == BH.oM.Adapters.Filing.SortOrder.ByCreationTime) + if (sortOrder == BH.oM.Adapters.File.SortOrder.ByCreationTime) output = output.OrderBy(x => x.CreationTimeUtc).Reverse(); - if (sortOrder == BH.oM.Adapters.Filing.SortOrder.ByLastModifiedTime) + if (sortOrder == BH.oM.Adapters.File.SortOrder.ByLastModifiedTime) output = output.OrderBy(x => x.ModifiedTimeUtc).Reverse(); return output.ToList(); diff --git a/Filing_Engine/Query/TryGetRegex.cs b/File_Engine/Query/TryGetRegex.cs similarity index 98% rename from Filing_Engine/Query/TryGetRegex.cs rename to File_Engine/Query/TryGetRegex.cs index 126bad7..df3557e 100644 --- a/Filing_Engine/Query/TryGetRegex.cs +++ b/File_Engine/Query/TryGetRegex.cs @@ -20,7 +20,7 @@ * along with this code. If not, see . */ -using BH.oM.Adapters.Filing; +using BH.oM.Adapters.File; using BH.oM.Reflection.Attributes; using System; using System.Collections.Generic; @@ -31,7 +31,7 @@ using System.Text.RegularExpressions; using System.Threading.Tasks; -namespace BH.Engine.Adapters.Filing +namespace BH.Engine.Adapters.File { public static partial class Query { diff --git a/File_Engine/Versioning_40.json b/File_Engine/Versioning_40.json new file mode 100644 index 0000000..177e0ed --- /dev/null +++ b/File_Engine/Versioning_40.json @@ -0,0 +1,10 @@ +{ + "Namespace": { + "ToNew": { + "BH.Engine.Adapters.Filing": "BH.Engine.Adapters.File" + }, + "ToOld": { + "BH.Engine.Adapters.File": "BH.Engine.Adapters.Filing" + } + } +} diff --git a/Filing_Engine/packages.config b/File_Engine/packages.config similarity index 100% rename from Filing_Engine/packages.config rename to File_Engine/packages.config diff --git a/Filing_Toolkit.sln b/File_Toolkit.sln similarity index 79% rename from Filing_Toolkit.sln rename to File_Toolkit.sln index 423b2d8..d3f21e9 100644 --- a/Filing_Toolkit.sln +++ b/File_Toolkit.sln @@ -3,11 +3,11 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 VisualStudioVersion = 15.0.28307.852 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Filing_Engine", "Filing_Engine\Filing_Engine.csproj", "{D0B2A7E0-1D68-42A6-B699-8BB648D50932}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "File_Adapter", "File_Adapter\File_Adapter.csproj", "{9FF48041-B1F9-4C39-9629-9DF1E0B48C97}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Filing_Adapter", "Filing_Adapter\Filing_Adapter.csproj", "{9FF48041-B1F9-4C39-9629-9DF1E0B48C97}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "File_Engine", "File_Engine\File_Engine.csproj", "{D0B2A7E0-1D68-42A6-B699-8BB648D50932}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Filing_oM", "Filing_oM\Filing_oM.csproj", "{D344DCF0-788D-4E0A-8596-70199A080619}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "File_oM", "File_oM\File_oM.csproj", "{D344DCF0-788D-4E0A-8596-70199A080619}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -15,14 +15,14 @@ Global Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {D0B2A7E0-1D68-42A6-B699-8BB648D50932}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {D0B2A7E0-1D68-42A6-B699-8BB648D50932}.Debug|Any CPU.Build.0 = Debug|Any CPU - {D0B2A7E0-1D68-42A6-B699-8BB648D50932}.Release|Any CPU.ActiveCfg = Release|Any CPU - {D0B2A7E0-1D68-42A6-B699-8BB648D50932}.Release|Any CPU.Build.0 = Release|Any CPU {9FF48041-B1F9-4C39-9629-9DF1E0B48C97}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {9FF48041-B1F9-4C39-9629-9DF1E0B48C97}.Debug|Any CPU.Build.0 = Debug|Any CPU {9FF48041-B1F9-4C39-9629-9DF1E0B48C97}.Release|Any CPU.ActiveCfg = Release|Any CPU {9FF48041-B1F9-4C39-9629-9DF1E0B48C97}.Release|Any CPU.Build.0 = Release|Any CPU + {D0B2A7E0-1D68-42A6-B699-8BB648D50932}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D0B2A7E0-1D68-42A6-B699-8BB648D50932}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D0B2A7E0-1D68-42A6-B699-8BB648D50932}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D0B2A7E0-1D68-42A6-B699-8BB648D50932}.Release|Any CPU.Build.0 = Release|Any CPU {D344DCF0-788D-4E0A-8596-70199A080619}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {D344DCF0-788D-4E0A-8596-70199A080619}.Debug|Any CPU.Build.0 = Debug|Any CPU {D344DCF0-788D-4E0A-8596-70199A080619}.Release|Any CPU.ActiveCfg = Release|Any CPU diff --git a/Filing_oM/Commands/CopyCommand.cs b/File_oM/Commands/CopyCommand.cs similarity index 98% rename from Filing_oM/Commands/CopyCommand.cs rename to File_oM/Commands/CopyCommand.cs index 1afc4b3..b65cf23 100644 --- a/Filing_oM/Commands/CopyCommand.cs +++ b/File_oM/Commands/CopyCommand.cs @@ -29,7 +29,7 @@ using System.Text; using System.Threading.Tasks; -namespace BH.oM.Adapters.Filing +namespace BH.oM.Adapters.File { public class CopyCommand : IMRCCommand { diff --git a/Filing_oM/Commands/IMRCCommand.cs b/File_oM/Commands/IMRCCommand.cs similarity index 98% rename from Filing_oM/Commands/IMRCCommand.cs rename to File_oM/Commands/IMRCCommand.cs index d5b08a0..30dede5 100644 --- a/Filing_oM/Commands/IMRCCommand.cs +++ b/File_oM/Commands/IMRCCommand.cs @@ -29,7 +29,7 @@ using System.Text; using System.Threading.Tasks; -namespace BH.oM.Adapters.Filing +namespace BH.oM.Adapters.File { [Description("Interface for Move, Rename and Copy commands.")] public interface IMRCCommand : IExecuteCommand diff --git a/Filing_oM/Commands/MoveCommand.cs b/File_oM/Commands/MoveCommand.cs similarity index 98% rename from Filing_oM/Commands/MoveCommand.cs rename to File_oM/Commands/MoveCommand.cs index a2ad974..7234c46 100644 --- a/Filing_oM/Commands/MoveCommand.cs +++ b/File_oM/Commands/MoveCommand.cs @@ -29,7 +29,7 @@ using System.Text; using System.Threading.Tasks; -namespace BH.oM.Adapters.Filing +namespace BH.oM.Adapters.File { public class MoveCommand : IMRCCommand { diff --git a/Filing_oM/Commands/RenameCommand.cs b/File_oM/Commands/RenameCommand.cs similarity index 98% rename from Filing_oM/Commands/RenameCommand.cs rename to File_oM/Commands/RenameCommand.cs index 0a34b55..dc73e9b 100644 --- a/Filing_oM/Commands/RenameCommand.cs +++ b/File_oM/Commands/RenameCommand.cs @@ -29,7 +29,7 @@ using System.Text; using System.Threading.Tasks; -namespace BH.oM.Adapters.Filing +namespace BH.oM.Adapters.File { public class RenameCommand : IMRCCommand { diff --git a/Filing_oM/Config/ExecuteConfig.cs b/File_oM/Config/ExecuteConfig.cs similarity index 98% rename from Filing_oM/Config/ExecuteConfig.cs rename to File_oM/Config/ExecuteConfig.cs index 69ee640..44b793b 100644 --- a/Filing_oM/Config/ExecuteConfig.cs +++ b/File_oM/Config/ExecuteConfig.cs @@ -29,7 +29,7 @@ using System.Text; using System.Threading.Tasks; -namespace BH.oM.Adapters.Filing +namespace BH.oM.Adapters.File { public class ExecuteConfig : ActionConfig { diff --git a/Filing_oM/Config/PullConfig.cs b/File_oM/Config/PullConfig.cs similarity index 98% rename from Filing_oM/Config/PullConfig.cs rename to File_oM/Config/PullConfig.cs index 04920ae..d7e8d9a 100644 --- a/Filing_oM/Config/PullConfig.cs +++ b/File_oM/Config/PullConfig.cs @@ -29,7 +29,7 @@ using System.Text; using System.Threading.Tasks; -namespace BH.oM.Adapters.Filing +namespace BH.oM.Adapters.File { public class PullConfig : ActionConfig { diff --git a/Filing_oM/Config/PushConfig.cs b/File_oM/Config/PushConfig.cs similarity index 88% rename from Filing_oM/Config/PushConfig.cs rename to File_oM/Config/PushConfig.cs index 07f9d3f..8837a2d 100644 --- a/Filing_oM/Config/PushConfig.cs +++ b/File_oM/Config/PushConfig.cs @@ -30,14 +30,10 @@ using System.Text; using System.Threading.Tasks; -namespace BH.oM.Adapters.Filing +namespace BH.oM.Adapters.File { public class PushConfig : ActionConfig { - [Description("When updating a File, set whether the input content should be appended to the existing or overwritten." + - "\nBy default is `false` (= the content of the File is entirely overwritten).")] - public bool AppendContent { get; set; } = false; - [Description("When serialising to JSON, use the Dataset serialization style." + "\nThis serializes the individual objects, and then concatenates the strings separating with a newline." + "\nThe obtained format is not valid JSON. You will need to deserialize each individual line." + diff --git a/Filing_oM/Config/RemoveConfig.cs b/File_oM/Config/RemoveConfig.cs similarity index 98% rename from Filing_oM/Config/RemoveConfig.cs rename to File_oM/Config/RemoveConfig.cs index 752c819..24ddb31 100644 --- a/Filing_oM/Config/RemoveConfig.cs +++ b/File_oM/Config/RemoveConfig.cs @@ -29,7 +29,7 @@ using System.Text; using System.Threading.Tasks; -namespace BH.oM.Adapters.Filing +namespace BH.oM.Adapters.File { public class RemoveConfig : ActionConfig { diff --git a/Filing_oM/Directory.cs b/File_oM/Directory.cs similarity index 93% rename from Filing_oM/Directory.cs rename to File_oM/Directory.cs index c954517..24d676c 100644 --- a/Filing_oM/Directory.cs +++ b/File_oM/Directory.cs @@ -30,7 +30,7 @@ using System.IO; using System.ComponentModel; -namespace BH.oM.Adapters.Filing +namespace BH.oM.Adapters.File { [Description("A Directory. It can include the content of the Directory.")] public class Directory : BHoMObject, IDirectory, ILocatableResource, IContainableResource @@ -47,5 +47,10 @@ public class Directory : BHoMObject, IDirectory, ILocatableResource, IContainabl [Description("The content of the Directory.")] public virtual List Content { get; set; } = new List(); + + public override string ToString() + { + return Path.Combine(this.Location ?? "", this.Name ?? ""); + } } } diff --git a/Filing_oM/FSDirectory.cs b/File_oM/FSDirectory.cs similarity index 99% rename from Filing_oM/FSDirectory.cs rename to File_oM/FSDirectory.cs index 2fb03c7..4912699 100644 --- a/Filing_oM/FSDirectory.cs +++ b/File_oM/FSDirectory.cs @@ -30,7 +30,7 @@ using System.IO; using System.ComponentModel; -namespace BH.oM.Adapters.Filing +namespace BH.oM.Adapters.File { [Description("A FileSystem-hosted Directory. It can include the content of the Directory.")] public class FSDirectory : BHoMObject, IFSContainer, IDirectory, ISizeableResource diff --git a/Filing_oM/FSFile.cs b/File_oM/FSFile.cs similarity index 99% rename from Filing_oM/FSFile.cs rename to File_oM/FSFile.cs index 7ca8f69..c624dfb 100644 --- a/Filing_oM/FSFile.cs +++ b/File_oM/FSFile.cs @@ -30,7 +30,7 @@ using System.IO; using System.ComponentModel; -namespace BH.oM.Adapters.Filing +namespace BH.oM.Adapters.File { [Description("A FileSystem-hosted File. It can include the content of the File.")] public class FSFile : BHoMObject, IFSContainer, IFile, ISizeableResource diff --git a/Filing_oM/File.cs b/File_oM/File.cs similarity index 93% rename from Filing_oM/File.cs rename to File_oM/File.cs index c22aa99..255b533 100644 --- a/Filing_oM/File.cs +++ b/File_oM/File.cs @@ -30,7 +30,7 @@ using System.IO; using System.ComponentModel; -namespace BH.oM.Adapters.Filing +namespace BH.oM.Adapters.File { [Description("A File. It can include the content of the File.")] public class File : BHoMObject, IFile, ILocatableResource, IContainableResource @@ -47,5 +47,10 @@ public class File : BHoMObject, IFile, ILocatableResource, IContainableResource [Description("The content of the file.")] public virtual List Content { get; set; } = new List(); + + public override string ToString() + { + return Path.Combine(this.Location ?? "", this.Name ?? ""); + } } } diff --git a/Filing_oM/Filing_oM.csproj b/File_oM/File_oM.csproj similarity index 96% rename from Filing_oM/Filing_oM.csproj rename to File_oM/File_oM.csproj index 961ad69..871745f 100644 --- a/Filing_oM/Filing_oM.csproj +++ b/File_oM/File_oM.csproj @@ -7,8 +7,8 @@ {D344DCF0-788D-4E0A-8596-70199A080619} Library Properties - BH.oM.Adapters.Filing - Filing_oM + BH.oM.Adapters.File + File_oM v4.6.1 512 @@ -96,7 +96,9 @@ - + + + diff --git a/Filing_oM/Interfaces/IContainableResource.cs b/File_oM/Interfaces/IContainableResource.cs similarity index 98% rename from Filing_oM/Interfaces/IContainableResource.cs rename to File_oM/Interfaces/IContainableResource.cs index e687b59..667bb6c 100644 --- a/Filing_oM/Interfaces/IContainableResource.cs +++ b/File_oM/Interfaces/IContainableResource.cs @@ -30,7 +30,7 @@ using System.Text; using System.Threading.Tasks; -namespace BH.oM.Adapters.Filing +namespace BH.oM.Adapters.File { [Description("Identifies a general data Resource, whether a File or a Directory or other, that can hold some content.")] public interface IContainableResource : IResource diff --git a/Filing_oM/Interfaces/IContainer.cs b/File_oM/Interfaces/IContainer.cs similarity index 98% rename from Filing_oM/Interfaces/IContainer.cs rename to File_oM/Interfaces/IContainer.cs index 1ebf727..b72e2cc 100644 --- a/Filing_oM/Interfaces/IContainer.cs +++ b/File_oM/Interfaces/IContainer.cs @@ -30,7 +30,7 @@ using System.Text; using System.Threading.Tasks; -namespace BH.oM.Adapters.Filing +namespace BH.oM.Adapters.File { [Description("Identifies a Resource (a File or Directory or other) that is locatable and holds some content.")] public interface IContainer : ILocatableResource, IContainableResource, IBHoMObject diff --git a/Filing_oM/Interfaces/IDirectory.cs b/File_oM/Interfaces/IDirectory.cs similarity index 98% rename from Filing_oM/Interfaces/IDirectory.cs rename to File_oM/Interfaces/IDirectory.cs index 1dfd300..da81a5c 100644 --- a/Filing_oM/Interfaces/IDirectory.cs +++ b/File_oM/Interfaces/IDirectory.cs @@ -30,7 +30,7 @@ using System.Text; using System.Threading.Tasks; -namespace BH.oM.Adapters.Filing +namespace BH.oM.Adapters.File { [Description("Identifies a Directory.")] public interface IDirectory : IResource diff --git a/Filing_oM/Interfaces/IFSContainer.cs b/File_oM/Interfaces/IFSContainer.cs similarity index 98% rename from Filing_oM/Interfaces/IFSContainer.cs rename to File_oM/Interfaces/IFSContainer.cs index 6d42255..b0fd9a4 100644 --- a/Filing_oM/Interfaces/IFSContainer.cs +++ b/File_oM/Interfaces/IFSContainer.cs @@ -30,7 +30,7 @@ using System.Text; using System.Threading.Tasks; -namespace BH.oM.Adapters.Filing +namespace BH.oM.Adapters.File { [Description("Identifies a FileSystem-hosted Resource (a File or Directory or other) that holds some content.")] public interface IFSContainer : IFSInfo, IContainableResource, IBHoMObject diff --git a/Filing_oM/Interfaces/IFSInfo.cs b/File_oM/Interfaces/IFSInfo.cs similarity index 98% rename from Filing_oM/Interfaces/IFSInfo.cs rename to File_oM/Interfaces/IFSInfo.cs index c159e8c..60067f5 100644 --- a/Filing_oM/Interfaces/IFSInfo.cs +++ b/File_oM/Interfaces/IFSInfo.cs @@ -30,7 +30,7 @@ using System.Text; using System.Threading.Tasks; -namespace BH.oM.Adapters.Filing +namespace BH.oM.Adapters.File { [Description("Identifies a FileSystem Resource with basic information attached." + "\nRehash of the .NET's base class 'FileSystemInfo' in BHoM flavour.")] diff --git a/Filing_oM/Interfaces/IFSResource.cs b/File_oM/Interfaces/IFSResource.cs similarity index 98% rename from Filing_oM/Interfaces/IFSResource.cs rename to File_oM/Interfaces/IFSResource.cs index f525465..b363f13 100644 --- a/Filing_oM/Interfaces/IFSResource.cs +++ b/File_oM/Interfaces/IFSResource.cs @@ -30,7 +30,7 @@ using System.Text; using System.Threading.Tasks; -namespace BH.oM.Adapters.Filing +namespace BH.oM.Adapters.File { [Description("Identifies a general data Resource, whether a File or a Directory or other, that resides on a File System.")] public interface IFSResource : IResource diff --git a/Filing_oM/Interfaces/IFile.cs b/File_oM/Interfaces/IFile.cs similarity index 98% rename from Filing_oM/Interfaces/IFile.cs rename to File_oM/Interfaces/IFile.cs index 99c1a8b..8539f31 100644 --- a/Filing_oM/Interfaces/IFile.cs +++ b/File_oM/Interfaces/IFile.cs @@ -30,7 +30,7 @@ using System.Text; using System.Threading.Tasks; -namespace BH.oM.Adapters.Filing +namespace BH.oM.Adapters.File { [Description("Identifies a File.")] public interface IFile : IResource diff --git a/Filing_oM/Interfaces/ILocatableResource.cs b/File_oM/Interfaces/ILocatableResource.cs similarity index 98% rename from Filing_oM/Interfaces/ILocatableResource.cs rename to File_oM/Interfaces/ILocatableResource.cs index 659edfb..97f645b 100644 --- a/Filing_oM/Interfaces/ILocatableResource.cs +++ b/File_oM/Interfaces/ILocatableResource.cs @@ -30,7 +30,7 @@ using System.Text; using System.Threading.Tasks; -namespace BH.oM.Adapters.Filing +namespace BH.oM.Adapters.File { [Description("Identifies a general data Resource, whether a File or a Directory or other, that can be found at a certain location.")] public interface ILocatableResource : IResource diff --git a/Filing_oM/Interfaces/IResource.cs b/File_oM/Interfaces/IResource.cs similarity index 98% rename from Filing_oM/Interfaces/IResource.cs rename to File_oM/Interfaces/IResource.cs index 60fea6f..7b13a4d 100644 --- a/Filing_oM/Interfaces/IResource.cs +++ b/File_oM/Interfaces/IResource.cs @@ -30,7 +30,7 @@ using System.Text; using System.Threading.Tasks; -namespace BH.oM.Adapters.Filing +namespace BH.oM.Adapters.File { [Description("Identifies a general data Resource, whether a File or a Directory or other.")] public interface IResource : IBHoMObject diff --git a/Filing_oM/Interfaces/ISizeableResource.cs b/File_oM/Interfaces/ISizeableResource.cs similarity index 98% rename from Filing_oM/Interfaces/ISizeableResource.cs rename to File_oM/Interfaces/ISizeableResource.cs index 3624234..5f96ca6 100644 --- a/Filing_oM/Interfaces/ISizeableResource.cs +++ b/File_oM/Interfaces/ISizeableResource.cs @@ -30,7 +30,7 @@ using System.Text; using System.Threading.Tasks; -namespace BH.oM.Adapters.Filing +namespace BH.oM.Adapters.File { [Description("Identifies a resource whose Size can be obtained.")] public interface ISizeableResource : IResource diff --git a/Filing_oM/Properties/AssemblyInfo.cs b/File_oM/Properties/AssemblyInfo.cs similarity index 100% rename from Filing_oM/Properties/AssemblyInfo.cs rename to File_oM/Properties/AssemblyInfo.cs diff --git a/Filing_oM/Requests/DirectoryRequest.cs b/File_oM/Requests/DirectoryRequest.cs similarity index 99% rename from Filing_oM/Requests/DirectoryRequest.cs rename to File_oM/Requests/DirectoryRequest.cs index b7c212b..17605b5 100644 --- a/Filing_oM/Requests/DirectoryRequest.cs +++ b/File_oM/Requests/DirectoryRequest.cs @@ -31,7 +31,7 @@ using System.ComponentModel; using BH.oM.Data.Requests; -namespace BH.oM.Adapters.Filing +namespace BH.oM.Adapters.File { [Description("Used to query Directories or Files.")] public class DirectoryRequest : IDirectoryRequest diff --git a/Filing_oM/Requests/FileContentRequest.cs b/File_oM/Requests/FileContentRequest.cs similarity index 98% rename from Filing_oM/Requests/FileContentRequest.cs rename to File_oM/Requests/FileContentRequest.cs index e9efa91..8d0e1f2 100644 --- a/Filing_oM/Requests/FileContentRequest.cs +++ b/File_oM/Requests/FileContentRequest.cs @@ -31,7 +31,7 @@ using System.ComponentModel; using BH.oM.Data.Requests; -namespace BH.oM.Adapters.Filing +namespace BH.oM.Adapters.File { [Description("Used to read contents of one or more files.")] public class FileContentRequest : IFilingRequest diff --git a/Filing_oM/Requests/FileDirRequest.cs b/File_oM/Requests/FileDirRequest.cs similarity index 99% rename from Filing_oM/Requests/FileDirRequest.cs rename to File_oM/Requests/FileDirRequest.cs index 12fb095..7b3d49c 100644 --- a/Filing_oM/Requests/FileDirRequest.cs +++ b/File_oM/Requests/FileDirRequest.cs @@ -31,7 +31,7 @@ using System.ComponentModel; using BH.oM.Data.Requests; -namespace BH.oM.Adapters.Filing +namespace BH.oM.Adapters.File { [Description("Used to query Directories or Files.")] public class FileDirRequest : IFileRequest, IDirectoryRequest diff --git a/Filing_oM/Requests/FileRequest.cs b/File_oM/Requests/FileRequest.cs similarity index 99% rename from Filing_oM/Requests/FileRequest.cs rename to File_oM/Requests/FileRequest.cs index 9152083..23e6e2b 100644 --- a/Filing_oM/Requests/FileRequest.cs +++ b/File_oM/Requests/FileRequest.cs @@ -31,7 +31,7 @@ using System.ComponentModel; using BH.oM.Data.Requests; -namespace BH.oM.Adapters.Filing +namespace BH.oM.Adapters.File { [Description("Used to query Files from a Parent directory.")] public class FileRequest : IFileRequest diff --git a/Filing_oM/Requests/IRemoveRequest.cs b/File_oM/Requests/IRemoveRequest.cs similarity index 98% rename from Filing_oM/Requests/IRemoveRequest.cs rename to File_oM/Requests/IRemoveRequest.cs index f61eedb..0c82183 100644 --- a/Filing_oM/Requests/IRemoveRequest.cs +++ b/File_oM/Requests/IRemoveRequest.cs @@ -31,7 +31,7 @@ using System.ComponentModel; using BH.oM.Data.Requests; -namespace BH.oM.Adapters.Filing +namespace BH.oM.Adapters.File { public class RemoveRequest : IRequest { diff --git a/Filing_oM/Requests/Interfaces/IDirectoryRequest.cs b/File_oM/Requests/Interfaces/IDirectoryRequest.cs similarity index 98% rename from Filing_oM/Requests/Interfaces/IDirectoryRequest.cs rename to File_oM/Requests/Interfaces/IDirectoryRequest.cs index ee66b40..8641aa5 100644 --- a/Filing_oM/Requests/Interfaces/IDirectoryRequest.cs +++ b/File_oM/Requests/Interfaces/IDirectoryRequest.cs @@ -31,7 +31,7 @@ using System.ComponentModel; using BH.oM.Data.Requests; -namespace BH.oM.Adapters.Filing +namespace BH.oM.Adapters.File { public interface IDirectoryRequest : ISortableRequest, IResourceRequest { diff --git a/Filing_oM/Requests/Interfaces/IFileRequest.cs b/File_oM/Requests/Interfaces/IFileRequest.cs similarity index 98% rename from Filing_oM/Requests/Interfaces/IFileRequest.cs rename to File_oM/Requests/Interfaces/IFileRequest.cs index 9b0c923..5768664 100644 --- a/Filing_oM/Requests/Interfaces/IFileRequest.cs +++ b/File_oM/Requests/Interfaces/IFileRequest.cs @@ -31,7 +31,7 @@ using System.ComponentModel; using BH.oM.Data.Requests; -namespace BH.oM.Adapters.Filing +namespace BH.oM.Adapters.File { public interface IFileRequest : ISortableRequest, IResourceRequest { diff --git a/Filing_oM/Requests/Interfaces/IFilingRequest.cs b/File_oM/Requests/Interfaces/IFilingRequest.cs similarity index 98% rename from Filing_oM/Requests/Interfaces/IFilingRequest.cs rename to File_oM/Requests/Interfaces/IFilingRequest.cs index 13a5de0..9011a84 100644 --- a/Filing_oM/Requests/Interfaces/IFilingRequest.cs +++ b/File_oM/Requests/Interfaces/IFilingRequest.cs @@ -31,7 +31,7 @@ using System.ComponentModel; using BH.oM.Data.Requests; -namespace BH.oM.Adapters.Filing +namespace BH.oM.Adapters.File { public interface IFilingRequest : IRequest { diff --git a/Filing_oM/Requests/Interfaces/IResourceRequest.cs b/File_oM/Requests/Interfaces/IResourceRequest.cs similarity index 98% rename from Filing_oM/Requests/Interfaces/IResourceRequest.cs rename to File_oM/Requests/Interfaces/IResourceRequest.cs index 950559e..433d17e 100644 --- a/Filing_oM/Requests/Interfaces/IResourceRequest.cs +++ b/File_oM/Requests/Interfaces/IResourceRequest.cs @@ -31,7 +31,7 @@ using System.ComponentModel; using BH.oM.Data.Requests; -namespace BH.oM.Adapters.Filing +namespace BH.oM.Adapters.File { public interface IResourceRequest : IRequest { diff --git a/Filing_oM/Requests/Interfaces/ISortableRequest.cs b/File_oM/Requests/Interfaces/ISortableRequest.cs similarity index 98% rename from Filing_oM/Requests/Interfaces/ISortableRequest.cs rename to File_oM/Requests/Interfaces/ISortableRequest.cs index 3c1996a..1b68dc2 100644 --- a/Filing_oM/Requests/Interfaces/ISortableRequest.cs +++ b/File_oM/Requests/Interfaces/ISortableRequest.cs @@ -31,7 +31,7 @@ using System.ComponentModel; using BH.oM.Data.Requests; -namespace BH.oM.Adapters.Filing +namespace BH.oM.Adapters.File { public interface ISortableRequest : IRequest { diff --git a/File_oM/Versioning_40.json b/File_oM/Versioning_40.json new file mode 100644 index 0000000..8b1c76a --- /dev/null +++ b/File_oM/Versioning_40.json @@ -0,0 +1,10 @@ +{ + "Namespace": { + "ToNew": { + "BH.oM.Adapters.Filing": "BH.oM.Adapters.File" + }, + "ToOld": { + "BH.oM.Adapters.File": "BH.oM.Adapters.Filing" + } + } +} diff --git a/Filing_oM/enums/Encodings.cs b/File_oM/enums/Encodings.cs similarity index 98% rename from Filing_oM/enums/Encodings.cs rename to File_oM/enums/Encodings.cs index 85144e2..cf7b8f1 100644 --- a/Filing_oM/enums/Encodings.cs +++ b/File_oM/enums/Encodings.cs @@ -26,7 +26,7 @@ using System.Text; using System.Threading.Tasks; -namespace BH.oM.Adapters.Filing +namespace BH.oM.Adapters.File { public enum Encodings { diff --git a/Filing_oM/enums/FileFormat.cs b/File_oM/enums/FileFormat.cs similarity index 98% rename from Filing_oM/enums/FileFormat.cs rename to File_oM/enums/FileFormat.cs index f2c1c10..a070a37 100644 --- a/Filing_oM/enums/FileFormat.cs +++ b/File_oM/enums/FileFormat.cs @@ -26,7 +26,7 @@ using System.Text; using System.Threading.Tasks; -namespace BH.oM.Adapters.Filing +namespace BH.oM.Adapters.File { public enum FileFormat { diff --git a/Filing_oM/enums/SortOrder.cs b/File_oM/enums/SortOrder.cs similarity index 98% rename from Filing_oM/enums/SortOrder.cs rename to File_oM/enums/SortOrder.cs index 22b677e..c15e0f1 100644 --- a/Filing_oM/enums/SortOrder.cs +++ b/File_oM/enums/SortOrder.cs @@ -26,7 +26,7 @@ using System.Text; using System.Threading.Tasks; -namespace BH.oM.Adapters.Filing +namespace BH.oM.Adapters.File { public enum SortOrder { diff --git a/Filing_Adapter/AdapterActions/Pull.cs b/Filing_Adapter/AdapterActions/Pull.cs deleted file mode 100644 index 6fb979a..0000000 --- a/Filing_Adapter/AdapterActions/Pull.cs +++ /dev/null @@ -1,74 +0,0 @@ -/* - * This file is part of the Buildings and Habitats object Model (BHoM) - * Copyright (c) 2015 - 2020, the respective contributors. All rights reserved. - * - * Each contributor holds copyright over their respective contributions. - * The project versioning (Git) records all such contribution source information. - * - * - * The BHoM is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3.0 of the License, or - * (at your option) any later version. - * - * The BHoM is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this code. If not, see . - */ - -using BH.Engine.Adapters.Filing; -using BH.Engine.Reflection; -using BH.oM.Adapter; -using BH.oM.Data.Requests; -using BH.oM.Adapters.Filing; -using System; -using System.Collections; -using System.Collections.Generic; -using System.IO; -using System.IO.Abstractions; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using BH.Engine.Base; - -namespace BH.Adapter.Filing -{ - public partial class FilingAdapter - { - /***************************************************/ - /**** Methods *****/ - /***************************************************/ - - public override IEnumerable Pull(IRequest request, PullType pullType = PullType.AdapterDefault, ActionConfig actionConfig = null) - { - PullConfig pullConfig = actionConfig as PullConfig ?? new PullConfig(); - - // Usual needed check onto badly automated FilterRequest - FilterRequest fr = request as FilterRequest; - if (fr != null && !fr.Equalities.Any() && string.IsNullOrWhiteSpace(fr.Tag) && fr.Type == null) - request = null; - - if (request == null && string.IsNullOrWhiteSpace(m_defaultFilePath)) - { - BH.Engine.Reflection.Compute.RecordWarning($"Please specify a valid Request, or a Default Filepath in the Filing_Adapter."); - return new List(); - } - - IRequest ifr = request; - - if (request == null && !string.IsNullOrWhiteSpace(m_defaultFilePath)) - { - ifr = new FileContentRequest() { File = m_defaultFilePath }; - } - - return Read(ifr as dynamic, pullConfig); - } - - /***************************************************/ - - } -} diff --git a/Filing_Adapter/AdapterActions/Push.cs b/Filing_Adapter/AdapterActions/Push.cs deleted file mode 100644 index f20e3be..0000000 --- a/Filing_Adapter/AdapterActions/Push.cs +++ /dev/null @@ -1,104 +0,0 @@ -/* - * This file is part of the Buildings and Habitats object Model (BHoM) - * Copyright (c) 2015 - 2020, the respective contributors. All rights reserved. - * - * Each contributor holds copyright over their respective contributions. - * The project versioning (Git) records all such contribution source information. - * - * - * The BHoM is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3.0 of the License, or - * (at your option) any later version. - * - * The BHoM is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this code. If not, see . - */ - -using BH.Engine.Adapters.Filing; -using BH.Engine.Reflection; -using BH.oM.Adapter; -using BH.oM.Data.Requests; -using BH.oM.Adapters.Filing; -using System; -using System.Collections; -using System.Collections.Generic; -using System.IO; -using System.IO.Abstractions; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using BH.Engine.Base; -using BH.oM.Base; - -namespace BH.Adapter.Filing -{ - public partial class FilingAdapter - { - /***************************************************/ - /**** Methods *****/ - /***************************************************/ - - public override List Push(IEnumerable objects, string tag = "", PushType pushType = PushType.AdapterDefault, ActionConfig actionConfig = null) - { - PushConfig pushConfig = actionConfig as PushConfig ?? new PushConfig(); - - if (pushType == PushType.AdapterDefault) - pushType = m_AdapterSettings.DefaultPushType; - - if (pushType == PushType.FullPush) - { - BH.Engine.Reflection.Compute.RecordWarning($"The specified {nameof(PushType)} {nameof(PushType.FullPush)} is not supported."); - return new List(); - } - - if (pushType == PushType.DeleteThenCreate) - if (m_Push_enableDeleteWarning && !pushConfig.DisableWarnings) - { - BH.Engine.Reflection.Compute.RecordWarning($"You have selected the {nameof(PushType)} {nameof(PushType.DeleteThenCreate)}." + - $"\nThis has the potential of deleting files and folders with their contents." + - $"\nMake sure that you know what you are doing. This warning will not be repeated." + - $"\nRe-enable the component to continue."); - - m_Push_enableDeleteWarning = false; - - return new List(); - } - - List createdFiles = new List(); - - List filesOrDirs = objects.OfType().ToList(); - List remainder = objects.Where(v => !filesOrDirs.Contains(v)).ToList(); - - if (remainder.Any()) - { - BH.Engine.Reflection.Compute.RecordNote($"Objects that are not Files or Directories " + - $"\nwill be Pushed using the Filing Adapter default filePath: `{m_defaultFilePath}`."); - string defaultDirectory = Path.GetDirectoryName(m_defaultFilePath); - string defaultFileName = Path.GetFileName(m_defaultFilePath); - - FSFile file = CreateFSFile(defaultDirectory, defaultFileName, remainder); - filesOrDirs.Add(file); - } - - foreach (IResource fileOrDir in filesOrDirs) - { - if (fileOrDir == null) - continue; - - IResource created = Create(fileOrDir as dynamic, pushType, pushConfig); - createdFiles.Add(created); - } - - return createdFiles.OfType().ToList(); - } - - /***************************************************/ - - } -} diff --git a/Filing_Adapter/CRUD/Create/CreateBSON.cs b/Filing_Adapter/CRUD/Create/CreateBSON.cs deleted file mode 100644 index 2418fdf..0000000 --- a/Filing_Adapter/CRUD/Create/CreateBSON.cs +++ /dev/null @@ -1,119 +0,0 @@ -/* - * This file is part of the Buildings and Habitats object Model (BHoM) - * Copyright (c) 2015 - 2020, the respective contributors. All rights reserved. - * - * Each contributor holds copyright over their respective contributions. - * The project versioning (Git) records all such contribution source information. - * - * - * The BHoM is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3.0 of the License, or - * (at your option) any later version. - * - * The BHoM is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this code. If not, see . - */ - -using BH.oM.Base; -using MongoDB.Bson.Serialization; -using MongoDB.Bson.IO; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using BH.Engine.Serialiser; -using BH.oM.Adapter; -using BH.Engine.Adapters.Filing; -using BH.oM.Adapters.Filing; - -namespace BH.Adapter.Filing -{ - public partial class FilingAdapter : BHoMAdapter - { - /***************************************************/ - /**** Public Methods ****/ - /***************************************************/ - - public static IFSContainer CreateBson(FSFile file, PushType pushType, PushConfig pushConfig) - { - string fullPath = file.IFullPath(); - bool fileExisted = System.IO.File.Exists(fullPath); - - bool filecreated = true; - - try - { - if (pushType == PushType.DeleteThenCreate) - { - if (fileExisted) - System.IO.File.Delete(fullPath); - - WriteBsonWithStream(file, fullPath, FileMode.CreateNew); - } - else if ((pushType == PushType.UpdateOnly && fileExisted) || pushType == PushType.UpdateOrCreateOnly) - { - if (fileExisted && pushConfig.AppendContent) - { - // Append the text to existing file. - WriteBsonWithStream(file, fullPath, FileMode.Append); - } - else - { - // Override existing file. - WriteBsonWithStream(file, fullPath, FileMode.Create); - } - } - else if (pushType == PushType.CreateOnly) - { - // Create only if file didn't exist. Do not touch existing ones. - if (!fileExisted) - WriteBsonWithStream(file, fullPath, FileMode.CreateNew); - else - BH.Engine.Reflection.Compute.RecordNote($"File {fullPath} was not created as it existed already (Pushtype {pushType.ToString()} was specified)."); - } - else - { - BH.Engine.Reflection.Compute.RecordWarning($"The specified Pushtype of {pushType.ToString()} is not supported for .bson files."); - filecreated = false; - } - - } - catch (Exception e) - { - BH.Engine.Reflection.Compute.RecordError(e.Message); - } - - if (filecreated) - { - System.IO.FileInfo fileinfo = new System.IO.FileInfo(fullPath); - oM.Adapters.Filing.FSFile createdFile = fileinfo.ToFiling(); - createdFile.Content = file.Content; - - return createdFile; - } - - BH.Engine.Reflection.Compute.RecordError($"Could not create {file.ToString()}"); - return null; - } - - /***************************************************/ - - public static void WriteBsonWithStream(oM.Adapters.Filing.FSFile file, string fullPath, FileMode fileMode) - { - FileStream stream = new FileStream(fullPath, FileMode.CreateNew); - var writer = new BsonBinaryWriter(stream); - BsonSerializer.Serialize(writer, typeof(object), file); - stream.Flush(); - stream.Close(); - } - - /***************************************************/ - } -} - diff --git a/Filing_Adapter/CRUD/Create/CreateJson.cs b/Filing_Adapter/CRUD/Create/CreateJson.cs deleted file mode 100644 index 46579dc..0000000 --- a/Filing_Adapter/CRUD/Create/CreateJson.cs +++ /dev/null @@ -1,162 +0,0 @@ -/* - * This file is part of the Buildings and Habitats object Model (BHoM) - * Copyright (c) 2015 - 2020, the respective contributors. All rights reserved. - * - * Each contributor holds copyright over their respective contributions. - * The project versioning (Git) records all such contribution source information. - * - * - * The BHoM is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3.0 of the License, or - * (at your option) any later version. - * - * The BHoM is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this code. If not, see . - */ - -using BH.oM.Base; -using MongoDB.Bson.Serialization; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using BH.Engine.Serialiser; -using BH.oM.Adapter; -using BH.Engine.Adapters.Filing; -using BH.oM.Adapters.Filing; -using System.Text.Json; - -namespace BH.Adapter.Filing -{ - public partial class FilingAdapter : BHoMAdapter - { - /***************************************************/ - /**** Public Methods ****/ - /***************************************************/ - - public static FSFile CreateJson(FSFile file, PushType pushType, PushConfig pushConfig) - { - string fullPath = file.IFullPath(); - bool fileExisted = System.IO.File.Exists(fullPath); - - // Put together all of the file content. - List allLines = new List(); - string json = ""; - - if (file.Content != null) - { - if (!pushConfig.UseDatasetSerialization) - { - allLines.AddRange(file.Content.Where(c => c != null).Select(obj => obj.ToJson() + ",")); - - // Remove the trailing comma if there is only one element. - if (string.IsNullOrWhiteSpace(allLines.ElementAtOrDefault(1)) && !string.IsNullOrWhiteSpace(allLines.FirstOrDefault())) - allLines[0] = allLines[0].Remove(allLines.FirstOrDefault().Length - 1); - - // Join all between square brackets to make a valid JSON array. - json = String.Join(Environment.NewLine, allLines); - json = "[" + json + "]"; - } - else - { - // Use the non-JSON compliant "Dataset" serialization style. - // This is a newline-separated concatenation of individual JSON-serialized objects. - allLines.AddRange(file.Content.Where(c => c != null).Select(obj => obj.ToJson())); - json = String.Join(Environment.NewLine, allLines); - } - } - - bool filecreated = true; - try - { - if (pushType == PushType.DeleteThenCreate) - { - if (fileExisted) - System.IO.File.Delete(fullPath); - - System.IO.File.WriteAllText(fullPath, json); - } - else if ((pushType == PushType.UpdateOnly && fileExisted) || pushType == PushType.UpdateOrCreateOnly) - { - if (fileExisted && pushConfig.AppendContent) - { - // Append the text to existing file. - System.IO.File.AppendAllText(fullPath, json); - } - else - { - // Overwrite existing file. - System.IO.File.WriteAllText(fullPath, json); - } - } - else if (pushType == PushType.CreateOnly || pushType == PushType.CreateNonExisting) - { - // Create only if file didn't exist. Do not touch existing ones. - if (!fileExisted) - System.IO.File.WriteAllText(fullPath, json); - else - BH.Engine.Reflection.Compute.RecordNote($"File {fullPath} was not created as it existed already (Pushtype {pushType.ToString()} was specified)."); - } - else - { - BH.Engine.Reflection.Compute.RecordWarning($"The specified Pushtype of {pushType.ToString()} is not supported for .json files."); - filecreated = false; - } - } - catch (Exception e) - { - BH.Engine.Reflection.Compute.RecordError(e.Message); - } - - if (filecreated) - { - System.IO.FileInfo fileinfo = new System.IO.FileInfo(fullPath); - oM.Adapters.Filing.FSFile createdFile = fileinfo.ToFiling(); - createdFile.Content = file.Content; - - return createdFile; - } - - BH.Engine.Reflection.Compute.RecordError($"Could not create {file.ToString()}"); - return null; - } - - - /***************************************************/ - /**** Private Methods ****/ - /***************************************************/ - - private static string BeautifyJson(string jsonString) - { - JsonDocument doc = JsonDocument.Parse( - jsonString, - new JsonDocumentOptions - { - AllowTrailingCommas = true - } - ); - MemoryStream memoryStream = new MemoryStream(); - using ( - var utf8JsonWriter = new Utf8JsonWriter( - memoryStream, - new JsonWriterOptions - { - Indented = true - } - ) - ) - { - doc.WriteTo(utf8JsonWriter); - } - return new System.Text.UTF8Encoding() - .GetString(memoryStream.ToArray()); - } - } -} - diff --git a/Filing_Adapter/FilingAdapter.cs b/Filing_Adapter/FilingAdapter.cs deleted file mode 100644 index 47ede49..0000000 --- a/Filing_Adapter/FilingAdapter.cs +++ /dev/null @@ -1,55 +0,0 @@ -/* - * This file is part of the Buildings and Habitats object Model (BHoM) - * Copyright (c) 2015 - 2020, the respective contributors. All rights reserved. - * - * Each contributor holds copyright over their respective contributions. - * The project versioning (Git) records all such contribution source information. - * - * - * The BHoM is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3.0 of the License, or - * (at your option) any later version. - * - * The BHoM is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this code. If not, see . - */ - -using BH.Adapter; -using BH.Engine.Reflection; -using BH.oM.Base; -using BH.oM.Data.Requests; -using BH.oM.Reflection.Attributes; -using System.Collections.Generic; -using System.ComponentModel; -using System.IO.Abstractions; - -namespace BH.Adapter.Filing -{ - public partial class FilingAdapter : BHoMAdapter - { - [Input("defaultFilepath", "Default filePath, including file extension. " + - "\nWhen Pushing, this is used for pushing objects that are not BHoM `File` or `Directory`." + - "\nWhen Pulling, if no request is specified, a FileContentRequest is automatically generated with this location." + - "\nBy default this is `C:/temp/Filing_Adapter-objects.json`.")] - [PreviousVersion("3.3", "BH.Adapter.Filing.FilingAdapter()")] - public FilingAdapter(string defaultLocation = "C:/temp/Filing_Adapter-objects.json") - { - m_defaultFilePath = defaultLocation; - - // By default, if they exist already, the files to be created are wiped out and then re-created. - this.m_AdapterSettings.DefaultPushType = oM.Adapter.PushType.UpdateOrCreateOnly; - } - - private bool m_Push_enableDeleteWarning = true; - private bool m_Remove_enableDeleteWarning = true; - private bool m_Remove_enableDeleteAlert = true; - private bool m_Execute_enableWarning = true; - private string m_defaultFilePath = null; - } -}