Example #1
0
 /// <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)
 {
 }
Example #2
0
        /// <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);
        }
Example #3
0
        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);
        }
Example #4
0
        /// <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);
        }
Example #5
0
        /// <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);
        }
Example #6
0
 /// <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)));
 }
Example #7
0
 /// <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);
Example #8
0
 /// <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)));
 }
Example #9
0
 /// <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)
 {
 }
Example #10
0
 /// <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)
 {
 }
Example #11
0
 /// <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)));
 }
Example #12
0
 /// <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);
 }
Example #13
0
 /// <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)));
 }
Example #14
0
 /// <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)
 {
 }
Example #15
0
 /// <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);
 }
Example #16
0
 /// <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)));
 }