private UploadFinished ( string parentId, string name, bool withError ) : Task | ||
parentId | string | |
name | string | |
withError | bool | |
return | Task |
internal async Task UploadFinished(string parentId, string name, bool withError)
{
BackgroundUpload uploader;
var id = GetFileId(parentId, name);
_uploadsLock.Wait();
try
{
uploader = _uploads[id];
if (withError)
{
_cache.Remove(id);
}
else
{
_cache.Set(id, uploader.Item, _defaultCacheTimeSpan);
}
_uploads.Remove(id);
}
finally
{
_uploadsLock.Release();
}
if (!withError && uploader.ItemChanges != null)
{
var updatedItem = await Service.UpdateAsync(Drive.Id, uploader.Item.Id, uploader.ItemChanges, CancellationToken.None);
_cache.Set(id, updatedItem, _defaultCacheTimeSpan);
}
}
public async Task Start(CancellationToken cancellationToken) { using (var stream = await _tempData.OpenAsync()) { bool withError = false; try { Item = await _fileSystem.Service.UploadFileAsync(_fileSystem.Drive.Id, ParentId, Name, stream, cancellationToken); } catch (OperationCanceledException) { withError = true; if (Item == null) { throw new InvalidOperationException("The Item property must be set. The UploadFileAsync function must not return a NULL value."); } Item.Size = stream.Position; throw; } finally { _notifiedAsFinished = true; await _fileSystem.UploadFinished(ParentId, Name, withError); } } }