예제 #1
0
        /// <summary>
        /// Creates a file.
        /// </summary>
        /// <param name="directory">The directory.</param>
        /// <param name="name">The name.</param>
        /// <param name="collisionOption">The collision option. Defaults to FailIfExists.</param>
        /// <returns>An AFile representing the file.</returns>
        public override AFile CreateFile(string directory, string name, FileCollisionOption collisionOption = FileCollisionOption.FailIfExists)
        {
            Exceptions.NotNullOrEmptyCheck(directory, nameof(directory));
            Exceptions.NotNullOrEmptyCheck(name, nameof(name));

            switch (collisionOption)
            {
                case FileCollisionOption.FailIfExists:
                    if (Fenrir.FileSystem.FileExists(System.IO.Path.Combine(directory, name)))
                        return null;
                    break;

                case FileCollisionOption.GenerateUniqueName:
                    name = Fenrir.FileSystem.GenerateFileUniqueName(directory, name);
                    break;
            }

            string file = System.IO.Path.Combine(directory, name);
            System.IO.File.Create(file).Dispose();
            return new FenrirFile(file);
        }
예제 #2
0
 /// <summary>
 /// Creates a file.
 /// </summary>
 /// <param name="directory">The directory.</param>
 /// <param name="name">The name.</param>
 /// <param name="collisionOption">The collision option. Defaults to FailIfExists.</param>
 /// <returns>An AFile representing the file.</returns>
 /// <exception cref="System.NotImplementedException">
 /// Exception representing that this function is not implemented.
 /// </exception>
 public virtual AFile CreateFile(AFolder directory, string name, FileCollisionOption collisionOption = FileCollisionOption.FailIfExists)
 {
     throw new NotImplementedException();
 }
예제 #3
0
 /// <summary>
 /// Creates a folder asynchronously.
 /// </summary>
 /// <param name="path">The path.</param>
 /// <param name="collisionOption">The collision option. Defaults to FailIfExists.</param>
 /// <param name="cancellationToken">The cancellation token. Defaults to null.</param>
 /// <returns>An AFolder task to create a new folder. The AFolder represents the folder.</returns>
 public async Task<AFolder> CreateFolderAsync(string path, FileCollisionOption collisionOption = FileCollisionOption.FailIfExists, CancellationToken? cancellationToken = null)
 {
     await AwaitHelpers.CreateTaskScheduler(AwaitHelpers.CheckCancellationToken(cancellationToken));
     return CreateFolder(path, collisionOption);
 }
예제 #4
0
 /// <summary>
 /// Creates a folder.
 /// </summary>
 /// <param name="path">The path.</param>
 /// <param name="collisionOption">The collision option. Defaults to FailIfExists.</param>
 /// <returns>An AFolder representing the folder.</returns>
 /// <exception cref="System.NotImplementedException">
 /// Exception representing that this function is not implemented.
 /// </exception>
 public virtual AFolder CreateFolder(string path, FileCollisionOption collisionOption = FileCollisionOption.FailIfExists)
 {
     throw new NotImplementedException();
 }
예제 #5
0
 /// <summary>
 /// Creates a file asynchronously.
 /// </summary>
 /// <param name="directory">The directory.</param>
 /// <param name="name">The name.</param>
 /// <param name="collisionOption">The collision option. Defaults to FailIfExists.</param>
 /// <param name="cancellationToken">The cancellation token. Defaults to null.</param>
 /// <returns>An AFile task to create a new file. The AFile represents the file.</returns>
 public async Task<AFile> CreateFileAsync(AFolder directory, string name, FileCollisionOption collisionOption = FileCollisionOption.FailIfExists, CancellationToken? cancellationToken = null)
 {
     await AwaitHelpers.CreateTaskScheduler(AwaitHelpers.CheckCancellationToken(cancellationToken));
     return CreateFile(directory, name, collisionOption);
 }
