IDocumentFileLease interface

Namespace Runic.Platform in Runic.Platform 0.23.0

public interface IDocumentFileLease : ISaveFileLease, IAsyncDisposable

Inherits or implements ISaveFileLease, IAsyncDisposable.

Owns read and write access to one document the user opened or saved: the application reads it, saves it back as often as it needs and keeps it in a recent-files list.

Remarks

A lease from IFileDialogs.OpenDocumentAsync or IFileDialogs.SaveDocumentAsync is released when its presentation closes, as every dialog lease is; one from IDesktopFileBookmarks.OpenDocumentAsync keeps the bookmark's access until it is disposed.

Writes follow ISaveFileLease.BeginWriteAsync. To overwrite a file after a PlatformFailureCode.Conflict, read it with IDocumentFileLease.OpenReadAsync, which makes its current content the content the application last saw, and write again.

Properties

LocalPath

string LocalPath { get; }

The document's local path, such as for detecting a document that is already open or showing where it is. In a Flatpak it is the document portal's path. Throws after the lease is released.

Remarks

Read and write the document through the lease; access to the path itself ends with the lease.

Methods

OpenReadAsync

ValueTask<PlatformResult<Stream>> OpenReadAsync(CancellationToken cancellationToken = default)

Opens a new seekable stream of the document's current content, which the caller owns.

Returns

The stream; PlatformFailureCode.NotFound when the file no longer exists, PlatformFailureCode.PermissionDenied when it cannot be read and PlatformFailureCode.IOError for another failure, including a path that is no longer a regular file.

Remarks

Each call opens the file again; during an open write transaction it reads the committed file, never the staged bytes. The content read becomes the content a later commit compares with, also for a transaction that is already open; a missing file makes its absence that content. Disposing the lease closes the streams still open.