Class LocalStorageService
This class implements the storage interface for implementing file IO with the local server disk storage.
Inheritance
Implements
Inherited Members
Namespace: Talegen.Storage.Net.Core.Disk
Assembly: Talegen.Storage.Net.Core.dll
Syntax
public class LocalStorageService : IStorageService
Constructors
| Improve this Doc View SourceLocalStorageService(String, Boolean)
Initializes a new instance of the LocalStorageService class.
Declaration
public LocalStorageService(string workspacePath, bool uniqueWorkspace = false)
Parameters
Type | Name | Description |
---|---|---|
System.String | workspacePath | Contains the root path where the local storage folder and file structure begins. |
System.Boolean | uniqueWorkspace | Contains a value indicating whether the storage service shall use a unique workspace sub-folder. |
LocalStorageService(LocalStorageContext)
Initializes a new instance of the LocalStorageService class.
Declaration
public LocalStorageService(LocalStorageContext storageContext)
Parameters
Type | Name | Description |
---|---|---|
LocalStorageContext | storageContext | Contains an implementation of the storage context. |
Properties
| Improve this Doc View SourceRootPath
Gets or sets the root folder path for this service instance.
Declaration
public string RootPath { get; set; }
Property Value
Type | Description |
---|---|
System.String |
StorageId
Gets or sets the storage identity for this service instance.
Declaration
public string StorageId { get; }
Property Value
Type | Description |
---|---|
System.String |
Methods
| Improve this Doc View SourceCopyFile(String, String, Boolean)
This method is used to copy a file.
Declaration
public void CopyFile(string sourceFilePath, string targetFilePath, bool overwrite = true)
Parameters
Type | Name | Description |
---|---|---|
System.String | sourceFilePath | Contains a the path to the file that will be copied. |
System.String | targetFilePath | Contains the path to the target where the file is to be copied. |
System.Boolean | overwrite | Contains a value indicating if the target should be overwritten if it already exists. Default is true. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | sourceFilePath or targetFilePath |
StorageException |
CreateDirectory(String, Boolean)
This method is used to create a temporary directory within the Inspire application path.
Declaration
public string CreateDirectory(string subFolderName, bool silentExists = false)
Parameters
Type | Name | Description |
---|---|---|
System.String | subFolderName | Contains a sub-folder that will be included in the working directory path. |
System.Boolean | silentExists | Contains a value indicating whether the method is silently return successfully if the folder path already exists. |
Returns
Type | Description |
---|---|
System.String | Returns the name of the directory that was created. |
Exceptions
Type | Condition |
---|---|
StorageException | This exception is thrown if the directory is unable to be created. |
DeleteDirectory(String, Boolean, Boolean)
This method is used to delete a sub-folder directory and all of its files.
Declaration
public void DeleteDirectory(string subFolderName, bool recursive = true, bool silentNoExist = true)
Parameters
Type | Name | Description |
---|---|---|
System.String | subFolderName | Contains the sub-folder name of the directory off the root working folder that will be deleted. |
System.Boolean | recursive | Delete all contents within the folder. |
System.Boolean | silentNoExist | Contains a value indicating whether an exception is thrown if the target folder does not exist. Default is true; no exception is thrown if the folder does not exist. |
Exceptions
Type | Condition |
---|---|
StorageException | This exception is thrown if the directory is unable to be deleted. |
DeleteFile(String, Boolean)
This method is used to delete a file.
Declaration
public void DeleteFile(string filePath, bool deleteDirectory = false)
Parameters
Type | Name | Description |
---|---|---|
System.String | filePath | Contains a the path to the file that will be deleted. |
System.Boolean | deleteDirectory | Contains a value indicating whether the directory the file is within will be deleted. This will only occur if no other files remain in the directory after the list of files have been deleted. |
DeleteFiles(List<String>, Boolean)
This method is used to delete a a list of files.
Declaration
public void DeleteFiles(List<string> filePathNames, bool deleteFolders = false)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.List<System.String> | filePathNames | Contains a list of file names that will be deleted. |
System.Boolean | deleteFolders | Contains a value indicating whether the directory or directories the files are within will be deleted. This will only occur if no other files remain in the directory after the list of files have been deleted. |
DirectoryExists(String)
Contains a value indicating whether the folder already exists.
Declaration
public bool DirectoryExists(string subFolderName)
Parameters
Type | Name | Description |
---|---|---|
System.String | subFolderName | Contains the sub-folder name excluding the root folder path. |
Returns
Type | Description |
---|---|
System.Boolean | Returns a value indicating whether the directory exists. |
EmptyDirectory(String)
This method is used to delete all directories and files inside of a sub-folder within the specified workspace root path, however the folder is left in place empty.
Declaration
public void EmptyDirectory(string subFolderName)
Parameters
Type | Name | Description |
---|---|---|
System.String | subFolderName | Contains the sub-folder within the within the specified workspace root path to empty. |
FileExists(String)
Contains a value indicating whether the file exists.
Declaration
public bool FileExists(string filePath)
Parameters
Type | Name | Description |
---|---|---|
System.String | filePath | Contains the sub-folder path and file name excluding the root folder path to determine if exists. |
Returns
Type | Description |
---|---|
System.Boolean | Returns a value indicating whether the file exists. |
FileHash(String)
This method is used to create a hash of the file contents.
Declaration
public string FileHash(string filePath)
Parameters
Type | Name | Description |
---|---|---|
System.String | filePath | Contains the path to the file to hash. |
Returns
Type | Description |
---|---|
System.String | Returns a hash of the file contents. |
FindFiles(String, String, SearchOption)
This method is used to get the files from a directory.
Declaration
public List<string> FindFiles(string subFolderName, string searchPattern = "*.*", SearchOption searchOption = SearchOption.AllDirectories)
Parameters
Type | Name | Description |
---|---|---|
System.String | subFolderName | Contains the directory name to get the files. |
System.String | searchPattern | Contains an optional file name search pattern. If not specified, . is used. |
System.IO.SearchOption | searchOption | Contains search options. If not specified, all sub-folders are searched for the file pattern. |
Returns
Type | Description |
---|---|
System.Collections.Generic.List<System.String> | Returns a list of files in the directory path. |
Initialize(LocalStorageContext)
This method is used to initialize a storage service with the specified settings provided within the IStorageContext object.
Declaration
public void Initialize(LocalStorageContext storageContext)
Parameters
Type | Name | Description |
---|---|---|
LocalStorageContext | storageContext | Contains the settings used to initialize the storage service. |
MoveFile(String, String, Boolean)
This method is used to move a file.
Declaration
public void MoveFile(string sourceFilePath, string targetFilePath, bool overwrite = true)
Parameters
Type | Name | Description |
---|---|---|
System.String | sourceFilePath | Contains a the path to the file that will be moved. |
System.String | targetFilePath | Contains the path to the target where the file is to be moved. |
System.Boolean | overwrite | Contains a value indicating if the target should be overwritten if it already exists. Default is true. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | sourceFilePath or targetFilePath |
StorageException |
ReadBinaryFile(String)
This method is used to read all the bytes from a binary file.
Declaration
public byte[] ReadBinaryFile(string path)
Parameters
Type | Name | Description |
---|---|---|
System.String | path | Contains the path to the file to load and return. |
Returns
Type | Description |
---|---|
System.Byte[] | Returns a byte array containing the binary bytes of the target file. |
ReadBinaryFile(String, Stream)
This method is used to read all the bytes from a binary file to a provided stream.
Declaration
public void ReadBinaryFile(string path, Stream outputStream)
Parameters
Type | Name | Description |
---|---|---|
System.String | path | Contains the path to the file to load into the stream. |
System.IO.Stream | outputStream | The stream to write the file to. |
ReadTextFile(String, Encoding)
This method is used to read all the bytes from a text file.
Declaration
public string ReadTextFile(string path, Encoding encoding = null)
Parameters
Type | Name | Description |
---|---|---|
System.String | path | Contains the path to the file to load and return. |
System.Text.Encoding | encoding | Contains the text encoding type. If none is specified, Encoding.Default is used. |
Returns
Type | Description |
---|---|
System.String | Returns a string containing the content of the target file. |
WriteBinaryFile(FileStream, Byte[])
This method is used to write content to the specified file stream.
Declaration
public bool WriteBinaryFile(FileStream fileStream, byte[] content)
Parameters
Type | Name | Description |
---|---|---|
System.IO.FileStream | fileStream | Contains the file stream to which the binary content shall be written. |
System.Byte[] | content | Contains a byte array of the content to be written. |
Returns
Type | Description |
---|---|
System.Boolean | Returns a value indicating whether the write was successful. |
WriteBinaryFile(String, Byte[])
This method is used to write content to the specified path.
Declaration
public bool WriteBinaryFile(string path, byte[] content)
Parameters
Type | Name | Description |
---|---|---|
System.String | path | Contains the fully qualified path, including file name, to the location in which the binary content shall be written. |
System.Byte[] | content | Contains a byte array of the content to be written. |
Returns
Type | Description |
---|---|
System.Boolean | Returns a value indicating whether the write was successful. |
WriteBinaryFile(String, Stream)
This method is used to write content to the specified path.
Declaration
public bool WriteBinaryFile(string path, Stream inputStream)
Parameters
Type | Name | Description |
---|---|---|
System.String | path | Contains the fully qualified path, including file name, to the location in which the binary content shall be written. |
System.IO.Stream | inputStream | Contains a stream of the content to be written. |
Returns
Type | Description |
---|---|
System.Boolean | Returns a value indicating whether the write was successful. |
WriteTextFile(String, String, Encoding)
This method is used to write content to the specified path.
Declaration
public bool WriteTextFile(string path, string content, Encoding encoding = null)
Parameters
Type | Name | Description |
---|---|---|
System.String | path | Contains the fully qualified path, including file name, to the location in which the text content shall be written. |
System.String | content | Contains a string of the content to be written. |
System.Text.Encoding | encoding | Contains the text file encoding. If none specified, Encoding.Default is used. |
Returns
Type | Description |
---|---|
System.Boolean | Returns a value indicating whether the write was successful. |