예제 #6
0
        /// <summary>
        /// Copies a folder.
        /// </summary>
        /// <param name="folder">The folder.</param>
        /// <param name="destinationPath">The destination path.</param>
        /// <param name="destinationName">Name of the destination.</param>
        /// <param name="folderCollisionOption">The folder collision option.</param>
        /// <param name="fileCollisionOption">The file collision option.</param>
        /// <returns>An AFolder representing the file.</returns>
        public override AFolder CopyFolder(string folder, AFolder destinationPath, string destinationName, FolderCollisionOption folderCollisionOption, FileCollisionOption fileCollisionOption)
        {
            Exceptions.NotNullCheck<AFolder>(destinationPath, nameof(destinationPath));
            Exceptions.NotNullOrEmptyCheck(Name, nameof(destinationName));

            string path = System.IO.Path.Combine(FullPath, folder);
            if (Fenrir.FileSystem.FolderExists(path))
            {
                AFolder newFolder = new FenrirFolder(path);
                return newFolder.Copy(destinationPath.FullPath, destinationName, folderCollisionOption, fileCollisionOption);
            }

            return null;
        }
예제 #7
0
        /// <summary>
        /// Creates a folder.
        /// </summary>
        /// <param name="directory">The directory.</param>
        /// <param name="name">The name.</param>
        /// <param name="collisionOption">The collision option. Defaults to FailIfExists.</param>
        /// <returns>An AFolder representing the folder.</returns>
        public override AFolder CreateFolder(AFolder directory, string name, FileCollisionOption collisionOption = FileCollisionOption.FailIfExists)
        {
            Exceptions.NotNullCheck<AFolder>(directory, nameof(directory));
            Exceptions.NotNullOrEmptyCheck(name, nameof(name));

            switch (collisionOption)
            {
                case FileCollisionOption.FailIfExists:
                    if (Fenrir.FileSystem.FolderExists(System.IO.Path.Combine(directory.FullPath, name)))
                        return null;
                    break;

                case FileCollisionOption.GenerateUniqueName:
                    name = Fenrir.FileSystem.GenerateFileUniqueName(directory.FullPath, name);
                    break;
            }

            string folder = System.IO.Path.Combine(directory.FullPath, name);
            Directory.CreateDirectory(folder);
            return new FenrirFolder(folder);
        }
예제 #8
0
        /// <summary>
        /// Copies the folder to the destination.
        /// </summary>
        /// <param name="destinationPath">The destination path.</param>
        /// <param name="destinationName">Name of the destination.</param>
        /// <param name="folderCollisionOption">The folder collision option.</param>
        /// <param name="fileCollisionOption">The file collision option.</param>
        /// <returns>An AFolder representing the new folder.</returns>
        public override AFolder Copy(AFolder destinationPath, string destinationName, FolderCollisionOption folderCollisionOption, FileCollisionOption fileCollisionOption)
        {
            Exceptions.NotNullCheck<AFolder>(destinationPath, nameof(destinationPath));
            Exceptions.NotNullOrEmptyCheck(Name, nameof(destinationName));

            string destination = destinationPath.FullPath;
            string path = System.IO.Path.Combine(destination, destinationName);

            switch (folderCollisionOption)
            {
                case FolderCollisionOption.FailIfExists:
                    if (Fenrir.FileSystem.FolderExists(path))
                        return null;
                    break;

                case FolderCollisionOption.GenerateUniqueName:
                    destinationName = Fenrir.FileSystem.GenerateFileUniqueName(destination, destinationName);
                    path = System.IO.Path.Combine(destination, destinationName);
                    break;

                case FolderCollisionOption.OpenIfExists:
                    if (Fenrir.FileSystem.FolderExists(path))
                        return new FenrirFolder(path);
                    break;
            }

            System.IO.Directory.CreateDirectory(path);

            List<string> files = this.GetFileNames();
            foreach (string str in files)
                CopyFile(str, destinationPath, str, fileCollisionOption);

            List<string> folders = this.GetFolderNames();
            foreach (string str in folders)
                CopyFolder(str, destinationPath, str, folderCollisionOption, fileCollisionOption);

            return new FenrirFolder(path);
        }
