/// <summary> /// Get a stream for writing the contents of an item /// </summary> /// <param name="entry">The entry representing the file to be uploaded</param> /// <param name="length">The length of the file to be uploaded</param> /// <returns>The <see cref="Stream"/>that the file's content can be written to</returns> public override Stream GetWriteStreamForEntry(SyncEntry entry, long length) { // Create a default session. By itself, the file will be uploaded to Backblaze when the stream // containins the session is disposed. BackblazeB2UploadSession session = new BackblazeB2UploadSession(entry, length); // If the file is large enough, call the method below to get the large file upload information. When // these properties are present, the stream will upload the file's parts individually. if (length >= this.TypedConfiguration.ConnectionInfo.RecommendedPartSize) { session.StartLargeFileResponse = this.backblazeClient.StartLargeUpload( this.TypedConfiguration.BucketId, entry.GetRelativePath(null, "/")) .Result; session.GetUploadPartUrlResponse = this.backblazeClient.GetUploadPartUrl(session.StartLargeFileResponse.FileId).Result; // Return the stream type dedicated to uploading large files (via parts) return(new BackblazeB2LargeUploadStream( this, session, Constants.LimitPartMaximumSize, length)); } // The file size is below the large-file limit, so upload directly return(new BackblazeB2UploadStream(this, session)); }
private void CreateItem(SyncEntry entry) { string fullPath; using (var database = this.Relationship.GetDatabase()) { fullPath = Path.Combine(this.Config.RootDirectory, entry.GetRelativePath(database, this.PathSeparator)); } switch (entry.Type) { case SyncEntryType.Directory: Directory.CreateDirectory(fullPath); break; case SyncEntryType.File: using (File.Create(fullPath)) { } break; default: throw new ArgumentOutOfRangeException(); } }
public override void DeleteItem(SyncEntry entry) { string fullPath; using (var database = this.Relationship.GetDatabase()) { fullPath = Path.Combine(this.Config.RootDirectory, entry.GetRelativePath(database, this.PathSeparator)); } switch (entry.Type) { case SyncEntryType.Directory: Directory.Delete(fullPath); break; case SyncEntryType.File: File.Delete(fullPath); break; default: throw new ArgumentOutOfRangeException(); } entry.EntryLastUpdatedDateTimeUtc = DateTime.UtcNow; }
public override Stream GetReadStreamForEntry(SyncEntry entry) { long size = entry.GetSize(this.Relationship, SyncEntryPropertyLocation.Destination); using (SyncDatabase db = this.Relationship.GetDatabase()) { return(new AzureStorageDownloadStream( this.storageClient, this.TypedConfiguration.ContainerName, entry.GetRelativePath(db, "/"), size)); } }
public async Task <BackblazeB2FileUploadResponse> UploadFileDirect( SyncEntry entry, Stream contentStream, byte[] sha1Hash) { long size = entry.GetSize(this.Relationship, SyncEntryPropertyLocation.Destination); return(await this.backblazeClient.UploadFile( entry.GetRelativePath(null, "/"), BitConverter.ToString(sha1Hash).Replace("-", ""), size, this.TypedConfiguration.BucketId, contentStream) .ConfigureAwait(false)); }
public override Stream GetWriteStreamForEntry(SyncEntry entry, long length) { if (entry.Type != SyncEntryType.File) { throw new InvalidOperationException("Cannot get a filestream for a non-file."); } string fullPath; using (var db = this.Relationship.GetDatabase()) { fullPath = Path.Combine(this.Config.RootDirectory, entry.GetRelativePath(db, this.PathSeparator)); } return(File.Open(fullPath, FileMode.OpenOrCreate, FileAccess.ReadWrite)); }
private void AddSyncEntriesRecursive( SyncDatabase db, List <EntryUpdateInfo> updatesToRestore, SyncEntry syncEntry, RestoreOnlyWindowsFileSystemAdapter destAdapter) { EntryUpdateInfo updateInfo = new EntryUpdateInfo( syncEntry, destAdapter, SyncEntryChangedFlags.Restored, syncEntry.GetRelativePath(db, "/")); updatesToRestore.Add(updateInfo); if (syncEntry.Type == SyncEntryType.Directory) { List <SyncEntry> childEntries = db.Entries.Where(e => e.ParentId == syncEntry.Id).ToList(); foreach (SyncEntry childEntry in childEntries) { this.AddSyncEntriesRecursive(db, updatesToRestore, childEntry, destAdapter); } } }
public override async Task CreateItemAsync(SyncEntry entry) { await Task.Factory.StartNew(() => { string fullPath; using (var database = this.Relationship.GetDatabase()) { fullPath = Path.Combine(this.Config.RootDirectory, entry.GetRelativePath(database, this.PathSeparator)); } FileSystemInfo fileSystemInfo; switch (entry.Type) { case SyncEntryType.Directory: fileSystemInfo = Directory.CreateDirectory(fullPath); break; case SyncEntryType.File: using (File.Create(fullPath)) { fileSystemInfo = new FileInfo(fullPath); } break; default: throw new ArgumentOutOfRangeException(); } entry.AdapterEntries.Add( new SyncEntryAdapterData() { SyncEntryId = entry.Id, AdapterId = this.Configuration.Id, AdapterEntryId = GetItemId(fileSystemInfo) }); }).ConfigureAwait(false); }