public override async Task <IList <IEntryModel> > ListAsync(IEntryModel entry, CancellationToken ct, Func <IEntryModel, bool> filter = null, bool refresh = false) { await checkLoginAsync(); if (filter == null) { filter = e => true; } GoogleDriveItemModel dirModel = (GoogleDriveItemModel)entry; if (dirModel != null) { if (!refresh) { var cachedChild = ModelCache.GetChildModel(dirModel); if (cachedChild != null) { return(cachedChild.Where(m => filter(m)).Cast <IEntryModel>().ToList()); } } var listRequest = _driveService.Files.List(); listRequest.Q = String.Format("'{0}' in parents", dirModel.UniqueId); var listResult = (await listRequest.ExecuteAsync().ConfigureAwait(false)); var listResultItems = listResult.Items.ToList(); var outputModels = listResultItems.Select(f => new GoogleDriveItemModel(this, f, dirModel.FullPath)).ToArray(); ModelCache.RegisterChildModels(dirModel, outputModels); return(outputModels.Where(m => filter(m)).Cast <IEntryModel>().ToList()); } return(new List <IEntryModel>()); }
public static WebFileStream OpenWrite(IEntryModel entryModel) { return(new WebFileStream(entryModel, null, (m, s) => { AsyncUtils.RunSync(() => updateSourceAsync(s)); })); }
public HierarchicalResult CompareHierarchy(IEntryModel a, IEntryModel b) { HierarchicalResult retVal = CompareHierarchyInner(a, b); //Debug.WriteLine(String.Format("{2} {0},{1}", a.FullPath, b.FullPath, retVal)); return(retVal); }
public async Task BroascastAsync(EntryChangedEvent message) { try { string[] paths = message.ParseNames .Where(p => p != null) .Select(p => p.Contains('\\') ? PathHelper.Disk.GetDirectoryName(p) : PathHelper.Web.GetDirectoryName(p)) .Distinct().ToArray(); foreach (var path in paths) { IEntryModel affectedParentEntry = await _rootProfiles.ParseAsync(path); if (affectedParentEntry != null) { await DirectoryTree.Selection.AsRoot().BroascastAsync(affectedParentEntry); await Breadcrumb.Selection.AsRoot().BroascastAsync(affectedParentEntry); if (FileList.CurrentDirectory.Equals(affectedParentEntry)) { await FileList.ProcessedEntries.EntriesHelper.LoadAsync(UpdateMode.Replace, true); } } } } catch (Exception ex) { Debug.WriteLine(ex); } }
public ExplorerViewModel(IWindowManager windowManager, IEventAggregator events) { _events = events; _rootModels = new IEntryModel[] { }; _windowManager = windowManager; _initializer = NullExplorerInitializer.Instance; WindowTitleMask = "{0}"; DisplayName = ""; //Toolbar = new ToolbarViewModel(events); Breadcrumb = new BreadcrumbViewModel(_internalEvents); Statusbar = new StatusbarViewModel(_internalEvents); Sidebar = new SidebarViewModel(_internalEvents); FileList = new FileListViewModel(_windowManager, _internalEvents, Sidebar); DirectoryTree = new DirectoryTreeViewModel(_windowManager, _internalEvents); Navigation = new NavigationViewModel(_internalEvents); DragHelper = NullSupportDrag.Instance; DropHelper = NullSupportDrop.Instance; Commands = new ExplorerCommandManager(this, FileList, DirectoryTree, Navigation, Breadcrumb); //setRootModels(_rootModels); if (_events != null) { _events.Subscribe(this); } _internalEvents.Subscribe(this); }
private IEnumerable <IEntryModel> getEntryModels(IDataObject dataObject) { if (dataObject.GetDataPresent(DataFormats.FileDrop)) { string[] fileNameList = dataObject.GetData(DataFormats.FileDrop) as string[]; foreach (var fn in fileNameList) { IEntryModel vm = null; try { if (Directory.Exists(fn)) { vm = new FileSystemInfoModel(_fsiProfile, new DirectoryInfo(fn)); } else if (File.Exists(fn)) { vm = new FileSystemInfoModel(_fsiProfile, new FileInfo(fn)); } } catch { vm = null; } if (vm != null) { yield return(vm); } } } }
public FileListCommandManager(IFileListViewModel flvm, IWindowManager windowManager, IEventAggregator events, params IExportCommandBindings[] additionalBindingExportSource) : base(additionalBindingExportSource) { _flvm = flvm; IEntryModel _currentDirectoryModel = null; InitCommandManager(); ToolbarCommands = new ToolbarCommandsHelper(events, ParameterDicConverter, message => { _currentDirectoryModel = message.NewModel; return(new IEntryModel[] { _currentDirectoryModel }); }, message => message.SelectedModels.Count() == 0 && _currentDirectoryModel != null ? new IEntryModel[] { _currentDirectoryModel } : message.SelectedModels.ToArray()) { ExtraCommandProviders = new[] { new StaticCommandProvider(new SelectGroupCommand(flvm), new ViewModeCommand(flvm), new SeparatorCommandModel(), new CommandModel(ExplorerCommands.NewFolder) { IsVisibleOnToolbar = true, HeaderIconExtractor = ResourceIconExtractor <ICommandModel> .ForSymbol(0xE188) }, new DirectoryCommandModel( new CommandModel(ExplorerCommands.NewFolder) { Header = Strings.strFolder, IsVisibleOnMenu = true }) { IsVisibleOnMenu = true, Header = Strings.strNew, IsEnabled = true }, new ToggleVisibilityCommand(flvm.Sidebar, ExplorerCommands.TogglePreviewer) ) } }; }
public override async Task <IScriptCommand> ExecuteAsync(ParameterDic pm) { IEntryModel entryModel = pm.GetValue <IEntryModel>(EntryKey); if (entryModel == null) { return(ResultCommand.Error(new ArgumentException(EntryKey + " is not found or not IEntryModel"))); } IDiskProfile profile = entryModel.Profile as IDiskProfile; if (profile == null) { return(ResultCommand.Error(new NotSupportedException(EntryKey + "'s Profile is not IDiskProfile"))); } using (var stream = await profile.DiskIO.OpenStreamAsync(entryModel, Access, pm.CancellationToken)) { ParameterDic pmClone = pm.Clone(); pmClone.SetValue(StreamKey, stream); logger.Debug(String.Format("{0} = Stream of {1}", StreamKey, EntryKey)); await ScriptRunner.RunScriptAsync(pmClone, NextCommand); } if (Access == FileAccess.ReadWrite || Access == FileAccess.Write) { return(CoreScriptCommands.NotifyEntryChangedProfile(ChangeType.Changed, null, EntryKey, ThenCommand)); } else { return(ThenCommand); } }
public override async Task <IScriptCommand> ExecuteAsync(ParameterDic pm) { var flValue = pm.GetValue(FileListKey); IFileListViewModel flvm = flValue is IExplorerViewModel ? (flValue as IExplorerViewModel).FileList : flValue as IFileListViewModel; if (flvm == null) { return(ResultCommand.Error(new KeyNotFoundException(FileListKey))); } IEntryModel[] value = new IEntryModel[] { }; switch (AssignType) { case FileListAssignType.All: value = flvm.ProcessedEntries.EntriesHelper.AllNonBindable .Select(evm => evm.EntryModel).ToArray(); break; case FileListAssignType.Selected: value = flvm.Selection.SelectedItems.Select(evm => evm.EntryModel).ToArray(); break; default: return(ResultCommand.Error(new NotSupportedException("AssignType"))); } return(ScriptCommands.Assign(DestinationKey, value, false, NextCommand)); }
public DiskMapInfo this[IEntryModel model] { get { string path = Path.Combine(_tempPath, model.FullPath.Replace(":\\", "").Replace("/", "\\").TrimStart('\\')); Directory.CreateDirectory(Path.GetDirectoryName(path)); bool isCached = _isCachedDictionary.ContainsKey(model.FullPath) && _isCachedDictionary[model.FullPath]; string sourceUrl = _urlFunc == null ? null : _urlFunc(model); if (sourceUrl == null) { if (model.IsDirectory) { return(new DiskMapInfo(path, isCached, true)); } else { return(new DiskMapInfo(path, isCached, true)); } } return(new DiskMapInfo(path, isCached, true) { SourceUrl = new Uri(sourceUrl) }); } }
public override async Task DeleteAsync(IEntryModel entryModel, CancellationToken ct) { await _profile.checkLoginAsync(); LiveConnectClient liveClient = new LiveConnectClient(_profile.Session); LiveOperationResult result = await liveClient.DeleteAsync((entryModel as SkyDriveItemModel).UniqueId, ct); }
public HierarchicalResult CompareHierarchy(IEntryModel a, IEntryModel b) { if (a == null || b == null || a.FullPath == null || b.FullPath == null) { return(HierarchicalResult.Unrelated); } string apath = a.FullPath.TrimEnd(_separator); string bpath = b.FullPath.TrimEnd(_separator); if (apath.Equals(bpath, _stringComparsion)) { return(HierarchicalResult.Current); } var aSplit = apath.Split(new char[] { _separator }, StringSplitOptions.RemoveEmptyEntries); var bSplit = bpath.Split(new char[] { _separator }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < Math.Min(aSplit.Length, bSplit.Length); i++) { if (!(aSplit[i].Equals(bSplit[i], _stringComparsion))) { return(HierarchicalResult.Unrelated); } } if (aSplit.Length > bSplit.Length) { return(HierarchicalResult.Parent); } else { return(HierarchicalResult.Child); } }
public async Task SelectAsync(IEntryModel value) { await Selection.LookupAsync(value, RecrusiveSearch <IDirectoryNodeViewModel, IEntryModel> .LoadSubentriesIfNotLoaded, SetSelected <IDirectoryNodeViewModel, IEntryModel> .WhenSelected, SetExpanded <IDirectoryNodeViewModel, IEntryModel> .WhenChildSelected); }
public override async Task DeleteAsync(IEntryModel entryModel, CancellationToken ct) { DropBoxItemModel entry = entryModel as DropBoxItemModel; var profile = entry.Profile as DropBoxProfile; await profile.GetClient().DeleteTask(entry.RemotePath); }
/// <summary> /// Not Serializable, create a folder by specified parameter. /// </summary> /// <param name="parentFolder"></param> /// <param name="folderName"></param> /// <param name="destVariable"></param> /// <param name="nameGenerationMode"></param> /// <param name="nextCommand"></param> /// <returns></returns> public static IScriptCommand DiskCreateFolder(IEntryModel parentFolder, string folderName, string destVariable = "{Entry}", NameGenerationMode nameGenerationMode = NameGenerationMode.Rename, IScriptCommand nextCommand = null) { return(ScriptCommands.Assign("{DiskCreateFolder-Profile}", parentFolder, false, ScriptCommands.Assign("{DiskCreateFolder-Path}", parentFolder.Profile.Path.Combine(parentFolder.FullPath, folderName), false, DiskCreateFolder("{DiskCreateFolder-Profile}", "{DiskCreateFolder-Path}", destVariable, nameGenerationMode, nextCommand)))); }
async Task <IEnumerable <IDirectoryNodeViewModel> > loadEntriesTask(bool refresh) { IEntryModel currentDir = Selection.Value; var subDir = await currentDir.Profile.ListAsync(currentDir, CancellationToken.None, em => em.IsDirectory, refresh); return(subDir.Select(s => CreateSubmodel(s))); }
public HierarchicalResult CompareHierarchy(IEntryModel value1, IEntryModel value2) { if (value1 is T && value2 is T) { if (value1 == null || value2 == null) { return(HierarchicalResult.Unrelated); } if (value1.FullPath.Equals(value2.FullPath, _comparsion)) { return(HierarchicalResult.Current); } if (value1.FullPath.StartsWith(value2.FullPath + _separator, _comparsion)) { return(HierarchicalResult.Parent); } if (value2.FullPath.StartsWith(value1.FullPath + _separator, _comparsion)) { return(HierarchicalResult.Child); } } return(HierarchicalResult.Unrelated); }
public static QueryDropEffects QueryDrop(this IDragDropHandler dragDropHandler, IEnumerable <IEntryModel> entries, IEntryModel dest, DragDropEffectsEx allowedEffects) { var dropHelper = dragDropHandler.GetDropHelper(dest); return(dropHelper.QueryDrop(entries.Cast <IDraggable>(), allowedEffects)); }
public override async Task DeleteAsync(IEntryModel entryModel, CancellationToken ct) { SzsProfile profile = Profile as SzsProfile; ISzsItemModel szsEntryModel = entryModel as ISzsItemModel; if (szsEntryModel is SzsRootModel) { IEntryModel rootFile = (szsEntryModel as SzsRootModel).ReferencedFile; await(rootFile.Profile as IDiskProfile) .DiskIO.DeleteAsync(rootFile, ct); return; } using (var releaser = await profile.WorkingLock.LockAsync()) using (var stream = await profile.DiskIO.OpenStreamAsync(szsEntryModel.Root, Defines.FileAccess.ReadWrite, ct)) { string type = profile.Path.GetExtension(szsEntryModel.Root.Name); profile.Wrapper.Delete(type, stream, szsEntryModel.RelativePath + (szsEntryModel.IsDirectory ? "\\*" : "")); lock (profile.VirtualModels) if (profile.VirtualModels.Contains(szsEntryModel)) { profile.VirtualModels.Remove(szsEntryModel); } } }
public override async Task <Stream> OpenStreamAsync(IEntryModel entryModel, FileExplorer.Defines.FileAccess access, CancellationToken ct) { //SevenZipWrapper wrapper = (Profile as SzsProfile).Wrapper; ISzsItemModel entryItemModel = entryModel as ISzsItemModel; //IEntryModel rootReferenceModel = itemModel.Root.ReferencedFile; //return new CompressMemoryStream(wrapper, rootReferenceModel, itemModel.RelativePath, access, ct); //To-DO: save to Profile.DiskIO.Mapper[itemModel].IOPath if (entryItemModel.Root.Equals(entryItemModel)) { IEntryModel referencedFile = entryItemModel.Root.ReferencedFile; return(await(referencedFile.Profile as IDiskProfile).DiskIO.OpenStreamAsync(referencedFile, access, ct)); } switch (access) { case FileExplorer.Defines.FileAccess.Read: return(await SzsFileStream.OpenReadAsync(entryModel, ct)); case FileExplorer.Defines.FileAccess.Write: return(SzsFileStream.OpenWrite(entryModel)); case FileExplorer.Defines.FileAccess.ReadWrite: return(await SzsFileStream.OpenReadWriteAsync(entryModel, ct)); } throw new NotSupportedException(); }
private bool parseEntryAndProfile(ParameterDic pm, string key, string profileKey, out string[] entryPath, out IProfile profile) { object value = pm.GetValue(key); if (value is string) { value = new string[] { value as string } } ; if (value is string[]) { entryPath = value as string[]; profile = pm.GetValue <IProfile>(profileKey); return(true); } if (value is IEntryModel) { value = new IEntryModel[] { value as IEntryModel } } ; if (value is IEntryModel[]) { IEntryModel[] ems = value as IEntryModel[]; entryPath = ems.Select(em => em.FullPath).ToArray(); profile = ems.First().Profile; return(true); } entryPath = null; profile = null; return(false); }
public override async Task <IEntryModel> RenameAsync(IEntryModel entryModel, string newName, CancellationToken ct) { SevenZipWrapper wrapper = (Profile as SzsProfile).Wrapper; string destPath = Profile.Path.Combine(Profile.Path.GetDirectoryName(entryModel.FullPath), newName); SzsProfile profile = Profile as SzsProfile; ISzsItemModel szsEntryModel = entryModel as ISzsItemModel; string type = profile.Path.GetExtension(szsEntryModel.Root.Name); using (var releaser = await profile.WorkingLock.LockAsync()) using (var stream = await profile.DiskIO.OpenStreamAsync(szsEntryModel.Root, Defines.FileAccess.ReadWrite, ct)) wrapper.Modify(type, stream, (entryModel as ISzsItemModel).RelativePath, newName, entryModel.IsDirectory && !(entryModel is SzsRootModel)); lock (profile.VirtualModels) { if (profile.VirtualModels.Contains(szsEntryModel)) { profile.VirtualModels.Remove(szsEntryModel); } } Profile.NotifyEntryChanges(this, destPath, Defines.ChangeType.Moved, entryModel.FullPath); return(await Profile.ParseAsync(destPath)); }
public static bool IsFileWithExtension(this IEntryModel model, string extensions) { string extension = model.Profile.Path.GetExtension(model.Name); return(!model.IsDirectory && extensions.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries) .Contains(extension, StringComparer.CurrentCultureIgnoreCase)); }
public bool Equals(IEntryModel other) { if (other == null) { return(false); } return(FullPath.Equals(other.FullPath)); }
//public static IScriptCommand List(IEntryModel directory, Func<IEntryModel, bool> filter = null, // bool recrusive = false, Func<IEntryModel[], IScriptCommand> nextCommandFunc = null) //{ // return new ListDirectoryCommand(directory, DirectoryOnlyFilter, filter, recrusive, nextCommandFunc); //} public static IScriptCommand CreatePath(IEntryModel parentModel, string name, bool isFolder, bool renameIfExists, Func <IEntryModel, IScriptCommand> thenFunc) { IProfile profile = parentModel.Profile; return(CreatePath(profile, profile.Path.Combine(parentModel.FullPath, name), isFolder, renameIfExists, thenFunc)); }
public static IScriptCommand DiskTransferChild(IEntryModel[] srcModels, IEntryModel destDirModel, bool removeOriginal = false, bool allowCustomImplementation = true, IScriptCommand nextCommand = null) { return(ScriptCommands.Assign("{SourceDiskTransferEntry}", srcModels, false, ScriptCommands.Assign("{DestinationDiskTransferEntry}", destDirModel, false, DiskTransferChild("{SourceDiskTransferEntry}", "{DestinationDiskTransferEntry}", removeOriginal, allowCustomImplementation, nextCommand)))); }
public static async Task <WebFileStream> OpenReadAsync(IEntryModel entryModel, CancellationToken ct) { var fileModel = entryModel as DropBoxItemModel; var profile = fileModel.Profile as DropBoxProfile; var contents = (await profile.GetClient().GetFileTask(fileModel.RemotePath)).RawBytes; return(new WebFileStream(entryModel, contents, null)); }
public override async Task <IScriptCommand> ExecuteAsync(ParameterDic pm) { IEntryModel[] srcEntries = null; IEntryModel destEntry = null; try { srcEntries = await pm.GetValueAsEntryModelArrayAsync(SourceEntryKey); destEntry = await pm.GetValueAsEntryModelAsync(DestinationDirectoryEntryKey, null); } catch (ArgumentException ex) { return(ResultCommand.Error(ex)); } if (!destEntry.IsDirectory) { return(ResultCommand.Error(new ArgumentException(DestinationDirectoryEntryKey + " is not a folder."))); } if (srcEntries.Length == 0) { return(ResultCommand.Error(new ArgumentException("Nothing to transfer."))); } var srcProfile = srcEntries.First().Profile as IDiskProfile; var destProfile = destEntry.Profile as IDiskProfile; if (srcEntries == null || destProfile == null) { return(ResultCommand.Error(new ArgumentException("Either source or dest is not IDiskProfile."))); } var progress = pm.GetProgress() ?? NullTransferProgress.Instance; if (AllowCustomImplementation) { logger.Info(String.Format("{0} {1} -> {2} using CustomImplementation", RemoveOriginal ? "Move" : "Copy", srcEntries.GetDescription(), destEntry.Name)); return(destProfile.DiskIO .GetTransferCommand(SourceEntryKey, DestinationDirectoryEntryKey, DestinationKey, RemoveOriginal, NextCommand)); } else { var srcMapper = srcProfile.DiskIO.Mapper; var destMapping = destProfile.DiskIO.Mapper[destEntry]; if (!destMapping.IsVirtual && RemoveOriginal && srcEntries.All(entry => !srcMapper[entry].IsVirtual)) { return(await transferSystemIOAsync(pm, srcEntries, destEntry, DestinationKey)); } else { return(await transferScriptCommandAsync(pm, srcEntries, destEntry, DestinationKey)); } } }
public override async Task <IScriptCommand> ExecuteAsync(ParameterDic pm) { IEntryModel entry = pm.GetValue <IEntryModel>(EntryKey); if (entry == null) { return(ResultCommand.Error(new KeyNotFoundException(EntryKey))); } IDiskProfile profile = entry.Profile as IDiskProfile; if (profile == null) { return(ResultCommand.Error(new ArgumentException(EntryKey + "'s Profile is not IDiskProfile"))); } var entryMapping = profile.DiskIO.Mapper[entry]; if (entryMapping.IsVirtual) { await profile.DiskIO.WriteToCacheAsync(entry, pm.CancellationToken, true); } if (ExecutableKey == null) //Default implementation { if (entry.IsDirectory) { try { Process.Start(entryMapping.IOPath); } catch (Exception ex) { return(ResultCommand.Error(ex)); } } else { if (File.Exists(entryMapping.IOPath)) { ProcessStartInfo psi = null; if (ExecutableKey == "OpenAs") { psi = new ProcessStartInfo("Rundll32.exe"); psi.Arguments = String.Format(" shell32.dll, OpenAs_RunDLL {0}", entryMapping.IOPath); } else { psi = new ProcessStartInfo(entryMapping.IOPath); } if (psi != null) { try { Process.Start(psi); } catch (Exception ex) { return(ResultCommand.Error(ex)); } } } } } else { } return(NextCommand); }
public static IScriptCommand Transfer(IEntryModel srcModel, IEntryModel destDirModel, bool removeOriginal = false, bool allowCustomImplementation = true, IScriptCommand nextCommand = null) { IScriptCommand retCommand = allowCustomImplementation ? (destDirModel.Profile as IDiskProfile).DiskIO.GetTransferCommand(srcModel, destDirModel, removeOriginal) : new FileTransferScriptCommand(srcModel, destDirModel, removeOriginal); return(nextCommand == null ? retCommand : ScriptCommands.RunInSequence(retCommand, nextCommand)); }
public SecureboxFileExplorer(IProfile[] profiles, IEntryModel[] rootDirs, string mask, string selectedPath = "c:\\") { InitializeComponent(); Securebox.CenterWindowOnScreen(this); _profiles = profiles; _rootDirs = rootDirs; _filterStr = mask; _selectedPath = selectedPath; }