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 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 async Task <IHttpActionResult> Get(string key) { var file = await fileCabinet.GetItemAsync(key); return(this.Ok(file)); }