Ejemplo n.º 1
0
        /// <inheritdoc/>
        public override async Task <bool> FilterAsync(string userFileSystemPath, string userFileSystemNewPath = null)
        {
            // IsMsOfficeLocked() check is required for MS Office PowerPoint.
            // PowerPoint does not block the file for reading when the file is opened for editing.
            // As a result the file will be sent to the remote storage during each file save operation.

            if (userFileSystemNewPath == null)
            {
                // Executed during create, update, delete, open, close.
                return(MsOfficeHelper.AvoidMsOfficeSync(userFileSystemPath));
            }
            else
            {
                // Executed during rename/move operation.
                return
                    (MsOfficeHelper.IsRecycleBin(userFileSystemNewPath) || // When a hydrated file is deleted, it is moved to a Recycle Bin.
                     MsOfficeHelper.AvoidMsOfficeSync(userFileSystemNewPath));
            }
        }
        /// <summary>
        /// Called when a file or folder is renamed in the user file system.
        /// </summary>
        private async void RenamedAsync(object sender, RenamedEventArgs e)
        {
            // If the item was previously filtered by EngineWindows.FilterAsync(),
            // for example temp MS Office file was renamed SGE4274H -> file.xlsx,
            // we need to convert the file to a pleaceholder and upload it to the remote storage.

            LogMessage("Renamed", e.OldFullPath, e.FullPath);

            string userFileSystemOldPath = e.OldFullPath;
            string userFileSystemNewPath = e.FullPath;

            try
            {
                if (System.IO.File.Exists(userFileSystemNewPath) &&
                    !MsOfficeHelper.AvoidMsOfficeSync(userFileSystemNewPath))
                {
                    if (!PlaceholderItem.IsPlaceholder(userFileSystemNewPath))
                    {
                        if (engine.CustomDataManager(userFileSystemNewPath).IsNew)
                        {
                            await engine.ClientNotifications(userFileSystemNewPath, this).CreateAsync();
                        }
                        else
                        {
                            LogMessage("Converting to placeholder", userFileSystemNewPath);
                            PlaceholderItem.ConvertToPlaceholder(userFileSystemNewPath, null, null, false);
                            await engine.ClientNotifications(userFileSystemNewPath, this).UpdateAsync();

                            await engine.CustomDataManager(userFileSystemNewPath).RefreshCustomColumnsAsync();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LogError($"{e.ChangeType} failed", userFileSystemOldPath, userFileSystemNewPath, ex);
            }
        }