Ejemplo n.º 1
0
        ///<inheritdoc>
        public async Task DeleteAsync(IOperationContext operationContext, IConfirmationResultContext resultContext)
        {
            /*
             * Logger.LogMessage($"{nameof(IFileSystemItem)}.{nameof(DeleteAsync)}()", this.UserFileSystemPath);
             * string userFileSystemPath = this.UserFileSystemPath;
             * Logger.LogMessage("Confirming delete in user file system", userFileSystemPath);
             * resultContext.ReturnConfirmationResult();
             */

            Logger.LogMessage("IFileSystemItem.DeleteAsync()", this.UserFileSystemPath);

            string userFileSystemPath = this.UserFileSystemPath;
            string remoteStoragePath  = null;

            try
            {
                if (Engine.ChangesProcessingEnabled &&
                    !FsPath.AvoidSync(userFileSystemPath))
                {
                    await new RemoteStorageRawItem <TItemType>(userFileSystemPath, VirtualDrive, Logger).DeleteAsync();
                    Logger.LogMessage("Deleted item in remote storage succesefully", userFileSystemPath);
                }
            }
            catch (Exception ex)
            {
                Logger.LogError("Delete failed", remoteStoragePath, null, ex);
            }
            finally
            {
                resultContext.ReturnConfirmationResult();
            }
        }
Ejemplo n.º 2
0
        //$>

        //$<IFileSystemItem.DeleteAsync
        ///<inheritdoc>
        public async Task DeleteAsync(IOperationContext operationContext, IConfirmationResultContext resultContext)
        {
            Logger.LogMessage("IFileSystemItem.DeleteAsync()", this.UserFileSystemPath);

            string userFileSystemPath = this.UserFileSystemPath;
            string remoteStoragePath  = null;

            try
            {
                if (Engine.ChangesProcessingEnabled &&
                    !FsPath.AvoidSync(userFileSystemPath))
                {
                    await new RemoteStorageRawItem(userFileSystemPath, Logger).DeleteAsync();
                    Logger.LogMessage("Deleted item in remote storage succesefully", userFileSystemPath);
                }
            }
            catch (Exception ex)
            {
                Logger.LogError("Delete failed", remoteStoragePath, null, ex);
            }
            finally
            {
                resultContext.ReturnConfirmationResult();
            }
        }
Ejemplo n.º 3
0
        /// <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);
            }
        }
Ejemplo n.º 4
0
        ///<inheritdoc>
        public async Task MoveToAsync(string userFileSystemNewPath, IOperationContext operationContext, IConfirmationResultContext resultContext)
        {
            // Here we will simply move the file in remote storage and confirm the operation.
            // In your implementation you may implement a more complex scenario with offline operations support.

            LogMessage("IFileSystemItem.MoveToAsync()", this.FullPath, userFileSystemNewPath);

            string userFileSystemOldPath = this.FullPath;

            try
            {
                bool?inSync = null;
                try
                {
                    Program.RemoteStorageMonitorInstance.Enabled = false; // Disable RemoteStorageMonitor to avoid circular calls.

                    // When a file is deleted, it is moved to a Recycle Bin, that is why we check for recycle bin here.
                    if (FsPath.Exists(userFileSystemOldPath) && !FsPath.IsRecycleBin(userFileSystemNewPath) &&
                        !FsPath.AvoidSync(userFileSystemOldPath) && !FsPath.AvoidSync(userFileSystemNewPath))
                    {
                        inSync = PlaceholderItem.GetItem(userFileSystemOldPath).GetInSync();

                        string remoteStorageOldPath = Mapping.MapPath(userFileSystemOldPath);
                        string remoteStorageNewPath = Mapping.MapPath(userFileSystemNewPath);

                        FileSystemInfo remoteStorageOldItem = FsPath.GetFileSystemItem(remoteStorageOldPath);

                        if (remoteStorageOldItem is FileInfo)
                        {
                            (remoteStorageOldItem as FileInfo).MoveTo(remoteStorageNewPath);
                        }
                        else
                        {
                            (remoteStorageOldItem as DirectoryInfo).MoveTo(remoteStorageNewPath);
                        }
                        LogMessage("Moved succesefully:", remoteStorageOldPath, remoteStorageNewPath);
                    }
                }
                finally
                {
                    resultContext.ReturnConfirmationResult();

                    // If a file with content is deleted it is moved to a recycle bin and converted
                    // to a regular file, so placeholder features are not available on it.
                    if ((inSync != null) && PlaceholderItem.IsPlaceholder(userFileSystemNewPath))
                    {
                        PlaceholderItem.GetItem(userFileSystemNewPath).SetInSync(inSync.Value);
                    }
                }
            }
            catch (Exception ex)
            {
                // remove try-catch when error processing inside CloudProvider is fixed.
                LogError("Move failed:", $"From: {this.FullPath} to:{userFileSystemNewPath}", ex);
            }
            finally
            {
                Program.RemoteStorageMonitorInstance.Enabled = true;
            }
        }
