public async Task GetChildrenAsync(string pattern, IOperationContext operationContext, IFolderListingResultContext resultContext) { IEnumerable <FileSystemInfo> remoteStorageChildren = new DirectoryInfo(Mapping.MapPath(Name)).EnumerateFileSystemInfos(pattern); List <IFileSystemItemBasicInfo> infos = new List <IFileSystemItemBasicInfo>(); foreach (FileSystemInfo remoteStorageItem in remoteStorageChildren) { VfsFileSystemItem info = (VfsFileSystemItem)Mapping.GetUserFileSysteItemBasicInfo(remoteStorageItem); info.Name = Mapping.ReverseMapPath(info.Name); infos.Add(info); } resultContext.ReturnChildren(infos.ToArray(), infos.Count); }
/// <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 }); } }
/// <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($"IFolder.GetChildrenAsync({pattern})", UserFileSystemPath); IVirtualFolder userFolder = await VirtualDrive.GetItemAsync <IVirtualFolder>(UserFileSystemPath, Logger); IEnumerable <FileSystemItemMetadataExt> children = await userFolder.EnumerateChildrenAsync(pattern); // Filtering existing files/folders. This is only required to avoid extra errors in the log. List <IFileSystemItemMetadata> newChildren = new List <IFileSystemItemMetadata>(); foreach (FileSystemItemMetadataExt child in children) { string userFileSystemItemPath = Path.Combine(UserFileSystemPath, child.Name); if (!FsPath.Exists(userFileSystemItemPath)) { Logger.LogMessage("Creating", child.Name); // If the file is moved/renamed and the app is not running this will help us // to sync the file/folder to remote storage after app starts. child.CustomData = new CustomData { OriginalPath = userFileSystemItemPath }.Serialize(); newChildren.Add(child); } } // To signal that the children enumeration is completed // always call ReturnChildren(), even if the folder is empty. resultContext.ReturnChildren(newChildren.ToArray(), newChildren.Count()); // Save ETags, the read-only attribute and all custom columns data. foreach (FileSystemItemMetadataExt child in children) { string userFileSystemItemPath = Path.Combine(UserFileSystemPath, child.Name); // Create ETags. // 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 VirtualDrive.GetETagManager(userFileSystemItemPath, Logger).SetETagAsync(child.ETag); // Set the read-only attribute and all custom columns data. UserFileSystemRawItem userFileSystemRawItem = VirtualDrive.GetUserFileSystemRawItem(userFileSystemItemPath, Logger); await userFileSystemRawItem.SetLockedByAnotherUserAsync(child.LockedByAnotherUser); await userFileSystemRawItem.SetCustomColumnsDataAsync(child.CustomProperties); } }
/// <inheritdoc/> public async Task GetChildrenAsync(string pattern, IOperationContext operationContext, IFolderListingResultContext resultContext) { 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); userFileSystemChildren.Add(itemInfo); } // To signal that the children enumeration is completed // always call ReturnChildren(), even if the folder is empty. resultContext.ReturnChildren(userFileSystemChildren.ToArray(), userFileSystemChildren.Count); }
/// <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); } } // To signal that the children enumeration is completed // always call ReturnChildren(), even if the folder is empty. resultContext.ReturnChildren(userFileSystemChildren.ToArray(), userFileSystemChildren.Count()); }
/// <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: // - IGetChildrenContext.ReturnChildren() method. // - IGetChildrenContext.ReportProgress() method. LogMessage($"IFolder.GetChildrenAsync({pattern})", this.FullPath); string remoreStoragePath = Mapping.MapPath(this.FullPath); IEnumerable <FileSystemInfo> remoteStorageChildren = new DirectoryInfo(remoreStoragePath).EnumerateFileSystemInfos(pattern); List <IFileSystemItemBasicInfo> userFileSystemChildren = new List <IFileSystemItemBasicInfo>(); foreach (FileSystemInfo remoteStorageItem in remoteStorageChildren) { string userFileSystemPath = Path.Combine(this.FullPath, Path.GetFileName(remoteStorageItem.Name)); if (!FsPath.Exists(userFileSystemPath)) { // Uncomment to simulate slow network access. //Thread.Sleep(10000); //resultContext.ReportProgress(remoteStorageChildren.Count(), userFileSystemChildren.Count()); LogMessage("Creating:", Path.GetFileName(remoteStorageItem.Name)); FileSystemItemBasicInfo userFileSystemItemInfo = Mapping.GetUserFileSysteItemInfo(remoteStorageItem); userFileSystemChildren.Add(userFileSystemItemInfo); } } // To signal that the children enumeration is completed // always call this method in GetChildrenAsync(), even if the folder is empty. resultContext.ReturnChildren(userFileSystemChildren.ToArray(), userFileSystemChildren.Count()); }
/// <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); } }
/// <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($"IFolder.GetChildrenAsync({pattern})", UserFileSystemPath); IEnumerable <FileSystemItemBasicInfo> children = await new UserFolder(UserFileSystemPath).EnumerateChildrenAsync(pattern); // Filtering existing files/folders. This is only required to avoid extra errors in the log. List <IFileSystemItemBasicInfo> newChildren = new List <IFileSystemItemBasicInfo>(); foreach (IFileSystemItemBasicInfo child in children) { string userFileSystemItemPath = Path.Combine(UserFileSystemPath, child.Name); if (!FsPath.Exists(userFileSystemItemPath)) { Logger.LogMessage("Creating", child.Name); newChildren.Add(child); } } // To signal that the children enumeration is completed // always call ReturnChildren(), even if the folder is empty. resultContext.ReturnChildren(newChildren.ToArray(), newChildren.Count()); // Save ETags and set "locked by another user" icon. foreach (FileSystemItemBasicInfo child in children) { string userFileSystemItemPath = Path.Combine(UserFileSystemPath, child.Name); // Create ETags. // 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. ETag.SetETagAsync(userFileSystemItemPath, child.ETag); // Set the lock icon and read-only attribute, to indicate that the item is locked by another user. new UserFileSystemRawItem(userFileSystemItemPath).SetLockedByAnotherUserAsync(child.LockedByAnotherUser); } }