private bool PrefixTest(Dictionary <string, ITreeNode> loaded, IVirtualPath path) { foreach (string prefix in loaded.Keys) { if (path.Name.StartsWith(prefix + ".")) { var obj = loaded[prefix].GetValidAppObjects().FirstWithType <FileAppObject>(); if (obj != null) { if (path is IVirtualFile) { if (obj.SubFiles != null) { obj.SubFiles.Add((IVirtualFile)path); } } if (path is IVirtualFolder) { if (obj.SubFolders != null) { obj.SubFolders.Add((IVirtualFolder)path); } } } return(true); } } return(false); }
/// <summary> /// Reads the binary file. /// </summary> /// <param name="path">The virtual path.</param> /// <returns></returns> /// <exception cref="bS.Sked2.Structure.Base.Exceptions.StorageException">Error reading file '{path.RealPath}'. - 12</exception> /// <exception cref="StorageException">Error reading file '{path.RealPath}'. - 12</exception> public byte[] FileReadBinary(IVirtualPath path) { try { return(workSpaceFileSystem.ReadAllBytes(path.RealPath)); } catch (Exception e) { throw new StorageException(logger, $"Error reading file '{path.RealPath}'.", e, 12); } }
/// <summary> /// Folders the exists. /// </summary> /// <param name="path">The path.</param> /// <returns></returns> /// <exception cref="bS.Sked2.Structure.Base.Exceptions.StorageException">Error checking folder '{path.RealPath}'. - 23</exception> /// <exception cref="StorageException">Error checking folder '{path.RealPath}'. - 23</exception> public bool FolderExists(IVirtualPath path) { try { return(workSpaceFileSystem.DirectoryExists(path.RealPath)); } catch (Exception e) { throw new StorageException(logger, $"Error checking folder '{path.RealPath}'.", e, 23); } }
/// <summary> /// Folders the enumerate paths. /// </summary> /// <param name="path">The path.</param> /// <param name="searchOption">The search option.</param> /// <param name="searchPattern">The search pattern.</param> /// <returns></returns> /// <exception cref="bS.Sked2.Structure.Base.Exceptions.StorageException">Error checking folder '{path.RealPath}'. - 22</exception> /// <exception cref="StorageException">Error checking folder '{path.RealPath}'. - 22</exception> public IVirtualPath[] FolderEnumeratePaths(IVirtualPath path, System.IO.SearchOption searchOption, string searchPattern = "*") { try { return(workSpaceFileSystem.EnumeratePaths(path.RealPath, searchPattern, searchOption).Select(p => new VirtualPath(p.ToAbsolute().ToString())).ToArray()); } catch (Exception e) { throw new StorageException(logger, $"Error checking folder '{path.RealPath}'.", e, 22); } }
/// <summary> /// Folders the move. /// </summary> /// <param name="source">The source.</param> /// <param name="target">The target.</param> /// <param name="overwrite">if set to <c>true</c> [overwrite].</param> /// <exception cref="bS.Sked2.Structure.Base.Exceptions.StorageException">Error moving folder from '{source.RealPath}' to '{target.RealPath}'. - 24</exception> /// <exception cref="StorageException">Error moving folder from '{source.RealPath}' to '{target.RealPath}'. - 24</exception> public void FolderMove(IVirtualPath source, IVirtualPath target, bool overwrite = false) { try { workSpaceFileSystem.MoveDirectory(source.RealPath, target.RealPath); } catch (Exception e) { throw new StorageException(logger, $"Error moving folder from '{source.RealPath}' to '{target.RealPath}'.", e, 24); } }
/// <summary> /// Files the exists. /// </summary> /// <param name="path">The path.</param> /// <returns></returns> /// <exception cref="bS.Sked2.Structure.Base.Exceptions.StorageException">Error checking if file '{path.RealPath}' exists. - 5</exception> /// <exception cref="StorageException">Error checking if file '{path.RealPath}' exists. - 5</exception> public bool FileExists(IVirtualPath path) { try { return(workSpaceFileSystem.FileExists(path.RealPath)); } catch (Exception e) { throw new StorageException(logger, $"Error checking if file '{path.RealPath}' exists.", e, 5); } }
/// <summary> /// Folders the create. /// </summary> /// <param name="path">The path.</param> /// <exception cref="bS.Sked2.Structure.Base.Exceptions.StorageException">Error creating directory '{path.RealPath}'. - 20</exception> /// <exception cref="StorageException">Error creating directory '{path.RealPath}'. - 20</exception> public void FolderCreate(IVirtualPath path) { try { workSpaceFileSystem.CreateDirectory(path.RealPath); } catch (Exception e) { throw new StorageException(logger, $"Error creating directory '{path.RealPath}'.", e, 20); } }
/// <summary> /// Reads the text file. /// </summary> /// <param name="path">The virtual path.</param> /// <returns></returns> /// <exception cref="bS.Sked2.Structure.Base.Exceptions.StorageException">Error reading file '{path.RealPath}'. - 13</exception> /// <exception cref="StorageException">Error reading file '{path.RealPath}'. - 13</exception> public string FileReadText(IVirtualPath path) { try { return(workSpaceFileSystem.ReadAllText(path.RealPath)); } catch (Exception e) { throw new StorageException(logger, $"Error reading file '{path.RealPath}'.", e, 13); } }
/// <summary> /// Save a bit array in a Binary File /// </summary> /// <param name="binaryContent">Content of the binary.</param> /// <param name="path">The path.</param> /// <exception cref="bS.Sked2.Structure.Base.Exceptions.StorageException">Error writing file '{path.RealPath}'. - 14</exception> /// <exception cref="StorageException">Error writing file '{path.RealPath}'. - 14</exception> public void FileSave(byte[] binaryContent, IVirtualPath path) { try { workSpaceFileSystem.WriteAllBytes(path.RealPath, binaryContent); } catch (Exception e) { throw new StorageException(logger, $"Error writing file '{path.RealPath}'.", e, 14); } }
/// <summary> /// Save a string in a Text File /// </summary> /// <param name="textContent">Content of the text.</param> /// <param name="path">The path.</param> /// <exception cref="bS.Sked2.Structure.Base.Exceptions.StorageException">Error writing file '{path.RealPath}'. - 15</exception> /// <exception cref="StorageException">Error writing file '{path.RealPath}'. - 15</exception> public void FileSave(string textContent, IVirtualPath path) { try { workSpaceFileSystem.WriteAllText(path.RealPath, textContent); } catch (Exception e) { throw new StorageException(logger, $"Error writing file '{path.RealPath}'.", e, 15); } }
/// <summary> /// Folders the delete. /// </summary> /// <param name="path">The path.</param> /// <param name="deleteSubElements">if set to <c>true</c> [delete sub elements].</param> /// <exception cref="bS.Sked2.Structure.Base.Exceptions.StorageException">Error deleting folder '{path.RealPath}'. - 21</exception> /// <exception cref="StorageException">Error deleting folder '{path.RealPath}'. - 21</exception> public void FolderDelete(IVirtualPath path, bool deleteSubElements = false) { try { workSpaceFileSystem.DeleteDirectory(path.RealPath, deleteSubElements); } catch (Exception e) { throw new StorageException(logger, $"Error deleting folder '{path.RealPath}'.", e, 21); } }
/// <summary> /// Moves the file from the origin to the target virtual path. /// </summary> /// <param name="source">The origin virtual path.</param> /// <param name="target">The target virtual path.</param> /// <exception cref="bS.Sked2.Structure.Base.Exceptions.StorageException">Error coping file from '{source.RealPath}' to '{target.RealPath}'. - 11</exception> /// <exception cref="StorageException">Error coping file from '{source.RealPath}' to '{target.RealPath}'. - 11</exception> public void FileMove(IVirtualPath source, IVirtualPath target) { try { workSpaceFileSystem.MoveFile(source.RealPath, target.RealPath); } catch (Exception e) { throw new StorageException(logger, $"Error coping file from '{source.RealPath}' to '{target.RealPath}'.", e, 11); } }
/// <summary> /// Files the get last write time. /// </summary> /// <param name="path">The path.</param> /// <returns></returns> /// <exception cref="bS.Sked2.Structure.Base.Exceptions.StorageException">Error checking file '{path.RealPath}'. - 9</exception> /// <exception cref="StorageException">Error checking file '{path.RealPath}'. - 9</exception> public DateTime FileGetLastWriteTime(IVirtualPath path) { try { return(workSpaceFileSystem.GetLastWriteTime(path.RealPath)); } catch (Exception e) { throw new StorageException(logger, $"Error checking file '{path.RealPath}'.", e, 9); } }
/// <summary> /// Files the get lenght. /// </summary> /// <param name="path">The path.</param> /// <returns></returns> /// <exception cref="bS.Sked2.Structure.Base.Exceptions.StorageException">Error checking lenght of file '{path.RealPath}'. - 10</exception> /// <exception cref="StorageException">Error checking lenght of file '{path.RealPath}'. - 10</exception> public long FileGetLenght(IVirtualPath path) { try { return(workSpaceFileSystem.GetFileLength(path.RealPath)); } catch (Exception e) { throw new StorageException(logger, $"Error checking lenght of file '{path.RealPath}'.", e, 10); } }
/// <summary> /// Set the file last write time. /// </summary> /// <param name="path">The path.</param> /// <param name="dateTime">The date time.</param> /// <exception cref="bS.Sked2.Structure.Base.Exceptions.StorageException">Error setting last write time to file '{path.RealPath}'. - 19</exception> /// <exception cref="StorageException">Error setting last write time to file '{path.RealPath}'. - 19</exception> public void FileSetLastWriteTime(IVirtualPath path, DateTime dateTime) { try { workSpaceFileSystem.SetLastWriteTime(path.RealPath, dateTime); } catch (Exception e) { throw new StorageException(logger, $"Error setting last write time to file '{path.RealPath}'.", e, 19); } }
/// <summary> /// Deletes the specified file. /// </summary> /// <param name="path">The virtual path.</param> /// <exception cref="bS.Sked2.Structure.Base.Exceptions.StorageException">Error deleting file '{path.RealPath}'. - 4</exception> /// <exception cref="StorageException">Error deleting file '{path.RealPath}'. - 4</exception> public void FileDelete(IVirtualPath path) { try { workSpaceFileSystem.DeleteFile(path.RealPath); } catch (Exception e) { throw new StorageException(logger, $"Error deleting file '{path.RealPath}'.", e, 4); } }
/// <summary> /// Copies the file from the origin to the target virtual path. /// </summary> /// <param name="source">The origin virtual path.</param> /// <param name="target">The target virtual path.</param> /// <param name="overwrite"></param> /// <exception cref="bS.Sked2.Structure.Base.Exceptions.StorageException">Error coping file from '{source.RealPath}' to '{target.RealPath}'. - 3</exception> /// <exception cref="StorageException">Error coping file from '{source.RealPath}' to '{target.RealPath}'. - 3</exception> public void FileCopy(IVirtualPath source, IVirtualPath target, bool overwrite = false) { try { workSpaceFileSystem.CopyFile(source.RealPath, target.RealPath, overwrite); } catch (Exception e) { throw new StorageException(logger, $"Error coping file from '{source.RealPath}' to '{target.RealPath}'.", e, 3); } }
/// <summary> /// Files the read text reader. /// </summary> /// <param name="path">The path.</param> /// <returns></returns> /// <exception cref="StorageException">Error opening file '{path.RealPath}'. - 16</exception> public TextReader FileOpenTextReader(IVirtualPath path) { try { var stream = workSpaceFileSystem.OpenFile(path.RealPath, FileMode.Open, FileAccess.Read); return(new StreamReader(stream)); } catch (Exception e) { throw new StorageException(logger, $"Error opening file '{path.RealPath}'.", e, 16); } }
public Module(string id, IVirtualPath virtualPath, Module parent, IModuleLoader loader) { Evaluator = loader.Evaluator; Id = id; Parent = parent; Loader = loader; VirtualPath = virtualPath; parent?.Children?.Add(this); Loaded = false; Children = new List <Module>(); RequireFunction = new RequireFunction(Evaluator, loader, this); }
public Module(string id, IVirtualPath virtualPath, Module parent, IModuleLoader loader) { Evaluator = loader.Evaluator; Id = id; Parent = parent; Loader = loader; VirtualPath = virtualPath; parent?.Children?.Add(this); Loaded = false; Children = new List<Module>(); RequireFunction = new RequireFunction(Evaluator, loader, this); }
public static IVirtualPath GetPath(this IVirtualFileSystem fs, IVirtualPath path) { if (path is IVirtualFile) { return(fs.GetFile(path.FullPath)); } if (path is IVirtualFolder) { return(fs.GetFolder(path.FullPath)); } return(null); }
public static IVirtualPath ChangeName(this IVirtualPath path, string newpath) { if (path is IVirtualFile) { return(path.FileSystem.GetFile(newpath)); } if (path is IVirtualFolder) { return(path.FileSystem.GetFolder(newpath)); } return(null); }
/// <summary> /// Watch the folder changes. You have to register the events that the return value implements for handle folder's changes. /// </summary> /// <param name="path">The path.</param> /// <returns></returns> /// <exception cref="bS.Sked2.Structure.Base.Exceptions.StorageException">Error watching folder '{path.RealPath}'. - 25</exception> /// <exception cref="StorageException">Error watching folder '{path.RealPath}'. - 25</exception> public IVirtualPathWatch FolderWatch(IVirtualPath path) { try { var res = workSpaceFileSystem.Watch(path.RealPath); return(new VirtualPathWatch(res)); } catch (Exception e) { throw new StorageException(logger, $"Error watching folder '{path.RealPath}'.", e, 25); } }
public static void CopyPathTo(this IVirtualPath path, IVirtualFileSystem dstfs, string newname) { if (path is IVirtualFile) { var dstf = dstfs.GetFile(newname); ((IVirtualFile)path).CopyFileTo(dstf, CopyFileMode.Copy); } else { var dstf = dstfs.GetFolder(newname); if (!dstf.Exists()) { dstf.Create(); } } }
protected string GetNewName(IVirtualPath oldpath, List <Tuple <string, string> > repls) { string path = oldpath.FullPath; if (repls != null) { foreach (var tpl in repls) { if (path.StartsWith(tpl.V1)) { path = tpl.V2 + path.Substring(tpl.V1.Length); break; } if (tpl.V1.EndsWith("$") && path == tpl.V1.Substring(0, tpl.V1.Length - 1)) { path = tpl.V2; break; } } } return(path); }
public ConfigNode(IVirtualPath rootPath) : base("config") { VirtualPath = rootPath; }
public ConfigNode(ITreeNode parent, IVirtualPath path) : base(parent, path.Name) { VirtualPath = path; }
public static bool PathStarts(this IVirtualPath vp, string path) { return(NormalizePath(vp.FullPath).StartsWith(NormalizePath(path))); }
public static string GetExtension(this IVirtualPath vp) { return(Path.GetExtension(vp.FullPath)); }
public static bool NameEnds(this IVirtualPath vp, string s) { return(NormalizePath(vp.FullPath).EndsWith(s.ToLower())); }
/// <summary> /// Set the file attributes. /// </summary> /// <param name="path">The path.</param> /// <returns></returns> /// <exception cref="NotImplementedException"></exception> public bool FileSetAttributes(IVirtualPath path) { throw new NotImplementedException(); }