/// <summary>
 /// Sets or removes icon.
 /// </summary>
 /// <param name="set">True to display the icon. False - to remove the icon.</param>
 private async Task SetIconAsync(bool set, int id, string iconFile = null, string description = null)
 {
     if (set)
     {
         string iconFilePath = Path.Combine(iconsFolderPath, iconFile);
         FileSystemItemPropertyData propData = new FileSystemItemPropertyData((int)id, description, iconFilePath);
         await SetCustomColumnsAsync(new [] { propData });
     }
     else
     {
         FileSystemItemPropertyData propData = new FileSystemItemPropertyData((int)id, null);
         await RemoveCustomColumnsAsync(new [] { propData });
     }
 }
Ejemplo n.º 2
0
        /// <inheritdoc/>
        public async Task GetChildrenAsync(string pattern, IOperationContext operationContext, IFolderListingResultContext resultContext)
        {
            // This method has a 60 sec timeout.
            // To process longer requests and reset the timout timer call one of the following:
            // - resultContext.ReturnChildren() method.
            // - resultContext.ReportProgress() method.

            Logger.LogMessage($"{nameof(IFolder)}.{nameof(GetChildrenAsync)}({pattern})", UserFileSystemPath);

            IEnumerable <FileSystemInfo> remoteStorageChildren = new DirectoryInfo(RemoteStoragePath).EnumerateFileSystemInfos(pattern);

            List <IFileSystemItemMetadata> userFileSystemChildren = new List <IFileSystemItemMetadata>();

            foreach (FileSystemInfo remoteStorageItem in remoteStorageChildren)
            {
                IFileSystemItemMetadata itemInfo = Mapping.GetUserFileSysteItemMetadata(remoteStorageItem);

                string userFileSystemItemPath = Path.Combine(UserFileSystemPath, itemInfo.Name);

                // Filtering existing files/folders. This is only required to avoid extra errors in the log.
                if (!FsPath.Exists(userFileSystemItemPath))
                {
                    Logger.LogMessage("Creating", userFileSystemItemPath);
                    userFileSystemChildren.Add(itemInfo);
                }

                ExternalDataManager customDataManager = Engine.CustomDataManager(userFileSystemItemPath);

                // Mark this item as not new, which is required for correct MS Office saving opertions.
                customDataManager.IsNew = false;

                // Save ETag on the client side, to be sent to the remote storage as part of the update.
                await customDataManager.ETagManager.SetETagAsync("1234567890");
            }

            // To signal that the children enumeration is completed
            // always call ReturnChildren(), even if the folder is empty.
            resultContext.ReturnChildren(userFileSystemChildren.ToArray(), userFileSystemChildren.Count());

            // Show some custom column in file manager for demo purposes.
            foreach (IFileSystemItemMetadata itemInfo in userFileSystemChildren)
            {
                string userFileSystemItemPath = Path.Combine(UserFileSystemPath, itemInfo.Name);

                FileSystemItemPropertyData eTagColumn = new FileSystemItemPropertyData((int)CustomColumnIds.ETag, "1234567890");
                await Engine.CustomDataManager(userFileSystemItemPath).SetCustomColumnsAsync(new [] { eTagColumn });
            }
        }