/// <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); IHierarchyItemAsync[] remoteStorageChildren = null; // Retry the request in case the log-in dialog is shown. try { remoteStorageChildren = await Program.DavClient.GetChildrenAsync(new Uri(RemoteStoragePath), false); } catch (ITHit.WebDAV.Client.Exceptions.Redirect302Exception) { remoteStorageChildren = await Program.DavClient.GetChildrenAsync(new Uri(RemoteStoragePath), false); } List <FileSystemItemMetadataExt> userFileSystemChildren = new List <FileSystemItemMetadataExt>(); foreach (IHierarchyItemAsync remoteStorageItem in remoteStorageChildren) { FileSystemItemMetadataExt itemInfo = Mapping.GetUserFileSystemItemMetadata(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; } // To signal that the children enumeration is completed // always call ReturnChildren(), even if the folder is empty. resultContext.ReturnChildren(userFileSystemChildren.ToArray(), userFileSystemChildren.Count()); // Save ETags, the read-only attribute and all custom columns data. foreach (FileSystemItemMetadataExt child in userFileSystemChildren) { string userFileSystemItemPath = Path.Combine(UserFileSystemPath, child.Name); ExternalDataManager customDataManager = Engine.CustomDataManager(userFileSystemItemPath); // Save ETag on the client side, to be sent to the remote storage as part of the update. // Setting ETag also marks an item as not new. // ETags must correspond with a server file/folder, NOT with a client placeholder. // It should NOT be moved/deleted/updated when a placeholder in the user file system is moved/deleted/updated. // It should be moved/deleted when a file/folder in the remote storage is moved/deleted. await customDataManager.ETagManager.SetETagAsync(child.ETag); // Set the read-only attribute and all custom columns data. await customDataManager.SetLockedByAnotherUserAsync(child.LockedByAnotherUser); await customDataManager.SetCustomColumnsAsync(child.CustomProperties); } }
/// <summary> /// Creates instance of this class. /// </summary> /// <param name="userFileSystemPath">Path of this file of folder in the user file system.</param> /// <param name="logger">Logger.</param> public VirtualFileSystemItem(string userFileSystemPath, ILogger logger) { this.UserFileSystemPath = userFileSystemPath; this.RemoteStorageUri = Mapping.MapPath(userFileSystemPath); this.Logger = logger; }