public FolderViewModel(DirectoryInfo info, CShell.Workspace workspace)
 {
     directoryInfo = info;
     this.workspace = workspace;
     DisplayName = directoryInfo.Name;
     IsEditable = true;
 }
Example #2
0
        public async Task Test_Log()
        {
            CShell shell = new CShell();

            shell.cd(testFolder);
            var commandResult = await shell.Cmd("dir /b TestA.txt").Execute(true);
        }
Example #3
0
        public void Test_PushPopFolder()
        {
            Environment.CurrentDirectory = testFolder;

            CShell shell = new CShell();

            shell.PushFolder("subfolder");
            Assert.AreEqual(subFolder, Environment.CurrentDirectory, "CurrentDirectory should be changed");
            Assert.AreEqual(subFolder, shell.CurrentFolder.FullName, "path should be changed");
            Assert.AreEqual(subFolder, shell.FolderHistory.Last(), "history should be updated");
            Assert.AreEqual(2, shell.FolderHistory.Count(), "history should be two");
            Assert.AreEqual(1, shell.FolderStack.Count, "stack should be one");

            shell.PushFolder("subfolder2");
            Assert.AreEqual(subFolder2, Environment.CurrentDirectory, "CurrentDirectory should be changed");
            Assert.AreEqual(subFolder2, shell.CurrentFolder.FullName, "path should be changed");
            Assert.AreEqual(subFolder2, shell.FolderHistory.Last(), "history should be updated");
            Assert.AreEqual(3, shell.FolderHistory.Count(), "history should be three");
            Assert.AreEqual(2, shell.FolderStack.Count, "stack should be two");

            shell.PopFolder();
            Assert.AreEqual(subFolder, Environment.CurrentDirectory, "CurrentDirectory should be changed");
            Assert.AreEqual(1, shell.FolderStack.Count, "stack should be one");

            shell.PopFolder();
            Assert.AreEqual(testFolder, Environment.CurrentDirectory, "CurrentDirectory should be changed");
            Assert.AreEqual(0, shell.FolderStack.Count, "stack should be zero");

            try
            {
                shell.PopFolder();
                Assert.Fail("PopFolder() Should have thrown when empty");
            }
            catch (Exception) { }
        }
 public WorkspaceViewModel(CShell.Workspace workspace)
 {
     this.shell = shell;
     DisplayName = "Workspace Explorer";
     this.workspace = workspace;
     this.workspace.PropertyChanged += WorkspaceOnPropertyChanged;
 }
        public IReplExecutor Create(CShell.Framework.Services.IRepl repl, string workspaceDirectory)
        {
            if (scriptServices == null)
            {
                scriptServices = builder.Build(repl);
            }

            scriptServices.FileSystem.CurrentDirectory = workspaceDirectory;
            scriptServices.InstallationProvider.Initialize();

            var replExecutor = new ReplExecutor(
                repl,
                scriptServices.ObjectSerializer,
                scriptServices.FileSystem,
                scriptServices.FilePreProcessor,
                scriptServices.Engine,
                scriptServices.PackageInstaller,
                scriptServices.PackageAssemblyResolver,
                scriptServices.Logger);

            var assemblies = scriptServices.AssemblyResolver.GetAssemblyPaths(scriptServices.FileSystem.CurrentDirectory);
            var scriptPacks = scriptServices.ScriptPackResolver.GetPacks();

            replExecutor.Initialize(assemblies, scriptPacks);
            repl.Initialize(replExecutor);

            return replExecutor;
        }
Example #6
0
        public async Task Test_Bash()
        {
            CShell shell = new CShell();

            shell.cd(testFolder);
            var result = await shell.Bash("ls TestA.txt").AsString();

            Assert.AreEqual("TestA.txt", result.Trim(), "AsString");
        }
        public FolderRootViewModel(string path, CShell.Workspace workspace)
            : base(path, workspace)
        {
            DisplayName = directoryInfo.FullName;
            IsEditable = false;
            IsExpanded = true;

            Initialize();
        }
