public override void FinalizeItemWrite(Stream stream, EntryUpdateInfo updateInfo) { stream.Flush(); stream.Close(); SyncEntryAdapterData adapterEntry = updateInfo.Entry.AdapterEntries.FirstOrDefault(e => e.AdapterId == this.Config.Id); if (adapterEntry == null) { adapterEntry = new SyncEntryAdapterData() { SyncEntry = updateInfo.Entry, AdapterId = this.Configuration.Id, }; // [2018-04-30] It appears that the SyncEntryId field needs to be set on the adapter entry // in order to avoid a referential integrity violation in the DB. adapterEntry.SyncEntryId = updateInfo.Entry.Id; updateInfo.Entry.AdapterEntries.Add(adapterEntry); } string fullPath; using (var db = this.Relationship.GetDatabase()) { fullPath = Path.Combine( this.Config.RootDirectory, updateInfo.Entry.GetRelativePath(db, this.PathSeparator)); } adapterEntry.AdapterEntryId = GetItemId(fullPath, false); }
public override void FinalizeItemWrite(Stream stream, EntryUpdateInfo updateInfo) { string fileId; if (stream is BackblazeB2LargeUploadStream largeUploadStream) { long size = largeUploadStream.Session.Entry.GetSize(this.Relationship, SyncEntryPropertyLocation.Destination); if (largeUploadStream.Session.BytesUploaded != size) { // TODO: Cancel the upload? throw new Exception( string.Format( "File size if {0}, but uploaded {1}", size, largeUploadStream.Session.BytesUploaded)); } // Allocate the hash array to contain exactly the expected number of hashes string[] partSha1Array = new string[largeUploadStream.Session.CurrentPartNumber]; for (int i = 1; i < largeUploadStream.Session.CurrentPartNumber; i++) { partSha1Array[i] = largeUploadStream.Session.PartHashes[i]; } this.backblazeClient.FinishLargeFile( largeUploadStream.Session.StartLargeFileResponse.FileId, partSha1Array).Wait(); fileId = largeUploadStream.Session.UploadResponse.FileId; } else if (stream is BackblazeB2UploadStream uploadStream) { uploadStream.Flush(); fileId = uploadStream.Session.UploadResponse.FileId; } else { throw new NotImplementedException(); } SyncEntryAdapterData adapterData = updateInfo.Entry.AdapterEntries.FirstOrDefault(a => a.AdapterId == this.Configuration.Id); if (adapterData == null) { adapterData = new SyncEntryAdapterData { SyncEntry = updateInfo.Entry, AdapterId = this.Configuration.Id }; updateInfo.Entry.AdapterEntries.Add(adapterData); } adapterData.AdapterEntryId = fileId; }
public override void FinalizeItemWrite(Stream stream, EntryUpdateInfo updateInfo) { AzureStorageUploadStream uploadStream = stream as AzureStorageUploadStream; Pre.ThrowIfArgumentNull(uploadStream, "uploadStream"); // If there are any block IDs in the block list, then the file was uploaded using blocks (as opposed to // uploading the file as a single blob). For this, we need to call PutBlockList to finalize the creation // of the blob in storage. if (uploadStream.BlockList.Any()) { HttpResponseMessage response = this.storageClient.PutBlockListAsync( this.TypedConfiguration.ContainerName, uploadStream.FileName, uploadStream.BlockList).Result; using (response) { if (!response.IsSuccessStatusCode) { throw new AzureStorageHttpException(); } } } SyncEntryAdapterData adapterData = updateInfo.Entry.AdapterEntries.FirstOrDefault(a => a.AdapterId == this.Configuration.Id); if (adapterData == null) { adapterData = new SyncEntryAdapterData { SyncEntry = updateInfo.Entry, AdapterId = this.Configuration.Id }; updateInfo.Entry.AdapterEntries.Add(adapterData); } adapterData.AdapterEntryId = GetUniqueIdForFile(updateInfo.RelativePath); }
public override void FinalizeItemWrite(Stream stream, EntryUpdateInfo updateInfo) { OneDriveFileUploadStream uploadStream = (OneDriveFileUploadStream)stream; SyncEntryAdapterData adapterEntry = updateInfo.Entry.AdapterEntries.FirstOrDefault(e => e.AdapterId == this.Config.Id); if (adapterEntry == null) { adapterEntry = new SyncEntryAdapterData() { SyncEntry = updateInfo.Entry, AdapterId = this.Config.Id }; updateInfo.Entry.AdapterEntries.Add(adapterEntry); } adapterEntry.AdapterEntryId = uploadStream.UploadSession.Item.Id; }