private void SetupMoveItem(FileSystemInfoContract directoryOrFile, string name, DirectoryInfoContract target) { gateway .Setup(g => g.MoveItem(rootName, directoryOrFile.Id, name, target.Id)) .Returns((RootName _rootName, FileSystemId source, string movePath, DirectoryId destination) => { var directorySource = source as DirectoryId; if (directorySource != null) { return new DirectoryInfoContract(source.Value, movePath, directoryOrFile.Created, directoryOrFile.Updated) { Parent = target } } ; var fileSource = source as FileId; if (fileSource != null) { return new FileInfoContract(source.Value, movePath, directoryOrFile.Created, directoryOrFile.Updated, ((FileInfoContract)directoryOrFile).Size, ((FileInfoContract)directoryOrFile).Hash) { Directory = target } } ; throw new InvalidOperationException($"Unsupported type '{source.GetType().Name}'".ToString(CultureInfo.CurrentCulture)); }); }
public FileSystemInfoContract MoveItem(FileSystemInfoContract source, string movePath, DirectoryInfoContract destination) { return(ExecuteInSemaphore(() => { Func <FileSystemInfoLocator> locator = () => new FileSystemInfoLocator(source); return gateway.MoveItemAsync(rootName, source.Id, movePath, destination.Id, locator).Result; }, nameof(MoveItem), true)); }
private void SetupMoveItem(FileSystemInfoContract directoryOrFile, string name, DirectoryInfoContract target, Action callback = null) { _drive .Setup(drive => drive.MoveItem(It.Is <FileSystemInfoContract>(item => item.Id == directoryOrFile.Id), name, target)) .Returns((FileSystemInfoContract source, string movePath, DirectoryInfoContract destination) => { var directorySource = source as DirectoryInfoContract; if (directorySource != null) { return new DirectoryInfoContract(source.Id.Value, movePath, source.Created, source.Updated) { Parent = target } } ; var fileSource = source as FileInfoContract; if (fileSource != null) { return new FileInfoContract(source.Id.Value, movePath, source.Created, source.Updated, fileSource.Size, fileSource.Hash) { Directory = target } } ; throw new InvalidOperationException($"Unsupported type '{source.GetType().Name}'".ToString(CultureInfo.CurrentCulture)); }) .Callback(() => { callback?.Invoke(); }) .Verifiable(); }
protected CloudItemNode(FileSystemInfoContract contract) { if (contract == null) throw new ArgumentNullException(nameof(contract)); Contract = contract; }
protected CloudItemNode(FileSystemInfoContract contract) { if (contract == null) { throw new ArgumentNullException(nameof(contract)); } Contract = contract; }
public void RemoveItem(FileSystemInfoContract target, bool recurse) { ExecuteInSemaphore(() => { if (!(target is ProxyFileInfoContract)) { _gateway.RemoveItem(_rootName, target.Id, recurse); } }, nameof(RemoveItem), true); }
public FileSystemInfoContract RenameItem(FileSystemInfoContract target, string newName) { try { Func <FileSystemInfoLocator> locator = () => new FileSystemInfoLocator(target); return(gateway.RenameItemAsync(rootName, target.Id, newName, locator).Result); } catch (AggregateException ex) when(ex.InnerExceptions.Count == 1) { throw ex.InnerExceptions[0]; } }
/// <summary> /// Initializes a new instance of the <see cref="FileSystemInfoLocator"/> class. /// </summary> /// <param name="fileSystem">The file system info object.</param> /// <exception cref="ArgumentNullException">The filesystem is <c>null</c>.</exception> public FileSystemInfoLocator(FileSystemInfoContract fileSystem) { if (fileSystem == null) { throw new ArgumentNullException(nameof(fileSystem)); } Id = fileSystem.Id; Name = fileSystem.Name; ParentId = (fileSystem as DirectoryInfoContract)?.Parent.Id ?? (fileSystem as FileInfoContract)?.Directory.Id; }
public void RemoveItem(FileSystemInfoContract target, bool recurse) { try { gateway.RemoveItemAsync(rootName, target.Id, recurse).Wait(); } catch (AggregateException ex) when(ex.InnerExceptions.Count == 1) { throw ex.InnerExceptions[0]; } finally { InvalidateDrive(); } }
public FileSystemInfoContract CopyItem(FileSystemInfoContract source, string copyPath, DirectoryInfoContract destination, bool recurse) { try { return(gateway.CopyItemAsync(rootName, source.Id, copyPath, destination.Id, recurse).Result); } catch (AggregateException ex) when(ex.InnerExceptions.Count == 1) { throw ex.InnerExceptions[0]; } finally { InvalidateDrive(); } }
public FileSystemInfoContract MoveItem(FileSystemInfoContract source, string movePath, DirectoryInfoContract destination) { try { Func <FileSystemInfoLocator> locator = () => new FileSystemInfoLocator(source); return(gateway.MoveItemAsync(rootName, source.Id, movePath, destination.Id, locator).Result); } catch (AggregateException ex) when(ex.InnerExceptions.Count == 1) { throw ex.InnerExceptions[0]; } finally { InvalidateDrive(); } }
public static CloudItemNode CreateNew(FileSystemInfoContract fileSystemInfo) { var fileInfoContract = fileSystemInfo as FileInfoContract; if (fileInfoContract != null) return new CloudFileNode(fileInfoContract); var directoryInfoContract = fileSystemInfo as DirectoryInfoContract; if (directoryInfoContract != null) return new CloudDirectoryNode(directoryInfoContract); throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, Resources.UnknownItemType, fileSystemInfo.GetType().Name)); }
public FileSystemInfoContract MoveItem(FileSystemInfoContract source, string movePath, DirectoryInfoContract destination) { return(ExecuteInSemaphore(() => { var proxySource = source as ProxyFileInfoContract; if (proxySource != null) { return new ProxyFileInfoContract(movePath); } FileSystemInfoLocator locator() => new FileSystemInfoLocator(source); return _gateway.MoveItemAsync(_rootName, source.Id, movePath, destination.Id, locator).Result; }, nameof(MoveItem), true)); }
protected void FixupSize(FileSystemInfoContract info, Func <FileId, Stream> readContent) { if (readContent == null) { throw new ArgumentNullException(nameof(readContent)); } var fileInfo = info as FileInfoContract; if (fileInfo != null && !string.IsNullOrEmpty(encryptionKey)) { var gatewayContent = readContent(fileInfo.Id); fileInfo.Size = gatewayContent.GetPlainFileSize(encryptionKey); } }
public static CloudItemNode CreateNew(FileSystemInfoContract fileSystemInfo) { var fileInfoContract = fileSystemInfo as FileInfoContract; if (fileInfoContract != null) { return(new CloudFileNode(fileInfoContract)); } var directoryInfoContract = fileSystemInfo as DirectoryInfoContract; if (directoryInfoContract != null) { return(new CloudDirectoryNode(directoryInfoContract)); } throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Unknown item type '{0}'", fileSystemInfo.GetType().Name)); }
public CloudPathNode(FileSystemInfoContract fileSystemInfo) { var directoryInfo = fileSystemInfo as DirectoryInfoContract; if (directoryInfo != null) { itemMode = Mode.Directory; nodeValue = new ContainerPathValue(directoryInfo, directoryInfo.Name); return; } var fileInfo = fileSystemInfo as FileInfoContract; if (fileInfo != null) { itemMode = Mode.File; nodeValue = new LeafPathValue(fileInfo, fileInfo.Name); return; } throw new InvalidOperationException(); }
void SetupMoveItemAsync(FileSystemInfoContract directoryOrFile, string name, DirectoryInfoContract target) { _gateway .Setup(g => g.MoveItemAsync(_rootName, directoryOrFile.Id, name, target.Id, It.IsAny <Func <FileSystemInfoLocator> >())) .Returns((RootName _rootName, FileSystemId source, string movePath, DirectoryId destination, Func <FileSystemInfoLocator> progress) => { var directorySource = source as DirectoryId; if (directorySource != null) { return(Task.FromResult((FileSystemInfoContract) new DirectoryInfoContract(source.Value, movePath, directoryOrFile.Created, directoryOrFile.Updated) { Parent = target })); } var fileSource = source as FileId; if (fileSource != null) { return(Task.FromResult((FileSystemInfoContract) new FileInfoContract(source.Value, movePath, directoryOrFile.Created, directoryOrFile.Updated, ((FileInfoContract)directoryOrFile).Size, ((FileInfoContract)directoryOrFile).Hash) { Directory = target })); } throw new InvalidOperationException($"Unsupported type '{source.GetType().Name}'".ToString(CultureInfo.CurrentCulture)); }); }
public FileSystemInfoContract MoveItem(FileSystemInfoContract source, string movePath, DirectoryInfoContract destination) { return ExecuteInSemaphore(() => { Func<FileSystemInfoLocator> locator = () => new FileSystemInfoLocator(source); return gateway.MoveItemAsync(rootName, source.Id, movePath, destination.Id, locator).Result; }, nameof(MoveItem), true); }
public void SetupMoveDirectoryOrFileAsync(FileSystemInfoContract directoryOrFile, DirectoryInfoContract target) => SetupMoveItemAsync(directoryOrFile, directoryOrFile.Name, target);
public void SetupMoveDirectoryOrFile(FileSystemInfoContract directoryOrFile, DirectoryInfoContract target, Action callback = null) => SetupMoveItem(directoryOrFile, directoryOrFile.Name, target, callback);
public void SetupDeleteDirectoryOrFile(FileSystemInfoContract directoryOrFile, bool recurse = false) { _drive .Setup(drive => drive.RemoveItem(It.Is <FileSystemInfoContract>(item => item.Id == directoryOrFile.Id), recurse)) .Verifiable(); }
internal void SetupRenameDirectoryOrFile(FileSystemInfoContract directoryOrFile, string name) { SetupMoveItem(directoryOrFile, name, (directoryOrFile as DirectoryInfoContract)?.Parent ?? (directoryOrFile as FileInfoContract)?.Directory ?? null); }
public void SetupRemoveDirectoryOrFile(FileSystemInfoContract directoryOrFile, bool recurse) { gateway .Setup(g => g.RemoveItem(rootName, directoryOrFile.Id, recurse)); }
public void SetupRenameDirectoryOrFile(FileSystemInfoContract directoryOrFile, string name) { SetupMoveItem(directoryOrFile, name, (directoryOrFile as DirectoryInfoContract)?.Parent ?? (directoryOrFile as FileInfoContract)?.Directory ?? null); }
public TestCloudItemNode(FileSystemInfoContract contract) : base(contract) { }
public CloudItemNode GetItem(FileSystemInfoContract contract) { return(new TestCloudItemNode(contract)); }
public FileSystemInfoContract RenameItem(FileSystemInfoContract target, string newName) { return(gateway.RenameItem(rootName, target.Id, newName)); }
public void RemoveItem(FileSystemInfoContract target, bool recurse) { gateway.RemoveItem(rootName, target.Id, recurse); InvalidateDrive(); }
public FileSystemInfoContract MoveItem(FileSystemInfoContract source, string movePath, DirectoryInfoContract destination) { InvalidateDrive(); return(gateway.MoveItem(rootName, source.Id, movePath, destination.Id)); }
internal void SetupDeleteDirectoryOrFile(FileSystemInfoContract directoryOrFile, bool recurse = false) { Drive .Setup(drive => drive.RemoveItem(It.Is<FileSystemInfoContract>(item => item.Id == directoryOrFile.Id), recurse)); }
private void SetupMoveItem(FileSystemInfoContract directoryOrFile, string name, DirectoryInfoContract target) { Drive .Setup(drive => drive.MoveItem(It.Is<FileSystemInfoContract>(item => item.Id == directoryOrFile.Id), name, target)) .Returns((FileSystemInfoContract source, string movePath, DirectoryInfoContract destination) => { var directorySource = source as DirectoryInfoContract; if (directorySource != null) return new DirectoryInfoContract(source.Id.Value, movePath, source.Created, source.Updated) { Parent = target }; var fileSource = source as FileInfoContract; if (fileSource != null) return new FileInfoContract(source.Id.Value, movePath, source.Created, source.Updated, fileSource.Size, fileSource.Hash) { Directory = target }; throw new InvalidOperationException($"Unsupported type '{source.GetType().Name}'"); }); }
public void RemoveItem(FileSystemInfoContract target, bool recurse) { ExecuteInSemaphore(() => { gateway.RemoveItemAsync(rootName, target.Id, recurse).Wait(); }, nameof(RemoveItem), true); }
public void SetupMoveDirectoryOrFile(FileSystemInfoContract directoryOrFile, DirectoryInfoContract target) { SetupMoveItem(directoryOrFile, directoryOrFile.Name, target); }
public FileSystemInfoContract MoveItem(FileSystemInfoContract source, string movePath, DirectoryInfoContract destination) { return(ExecuteInSemaphore(() => { return !(source is ProxyFileInfoContract) ? _gateway.MoveItem(_rootName, source.Id, movePath, destination.Id) : new ProxyFileInfoContract(movePath); }, nameof(MoveItem), true)); }
public FileSystemInfoContract MoveItem(FileSystemInfoContract source, string movePath, DirectoryInfoContract destination) { return ExecuteInSemaphore(() => { return gateway.MoveItem(rootName, source.Id, movePath, destination.Id); }, nameof(MoveItem), true); }
public void SetupRemoveDirectoryOrFileAsync(FileSystemInfoContract directoryOrFile, bool recurse) { gateway .Setup(g => g.RemoveItemAsync(rootName, directoryOrFile.Id, recurse)) .Returns(Task.FromResult(true)); }
public FileSystemInfoContract CopyItem(FileSystemInfoContract source, string copyPath, DirectoryInfoContract destination, bool recurse) { InvalidateDrive(); return(gateway.CopyItem(rootName, source.Id, copyPath, destination.Id, recurse)); }
internal void SetupMoveDirectoryOrFile(FileSystemInfoContract directoryOrFile, DirectoryInfoContract target) { SetupMoveItem(directoryOrFile, directoryOrFile.Name, target); }