private static FileEntryItem CreateFileEntryForUpload(VolumeWriterBase volume, Options options) { var fileEntry = new FileEntryItem(BackendActionType.Put, volume.RemoteFilename); fileEntry.SetLocalfilename(volume.LocalFilename); fileEntry.Encrypt(options); fileEntry.UpdateHashAndSize(options); return(fileEntry); }
private async Task UploadVolumeWriter(VolumeWriterBase volumeWriter, Worker worker, CancellationToken cancelToken) { var fileEntry = new FileEntryItem(BackendActionType.Put, volumeWriter.RemoteFilename); fileEntry.SetLocalfilename(volumeWriter.LocalFilename); fileEntry.Encrypt(m_options); fileEntry.UpdateHashAndSize(m_options); await UploadFileAsync(fileEntry, worker, cancelToken).ConfigureAwait(false); }
public Task PutUnencryptedAsync(string remotename, string localpath) { var fe = new FileEntryItem(BackendActionType.Put, remotename); fe.SetLocalfilename(localpath); fe.Encrypted = true; //Prevent encryption fe.TrackedInDb = false; //Prevent Db updates return(RunRetryOnMain <bool>(fe, async() => { await DoPut(fe).ConfigureAwait(false); m_uploadSuccess = true; return true; })); }
public async Task UploadFileAsync(VolumeWriterBase item, Func <string, Task <IndexVolumeWriter> > createIndexFile = null) { var fe = new FileEntryItem(BackendActionType.Put, item.RemoteFilename); fe.SetLocalfilename(item.LocalFilename); var tcs = new TaskCompletionSource <bool>(); var backgroundhashAndEncrypt = Task.Run(() => { fe.Encrypt(m_options); return(fe.UpdateHashAndSize(m_options)); }); await RunOnMain(async() => { try { await DoWithRetry(fe, async() => { if (fe.IsRetry) { await RenameFileAfterErrorAsync(fe).ConfigureAwait(false); } // Make sure the encryption and hashing has completed await backgroundhashAndEncrypt.ConfigureAwait(false); return(await DoPut(fe).ConfigureAwait(false)); }).ConfigureAwait(false); if (createIndexFile != null) { var ix = await createIndexFile(fe.RemoteFilename).ConfigureAwait(false); var indexFile = new FileEntryItem(BackendActionType.Put, ix.RemoteFilename); indexFile.SetLocalfilename(ix.LocalFilename); await m_database.UpdateRemoteVolumeAsync(indexFile.RemoteFilename, RemoteVolumeState.Uploading, -1, null); await DoWithRetry(indexFile, async() => { if (indexFile.IsRetry) { await RenameFileAfterErrorAsync(indexFile).ConfigureAwait(false); } var res = await DoPut(indexFile).ConfigureAwait(false); // Register that the index file is tracking the block file await m_database.AddIndexBlockLinkAsync( ix.VolumeID, await m_database.GetRemoteVolumeIDAsync(fe.RemoteFilename) ).ConfigureAwait(false); return(res); }); } tcs.TrySetResult(true); } catch (Exception ex) { if (ex is System.Threading.ThreadAbortException) { tcs.TrySetCanceled(); } else { tcs.TrySetException(ex); } } }); await tcs.Task.ConfigureAwait(false); }
public void PutUnencrypted(string remotename, string localpath) { if (m_lastException != null) throw m_lastException; var req = new FileEntryItem(OperationType.Put, remotename, null); req.SetLocalfilename(localpath); req.Encrypted = true; //Prevent encryption req.NotTrackedInDb = true; //Prevent Db updates if (m_queue.Enqueue(req) && m_options.SynchronousUpload) { req.WaitForComplete(); if (req.Exception != null) throw req.Exception; } if (m_lastException != null) throw m_lastException; }