/// <summary> /// Moves the item in the remote storage. This method is called by the platform. /// To move item manually use the <see cref="MoveToAsync(string)"/> method instead. /// </summary> /// <param name="userFileSystemNewPath">Target path in user file system.</param> /// <param name="resultContext">Confirms move competeion. Passed by the platform only.</param> internal async Task MoveToAsync(string userFileSystemNewPath, IConfirmationResultContext resultContext) { // In this method you must either confirm or reject the move by calling call either // IConfirmationResultContext.ReturnConfirmationResult() or IConfirmationResultContext.ReturnErrorResult(). string userFileSystemOldPath = userFileSystemPath; try { if (!FsPath.IsRecycleBin(userFileSystemNewPath) && // When a file is deleted, it is moved to a Recycle Bin. !FsPath.AvoidSync(userFileSystemOldPath) && !FsPath.AvoidSync(userFileSystemNewPath)) { logger.LogMessage("Moving item in remote storage", userFileSystemOldPath, userFileSystemNewPath); /* * // Read In-Sync state before move and set after move. * if (FsPath.Exists(userFileSystemOldPath)) * { * inSync = PlaceholderItem.GetItem(userFileSystemOldPath).GetInSync(); * } */ IVirtualFileSystemItem userFileSystemItemOld = await GetItemAsync(userFileSystemOldPath); await userFileSystemItemOld.MoveToAsync(userFileSystemNewPath); //updateTargetOnSuccess = true; logger.LogMessage("Moved succesefully in remote storage", userFileSystemOldPath, userFileSystemNewPath); ETagManager eTagManager = virtualDrive.GetETagManager(userFileSystemOldPath); if (FsPath.Exists(eTagManager.ETagFilePath)) { await eTagManager.MoveToAsync(userFileSystemNewPath); logger.LogMessage("Moved ETag succesefully", userFileSystemOldPath, userFileSystemNewPath); } } // Confirm move. if (resultContext != null) { // Calling ReturnConfirmationResult() moves file in the user file system. logger.LogMessage("Confirming move in user file system", userFileSystemOldPath, userFileSystemNewPath); resultContext.ReturnConfirmationResult(); // After ReturnConfirmationResult() call the MoveToCompletionAsync() method is called. // After that, in case of a file, the file handle is closed, triggering IFile.CloseAsync() call // and Windows File Manager move progress window is closed. // In addition to thos, in case the target is the offline folder, the IFolder.GetChildrenAsync() method is called. } } catch (Exception ex) { logger.LogError("Failed to move item", userFileSystemOldPath, userFileSystemNewPath, ex); resultContext.ReturnErrorResult(); //string userFileSystemExPath = FsPath.Exists(userFileSystemNewPath) ? userFileSystemNewPath : userFileSystemOldPath; //await virtualDrive.GetUserFileSystemRawItem(userFileSystemExPath, logger).SetUploadErrorStateAsync(ex); } }
/// <summary> /// Creates instance of this class. /// </summary> /// <param name="userFileSystemPath">File or folder path in user file system.</param> /// <param name="logger">Logger.</param> public UserFileSystemRawItem(string userFileSystemPath, VirtualDriveBase virtualDrive, ILogger logger) { if (string.IsNullOrEmpty(userFileSystemPath)) { throw new ArgumentNullException(nameof(userFileSystemPath)); } this.virtualDrive = virtualDrive ?? throw new ArgumentNullException(nameof(virtualDrive)); this.logger = logger ?? throw new ArgumentNullException(nameof(logger)); this.userFileSystemPath = userFileSystemPath; this.eTagManager = virtualDrive.GetETagManager(userFileSystemPath); }