Ejemplo n.º 1
0
        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();
            }
        }
Ejemplo n.º 2
0
 public UploadController(IFileCabinet fileCabinet, IUploadValidator uploadValidator, IKeyProvider keyProvider, IPathMapper pathMapper)
 {
     this.fileCabinet     = fileCabinet;
     this.uploadValidator = uploadValidator;
     this.keyProvider     = keyProvider;
     this.pathMapper      = pathMapper;
 }
Ejemplo n.º 3
0
        /// <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;
        }
Ejemplo n.º 6
0
        /// <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);
        }
Ejemplo n.º 7
0
        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();
            }
        }
Ejemplo n.º 8
0
 public UploadController(IFileCabinet fileCabinet, IUploadValidator uploadValidator, IKeyProvider keyProvider, IPathMapper pathMapper) {
     this.fileCabinet = fileCabinet;
     this.uploadValidator = uploadValidator;
     this.keyProvider = keyProvider;
     this.pathMapper = pathMapper;
 }
Ejemplo n.º 9
0
 public BrowseController(IFileCabinet fileCabinet, IKeyProvider keyProvider) {
     this.fileCabinet = fileCabinet;
     this.keyProvider = keyProvider;
 }
Ejemplo n.º 10
0
 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);
     }
 }
Ejemplo n.º 11
0
 public BrowseController(IFileCabinet fileCabinet, IKeyProvider keyProvider)
 {
     this.fileCabinet = fileCabinet;
     this.keyProvider = keyProvider;
 }
Ejemplo n.º 12
0
 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));
     }
 }