public TestDroppableViewModel() { IProfile exProfile = new FileSystemInfoExProfile(null, null); DropHelper = new LambdaShellDropHelper <IEntryModel>( new LambdaValueConverter <IEntryViewModel, IEntryModel>( (evm) => evm.EntryModel, (em) => EntryViewModel.FromEntryModel(em)), new LambdaValueConverter <IEnumerable <IEntryModel>, IDataObject>( (ems) => exProfile.DragDrop.GetDataObject(ems), (da) => exProfile.DragDrop.GetEntryModels(da)), (ems, eff) => { return(QueryDropEffects.CreateNew(DragDropEffectsEx.Copy)); }, (ems, da, eff) => { if (ems.Count() > 1) { Label = ems.Count() + " items."; } else { Label = ems.First().FullPath; } return(DragDropEffectsEx.Copy); }) { DisplayName = "TestLabel" }; }
public MainWindow() { InitializeComponent(); IProfile _profileEx = new FileSystemInfoExProfile(explorer.ViewModel.Events, explorer.ViewModel.WindowManager); explorer.RootDirectories = new IEntryModel[] { _profileEx.ParseAsync("").Result }; }
public AppViewModel() { LogManagerFactory.DefaultConfiguration.AddTarget(LogLevel.Info, LogLevel.Fatal, new ConsoleTarget()); LogManagerFactory.DefaultConfiguration.IsEnabled = true; LogManagerFactory.DefaultLogManager.GetLogger <AppViewModel>().Log(LogLevel.Debug, "Test"); //AsyncUtils.RunSync(() => ScriptCommandTests.Test_DownloadFile()); // IScriptCommand diskTransferCommand = //ScriptCommands.ParsePath("{SourceFile}", "{Source}", //ScriptCommands.DiskParseOrCreateFolder("{DestinationDirectory}", "{Destination}", //IOScriptCommands.DiskTransfer("{Source}", "{Destination}", false, false))); //await ScriptRunner.RunScriptAsync(new ParameterDic() { // { "Profile", FileSystemInfoExProfile.CreateNew() }, // { "SourceFile", srcFile }, // { "DestinationFile", destFile } // }, copyCommand); //string tempDirectory = "C:\\Temp"; //string destDirectory = "C:\\Temp\\Destination1"; //string srcFile = System.IO.Path.Combine(tempDirectory, "file1.txt"); //string destFile = System.IO.Path.Combine(destDirectory, "file2.txt"); //AsyncUtils.RunSync(() => ScriptRunner.RunScriptAsync(new ParameterDic() { // { "Profile", FileExplorer.Models.FileSystemInfoExProfile.CreateNew() }, // { "SourceFile", srcFile }, // { "DestinationDirectory", destDirectory } //}, diskTransferCommand)); string tempDirectory = "C:\\Temp"; string destDirectory = "C:\\Temp\\Debug2"; string srcDirectory = "C:\\Temp\\aaaaabc"; IScriptCommand diskTransferCommand = CoreScriptCommands.ParsePath("{Profile}", srcDirectory, "{Source}", CoreScriptCommands.DiskParseOrCreateFolder("{Profile}", destDirectory, "{Destination}", IOScriptCommands.DiskTransfer("{Source}", "{Destination}", null, false, false))); AsyncUtils.RunSync(() => ScriptRunner.RunScriptAsync(new ParameterDic() { { "Profile", FileSystemInfoExProfile.CreateNew() } }, diskTransferCommand)); }
public static async Task Test_CopyFile() { string tempDirectory = "C:\\Temp"; string srcFile = System.IO.Path.Combine(tempDirectory, "File1.txt"); string destFile = System.IO.Path.Combine(tempDirectory, "File2.txt"); string signature = "Created by testCopyFile at " + DateTime.Now.ToString(); Directory.CreateDirectory(tempDirectory); using (var sw = File.CreateText(srcFile)) sw.WriteLine(signature); //File.Delete(destFile); IProfile fsiProfile = new FileSystemInfoExProfile(null, null); IScriptCommand copyCommand = CoreScriptCommands.ParsePath("{Profile}", "{SourceFile}", "{Source}", CoreScriptCommands.DiskParseOrCreateFile("{Profile}", "{DestinationFile}", "{Destination}", CoreScriptCommands.DiskOpenStream("{Source}", "{SourceStream}", FileExplorer.Defines.FileAccess.Read, CoreScriptCommands.DiskOpenStream("{Destination}", "{DestinationStream}", FileExplorer.Defines.FileAccess.Write, CoreScriptCommands.CopyStream("{SourceStream}", "{DestinationStream}")))) , ResultCommand.Error(new FileNotFoundException(srcFile)) ); //copyCommand = ScriptCommands.CopyFile("SourceFile", "DestinationFile"); copyCommand = serializeAndDeserializeCommand(copyCommand); await ScriptRunner.RunScriptAsync(new ParameterDic() { { "Profile", fsiProfile }, { "SourceFile", srcFile }, { "DestinationFile", destFile } }, copyCommand); string actual = null; using (var sr = File.OpenText(destFile)) { actual = sr.ReadLine(); } Assert.AreEqual(signature, actual); }
public override void OnApplyTemplate() { base.OnApplyTemplate(); IEventAggregator _events = new EventAggregator(); IWindowManager _windowManager = new AppWindowManager(); IProfile _exProfile = new FileSystemInfoExProfile(_events, _windowManager); IProfile _ioProfile = new FileSystemInfoProfile(_events); IProfile[] _profiles = new IProfile[] { _exProfile, _ioProfile }; IEntryModel[] _rootDirs = new IEntryModel[] { AsyncUtils.RunSync(() => _exProfile.ParseAsync("")) }; explorer.WindowManager = _windowManager; explorer.ViewModel.Initializer = new ScriptCommandInitializer() { OnModelCreated = ScriptCommands.Run("{OnModelCreated}"), OnViewAttached = ScriptCommands.Run("{OnViewAttached}"), RootModels = _rootDirs, WindowManager = _windowManager, StartupParameters = new ParameterDic() { { "Profiles", _profiles }, { "RootDirectories", _rootDirs }, { "GlobalEvents", _events }, { "WindowManager", _windowManager }, { "StartupPath", "" }, { "ViewMode", "List" }, { "ItemSize", 16 }, { "EnableDrag", true }, { "EnableDrop", true }, { "FileListNewWindowCommand", NullScriptCommand.Instance }, //Disable NewWindow Command. { "EnableMultiSelect", true }, { "ShowToolbar", true }, { "ShowGridHeader", true }, { "OnModelCreated", IOInitializeHelpers.Explorer_Initialize_Default }, { "OnViewAttached", UIScriptCommands.ExplorerGotoStartupPathOrFirstRoot() } } }; cbCommand.ItemsSource = ScriptCommandDictionary.CommandList; }
public TestDroppableViewModel() { IProfile exProfile = new FileSystemInfoExProfile(null, null); DropHelper = new DropHelper <IEntryModel>( () => "Test Droppable", (ems, eff) => QueryDropResult.CreateNew(DragDropEffects.Copy), da => exProfile.DragDrop().GetEntryModels(da), (ems, da, eff) => { if (ems.Count() > 1) { Label = ems.Count() + " items."; } else { Label = ems.First().FullPath; } return(DragDropEffects.Copy); }, em => EntryViewModel.FromEntryModel(em)); }
public AppViewModel(IEventAggregator events, IWindowManager windowManager) { //FileExplorer.Models.Bookmark.BookmarkSerializeTest.Test(); _windowManager = windowManager; _events = events; _events.Subscribe(this); _profile = new FileSystemInfoProfile(_events); _profileEx = new FileSystemInfoExProfile(_events, _windowManager, new FileExplorer.Models.SevenZipSharp.SzsProfile(_events)); Func <string> loginSkyDrive = () => { var login = new SkyDriveLogin(AuthorizationKeys.SkyDrive_Client_Id); if (_windowManager.ShowDialog(new LoginViewModel(login)).Value) { return(login.AuthCode); } return(null); }; if (AuthorizationKeys.SkyDrive_Client_Secret != null) { _profileSkyDrive = new SkyDriveProfile(_events, AuthorizationKeys.SkyDrive_Client_Id, loginSkyDrive, skyDriveAliasMask); } Func <UserLogin> loginDropBox = () => { var login = new DropBoxLogin(AuthorizationKeys.DropBox_Client_Id, AuthorizationKeys.DropBox_Client_Secret); if (_windowManager.ShowDialog(new LoginViewModel(login)).Value) { return(login.AccessToken); } return(null); }; if (AuthorizationKeys.DropBox_Client_Secret != null) { _profileDropBox = new DropBoxProfile(_events, AuthorizationKeys.DropBox_Client_Id, AuthorizationKeys.DropBox_Client_Secret, loginDropBox); } if (System.IO.File.Exists("gapi_client_secret.json")) { using (var gapi_secret_stream = System.IO.File.OpenRead("gapi_client_secret.json")) //For demo only. { _profileGoogleDrive = new GoogleDriveProfile(_events, gapi_secret_stream); } } string appDataPath = Environment.ExpandEnvironmentVariables("%AppData%\\FileExplorer3"); System.IO.Directory.CreateDirectory(appDataPath); string bookmarkPath = Path.Combine(appDataPath, "Bookmarks.xml"); _profileBm = new BookmarkProfile(_profileEx as IDiskProfile, bookmarkPath, new IProfile[] { _profileEx, _profileSkyDrive, _profileDropBox, _profileGoogleDrive }); RootModels.Add((_profileBm as BookmarkProfile).RootModel); RootModels.Add(AsyncUtils.RunSync(() => _profileEx.ParseAsync(System.IO.DirectoryInfoEx.DesktopDirectory.FullName))); _profiles = new IProfile[] { _profileBm, _profileEx, _profileSkyDrive, _profileDropBox, _profileGoogleDrive }.Where(p => p != null).ToArray(); }