///<inheritdoc> public async Task MoveToAsync(string userFileSystemNewPath, byte[] newParentItemId, IOperationContext operationContext, IConfirmationResultContext resultContext) { string userFileSystemOldPath = this.UserFileSystemPath; Logger.LogMessage($"{nameof(IFileSystemItem)}.{nameof(MoveToAsync)}()", userFileSystemOldPath, userFileSystemNewPath); string remoteStorageOldPath = RemoteStoragePath; string remoteStorageNewParentPath = WindowsFileSystemItem.GetPathByItemId(newParentItemId); string remoteStorageNewPath = Path.Combine(remoteStorageNewParentPath, Path.GetFileName(userFileSystemNewPath)); FileSystemInfo remoteStorageOldItem = FsPath.GetFileSystemItem(remoteStorageOldPath); if (remoteStorageOldItem != null) { if (remoteStorageOldItem is FileInfo) { (remoteStorageOldItem as FileInfo).MoveTo(remoteStorageNewPath, true); } else { (remoteStorageOldItem as DirectoryInfo).MoveTo(remoteStorageNewPath); } Logger.LogMessage("Moved item in remote storage succesefully", userFileSystemOldPath, userFileSystemNewPath); } }
/// <summary> /// Creates instance of this class. /// </summary> /// <param name="userFileSystemPath">File or folder path in the user file system.</param> /// <param name="itemId">Remote storage item ID.</param> /// <param name="logger">Logger.</param> public VirtualFileSystemItem(string userFileSystemPath, byte[] itemId, ILogger logger) { if (string.IsNullOrEmpty(userFileSystemPath)) { throw new ArgumentNullException(nameof(userFileSystemPath)); } ItemId = itemId ?? throw new ArgumentNullException(nameof(itemId)); Logger = logger ?? throw new ArgumentNullException(nameof(logger)); UserFileSystemPath = userFileSystemPath; try { RemoteStoragePath = WindowsFileSystemItem.GetPathByItemId(ItemId); } catch (ArgumentException) { // When a file is deleted, the IFile.CloseAsync() is called for the deleted file. } }