Example #8
0
        public async Task Test_AsXml()
        {
            CShell shell = new CShell();

            shell.cd(testFolder);

            var record = await shell.ReadFile("TestB.txt").AsXml <TestRecord>();

            Assert.AreEqual("Joe Smith", record.Name, "name is wrong");
            Assert.AreEqual(42, record.Age, "age is wrong");
        }
Example #9
0
        public void Test_CurrentDirectory()
        {
            Environment.CurrentDirectory = testFolder;

            CShell shell = new CShell();

            shell.cd(subFolder);
            Assert.AreEqual(subFolder, Environment.CurrentDirectory, "environment path not changed");
            Assert.AreEqual(subFolder, shell.CurrentFolder.FullName, "currentFolder not changed");
            Assert.AreEqual(subFolder, shell.FolderHistory[1], "history should be updated");
            Assert.AreEqual(testFolder, shell.FolderHistory[0], "history should be updated");
            Assert.AreEqual(2, shell.FolderHistory.Count(), "history should be two");
        }
Example #10
0
        public async Task Test_AsString()
        {
            CShell shell = new CShell();

            shell.cd(testFolder);

            var result = await shell.Run("cmd", "/c", "echo this is a yo yo").AsString();

            Assert.AreEqual("this is a yo yo", result.Trim(), "AsString");

            var record = await shell.ReadFile("TestA.txt").AsString();

            var text = File.ReadAllText(Path.Combine(testFolder, "TestA.Txt"));

            Assert.AreEqual(record, text, "AsString");
        }
Example #11
0
        public void Test_Createrd()
        {
            Environment.CurrentDirectory = testFolder;
            var    shell = new CShell();
            string xyz   = Path.Combine(testFolder, "xyz");

            if (Directory.Exists(xyz))
            {
                Directory.Delete(xyz);
            }

            shell.md("xyz");
            Assert.IsTrue(Directory.EnumerateDirectories(testFolder).Where(path => Path.GetFileName(path) == "xyz").Any(), "xyz not created");

            shell.rd("xyz");
            Assert.IsFalse(Directory.EnumerateDirectories(testFolder).Where(path => Path.GetFileName(path) == "xyz").Any(), "xyz not created");
        }
Example #12
0
        public void Test_ChangeFolder()
        {
            Environment.CurrentDirectory = testFolder;

            var shell = new CShell();

            shell.cd(@"subfolder\subfolder2");
            Assert.AreEqual(subFolder2, shell.CurrentFolder.FullName, "currentFolder relative path failed");
            shell.cd(@"..\subfolder2");
            Assert.AreEqual(subFolder2, shell.CurrentFolder.FullName, "currentFolder relative path failed2");
            Assert.AreEqual(2, shell.FolderHistory.Count, "relative non-navigation shouldn't have created history record");
            shell.cd(@"..\..");
            Assert.AreEqual(testFolder, shell.CurrentFolder.FullName, "currentFolder relative path failed3");
            Assert.AreEqual(3, shell.FolderHistory.Count, "history ignored on relative path");
            shell.cd(subFolder2);
            Assert.AreEqual(subFolder2, shell.CurrentFolder.FullName, "absolute path failed");
        }
Example #13
0
        public async Task Test_AsResult()
        {
            CShell shell = new CShell();

            shell.ThrowOnError = false;
            shell.cd(testFolder);

            var result = await shell.ReadFile("TestA.txt").AsResult();

            var text = File.ReadAllText(Path.Combine(testFolder, "TestA.Txt"));

            Assert.AreEqual(text, result.StandardOutput, "result stdout");
            Assert.AreEqual("", result.StandardError, "result stderr");


            var badResult = await shell.ReadFile("sdfsdffd.txt").AsResult();

            Assert.AreEqual("", badResult.StandardOutput, "result stdout");
            Assert.AreEqual("The system cannot find the file specified.", badResult.StandardError.Trim(), "result stderr");
        }
