public async Task ReplicateKeyAsync(string key, IFileCabinet masterCabinet, IFileCabinet replicaCabinet) { var sourceFileTask = masterCabinet.GetItemAsync(key); var destFileTask = replicaCabinet.GetItemAsync(key); await Task.WhenAll(sourceFileTask, destFileTask); // Get items simultaneously var replicationAction = GetReplicationFileState(sourceFileTask.Result, destFileTask.Result); switch (replicationAction) { case ReplicationFileState.SourceAdded: case ReplicationFileState.SourceNewer: await SaveFileAsync(masterCabinet, replicaCabinet, key); break; case ReplicationFileState.SourceDeleted: await replicaCabinet.DeleteFileAsync(key); break; case ReplicationFileState.ReplicationNewer: // if the replication is newer it's aready been synced case ReplicationFileState.Same: break; default: throw new NotImplementedException(); } }
public UploadController(IFileCabinet fileCabinet, IUploadValidator uploadValidator, IKeyProvider keyProvider, IPathMapper pathMapper) { this.fileCabinet = fileCabinet; this.uploadValidator = uploadValidator; this.keyProvider = keyProvider; this.pathMapper = pathMapper; }
/// <summary> /// Syncs the Master Cabinet to the Replica Cabinet /// </summary> /// <param name="masterCabinet"></param> /// <param name="replicaCabinet"></param> /// <returns></returns> public async Task ReplicateCabinetAsync(IFileCabinet masterCabinet, IFileCabinet replicaCabinet, CancellationToken cancellationToken) { // Just get they keys here - by the time the item is processed it may have changed var sourceKeys = await masterCabinet.ListKeysAsync(recursive: true); if(!sourceKeys.Any()) return; await taskRunner.RunTasks(async (key) => { await cabinetReplicator.ReplicateKeyAsync(key, masterCabinet, replicaCabinet); }, sourceKeys, cancellationToken); }
public FileCabinetStreamProvider(IFileCabinet fileCabinet, IUploadValidator fileValidator, IKeyProvider keyProvider, string tempFileFolder) : base(tempFileFolder) { Contract.NotNull(fileCabinet, nameof(fileCabinet)); Contract.NotNull(fileValidator, nameof(fileValidator)); Contract.NotNull(keyProvider, nameof(keyProvider)); Contract.NotNullOrEmpty(tempFileFolder, nameof(tempFileFolder)); this.fileCabinet = fileCabinet; this.fileValidator = fileValidator; this.keyProvider = keyProvider; }
public FileCabinetStreamProvider(IFileCabinet fileCabinet, IUploadValidator fileValidator, IKeyProvider keyProvider, string tempFileFolder) : base(tempFileFolder) { Contract.NotNull(fileCabinet, nameof(fileCabinet)); Contract.NotNull(fileValidator, nameof(fileValidator)); Contract.NotNull(keyProvider, nameof(keyProvider)); Contract.NotNullOrEmpty(tempFileFolder, nameof(tempFileFolder)); this.fileCabinet = fileCabinet; this.fileValidator = fileValidator; this.keyProvider = keyProvider; }
/// <summary> /// Syncs the Master Cabinet to the Replica Cabinet /// </summary> /// <param name="masterCabinet"></param> /// <param name="replicaCabinet"></param> /// <returns></returns> public async Task ReplicateCabinetAsync(IFileCabinet masterCabinet, IFileCabinet replicaCabinet, CancellationToken cancellationToken) { // Just get they keys here - by the time the item is processed it may have changed var sourceKeys = await masterCabinet.ListKeysAsync(recursive : true); if (!sourceKeys.Any()) { return; } await taskRunner.RunTasks(async (key) => { await cabinetReplicator.ReplicateKeyAsync(key, masterCabinet, replicaCabinet); }, sourceKeys, cancellationToken); }
public async Task ReplicateKeyAsync(string key, IFileCabinet masterCabinet, IFileCabinet replicaCabinet) { var sourceFileTask = masterCabinet.GetItemAsync(key); var destFileTask = replicaCabinet.GetItemAsync(key); await Task.WhenAll(sourceFileTask, destFileTask); // Get items simultaneously var replicationAction = GetReplicationFileState(sourceFileTask.Result, destFileTask.Result); switch(replicationAction) { case ReplicationFileState.SourceAdded: case ReplicationFileState.SourceNewer: await SaveFileAsync(masterCabinet, replicaCabinet, key); break; case ReplicationFileState.SourceDeleted: await replicaCabinet.DeleteFileAsync(key); break; case ReplicationFileState.ReplicationNewer: // if the replication is newer it's aready been synced case ReplicationFileState.Same: break; default: throw new NotImplementedException(); } }
public UploadController(IFileCabinet fileCabinet, IUploadValidator uploadValidator, IKeyProvider keyProvider, IPathMapper pathMapper) { this.fileCabinet = fileCabinet; this.uploadValidator = uploadValidator; this.keyProvider = keyProvider; this.pathMapper = pathMapper; }
public BrowseController(IFileCabinet fileCabinet, IKeyProvider keyProvider) { this.fileCabinet = fileCabinet; this.keyProvider = keyProvider; }
private static async Task<ISaveResult> SaveFileAsync(IFileCabinet masterCabinet, IFileCabinet replicationCabinet, string key) { using(var stream = await masterCabinet.OpenReadStreamAsync(key)) { return await replicationCabinet.SaveFileAsync(key, stream, HandleExistingMethod.Overwrite); } }
public BrowseController(IFileCabinet fileCabinet, IKeyProvider keyProvider) { this.fileCabinet = fileCabinet; this.keyProvider = keyProvider; }
private static async Task <ISaveResult> SaveFileAsync(IFileCabinet masterCabinet, IFileCabinet replicationCabinet, string key) { using (var stream = await masterCabinet.OpenReadStreamAsync(key)) { return(await replicationCabinet.SaveFileAsync(key, stream, HandleExistingMethod.Overwrite)); } }