コード例 #1
0
        /// <summary>
        /// Displays custom columns in Windows file mnager.
        /// </summary>
        /// <param name="customColumnsData">list of columns to display.</param>
        private async Task ShowCustomColumnsAsync(IEnumerable <FileSystemItemPropertyData> customColumnsData)
        {
            List <StorageProviderItemProperty> customColumns = new List <StorageProviderItemProperty>();

            if (customColumnsData != null)
            {
                foreach (FileSystemItemPropertyData column in customColumnsData)
                {
                    customColumns.Add(new StorageProviderItemProperty()
                    {
                        Id = column.Id,
                        // If value is empty Windows File Manager crushes.
                        Value = string.IsNullOrEmpty(column.Value) ? "-" : column.Value,
                        // If icon is not set Windows File Manager crushes.
                        IconResource = column.IconResource ?? Path.Combine(iconsFolderPath, "Blank.ico")
                    });
                }
            }

            // This method may be called on temp files, typically created by MS Office, that exist for a short period of time.
            IStorageItem storageItem = await FsPath.GetStorageItemAsync(userFileSystemPath);

            if (storageItem == null)
            {
                // This method may be called on temp files, typically created by MS Office, that exist for a short period of time.
                // StorageProviderItemProperties.SetAsync(null,) causes AccessViolationException
                // which is not handled by .NET (nor handled by HandleProcessCorruptedStateExceptions) and causes a fatal crush.
                return;
            }

            FileInfo file = new FileInfo(userFileSystemPath);

            // Can not set provider properties on read-only files.
            // Changing read-only attribute on folders triggers folders listing. Changing on files only.
            bool readOnly = file.IsReadOnly;

            // Remove read-only attribute.
            if (readOnly && ((file.Attributes & System.IO.FileAttributes.Directory) == 0))
            {
                file.IsReadOnly = false;
                //new FileInfo(userFileSystemPath).Attributes &= ~System.IO.FileAttributes.ReadOnly;
            }

            // Update columns data.
            await StorageProviderItemProperties.SetAsync(storageItem, customColumns);

            // Set read-only attribute.
            if (readOnly && ((file.Attributes & System.IO.FileAttributes.Directory) == 0))
            {
                file.IsReadOnly = true;
                //new FileInfo(userFileSystemPath).Attributes |= System.IO.FileAttributes.ReadOnly;
            }
        }
コード例 #2
0
        /// <summary>
        /// Returns true if the file or folder is marked with Hidden or Temporaty attributes.
        /// </summary>
        /// <param name="path">Path to a file or folder.</param>
        /// <returns>
        /// True if the file or folder is marked with Hidden or Temporaty attributes.
        /// Returns false if no Hidden or Temporaty attributes found or file/folder does not exists.
        /// </returns>
        private static bool IsHiddenOrTemp(string path)
        {
            if (!FsPath.Exists(path))
            {
                return(false);
            }

            FileAttributes att = File.GetAttributes(path);

            return(((att & System.IO.FileAttributes.Hidden) != 0) ||
                   ((att & System.IO.FileAttributes.Temporary) != 0));
        }
コード例 #3
0
        /// <inheritdoc/>
        public async Task MoveToCompletionAsync(IMoveCompletionContext moveCompletionContext, IResultContext resultContext)
        {
            string userFileSystemNewPath = this.UserFileSystemPath;
            string userFileSystemOldPath = moveCompletionContext.SourcePath;

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

            if (Engine.ChangesProcessingEnabled)
            {
                if (FsPath.Exists(userFileSystemNewPath))
                {
                    FileSystemItemTypeEnum itemType = FsPath.GetItemType(userFileSystemNewPath);
                    await new RemoteStorageRawItem <TItemType>(userFileSystemNewPath, VirtualDrive, Logger).MoveToCompletionAsync();
                }
            }
        }
コード例 #4
0
        /// <inheritdoc/>
        public async Task CloseAsync(IOperationContext operationContext, IResultContext context)
        {
            // Here, if the file in the user file system is modified (not in-sync), you will send the file content,
            // creation time, modification time and attributes to the remote storage.
            // We also send ETag, to make sure the changes on the server, if any, are not overwritten.

            Logger.LogMessage("IFile.CloseAsync()", UserFileSystemPath);

            string userFileSystemFilePath = UserFileSystemPath;

            // In case the file is moved it does not exist in user file system when CloseAsync() is called.
            if (Engine.ChangesProcessingEnabled &&
                FsPath.Exists(userFileSystemFilePath) &&
                !FsPath.AvoidSync(userFileSystemFilePath))
            {
                // In case the file is overwritten it is converted to a regular file prior to CloseAsync().
                // we need to convert it back into file/folder placeholder.
                if (!PlaceholderItem.IsPlaceholder(userFileSystemFilePath))
                {
                    PlaceholderItem.ConvertToPlaceholder(userFileSystemFilePath, false);
                    Logger.LogMessage("Converted to placeholder", userFileSystemFilePath);
                }

                try
                {
                    if (PlaceholderItem.GetItem(userFileSystemFilePath).IsNew(VirtualDrive))
                    {
                        // Create new file in the remote storage.
                        await new RemoteStorageRawItem <IVirtualFile>(userFileSystemFilePath, VirtualDrive, Logger).CreateAsync();
                    }
                    else if (!PlaceholderItem.GetItem(userFileSystemFilePath).IsMoved())
                    {
                        // Send content to remote storage. Unlock if auto-locked.
                        await new RemoteStorageRawItem <IVirtualFile>(userFileSystemFilePath, VirtualDrive, Logger).UpdateAsync();
                    }
                }
                catch (IOException ex)
                {
                    // Either the file is already being synced in another thread or client or server file is blocked by concurrent process.
                    // This is a normal behaviour.
                    // The file must be synched by your synchronyzation service at a later time, when the file becomes available.
                    Logger.LogMessage("Failed to upload file. Possibly in use by an application or blocked for synchronization in another thread:", ex.Message);
                }
            }
        }
コード例 #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();
            }
        }
コード例 #6
0
 public static FileSystemItemTypeEnum GetItemType(string path)
 {
     return(FsPath.IsFile(path) ? FileSystemItemTypeEnum.File : FileSystemItemTypeEnum.Folder);
 }
コード例 #7
0
        /// <inheritdoc/>
        public IClientNotifications ClientNotifications(string userFileSystemPath, ILogger logger)
        {
            FileSystemItemTypeEnum itemType = FsPath.GetItemType(userFileSystemPath);

            return(GetRemoteStorageRawItem(userFileSystemPath, itemType, logger));
        }
コード例 #8
0
ファイル: Logger.cs プロジェクト: ITHit/UserFileSystemSamples
        /// <inheritdoc/>
        public void LogError(string message, string sourcePath = null, string targetPath = null, Exception ex = null)
        {
            string att = FsPath.Exists(sourcePath) ? FsPath.GetAttString(sourcePath) : null;

            Log.Error($"\n{DateTimeOffset.Now} [{Thread.CurrentThread.ManagedThreadId,2}] {componentName,-26}{message,-45} {sourcePath,-80} {att} ", ex);
        }