예제 #9
0
        /// <summary>
        /// Copies a file.
        /// </summary>
        /// <param name="file">The file.</param>
        /// <param name="destinationName">Name of the destination.</param>
        /// <param name="collisionOption">The collision option.</param>
        /// <returns>An AFile representing the file.</returns>
        public override AFile CopyFile(string file, string destinationName, FileCollisionOption collisionOption)
        {
            Exceptions.NotNullOrEmptyCheck(Name, nameof(destinationName));

            string path = System.IO.Path.Combine(FullPath, file);
            if (Fenrir.FileSystem.FolderExists(path))
            {
                AFile newFile = new FenrirFile(path);
                return newFile.Copy(destinationName, collisionOption);
            }

            return null;
        }
예제 #10
0
        /// <summary>
        /// Creates and opens the specified file.
        /// </summary>
        /// <param name="file">The file.</param>
        /// <param name="fileAccess">The file access.</param>
        /// <param name="fileMode">The file mode.</param>
        /// <param name="collisionOption">The collision option.</param>
        /// <returns>Returns the file stream of the new file.</returns>
        public static Stream CreateAndOpen(string file, FileAccess fileAccess = FileAccess.Write, FileMode fileMode = FileMode.Open, FileCollisionOption collisionOption = FileCollisionOption.FailIfExists)
        {
            Exceptions.NotNullOrEmptyException(file, nameof(file));

            return Fenrir.FileSystem.CreateFile(file, collisionOption).Open(fileAccess, fileMode);
        }
예제 #11
0
 /// <summary>
 /// Asynchronously creates and opens the specified file.
 /// </summary>
 /// <param name="file">The file.</param>
 /// <param name="fileAccess">The file access.</param>
 /// <param name="fileMode">The file mode.</param>
 /// <param name="collisionOption">The collision option.</param>
 /// <param name="cancellationToken">The cancellation token.</param>
 /// <returns>A Stream task to create and open the file. The Stream is the file's stream.</returns>
 public static async Task<Stream> CreateAndOpenAsync(string file, FileAccess fileAccess = FileAccess.Write, FileMode fileMode = FileMode.Open, FileCollisionOption collisionOption = FileCollisionOption.FailIfExists, CancellationToken? cancellationToken = null)
 {
     await AwaitHelpers.CreateTaskScheduler(AwaitHelpers.CheckCancellationToken(cancellationToken));
     return CreateAndOpen(file, fileAccess, fileMode, collisionOption);
 }
예제 #12
0
 /// <summary>
 /// Asynchronously creates the specified file.
 /// </summary>
 /// <param name="file">The file.</param>
 /// <param name="collisionOption">The collision option.</param>
 /// <param name="cancellationToken">The cancellation token.</param>
 /// <returns>An AFile task to create the file. The AFile represents the new file.</returns>
 public static async Task<AFile> CreateAFileAsync(string file, FileCollisionOption collisionOption = FileCollisionOption.FailIfExists, CancellationToken? cancellationToken = null)
 {
     await AwaitHelpers.CreateTaskScheduler(AwaitHelpers.CheckCancellationToken(cancellationToken));
     return CreateAFile(file, collisionOption);
 }
예제 #13
0
        /// <summary>
        /// Creates the specified file.
        /// </summary>
        /// <param name="file">The file.</param>
        /// <param name="collisionOption">The collision option.</param>
        /// <returns>Returns an AFile representing the new file.</returns>
        public static AFile CreateAFile(string file, FileCollisionOption collisionOption = FileCollisionOption.FailIfExists)
        {
            Exceptions.NotNullOrEmptyException(file, nameof(file));

            return Fenrir.FileSystem.CreateFile(file, collisionOption);
        }