Ejemplo n.º 5
0
        ///<inheritdoc>
        public async Task MoveToAsync(string userFileSystemNewPath, IOperationContext operationContext, IConfirmationResultContext resultContext)
        {
            string userFileSystemOldPath = this.UserFileSystemPath;

            Logger.LogMessage($"{nameof(IFileSystemItem)}.{nameof(MoveToAsync)}()", userFileSystemOldPath, userFileSystemNewPath);

            // Process move.
            if (Engine.ChangesProcessingEnabled)
            {
                if (FsPath.Exists(userFileSystemOldPath))
                {
                    await new RemoteStorageRawItem <TItemType>(userFileSystemOldPath, VirtualDrive, Logger).MoveToAsync(userFileSystemNewPath, resultContext);
                }
            }
            else
            {
                resultContext.ReturnConfirmationResult();
            }
        }
Ejemplo n.º 6
0
        ///<inheritdoc>
        public async Task DeleteAsync(IOperationContext operationContext, IConfirmationResultContext resultContext)
        {
            // Here we will simply delete the file in remote storage and confirm the operation.
            // In your implementation you may implement a more complex scenario with offline operations support.

            LogMessage("IFileSystemItem.DeleteAsync()", this.FullPath);
            string userFileSystemPath = this.FullPath;
            string remoteStoragePath  = null;

            try
            {
                try
                {
                    Program.RemoteStorageMonitorInstance.Enabled = false; // Disable RemoteStorageMonitor to avoid circular calls.

                    remoteStoragePath = Mapping.MapPath(userFileSystemPath);
                    if (FsPath.Exists(remoteStoragePath) && !FsPath.AvoidSync(userFileSystemPath))
                    {
                        FileSystemInfo remoteStorageItem = FsPath.GetFileSystemItem(remoteStoragePath);
                        remoteStorageItem.Delete();
                        LogMessage("Deleted succesefully:", remoteStoragePath);
                    }
                }
                finally
                {
                    resultContext.ReturnConfirmationResult();
                }
            }
            catch (Exception ex)
            {
                // remove try-catch when error processing inside CloudProvider is fixed.
                LogError("Delete failed:", remoteStoragePath, ex);
            }
            finally
            {
                Program.RemoteStorageMonitorInstance.Enabled = true;
            }
        }
        //$<IFileSystemItem.MoveToAsync
        ///<inheritdoc>
        public async Task MoveToAsync(string userFileSystemNewPath, IOperationContext operationContext, IConfirmationResultContext resultContext)
        {
            string userFileSystemOldPath = this.UserFileSystemPath;

            Logger.LogMessage("IFileSystemItem.MoveToAsync()", userFileSystemOldPath, userFileSystemNewPath);

            // Process move.
            if (Engine.ChangesProcessingEnabled)
            {
                if (FsPath.Exists(userFileSystemOldPath))
                {
                    await new RemoteStorageRawItem(userFileSystemOldPath, VirtualDrive, Logger).MoveToAsync(userFileSystemNewPath, resultContext);
                }
            }
            else
            {
                resultContext.ReturnConfirmationResult();
            }

            // Restore Original Path and locked icon, lost during MS Office transactional save.
            if (FsPath.Exists(userFileSystemNewPath) && PlaceholderItem.IsPlaceholder(userFileSystemNewPath))
            {
                PlaceholderItem userFileSystemNewItem = PlaceholderItem.GetItem(userFileSystemNewPath);
                if (!userFileSystemNewItem.IsNew() && string.IsNullOrEmpty(userFileSystemNewItem.GetOriginalPath()))
                {
                    // Restore Original Path.
                    Logger.LogMessage("Saving Original Path", userFileSystemNewPath);
                    userFileSystemNewItem.SetOriginalPath(userFileSystemNewPath);

                    // Restore the 'locked' icon.
                    bool isLocked = await Lock.IsLockedAsync(userFileSystemNewPath);

                    ServerLockInfo existingLock = isLocked ? await(await Lock.LockAsync(userFileSystemNewPath, FileMode.Open, LockMode.None, Logger)).GetLockInfoAsync() : null;
                    await new UserFileSystemRawItem(userFileSystemNewPath).SetLockInfoAsync(existingLock);
                }
            }
        }
        internal async Task MoveToAsync(string userFileSystemNewPath, IConfirmationResultContext resultContext = null)
        {
            string userFileSystemOldPath = userFileSystemPath;

            try
            {
                bool?  inSync = null;
                bool   updateTargetOnSuccess = false;
                string eTag = null;
                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();
                        }

                        eTag = await ETag.GetETagAsync(userFileSystemOldPath);

                        ETag.DeleteETag(userFileSystemOldPath);

                        IUserFileSystemItem userFileSystemItemOld = await virtualDrive.GetItemAsync <IUserFileSystemItem>(userFileSystemOldPath);

                        await userFileSystemItemOld.MoveToAsync(userFileSystemNewPath);

                        updateTargetOnSuccess = true;
                        logger.LogMessage("Moved succesefully in remote storage", userFileSystemOldPath, userFileSystemNewPath);
                    }
                }
                finally
                {
                    if (resultContext != null)
                    {
                        resultContext.ReturnConfirmationResult();
                    }

                    // This check is just to avoid extra error in the log.
                    if (FsPath.Exists(userFileSystemNewPath))
                    {
                        // Open file to preven reads and changes between GetFileDataSizeInfo() call and SetInSync() call.
                        using (WindowsFileSystemItem userFileSystemWinItem = WindowsFileSystemItem.OpenReadAttributes(userFileSystemNewPath, FileMode.Open, FileShare.None))
                        {
                            if ((eTag != null) && PlaceholderItem.IsPlaceholder(userFileSystemNewPath))
                            {
                                await ETag.SetETagAsync(userFileSystemNewPath, eTag);
                            }

                            // If a file with content is deleted it is moved to a recycle bin and converted
                            // to a regular file, so placeholder features are not available on it, checking if a file is a placeholder.
                            if (updateTargetOnSuccess && PlaceholderItem.IsPlaceholder(userFileSystemNewPath))
                            {
                                PlaceholderItem placeholderNew = PlaceholderItem.GetItem(userFileSystemNewPath);

                                // Update OriginalPath, so the item does not appear as moved.
                                placeholderNew.SetOriginalPath(userFileSystemNewPath);

                                if (inSync != null)
                                {
                                    placeholderNew.SetInSync(inSync.Value);
                                }
                                else if ((placeholderNew is PlaceholderFile) && ((PlaceholderFile)placeholderNew).GetFileDataSizeInfo().ModifiedDataSize == 0)
                                {
                                    placeholderNew.SetInSync(true);
                                }
                                await new UserFileSystemRawItem(userFileSystemNewPath).ClearStateAsync();
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                string userFileSystemPath = FsPath.Exists(userFileSystemNewPath) ? userFileSystemNewPath : userFileSystemOldPath;
                await new UserFileSystemRawItem(userFileSystemPath).SetUploadErrorStateAsync(ex);

                // Rethrow the exception preserving stack trace of the original exception.
                System.Runtime.ExceptionServices.ExceptionDispatchInfo.Capture(ex).Throw();
            }
        }