/// <summary> /// Internal method that should not be called by developers /// </summary> public FileSystemFile(FileSystemSession session, string parentPath, string name, IFileSystemHandle handle) : base(session, parentPath, name, handle) { }
/// <summary> /// Ensures that all directories of a fullPath exist creating them as needed. /// Returns false if fullPath did not supply valid path /// </summary> public static bool EnsureDirectoryPath(this FileSystemSession session, string fullPath) { var segments = session.NonNull(nameof(session)).FileSystem.SplitPathSegments(fullPath); if (segments == null || segments.Length == 0) { return(false); } //set to root var dir = session[session.FileSystem.GetPathRoot(fullPath)] as FileSystemDirectory; if (dir == null) { return(false); } foreach (var seg in segments) { var sub = dir.GetSubDirectory(seg); if (sub == null) { sub = dir.CreateDirectory(seg); } dir = sub; } return(true); }
protected FileSystemSessionItem(FileSystemSession session, string parentPath, string name, IFileSystemHandle handle) { m_FileSystem = session.FileSystem; m_Session = session; m_ParentPath = parentPath; m_Handle = handle; m_Name = name; m_Session.m_Items.Add(this); }
/// <summary> /// Ensures that all directories of a fullPath exist creating them as needed. /// Returns false if fullPath did not supply valid path /// </summary> public static bool EnsureDirectoryPath(this FileSystemSession session, string fullPath) { var segments = session.NonNull(nameof(session)).FileSystem.SplitPathSegments(fullPath); if (segments == null || segments.Length == 0) { return(false); } //set to root var dir = session[session.FileSystem.GetPathRoot(fullPath)] as FileSystemDirectory; if (dir == null) { return(false); } var toClean = new List <FileSystemSessionItem> { dir }; try { foreach (var seg in segments) { var sub = dir.GetSubDirectory(seg); if (sub == null) { sub = dir.CreateDirectory(seg); } toClean.Add(sub); dir = sub; } } finally { toClean.ForEach(i => i.Dispose()); } return(true); }
/// <summary> /// Opens existing or creates a new file /// </summary> public static FileSystemFile OpenOrCreateFile(this FileSystemSession session, string fullPath) { var(path, fileName) = session.NonNull(nameof(session)) .FileSystem .ExtractFilePathAndName(fullPath.NonBlank(nameof(fullPath))); var dir = session[path] as FileSystemDirectory; if (dir == null) { throw new FileSystemException(StringConsts.FS_DIRECTORY_DOES_NOT_EXIST_ERROR.Args(path.TakeLastChars(32, "..."))); } var file = dir[fileName] as FileSystemFile; if (file == null) { file = dir.CreateFile(fileName); } return(file); }
/// <summary> /// Async version of <see cref="DoNavigate(FileSystemSession, string)"/>. /// This base/default implementation just synchronously calls <see cref="DoNavigate(FileSystemSession, string)"/> and /// returns already completed Task with result returned by <see cref="DoNavigate(FileSystemSession, string)"/> /// </summary> protected internal virtual Task <FileSystemSessionItem> DoNavigateAsync(FileSystemSession session, string path) { return(TaskUtils.AsCompletedTask(() => DoNavigate(session, path))); }
/// <summary> /// Override to get file or directory from specified path. Return null if item does not exist. /// This method may be called by multiple threads /// </summary> protected internal abstract FileSystemSessionItem DoNavigate(FileSystemSession session, string path);
/// <summary> /// Async version of <see cref="DoRollbackTransaction(FileSystemSession)"/>. /// This base/default implementation just synchronously calls <see cref="DoRollbackTransaction(FileSystemSession)"/> and /// returns already completed Task with result returned by <see cref="DoRollbackTransaction(FileSystemSession)"/> /// </summary> protected internal virtual Task DoRollbackTransactionAsync(FileSystemSession session) { return(TaskUtils.AsCompletedTask(() => DoRollbackTransaction(session))); }
/// <summary> /// Override in particular file systems that support transactions to rollback transaction in specified session. /// This method may be called by multiple threads /// </summary> protected internal virtual void DoRollbackTransaction(FileSystemSession session) { }
/// <summary> /// Override in particular file systems that support transactions to commit transaction in specified session. /// This method may be called by multiple threads /// </summary> protected internal virtual void DoCommitTransaction(FileSystemSession session) { }
/// <summary> /// Async version of <see cref="DoBeginTransaction(FileSystemSession)"/>. /// This base/default implementation just synchronously calls <see cref="DoBeginTransaction(FileSystemSession)"/> and /// returns already completed Task with result returned by <see cref="DoBeginTransaction(FileSystemSession)"/> /// </summary> protected internal virtual Task <IFileSystemTransactionHandle> DoBeginTransactionAsync(FileSystemSession session) { return(TaskUtils.AsCompletedTask(() => DoBeginTransaction(session))); }
/// <summary> /// Override in particular file systems that support transactions to begin transaction in specified session. /// This method may be called by multiple threads /// </summary> protected internal virtual IFileSystemTransactionHandle DoBeginTransaction(FileSystemSession session) { return(null); }
/// <summary> /// Async version of <see cref="DoSetVersion (FileSystemSession, IFileSystemVersion)"/>. /// This base/default implementation just synchronously calls <see cref="DoSetVersion (FileSystemSession, IFileSystemVersion)"/> and /// returns already completed Task with result returned by <see cref="DoSetVersion (FileSystemSession, IFileSystemVersion)"/> /// </summary> protected internal virtual Task DoSetVersionAsync(FileSystemSession session, IFileSystemVersion version) { return(TaskUtils.AsCompletedTask(() => DoSetVersion(session, version))); }
/// <summary> /// Override in particular file systems that support versioning to set session to specific version. /// This method may be called by multiple threads /// </summary> protected internal virtual void DoSetVersion(FileSystemSession session, IFileSystemVersion version) { }
/// <summary> /// Override in particular file systems that support versioning to get version object for session. /// This method may be called by multiple threads /// </summary> protected internal virtual IFileSystemVersion DoGetVersion(FileSystemSession session) { return(null); }
/// <summary> /// Async version of <see cref="DoGetLatestVersion(FileSystemSession)"/>. /// This base/default implementation just synchronously calls <see cref="DoGetLatestVersion(FileSystemSession)"/> and /// returns already completed Task with result returned by <see cref="DoGetLatestVersion(FileSystemSession)"/> /// </summary> protected internal virtual Task <IFileSystemVersion> DoGetLatestVersionAsync(FileSystemSession session) { return(TaskUtils.AsCompletedTask(() => DoGetLatestVersion(session))); }