예제 #14
0
        /// <summary>
        /// Renames the System.IO.File.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="collisionOption">The collision option. Defaults to FailIfExists.</param>
        /// <returns>Whether the file was renamed (true) or not (false).</returns>
        public override bool Rename(string name, FileCollisionOption collisionOption = FileCollisionOption.FailIfExists)
        {
            Exceptions.NotNullOrEmptyCheck(name, nameof(name));

            if (!IsOpen)
            {
                Exceptions.NotNullOrEmptyException(name, nameof(name));

                string newPath = System.IO.Path.Combine(Path, name, Extension);
                switch (collisionOption)
                {
                    case FileCollisionOption.FailIfExists:
                        if (Fenrir.FileSystem.FileExists(newPath))
                            return false;
                        break;

                    case FileCollisionOption.GenerateUniqueName:
                        newPath = Fenrir.FileSystem.GenerateFileUniqueName(newPath);
                        break;

                    case FileCollisionOption.ReplaceExisting:
                        if (Fenrir.FileSystem.FileExists(newPath))
                            System.IO.File.Delete(newPath);
                        break;
                }

                System.IO.File.Copy(FullPath, newPath);
                System.IO.File.Delete(FullPath);
                Name = name;
                return true;
            }

            return false;
        }
예제 #15
0
        /// <summary>
        /// Moves the System.IO.File.
        /// </summary>
        /// <param name="destinationPath">The destination path.</param>
        /// <param name="destinationName">Name of the destination.</param>
        /// <param name="collisionOption">The collision option. Defaults to FailIfExists.</param>
        /// <returns>Whether the file was moved or not.</returns>
        public override bool Move(string destinationPath, string destinationName, FileCollisionOption collisionOption = FileCollisionOption.FailIfExists)
        {
            if (!IsOpen)
            {
                Exceptions.NotNullOrEmptyException(destinationPath, nameof(destinationPath));
                Exceptions.NotNullOrEmptyException(destinationName, nameof(destinationName));

                string newPath = System.IO.Path.Combine(destinationPath, destinationName);
                switch (collisionOption)
                {
                    case FileCollisionOption.FailIfExists:
                        if (Fenrir.FileSystem.FileExists(newPath))
                            return false;
                        break;

                    case FileCollisionOption.GenerateUniqueName:
                        newPath = Fenrir.FileSystem.GenerateFileUniqueName(newPath);
                        break;

                    case FileCollisionOption.ReplaceExisting:
                        if (Fenrir.FileSystem.FileExists(newPath))
                            System.IO.File.Delete(newPath);
                        break;
                }

                System.IO.File.Move(FullPath, newPath);
                SetupFile(newPath);
                return true;
            }

            return false;
        }
예제 #16
0
        /// <summary>
        /// Copies the System.IO.File.
        /// </summary>
        /// <param name="destinationPath">The destination path.</param>
        /// <param name="destinationName">Name of the destination.</param>
        /// <param name="collisionOption">The collision option. Defaults to FailIfExists.</param>
        /// <returns>An AFile representing the copied System.IO.File.</returns>
        public override AFile Copy(string destinationPath, string destinationName, FileCollisionOption collisionOption = FileCollisionOption.FailIfExists)
        {
            if (!IsOpen)
            {
                Exceptions.NotNullOrEmptyCheck(destinationPath, nameof(destinationPath));
                Exceptions.NotNullOrEmptyCheck(destinationName, nameof(destinationName));

                string destination = System.IO.Path.Combine(destinationPath, destinationName);

                switch (collisionOption)
                {
                    case FileCollisionOption.FailIfExists:
                        if (Fenrir.FileSystem.FileExists(destination))
                            return null;
                        break;

                    case FileCollisionOption.GenerateUniqueName:
                        destination = Fenrir.FileSystem.GenerateFileUniqueName(destination);
                        break;
                }

                System.IO.File.Copy(FullPath, destination, collisionOption == FileCollisionOption.ReplaceExisting);
                return new FenrirFile(destination);
            }

            return null;
        }