From ce9b6e67b250fbf74cf4072d8fae80353211bc80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AC=9D=E6=A1=82=E7=B6=B1?= Date: Thu, 4 Feb 2016 04:51:27 +0800 Subject: [PATCH] finish most of the remote file system API the file stream object needs finish --- .../FileSystem/FileStream/FileStream.vb | 49 +- .../FileSystem/FileSystem.vb | 1072 ++--------------- 2 files changed, 141 insertions(+), 980 deletions(-) diff --git a/ComputingServices/ComputingServices/FileSystem/FileStream/FileStream.vb b/ComputingServices/ComputingServices/FileSystem/FileStream/FileStream.vb index cdade7a..ac42f24 100644 --- a/ComputingServices/ComputingServices/FileSystem/FileStream/FileStream.vb +++ b/ComputingServices/ComputingServices/FileSystem/FileStream/FileStream.vb @@ -21,18 +21,7 @@ Namespace FileSystem.IO ''' Public Class FileStream Inherits BaseStream - ' - ' Summary: - ' - ' - ' Parameters: - ' path: - ' A relative or absolute path for the file that the current FileStream object will - ' encapsulate. - ' - ' mode: - ' A constant that determines how to open or create the file. - ' + ' Exceptions: ' T:System.ArgumentException: ' path is an empty string (""), contains only white space, or contains one or more @@ -72,14 +61,19 @@ Namespace FileSystem.IO ''' Initializes a new instance of the System.IO.FileStream class with the specified ''' path and creation mode. ''' - ''' 远程机器上面的文件 - ''' + ''' A relative or absolute path for the file that the current FileStream object will + ''' encapsulate.(远程机器上面的文件) + ''' A constant that determines how to open or create the file. Public Sub New(path As String, mode As FileMode, remote As FileSystem) Call MyBase.New(remote) Name = path FileHandle = remote.OpenFileHandle(path, mode) End Sub + ''' + ''' File handle on the remote machine file system + ''' + ''' Public ReadOnly Property FileHandle As FileHandle '' @@ -875,14 +869,11 @@ Namespace FileSystem.IO 'End Sub - ' - ' Summary: - ' Gets a value indicating whether the current stream supports reading. - ' - ' Returns: - ' true if the stream supports reading; false if the stream is closed or was opened - ' with write-only access. - + ''' + ''' Gets a value indicating whether the current stream supports reading. + ''' + ''' true if the stream supports reading; false if the stream is closed or was opened + ''' with write-only access. Public Overrides ReadOnly Property CanRead As Boolean Get @@ -898,7 +889,10 @@ Namespace FileSystem.IO ' FileStream was constructed from an operating-system handle such as a pipe or ' output to the console. Public Overrides ReadOnly Property CanSeek As Boolean - ' + Get + + End Get + End Property ' Summary: ' Gets a value indicating whether the current stream supports writing. ' @@ -906,7 +900,10 @@ Namespace FileSystem.IO ' true if the stream supports writing; false if the stream is closed or was opened ' with read-only access. Public Overrides ReadOnly Property CanWrite As Boolean - ' + Get + + End Get + End Property ' Summary: ' Gets the operating system file handle for the file that the current FileStream ' object encapsulates. @@ -941,6 +938,10 @@ Namespace FileSystem.IO ' T:System.IO.IOException: ' An I/O error, such as the file being closed, occurred. Public Overrides ReadOnly Property Length As Long + Get + + End Get + End Property ''' ''' Gets the name of the FileStream that was passed to the constructor. diff --git a/ComputingServices/ComputingServices/FileSystem/FileSystem.vb b/ComputingServices/ComputingServices/FileSystem/FileSystem.vb index 55c4d96..d04c2eb 100644 --- a/ComputingServices/ComputingServices/FileSystem/FileSystem.vb +++ b/ComputingServices/ComputingServices/FileSystem/FileSystem.vb @@ -6,6 +6,7 @@ Imports Microsoft.VisualBasic.FileIO Imports Microsoft.VisualBasic.Net Imports Microsoft.VisualBasic.Net.Protocol Imports Microsoft.VisualBasic.Serialization +Imports Microsoft.VisualBasic.LINQ Namespace FileSystem @@ -57,6 +58,15 @@ Namespace FileSystem ''' ''' A read-only collection of all available drives as System.IO.DriveInfo objects. Public ReadOnly Property Drives As ReadOnlyCollection(Of DriveInfo) + Get + Dim req As RequestStream = New RequestStream(ProtocolEntry, FileSystemAPI.Drives) + Dim invoke As New AsynInvoke(_Portal) + Dim rep As RequestStream = invoke.SendMessage(req) + Dim array As String() = req.GetUTF8String.LoadObject(Of String()) + Dim lst As DriveInfo() = array.ToArray(Function(s) s.LoadObject(Of DriveInfo)) + Return New ReadOnlyCollection(Of DriveInfo)(lst) + End Get + End Property ' Exceptions: ' T:System.ArgumentException: @@ -105,86 +115,7 @@ Namespace FileSystem Public Sub CopyDirectory(sourceDirectoryName As String, destinationDirectoryName As String) End Sub - ' - ' Summary: - ' - ' - ' Parameters: - ' sourceDirectoryName: - ' - ' - ' destinationDirectoryName: - ' - ' - ' showUI: - ' - ' - ' Exceptions: - ' T:System.ArgumentException: - ' The new name specified for the directory contains a colon (:) or slash (\ or - ' /). - ' - ' T:System.ArgumentException: - ' The path is not valid for one of the following reasons: it is a zero-length string; - ' it contains only white space; it contains invalid characters; or it is a device - ' path (starts with \\.\). - ' - ' T:System.ArgumentNullException: - ' destinationDirectoryName or sourceDirectoryName is Nothing or an empty string. - ' - ' T:System.IO.DirectoryNotFoundException: - ' The source directory does not exist. - ' - ' T:System.IO.IOException: - ' The source directory is a root directory - ' - ' T:System.IO.IOException: - ' The combined path points to an existing file. - ' - ' T:System.IO.IOException: - ' The source path and target path are the same. - ' - ' T:System.InvalidOperationException: - ' The operation is cyclic. - ' - ' T:System.IO.PathTooLongException: - ' The path exceeds the system-defined maximum length. - ' - ' T:System.NotSupportedException: - ' A folder name in the path contains a colon (:) or is in an invalid format. - ' - ' T:System.Security.SecurityException: - ' The user lacks necessary permissions to view the path. - ' - ' T:System.UnauthorizedAccessException: - ' A destination file exists but cannot be accessed. - ' - ' T:System.OperationCanceledException: - ' ShowUI is set to UIOption.AllDialogs and the user cancels the operation, or one - ' or more files in the directory cannot be copied. - ''' - ''' Copies the contents of a directory to another directory. - ''' - ''' The directory to be copied. - ''' The location to which the directory contents should be copied. - ''' Whether to visually track the operation's progress. Default is UIOption.OnlyErrorDialogs. - Public Sub CopyDirectory(sourceDirectoryName As String, destinationDirectoryName As String, showUI As UIOption) - End Sub - ' - ' Summary: - ' - ' - ' Parameters: - ' sourceDirectoryName: - ' - ' - ' destinationDirectoryName: - ' - ' - ' overwrite: - ' - ' ' Exceptions: ' T:System.ArgumentException: ' The new name specified for the directory contains a colon (:) or slash (\ or @@ -233,77 +164,7 @@ Namespace FileSystem Public Sub CopyDirectory(sourceDirectoryName As String, destinationDirectoryName As String, overwrite As Boolean) End Sub - ' - ' Summary: - ' Copies the contents of a directory to another directory. - ' - ' Parameters: - ' sourceDirectoryName: - ' The directory to be copied. - ' - ' destinationDirectoryName: - ' The location to which the directory contents should be copied. - ' - ' showUI: - ' Whether to visually track the operation's progress. Default is UIOption.OnlyErrorDialogs. - ' - ' onUserCancel: - ' Specifies what should be done if the user clicks Cancel during the operation. - ' Default is Microsoft.VisualBasic.FileIO.UICancelOption.ThrowException. - ' - ' Exceptions: - ' T:System.ArgumentException: - ' The new name specified for the directory contains a colon (:) or slash (\ or - ' /). - ' - ' T:System.ArgumentException: - ' The path is not valid for one of the following reasons: it is a zero-length string; - ' it contains only white space; it contains invalid characters; or it is a device - ' path (starts with \\.\). - ' - ' T:System.ArgumentNullException: - ' destinationDirectoryName or sourceDirectoryName is Nothing or an empty string. - ' - ' T:System.IO.DirectoryNotFoundException: - ' The source directory does not exist. - ' - ' T:System.IO.IOException: - ' The source directory is a root directory - ' - ' T:System.IO.IOException: - ' The combined path points to an existing file. - ' - ' T:System.IO.IOException: - ' The source path and target path are the same. - ' - ' T:System.InvalidOperationException: - ' The operation is cyclic. - ' - ' T:System.IO.PathTooLongException: - ' The path exceeds the system-defined maximum length. - ' - ' T:System.NotSupportedException: - ' A folder name in the path contains a colon (:) or is in an invalid format. - ' - ' T:System.Security.SecurityException: - ' The user lacks necessary permissions to view the path. - ' - ' T:System.UnauthorizedAccessException: - ' A destination file exists but cannot be accessed. - ' - ' T:System.OperationCanceledException: - ' ShowUI is set to UIOption.AllDialogs and the user cancels the operation, or one - ' or more files in the directory cannot be copied. - ''' - ''' - ''' - ''' - ''' - ''' - ''' - Public Sub CopyDirectory(sourceDirectoryName As String, destinationDirectoryName As String, showUI As UIOption, onUserCancel As UICancelOption) - End Sub ' ' Summary: ' Copies a file to a new location. @@ -363,71 +224,7 @@ Namespace FileSystem Public Sub CopyFile(sourceFileName As String, destinationFileName As String) End Sub - ' - ' Summary: - ' Copies a file to a new location. - ' - ' Parameters: - ' sourceFileName: - ' The file to be copied. - ' - ' destinationFileName: - ' The location to which the file should be copied. - ' - ' showUI: - ' Whether to visually track the operation's progress. Default is UIOption.OnlyErrorDialogs. - ' - ' Exceptions: - ' T:System.ArgumentException: - ' The path is not valid for one of the following reasons: it is a zero-length string; - ' it contains only white space; it contains invalid characters; or it is a device - ' path (starts with \\.\). - ' - ' T:System.ArgumentException: - ' The system could not retrieve the absolute path. - ' - ' T:System.ArgumentException: - ' destinationFileName contains path information. - ' - ' T:System.ArgumentNullException: - ' destinationFileName or sourceFileName is Nothing or an empty string. - ' - ' T:System.IO.FileNotFoundException: - ' The source file is not valid or does not exist. - ' - ' T:System.IO.IOException: - ' The combined path points to an existing directory. - ' - ' T:System.IO.IOException: - ' The user does not have sufficient permissions to access the file. - ' - ' T:System.IO.IOException: - ' A file in the target directory with the same name is in use. - ' - ' T:System.IO.IOException: - ' The destination file exists and overwrite is set to False. - ' - ' T:System.NotSupportedException: - ' A file or directory name in the path contains a colon (:) or is in an invalid - ' format. - ' - ' T:System.IO.PathTooLongException: - ' The path exceeds the system-defined maximum length. - ' - ' T:System.UnauthorizedAccessException: - ' The user does not have required permission. - ' - ' T:System.Security.SecurityException: - ' The user lacks necessary permissions to view the path. - ''' - ''' - ''' - ''' - ''' - ''' - Public Sub CopyFile(sourceFileName As String, destinationFileName As String, showUI As UIOption) - End Sub ' ' Summary: ' Copies a file to a new location. @@ -493,80 +290,7 @@ Namespace FileSystem Public Sub CopyFile(sourceFileName As String, destinationFileName As String, overwrite As Boolean) End Sub - ' - ' Summary: - ' Copies a file to a new location. - ' - ' Parameters: - ' sourceFileName: - ' The file to be copied. - ' - ' destinationFileName: - ' The location to which the file should be copied. - ' - ' showUI: - ' Whether to visually track the operation's progress. Default is UIOption.OnlyErrorDialogs. - ' - ' onUserCancel: - ' Specifies what should be done if the user clicks Cancel during the operation. - ' Default is Microsoft.VisualBasic.FileIO.UICancelOption.ThrowException. - ' - ' Exceptions: - ' T:System.ArgumentException: - ' The path is not valid for one of the following reasons: it is a zero-length string; - ' it contains only white space; it contains invalid characters; or it is a device - ' path (starts with \\.\). - ' - ' T:System.ArgumentException: - ' The system could not retrieve the absolute path. - ' - ' T:System.ArgumentException: - ' destinationFileName contains path information. - ' - ' T:System.ArgumentNullException: - ' destinationFileName or sourceFileName is Nothing or an empty string. - ' - ' T:System.IO.FileNotFoundException: - ' The source file is not valid or does not exist. - ' - ' T:System.IO.IOException: - ' The combined path points to an existing directory. - ' - ' T:System.IO.IOException: - ' The user does not have sufficient permissions to access the file. - ' - ' T:System.IO.IOException: - ' A file in the target directory with the same name is in use. - ' - ' T:System.IO.IOException: - ' The destination file exists and overwrite is set to False. - ' - ' T:System.NotSupportedException: - ' A file or directory name in the path contains a colon (:) or is in an invalid - ' format. - ' - ' T:System.IO.PathTooLongException: - ' The path exceeds the system-defined maximum length. - ' - ' T:System.UnauthorizedAccessException: - ' The user does not have required permission. - ' - ' T:System.Security.SecurityException: - ' The user lacks necessary permissions to view the path. - ' - ' T:System.OperationCanceledException: - ' UICancelOption is set to ThrowException, and the user has canceled the operation - ' or an unspecified I/O error occurs. - ''' - ''' - ''' - ''' - ''' - ''' - ''' - Public Sub CopyFile(sourceFileName As String, destinationFileName As String, showUI As UIOption, onUserCancel As UICancelOption) - End Sub ' ' Summary: ' Creates a directory. @@ -653,125 +377,10 @@ Namespace FileSystem Public Sub DeleteDirectory(directory As String, onDirectoryNotEmpty As DeleteDirectoryOption) End Sub + ' ' Summary: - ' Deletes a directory. - ' - ' Parameters: - ' directory: - ' Directory to be deleted. - ' - ' showUI: - ' Specifies whether to visually track the operation's progress. Default is UIOption.OnlyErrorDialogs. - ' - ' recycle: - ' Specifies whether or not the deleted file should be sent to the Recycle Bin. - ' Default is RecycleOption.DeletePermanently. - ' - ' Exceptions: - ' T:System.ArgumentException: - ' The path is a zero-length string, is malformed, contains only white space, or - ' contains invalid characters (including wildcard characters). The path is a device - ' path (starts with \\.\). - ' - ' T:System.ArgumentNullException: - ' directory is Nothing or an empty string. - ' - ' T:System.IO.DirectoryNotFoundException: - ' The directory does not exist or is a file. - ' - ' T:System.IO.IOException: - ' The directory is not empty, and onDirectoryNotEmpty is set to ThrowIfDirectoryNonEmpty. - ' - ' T:System.IO.IOException: - ' The user does not have permission to delete the directory or subdirectory. - ' - ' T:System.IO.IOException: - ' A file in the directory or subdirectory is in use. - ' - ' T:System.NotSupportedException: - ' The directory name contains a colon (:). - ' - ' T:System.IO.PathTooLongException: - ' The path exceeds the system-defined maximum length. - ' - ' T:System.Security.SecurityException: - ' The user does not have required permissions. - ' - ' T:System.OperationCanceledException: - ' The user cancels the operation or the directory cannot be deleted. - ''' - ''' - ''' - ''' - ''' - ''' - Public Sub DeleteDirectory(directory As String, showUI As UIOption, recycle As RecycleOption) - - End Sub - ' - ' Summary: - ' Deletes a directory. - ' - ' Parameters: - ' directory: - ' Directory to be deleted. - ' - ' showUI: - ' Specifies whether to visually track the operation's progress. Default is UIOption.OnlyErrorDialogs. - ' - ' recycle: - ' Specifies whether or not the deleted file should be sent to the Recycle Bin. - ' Default is RecycleOption.DeletePermanently. - ' - ' onUserCancel: - ' Specifies whether to throw an exception if the user clicks Cancel. - ' - ' Exceptions: - ' T:System.ArgumentException: - ' The path is a zero-length string, is malformed, contains only white space, or - ' contains invalid characters (including wildcard characters). The path is a device - ' path (starts with \\.\). - ' - ' T:System.ArgumentNullException: - ' directory is Nothing or an empty string. - ' - ' T:System.IO.DirectoryNotFoundException: - ' The directory does not exist or is a file. - ' - ' T:System.IO.IOException: - ' The directory is not empty, and onDirectoryNotEmpty is set to ThrowIfDirectoryNonEmpty. - ' - ' T:System.IO.IOException: - ' The user does not have permission to delete the directory or subdirectory. - ' - ' T:System.IO.IOException: - ' A file in the directory or subdirectory is in use. - ' - ' T:System.NotSupportedException: - ' The directory name contains a colon (:). - ' - ' T:System.IO.PathTooLongException: - ' The path exceeds the system-defined maximum length. - ' - ' T:System.Security.SecurityException: - ' The user does not have required permissions. - ' - ' T:System.OperationCanceledException: - ' The user cancels the operation or the directory cannot be deleted. - ''' - ''' - ''' - ''' - ''' - ''' - ''' - Public Sub DeleteDirectory(directory As String, showUI As UIOption, recycle As RecycleOption, onUserCancel As UICancelOption) - - End Sub - ' - ' Summary: - ' Deletes a file. + ' Deletes a file. ' ' Parameters: ' file: @@ -794,247 +403,24 @@ Namespace FileSystem ' format. ' ' T:System.IO.IOException: - ' The file is in use. - ' - ' T:System.Security.SecurityException: - ' The user lacks necessary permissions to view the path. - ' - ' T:System.IO.FileNotFoundException: - ' The file does not exist. - ' - ' T:System.UnauthorizedAccessException: - ' The user does not have permission to delete the file or the file is read-only. - ''' - ''' - ''' - ''' - Public Sub DeleteFile(file As String) - - End Sub - ' - ' Summary: - ' Deletes a file. - ' - ' Parameters: - ' file: - ' Name and path of the file to be deleted. - ' - ' showUI: - ' Whether to visually track the operation's progress. Default is UIOption.OnlyErrorDialogs. - ' - ' recycle: - ' Whether or not the deleted file should be sent to the Recycle Bin. Default is - ' RecycleOption.DeletePermanently. - ' - ' Exceptions: - ' T:System.ArgumentException: - ' The path is not valid for one of the following reasons: it is a zero-length string; - ' it contains only white space; it contains invalid characters; it has a trailing - ' slash where a file must be specified; or it is a device path (starts with \\.\). - ' - ' T:System.ArgumentNullException: - ' file is Nothing or an empty string. - ' - ' T:System.IO.PathTooLongException: - ' The path exceeds the system-defined maximum length. - ' - ' T:System.NotSupportedException: - ' A file or directory name in the path contains a colon (:) or is in an invalid - ' format. - ' - ' T:System.IO.IOException: - ' The file is in use. - ' - ' T:System.Security.SecurityException: - ' The user lacks necessary permissions to view the path. - ' - ' T:System.IO.FileNotFoundException: - ' The file does not exist. - ' - ' T:System.UnauthorizedAccessException: - ' The user does not have permission to delete the file or the file is read-only. - ''' - ''' - ''' - ''' - ''' - ''' - Public Sub DeleteFile(file As String, showUI As UIOption, recycle As RecycleOption) - - End Sub - ' - ' Summary: - ' Deletes a file. - ' - ' Parameters: - ' file: - ' Name and path of the file to be deleted. - ' - ' showUI: - ' Whether to visually track the operation's progress. Default is UIOption.OnlyErrorDialogs. - ' - ' recycle: - ' Whether or not the deleted file should be sent to the Recycle Bin. Default is - ' RecycleOption.DeletePermanently. - ' - ' onUserCancel: - ' Specifies whether or not an exception is thrown when the user cancels the operation. - ' Default is UICancelOption.ThrowException. - ' - ' Exceptions: - ' T:System.ArgumentException: - ' The path is not valid for one of the following reasons: it is a zero-length string; - ' it contains only white space; it contains invalid characters; it has a trailing - ' slash where a file must be specified; or it is a device path (starts with \\.\). - ' - ' T:System.ArgumentNullException: - ' file is Nothing or an empty string. - ' - ' T:System.IO.PathTooLongException: - ' The path exceeds the system-defined maximum length. - ' - ' T:System.NotSupportedException: - ' A file or directory name in the path contains a colon (:) or is in an invalid - ' format. - ' - ' T:System.IO.IOException: - ' The file is in use. - ' - ' T:System.Security.SecurityException: - ' The user lacks necessary permissions to view the path. - ' - ' T:System.IO.FileNotFoundException: - ' The file does not exist. - ' - ' T:System.UnauthorizedAccessException: - ' The user does not have permission to delete the file or the file is read-only. - ' - ' T:System.OperationCanceledException: - ' The user cancelled the operation and onUserCancel is set to Microsoft.VisualBasic.FileIO.UICancelOption.ThrowException. - ''' - ''' - ''' - ''' - ''' - ''' - ''' - Public Sub DeleteFile(file As String, showUI As UIOption, recycle As RecycleOption, onUserCancel As UICancelOption) - - End Sub - ' - ' Summary: - ' Moves a directory from one location to another. - ' - ' Parameters: - ' sourceDirectoryName: - ' Path of the directory to be moved. - ' - ' destinationDirectoryName: - ' Path of the directory to which the source directory is being moved. - ' - ' Exceptions: - ' T:System.ArgumentException: - ' The path is not valid for one of the following reasons: it is a zero-length string; - ' it contains only white space; it contains invalid characters; or it is a device - ' path (starts with \\.\). - ' - ' T:System.ArgumentNullException: - ' sourceDirectoryName or destinationDirectoryName is Nothing or an empty string. - ' - ' T:System.ArgumentNullException: - ' sourceDirectoryName or destinationDirectoryName is Nothing or an empty string. - ' - ' T:System.IO.DirectoryNotFoundException: - ' The directory does not exist. - ' - ' T:System.IO.IOException: - ' The source is a root directory or The source path and the target path are the - ' same. - ' - ' T:System.IO.PathTooLongException: - ' The path exceeds the system-defined maximum length. - ' - ' T:System.InvalidOperationException: - ' The operation is cyclic. - ' - ' T:System.NotSupportedException: - ' A file or directory name in the path contains a colon (:) or is in an invalid - ' format. - ' - ' T:System.Security.SecurityException: - ' The user lacks necessary permissions to view the path. - ' - ' T:System.UnauthorizedAccessException: - ' The user does not have required permission. - ''' - ''' - ''' - ''' - ''' - Public Sub MoveDirectory(sourceDirectoryName As String, destinationDirectoryName As String) - - End Sub - ' - ' Summary: - ' Moves a directory from one location to another. - ' - ' Parameters: - ' sourceDirectoryName: - ' Path of the directory to be moved. - ' - ' destinationDirectoryName: - ' Path of the directory to which the source directory is being moved. - ' - ' overwrite: - ' True if existing directories should be overwritten; otherwise False. Default - ' is False. - ' - ' Exceptions: - ' T:System.ArgumentException: - ' The path is not valid for one of the following reasons: it is a zero-length string; - ' it contains only white space; it contains invalid characters; or it is a device - ' path (starts with \\.\). - ' - ' T:System.ArgumentNullException: - ' sourceDirectoryName or destinationDirectoryName is Nothing or an empty string. - ' - ' T:System.ArgumentNullException: - ' sourceDirectoryName or destinationDirectoryName is Nothing or an empty string. - ' - ' T:System.IO.DirectoryNotFoundException: - ' The directory does not exist. - ' - ' T:System.IO.IOException: - ' The source is a root directory or The source path and the target path are the - ' same. - ' - ' T:System.IO.IOException: - ' The target directory already exists and overwrite is set to False. - ' - ' T:System.IO.PathTooLongException: - ' The path exceeds the system-defined maximum length. - ' - ' T:System.InvalidOperationException: - ' The operation is cyclic. - ' - ' T:System.NotSupportedException: - ' A file or directory name in the path contains a colon (:) or is in an invalid - ' format. + ' The file is in use. ' ' T:System.Security.SecurityException: ' The user lacks necessary permissions to view the path. ' + ' T:System.IO.FileNotFoundException: + ' The file does not exist. + ' ' T:System.UnauthorizedAccessException: - ' The user does not have required permission. + ' The user does not have permission to delete the file or the file is read-only. ''' ''' ''' - ''' - ''' - ''' - Public Sub MoveDirectory(sourceDirectoryName As String, destinationDirectoryName As String, overwrite As Boolean) + ''' + Public Sub DeleteFile(file As String) End Sub + ' ' Summary: ' Moves a directory from one location to another. @@ -1046,9 +432,6 @@ Namespace FileSystem ' destinationDirectoryName: ' Path of the directory to which the source directory is being moved. ' - ' showUI: - ' Specifies whether to visually track the operation's progress. Default is UIOption.OnlyErrorDialogs. - ' ' Exceptions: ' T:System.ArgumentException: ' The path is not valid for one of the following reasons: it is a zero-length string; @@ -1068,9 +451,6 @@ Namespace FileSystem ' The source is a root directory or The source path and the target path are the ' same. ' - ' T:System.IO.IOException: - ' The target directory already exists and overwrite is set to False. - ' ' T:System.IO.PathTooLongException: ' The path exceeds the system-defined maximum length. ' @@ -1091,8 +471,7 @@ Namespace FileSystem ''' ''' ''' - ''' - Public Sub MoveDirectory(sourceDirectoryName As String, destinationDirectoryName As String, showUI As UIOption) + Public Sub MoveDirectory(sourceDirectoryName As String, destinationDirectoryName As String) End Sub ' @@ -1106,12 +485,9 @@ Namespace FileSystem ' destinationDirectoryName: ' Path of the directory to which the source directory is being moved. ' - ' showUI: - ' Specifies whether to visually track the operation's progress. Default is UIOption.OnlyErrorDialogs. - ' - ' onUserCancel: - ' Specifies whether or not an exception is thrown when the user cancels the operation. - ' Default is UICancelOption.ThrowException. + ' overwrite: + ' True if existing directories should be overwritten; otherwise False. Default + ' is False. ' ' Exceptions: ' T:System.ArgumentException: @@ -1135,20 +511,6 @@ Namespace FileSystem ' T:System.IO.IOException: ' The target directory already exists and overwrite is set to False. ' - ' T:System.IO.IOException: - ' onUserCancel is set to ThrowException and a subdirectory of the file cannot be - ' copied. - ' - ' T:System.OperationCanceledException: - ' onUserCancel is set to ThrowException, and the user cancels the operation, or - ' the operation cannot be completed. - ' - ' T:System.Security.SecurityException: - ' onUserCancel is set to ThrowException, and the user lacks necessary permissions. - ' - ' T:System.Security.SecurityException: - ' The user lacks necessary permissions to view the path. - ' ' T:System.IO.PathTooLongException: ' The path exceeds the system-defined maximum length. ' @@ -1159,6 +521,9 @@ Namespace FileSystem ' A file or directory name in the path contains a colon (:) or is in an invalid ' format. ' + ' T:System.Security.SecurityException: + ' The user lacks necessary permissions to view the path. + ' ' T:System.UnauthorizedAccessException: ' The user does not have required permission. ''' @@ -1166,11 +531,11 @@ Namespace FileSystem ''' ''' ''' - ''' - ''' - Public Sub MoveDirectory(sourceDirectoryName As String, destinationDirectoryName As String, showUI As UIOption, onUserCancel As UICancelOption) + ''' + Public Sub MoveDirectory(sourceDirectoryName As String, destinationDirectoryName As String, overwrite As Boolean) End Sub + ' ' Summary: ' Moves a file to a new location. @@ -1264,115 +629,7 @@ Namespace FileSystem Public Sub MoveFile(sourceFileName As String, destinationFileName As String, overwrite As Boolean) End Sub - ' - ' Summary: - ' Moves a file to a new location. - ' - ' Parameters: - ' sourceFileName: - ' Path of the file to be moved. - ' - ' destinationFileName: - ' Path of the directory into which the file should be moved. - ' - ' showUI: - ' Specifies whether to visually track the operation's progress. Default is UIOption.OnlyErrorDialogs. - ' - ' Exceptions: - ' T:System.ArgumentException: - ' The path is not valid for one of the following reasons: it is a zero-length string; - ' it contains only white space; it contains invalid characters; or it is a device - ' path (starts with \\.\); it ends with a trailing slash. - ' - ' T:System.ArgumentNullException: - ' destinationFileName is Nothing or an empty string. - ' - ' T:System.IO.FileNotFoundException: - ' The source file is not valid or does not exist. - ' - ' T:System.IO.IOException: - ' The destination file exists and overwrite is set to False. - ' - ' T:System.IO.IOException: - ' The file is in use by another process, or an I/O error occurs. - ' - ' T:System.IO.PathTooLongException: - ' The path exceeds the system-defined maximum length. - ' - ' T:System.NotSupportedException: - ' A file or directory name in the path contains a colon (:) or is in an invalid - ' format. - ' - ' T:System.Security.SecurityException: - ' The user lacks necessary permissions to view the path. - ''' - ''' - ''' - ''' - ''' - ''' - Public Sub MoveFile(sourceFileName As String, destinationFileName As String, showUI As UIOption) - - End Sub - ' - ' Summary: - ' Moves a file to a new location. - ' - ' Parameters: - ' sourceFileName: - ' Path of the file to be moved. - ' - ' destinationFileName: - ' Path of the directory into which the file should be moved. - ' - ' showUI: - ' Specifies whether to visually track the operation's progress. Default is UIOption.OnlyErrorDialogs. - ' - ' onUserCancel: - ' Specifies whether or not an exception is thrown when the user cancels the operation. - ' Default is UICancelOption.ThrowException. - ' - ' Exceptions: - ' T:System.ArgumentException: - ' The path is not valid for one of the following reasons: it is a zero-length string; - ' it contains only white space; it contains invalid characters; or it is a device - ' path (starts with \\.\); it ends with a trailing slash. - ' - ' T:System.ArgumentNullException: - ' destinationFileName is Nothing or an empty string. - ' - ' T:System.IO.FileNotFoundException: - ' The source file is not valid or does not exist. - ' - ' T:System.IO.IOException: - ' The destination file exists and overwrite is set to False. - ' - ' T:System.IO.IOException: - ' The file is in use by another process, or an I/O error occurs. - ' - ' T:System.OperationCanceledException: - ' onUserCancel is set to ThrowException, and either the user has cancelled the - ' operation or an unspecified I/O error occurs. - ' - ' T:System.IO.PathTooLongException: - ' The path exceeds the system-defined maximum length. - ' - ' T:System.NotSupportedException: - ' A file or directory name in the path contains a colon (:) or is in an invalid - ' format. - ' - ' T:System.Security.SecurityException: - ' The user lacks necessary permissions to view the path. - ''' - ''' - ''' - ''' - ''' - ''' - ''' - Public Sub MoveFile(sourceFileName As String, destinationFileName As String, showUI As UIOption, onUserCancel As UICancelOption) - End Sub ' ' Summary: ' Renames a directory. @@ -2215,23 +1472,7 @@ Namespace FileSystem Dim rep As RequestStream = invoke.SendMessage(req) Return rep.GetUTF8String.LoadObject(Of FileHandle) End Function - ' - ' Summary: - ' The OpenTextFieldParser method allows you to create a Microsoft.VisualBasic.FileIO.TextFieldParser - ' object, which provides a way to easily and efficiently parse structured text - ' files, such as logs. The TextFieldParser object can be used to read both delimited - ' and fixed-width files. - ' - ' Parameters: - ' file: - ' The file to be opened with the TextFieldParser. - ' - ' delimiters: - ' Delimiters for the fields. - ' - ' Returns: - ' Microsoft.VisualBasic.FileIO.TextFieldParser to read the specified file. - ' + ' Exceptions: ' T:System.ArgumentException: ' The path is not valid for one of the following reasons: it is a zero-length string; @@ -2262,31 +1503,21 @@ Namespace FileSystem ' T:System.Security.SecurityException: ' The user lacks necessary permissions to view the path. ''' - ''' + ''' The OpenTextFieldParser method allows you to create a Microsoft.VisualBasic.FileIO.TextFieldParser + ''' object, which provides a way to easily and efficiently parse structured text + ''' files, such as logs. The TextFieldParser object can be used to read both delimited + ''' and fixed-width files. ''' - ''' - ''' - ''' + ''' The file to be opened with the TextFieldParser. + ''' Delimiters for the fields. + ''' Microsoft.VisualBasic.FileIO.TextFieldParser to read the specified file. Public Function OpenTextFieldParser(file As String, ParamArray delimiters() As String) As TextFieldParser - + Dim fileStream As New IO.FileStream(file, FileMode.Open, Me) + Dim parser As New TextFieldParser(fileStream, System.Text.Encoding.Default, True) + parser.Delimiters = delimiters + Return parser End Function - ' - ' Summary: - ' The OpenTextFieldParser method allows you to create a Microsoft.VisualBasic.FileIO.TextFieldParser - ' object, which provides a way to easily and efficiently parse structured text - ' files, such as logs. The TextFieldParser object can be used to read both delimited - ' and fixed-width files. - ' - ' Parameters: - ' file: - ' The file to be opened with the TextFieldParser. - ' - ' fieldWidths: - ' Widths of the fields. - ' - ' Returns: - ' Microsoft.VisualBasic.FileIO.TextFieldParser to read the specified file. - ' + ' Exceptions: ' T:System.ArgumentException: ' The path is not valid for one of the following reasons: it is a zero-length string; @@ -2317,25 +1548,21 @@ Namespace FileSystem ' T:System.Security.SecurityException: ' The user lacks necessary permissions to view the path. ''' - ''' + ''' The OpenTextFieldParser method allows you to create a Microsoft.VisualBasic.FileIO.TextFieldParser + ''' object, which provides a way to easily and efficiently parse structured text + ''' files, such as logs. The TextFieldParser object can be used to read both delimited + ''' and fixed-width files. ''' - ''' - ''' - ''' + ''' The file to be opened with the TextFieldParser. + ''' Widths of the fields. + ''' Microsoft.VisualBasic.FileIO.TextFieldParser to read the specified file. Public Function OpenTextFieldParser(file As String, ParamArray fieldWidths() As Integer) As TextFieldParser - + Dim fileStream As New IO.FileStream(file, FileMode.Open, Me) + Dim parser As New TextFieldParser(fileStream, System.Text.Encoding.Default, True) + parser.FieldWidths = fieldWidths + Return parser End Function - ' - ' Summary: - ' Opens a System.IO.StreamReader object to read from a file. - ' - ' Parameters: - ' file: - ' File to be read. - ' - ' Returns: - ' System.IO.StreamReader object to read from the file - ' + ' Exceptions: ' T:System.ArgumentException: ' The file name ends with a backslash (\). @@ -2345,28 +1572,15 @@ Namespace FileSystem ' ' T:System.Security.SecurityException: ' The user lacks necessary permissions to read from the file. - '''' - '''' - '''' - '''' - '''' - 'Public Function OpenTextFileReader(file As String) As IO.StreamReader + ''' + ''' Opens a System.IO.StreamReader object to read from a file. + ''' + ''' File to be read. + ''' System.IO.StreamReader object to read from the file + Public Function OpenTextFileReader(file As String) As System.IO.StreamReader + Return OpenTextFileReader(file, Encoding.ASCII) + End Function - 'End Function - ' - ' Summary: - ' Opens a System.IO.StreamReader object to read from a file. - ' - ' Parameters: - ' file: - ' File to be read. - ' - ' encoding: - ' The encoding to use for the file contents. Default is ASCII. - ' - ' Returns: - ' System.IO.StreamReader object to read from the file - ' ' Exceptions: ' T:System.ArgumentException: ' The file name ends with a backslash (\). @@ -2376,84 +1590,49 @@ Namespace FileSystem ' ' T:System.Security.SecurityException: ' The user lacks necessary permissions to read from the file. - '''' - '''' - '''' - '''' - '''' - '''' - 'Public Function OpenTextFileReader(file As String, encoding As Encoding) As IO.StreamReader + ''' + ''' Opens a System.IO.StreamReader object to read from a file. + ''' + ''' File to be read. + ''' The encoding to use for the file contents. Default is ASCII. + ''' System.IO.StreamReader object to read from the file + Public Function OpenTextFileReader(file As String, encoding As Encoding) As System.IO.StreamReader + Dim fileStream As New IO.FileStream(file, FileMode.OpenOrCreate, Me) + Dim reader As New System.IO.StreamReader(fileStream, encoding) + Return reader + End Function - 'End Function - ' - ' Summary: - ' Opens a System.IO.StreamWriter object to write to the specified file. - ' - ' Parameters: - ' file: - ' File to be written to. - ' - ' append: - ' True to append to the contents of the file; False to overwrite the contents of - ' the file. Default is False. - ' - ' Returns: - ' System.IO.StreamWriter object to write to the specified file. - ' ' Exceptions: ' T:System.ArgumentException: ' The file name ends with a trailing slash. - '''' - '''' - '''' - '''' - '''' - '''' - 'Public Function OpenTextFileWriter(file As String, append As Boolean) As IO.StreamWriter + ''' + ''' Opens a System.IO.StreamWriter object to write to the specified file. + ''' + ''' File to be written to. + ''' True to append to the contents of the file; False to overwrite the contents of + ''' the file. Default is False. + ''' System.IO.StreamWriter object to write to the specified file. + Public Function OpenTextFileWriter(file As String, append As Boolean) As System.IO.StreamWriter + Return OpenTextFileWriter(file, append, System.Text.Encoding.ASCII) + End Function - 'End Function - ' - ' Summary: - ' Opens a System.IO.StreamWriter to write to the specified file. - ' - ' Parameters: - ' file: - ' File to be written to. - ' - ' append: - ' True to append to the contents in the file; False to overwrite the contents of - ' the file. Default is False. - ' - ' encoding: - ' Encoding to be used in writing to the file. Default is ASCII. - ' - ' Returns: - ' System.IO.StreamWriter object to write to the specified file. - ' ' Exceptions: ' T:System.ArgumentException: ' The file name ends with a trailing slash. - '''' - '''' - '''' - '''' - '''' - '''' - '''' - 'Public Function OpenTextFileWriter(file As String, append As Boolean, encoding As Encoding) As IO.StreamWriter + ''' + ''' Opens a System.IO.StreamWriter to write to the specified file. + ''' + ''' File to be written to. + ''' True to append to the contents in the file; False to overwrite the contents of + ''' the file. Default is False. + ''' Encoding to be used in writing to the file. Default is ASCII. + ''' System.IO.StreamWriter object to write to the specified file. + Public Function OpenTextFileWriter(file As String, append As Boolean, encoding As Encoding) As System.IO.StreamWriter + Dim mode As FileMode = If(append, FileMode.Append, FileMode.OpenOrCreate) + Dim fileStream As New IO.FileStream(file, mode, Me) + Return New StreamWriter(fileStream, encoding) + End Function - 'End Function - ' - ' Summary: - ' Returns the contents of a file as a byte array. - ' - ' Parameters: - ' file: - ' File to be read. - ' - ' Returns: - ' Byte array containing the contents of the file. - ' ' Exceptions: ' T:System.ArgumentException: ' The path is not valid for one of the following reasons: it is a zero-length string; @@ -2482,24 +1661,17 @@ Namespace FileSystem ' T:System.Security.SecurityException: ' The user lacks necessary permissions to view the path. ''' - ''' + ''' Returns the contents of a file as a byte array. ''' - ''' - ''' + ''' File to be read. + ''' Byte array containing the contents of the file. Public Function ReadAllBytes(file As String) As Byte() - + Dim fileStream As New IO.FileStream(file, FileMode.Open, Me) + Dim buffer As Byte() = New Byte(fileStream.Length - 1) {} + Call fileStream.Read(buffer, Scan0, buffer.Length) + Return buffer End Function - ' - ' Summary: - ' Returns the contents of a text file as a String. - ' - ' Parameters: - ' file: - ' Name and path of the file to read. - ' - ' Returns: - ' String containing the contents of the file. - ' + ' Exceptions: ' T:System.ArgumentException: ' The path is not valid for one of the following reasons: it is a zero-length string; @@ -2529,27 +1701,14 @@ Namespace FileSystem ' The user lacks necessary permissions to view the path. ''' - ''' + ''' Returns the contents of a text file as a String. ''' - ''' - ''' + ''' Name and path of the file to read. + ''' String containing the contents of the file. Public Function ReadAllText(file As String) As String - + Return ReadAllText(file, Encoding.ASCII) End Function - ' - ' Summary: - ' Returns the contents of a text file as a String. - ' - ' Parameters: - ' file: - ' Name and path of the file to read. - ' - ' encoding: - ' Character encoding to use in reading the file. Default is UTF-8. - ' - ' Returns: - ' String containing the contents of the file. - ' + ' Exceptions: ' T:System.ArgumentException: ' The path is not valid for one of the following reasons: it is a zero-length string; @@ -2578,13 +1737,14 @@ Namespace FileSystem ' T:System.Security.SecurityException: ' The user lacks necessary permissions to view the path. ''' - ''' + ''' Returns the contents of a text file as a String. ''' - ''' - ''' - ''' + ''' Name and path of the file to read. + ''' Character encoding to use in reading the file. Default is UTF-8. + ''' String containing the contents of the file. Public Function ReadAllText(file As String, encoding As Encoding) As String - + Dim reader = OpenTextFileReader(file, encoding) + Return reader.ReadToEnd End Function End Class End Namespace