Example #14
0
        public async Task Test_AsJson()
        {
            CShell shell = new CShell();

            shell.cd(testFolder);

            var record = await shell.ReadFile("TestA.txt").AsJson <TestRecord>();

            Assert.AreEqual("Joe Smith", record.Name, "name is wrong");
            Assert.AreEqual(42, record.Age, "age is wrong");

            JObject record2 = (JObject)await shell.ReadFile("TestA.txt").AsJson();

            Assert.AreEqual("Joe Smith", (string)record2["name"], "JOBject name is wrong");
            Assert.AreEqual(42, (int)record2["age"], "JOBject age is wrong");

            dynamic record3 = await shell.ReadFile("TestA.txt").AsJson();

            Assert.AreEqual("Joe Smith", (string)record3.name, "dynamic name is wrong");
            Assert.AreEqual(42, (int)record3.age, "dynamic age is wrong");
        }
Example #15
0
        public void Test_MoveCopyFolder()
        {
            Environment.CurrentDirectory = testFolder;

            var shell = new CShell();

            shell.cd(testFolder);
            if (Directory.Exists(shell.ResolvePath("test2")))
            {
                shell.rd("test2", recursive: true);
            }

            shell.copy("subfolder", "test2");
            Assert.IsTrue(File.Exists(Path.Combine(testFolder, "test2", "TestC.txt")));
            Assert.IsTrue(File.Exists(Path.Combine(testFolder, "test2", "subfolder2", "TestE.txt")));
            shell.move("test2", "test3");
            Assert.IsTrue(!Directory.Exists("test2"));
            Assert.IsTrue(File.Exists(Path.Combine(testFolder, "test3", "TestC.txt")));
            Assert.IsTrue(File.Exists(Path.Combine(testFolder, "test3", "subfolder2", "TestE.txt")));

            shell.rd("test3", recursive: true);
        }
Example #16
0
        public void Test_move()
        {
            Environment.CurrentDirectory = testFolder;

            var shell = new CShell();

            shell.cd(testFolder);
            File.WriteAllText(Path.Combine(shell.CurrentFolder.FullName, "test.txt"), "test");

            shell.move("test.txt", subFolder);
            string path2 = Path.Combine(subFolder, "test.txt");

            Assert.IsTrue(File.Exists(path2));

            shell.cd(subFolder);
            shell.move("test.txt", Path.Combine("..", "test2.txt"));
            string path3 = Path.Combine(testFolder, "test2.txt");

            Assert.IsTrue(File.Exists(path3));

            File.Delete(Path.Combine(testFolder, "test2.txt"));
        }
Example #17
0
        public async Task Test_AsFile()
        {
            CShell shell = new CShell();

            shell.ThrowOnError = false;
            shell.cd(testFolder);

            var tmpOut = Path.GetTempFileName();
            var tmpErr = Path.GetTempFileName();

            var result = await shell.ReadFile("TestA.txt").AsFile(tmpOut);

            var stdout = File.ReadAllText(tmpOut);

            Assert.AreEqual(stdout, result.StandardOutput, "result stdout");

            var result2 = await shell.ReadFile("TestAsdfsdf.txt").AsFile(tmpOut, tmpErr);

            var stdout2 = File.ReadAllText(tmpOut);
            var stderr2 = File.ReadAllText(tmpErr);

            Assert.AreEqual(stdout2, result2.StandardOutput, "result stdout");
            Assert.AreEqual(stderr2, result2.StandardError, "result stderr");
        }
 public FolderPackagesViewModel(DirectoryInfo info, CShell.Workspace workspace)
     : base(info, workspace)
 {
 }
Example #19
0
 protected FolderViewModel(string path, CShell.Workspace workspace)
     : this(new DirectoryInfo(path),workspace)
 {
 }
Example #20
0
        public void RestoreWindowLocation(CShell.Workspace.WindowLocation location)
        {
            Execute.OnUIThread(() =>
            {
                Top = location.Top;
                Left = location.Left;
                Height = location.Height;
                Width = location.Width;
                WindowState windowState;
                if (WindowState.TryParse(location.State, out windowState))
                {
                    WindowState = windowState;
                }

                //TODO: this is not working yet with multiple screens
                //Size it to fit the current screen
                //SizeToFit();
                //Move the window at least partially into view
                //MoveIntoView();
            });
        }
Example #21
0
 public EditorViewModel(CShell.Workspace workspace)
 {
     this.workspace = workspace;
 }
 protected FolderPackagesViewModel(string path, CShell.Workspace workspace)
     : base(path, workspace)
 {
 }