Skip to main content

RemoteFiles.RemoteAltaFile<TFileType>

An abstract class in Alta.IO, Alta.Utilities.

Base for a save file that works on a local copy and syncs it with a remote store (disk path or S3). The local copy is pulled from remote on first read and pushed back on backup.

Constructors​

MemberWhat it is
RemoteAltaFile(IAltaFile internalFile, TFileType remoteFileInfo)Creates a RemoteFiles.RemoteAltaFile from internalFile and remoteFileInfo.

Fields​

MemberWhat it is
protected IAltaFile localFileThe local working copy.
protected TFileType remoteFileInfoAccess to the remote copy.
4 private and internal fields
MemberWhat it is
private Task backupToRemoteThe backup task in progress, or null.
private Task copyFromRemoteThe download task in progress, or null.
private bool hasBeenCopiedSet once the first pull from remote has started.
private Stopwatch timerStopwatch used to log how long copies take.

Properties​

MemberWhat it is
IAltaFileFormat Content { get; set; }The local file's loaded content.
string FullName { get; }The local file's full path.
bool HasChanged { get; }Whether the local file has unsaved-to-remote changes.
bool IsExisting { get; }Checks the remote file until the first copy, then the local file.
bool IsReading { get; }Whether the local file is being read.
bool IsWriting { get; }Whether the local file is being written.
string Name { get; }The local file's name.

Methods​

MemberWhat it is
void BackupInstant()Blocking backup of the local file to remote. Errors are logged, not thrown.
Task BackupToRemote()Starts an async backup unless one is already running for this file.
void Delete(bool isDeletingBackup = false)Deletes the remote file, then the local one.
async Task DeleteAsync(bool isDeletingBackup = false)Async version of Delete.
async Task EnsureCopied()Pulls the file from remote the first time it is called and waits for any copy still running.
void FinishReading()Passes through to the local file.
void FinishWriting()Passes through to the local file.
void MoveTo(IAltaFolder folder)Moves the local file only; the remote copy stays where it is.
void QueueUnload()Passes through to the local file.
async Task QueueUnloadAsync()Passes through to the local file.
Task<T> ReadAsync<T>()Pulls the file from remote if not done yet, then reads it from the local copy.
async Task<T> ReadAsync<T>(Func<T> create)Pulls the file from remote if not done yet, then reads it from the local copy.
void Refresh()Refreshes both the remote and local file info.
void ResetHasChanged()Clears the local file's changed flag.
async void WriteAsync()Waits for any running backup, then writes the local file.
protected virtual void BackupInstantInternal()Blocking upload. Default waits on BackupToRemoteInternal.
protected abstract Task BackupToRemoteInternal()Implemented by subclasses to upload the local file.
protected abstract Task CopyFromRemoteInternal()Implemented by subclasses to download the remote file.
protected override void Finalize()Removes the file from allRemoteFiles. In practice that list keeps it alive, so this does not run.
3 private and internal methods
MemberWhat it is
private async Task BackUpAsync()Uploads the local file if it exists, clears the changed flag, and removes the file from the backing-up set.
private async Task CopyFromRemote()Downloads the remote file over the local one if it exists, then refreshes both.
private Task WaitForBackup()Returns the running backup task, or a completed task if none.