Class Storage
Allows access to an isolated storage area containing application files.
Implements
Inherited Members
Namespace: Evergine.Framework.Services
Assembly: Evergine.Framework.dll
Syntax
public sealed class Storage : Service, IDependencyObject
Remarks
The access is not thread-safe.
Constructors
Storage()
Initializes a new instance of the Storage class.
Declaration
public Storage()
Storage(string)
Initializes a new instance of the Storage class.
Declaration
public Storage(string rootPath)
Parameters
Type | Name | Description |
---|---|---|
string | rootPath | The root path of the isolated storage. |
Properties
RootPath
Gets the root path of the isolated storage.
Declaration
public string RootPath { get; }
Property Value
Type | Description |
---|---|
string |
Methods
AppendAllTextAsync(string, string)
Asynchronously appends the specified string to the file, creating the file if it does not already exist.
Declaration
public Task AppendAllTextAsync(string filename, string contents)
Parameters
Type | Name | Description |
---|---|---|
string | filename | The file to append the specified string to. |
string | contents | The string to append to the file. |
Returns
Type | Description |
---|---|
Task | Task that represents asynchronous operation. |
Remarks
This method opens the specified file, appends the string to the end of the file using the specified encoding, and then closes the file. The file handle is guaranteed to be closed by this method, even if exceptions are raised.
The method creates the file if it doesn't exist.
ClearAsync()
Asynchronously deletes all the files in the isolated storage.
Declaration
public Task ClearAsync()
Returns
Type | Description |
---|---|
Task | Task that represents asynchronous operation. |
DeleteAsync(string)
Asynchronously deletes the specified file.
Declaration
public Task DeleteAsync(string filename)
Parameters
Type | Name | Description |
---|---|---|
string | filename | The name of the file to be deleted. Wildcard characters are not supported. |
Returns
Type | Description |
---|---|
Task | Task that represents asynchronous operation. |
Remarks
If the file to be deleted does not exist, no exception is thrown.
DeleteAsync<T>()
Asynchronously deletes the specified type file.
Declaration
public Task DeleteAsync<T>()
Returns
Type | Description |
---|---|
Task | Task that represents asynchronous operation. |
Type Parameters
Name | Description |
---|---|
T | The type of the file to be removed. |
Remarks
If the file to be deleted does not exist, no exception is thrown.
EnumerateFiles()
Returns an enumerable collection of file names in the isolated storage area.
Declaration
public IEnumerable<string> EnumerateFiles()
Returns
Type | Description |
---|---|
IEnumerable<string> | An enumerable collection of the file names in the isolated storage area. |
EnumerateFiles(string)
Returns an enumerable collection of file names in the isolated storage area.
Declaration
public IEnumerable<string> EnumerateFiles(string searchPattern)
Parameters
Type | Name | Description |
---|---|---|
string | searchPattern | The search string to match against the names of files. This parameter can contain a combination of valid literal path and wildcard (* and ?) characters, but it doesn't support regular expressions. |
Returns
Type | Description |
---|---|
IEnumerable<string> | An enumerable collection of the file names in the isolated storage area. |
Exists(string)
Determines whether the specified file exists.
Declaration
public bool Exists(string filename)
Parameters
Type | Name | Description |
---|---|---|
string | filename | The file to check. |
Returns
Type | Description |
---|---|
bool |
|
Exists<T>()
Determines whether the isolated storage contains a file for the specified type.
Declaration
public bool Exists<T>()
Returns
Type | Description |
---|---|
bool |
|
Type Parameters
Name | Description |
---|---|
T | The type of the file to check. |
GetFullPath(string)
Gets file full path from storage.
Declaration
public string GetFullPath(string filename)
Parameters
Type | Name | Description |
---|---|---|
string | filename | Storage file name. |
Returns
Type | Description |
---|---|
string | File full path. |
OnLoaded()
Invoked when the object is loaded.
Declaration
protected override void OnLoaded()
Overrides
ReadAllTextAsync(string)
Opens a file, asynchronously reads all lines of the file, and then closes the file.
Declaration
public Task<string> ReadAllTextAsync(string filename)
Parameters
Type | Name | Description |
---|---|---|
string | filename | The file to open for reading. |
Returns
Type | Description |
---|---|
Task<string> | A task with a string containing all lines of the file. |
Remarks
This method opens a file, reads each line of the file, and then adds each line as an element of a string. It then closes the file. A line is defined as a sequence of characters followed by a carriage return ('\r'), a line feed ('\n'), or a carriage return immediately followed by a line feed. The resulting string does not contain the terminating carriage return and/or line feed.
The file handle is guaranteed to be closed by this method, even if exceptions are raised.
ReadAsync(string)
Opens a binary file, asynchronously reads the contents of the file into a memory stream, and then closes the file.
Declaration
public Task<MemoryStream> ReadAsync(string filename)
Parameters
Type | Name | Description |
---|---|---|
string | filename | The file to open for reading. |
Returns
Type | Description |
---|---|
Task<MemoryStream> | A task with a stream containing the contents of the file. |
Remarks
This method opens the file, reads the contents of the file into a memory stream, and then closes the file.
ReadAsync(string, CancellationToken)
Opens a binary file, asynchronously reads the contents of the file into a memory stream, and then closes the file, and monitors cancellation requests.
Declaration
public Task<MemoryStream> ReadAsync(string filename, CancellationToken cancellationToken)
Parameters
Type | Name | Description |
---|---|---|
string | filename | The file to open for reading. |
CancellationToken | cancellationToken | The cancellation token. |
Returns
Type | Description |
---|---|
Task<MemoryStream> | A task with a stream containing the contents of the file. |
Remarks
This method opens the file, reads the contents of the file into a memory stream, and then closes the file.
ReadAsync<T>()
Opens a file, asynchronously deserializes the contents of the file into a object, and then closes the file.
Declaration
public Task<T> ReadAsync<T>()
Returns
Type | Description |
---|---|
Task<T> | A task with the deserialized object. |
Type Parameters
Name | Description |
---|---|
T | The type of the file for reading. |
Remarks
This method opens the file, reads the contents of the file, and then closes the file.
WriteAllTextAsync(string, string)
Creates a new file, asynchronously writes the specified string to the file, and then closes the file. If the target file already exists, it is overwritten.
Declaration
public Task WriteAllTextAsync(string filename, string contents)
Parameters
Type | Name | Description |
---|---|---|
string | filename | The file to write to. |
string | contents | The string to write to the file. |
Returns
Type | Description |
---|---|
Task | Task that represents asynchronous operation. |
Remarks
The method creates the file if it doesn't exist.
WriteAsync(string, Stream)
Creates a new file, asynchronously writes the specified stream to the file, and then closes the file. If the target file already exists, it is overwritten.
Declaration
public Task WriteAsync(string filename, Stream stream)
Parameters
Type | Name | Description |
---|---|---|
string | filename | The file to write to. |
Stream | stream | The stream to write to the file. |
Returns
Type | Description |
---|---|
Task | Task that represents asynchronous operation. |
Remarks
The method creates the file if it doesn't exist.
WriteAsync(string, Stream, CancellationToken)
Creates a new file, asynchronously writes the specified stream to the file, and then closes the file, and monitors cancellation requests. If the target file already exists, it is overwritten.
Declaration
public Task WriteAsync(string filename, Stream stream, CancellationToken cancellationToken)
Parameters
Type | Name | Description |
---|---|---|
string | filename | The file to write to. |
Stream | stream | The stream to write to the file. |
CancellationToken | cancellationToken | The cancellation token. |
Returns
Type | Description |
---|---|
Task | Task that represents asynchronous operation. |
Remarks
The method creates the file if it doesn't exist.
WriteAsync<T>(T)
Creates a new file, asynchronously writes the serialized object to the file, and then closes the file. If the target file already exists, it is overwritten.
Declaration
public Task WriteAsync<T>(T obj)
Parameters
Type | Name | Description |
---|---|---|
T | obj | The instance to be serialized. |
Returns
Type | Description |
---|---|
Task | Task that represents asynchronous operation. |
Type Parameters
Name | Description |
---|---|
T | The type of the file to write to. |
Remarks
The method creates the file if it doesn't exist.