Exemplo n.º 1
0
        public void Execute(ISession session)
        {
            using (var sanityCheck = new SanityCheck()) {
                sanityCheck.Config = Config;
                sanityCheck.InitDb();
            }

            var result = Files.GroupBy(f => f.ArchiveFileName.Replace(".meta", ""))
                         .Where(g => g.Count() > 1)
                         .Select(g => Tuple.Create(
                                     g.First(f => f.ArchiveFileName.IndexOf(".meta.") == -1).LocalFileName,
                                     g.First(f => f.ArchiveFileName.IndexOf(".meta.") >= 0)
                                     .ReadContent()
                                     .Split(new[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries)))
                         .ToList();

            using (var importer = new ImportCommand(result)) {
                importer.Config = Config;
                importer.InitSession();
                importer.Execute();
            }

            var settings = session.Query <Settings>().First();

            settings.UserName   = "******";
            settings.Password   = "******";
            settings.LastUpdate = DateTime.Now;
            session.Save(settings);
        }
Exemplo n.º 2
0
        public void ExecuteImportCommand()
        {
            ImportCommand importcmd = new ImportCommand("setvar");

            Machine machine = new Machine();

            importcmd.Execute(machine.Environment);

            object setvar = machine.Environment.GetValue("setvar");

            Assert.IsNotNull(setvar);
            Assert.IsInstanceOfType(setvar, typeof(IValues));

            IValues setvarenv = (IValues)setvar;

            object var = setvarenv.GetValue("a");

            Assert.IsNotNull(var);
            Assert.AreEqual(1, var);

            object doc = setvarenv.GetValue("__doc__");

            Assert.IsNotNull(doc);
            Assert.AreEqual("setvar module", doc);
        }
        public void ConfigImport_Execute_ReturnsSuccess()
        {
            var content = new Dictionary <string, string>
            {
                { "config1", "config 1 value edited" },
                { "config2", "config 2 value" }
            };

            var filePath = Path.Combine(AppContext.BaseDirectory, "exists.json");

            if (!File.Exists(filePath))
            {
                File.WriteAllText(filePath, JsonConvert.SerializeObject(content));
            }

            var console = new TestConsole(_output);
            var command = new ImportCommand(_engineConfig.Object, console, (new Mock <ILogger <ImportCommand> >()).Object)
            {
                InputFile = filePath
            };

            var message = command.Execute();

            var sb = new StringBuilder("Configs have been imported.");

            sb.AppendLine("- Modified:");
            sb.AppendLine("  - config1: config 1 value edited");
            sb.AppendLine("- Added:");
            sb.AppendLine("  - config2: config 2 value");

            Assert.Equal(sb.ToString(), message);
        }
Exemplo n.º 4
0
 private void OnImportClick(CommandBarButton Ctrl, ref bool CancelDefault)
 {
     using (var command = new ImportCommand(base.IDE))
     {
         command.Execute();
     }
 }
Exemplo n.º 5
0
        public void ImportModuleWithEmptyDocString()
        {
            ImportCommand importcmd = new ImportCommand("setvars");

            Machine machine = new Machine();

            importcmd.Execute(machine.Environment);

            var setvar = (IValues)machine.Environment.GetValue("setvars");

            Assert.IsNull(setvar.GetValue("__doc__"));
            Assert.IsTrue(setvar.HasValue("__doc__"));
        }
Exemplo n.º 6
0
        static IEnumerable <T> Import <T>(string filePath) where T : new()
        {
            var csvLines = File.ReadAllLines(filePath);
            var importSchemaValidatorCommand = new ValidateNameSpaceCommand <T>(csvLines.First());

            if (importSchemaValidatorCommand.Execute() == false)
            {
                Console.WriteLine($"Schema validation failed for {(new T()).GetType()} and {filePath}");
                return(new List <T>());
            }

            var importCommand = new ImportCommand <T>(csvLines.Skip(1));

            return(importCommand.Execute());
        }
Exemplo n.º 7
0
        private void OnKeyDown(object sender, KeyEventArgs e)
        {
            switch (e.Key)
            {
            case Key.Enter when Keyboard.Modifiers.HasFlag(ModifierKeys.Control):
                ImportCommand.Execute(null);

                e.Handled = true;
                break;

            case Key.Escape:
                CancelCommand.Execute(null);
                e.Handled = true;
                break;
            }
        }
Exemplo n.º 8
0
        public void RaiseWhenImportModuleDoesNotExist()
        {
            ImportCommand importcmd = new ImportCommand("spam");

            Machine machine = new Machine();

            try
            {
                importcmd.Execute(machine.Environment);
                Assert.Fail("Exception expected");
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOfType(ex, typeof(ImportError));
                Assert.AreEqual("No module named spam", ex.Message);
            }
        }
        public void ConfigImport_Execute_ReturnsNotFound()
        {
            var filePath = Path.Combine(AppContext.BaseDirectory, "notexist.json");

            if (File.Exists(filePath))
            {
                File.Delete(filePath);
            }

            var console = new TestConsole(_output);
            var command = new ImportCommand(_engineConfig.Object, console, (new Mock <ILogger <ImportCommand> >()).Object)
            {
                InputFile = filePath
            };

            var message = command.Execute();

            Assert.Equal($"File \"{filePath}\" could not be found.", message);
        }
Exemplo n.º 10
0
        public void ExecuteImportCommand()
        {
            ImportCommand importcmd = new ImportCommand("setvar");

            Machine machine = new Machine();

            importcmd.Execute(machine, machine.Environment);

            object setvar = machine.Environment.GetValue("setvar");

            Assert.IsNotNull(setvar);
            Assert.IsInstanceOfType(setvar, typeof(BindingEnvironment));

            BindingEnvironment setvarenv = (BindingEnvironment)setvar;

            object var = setvarenv.GetValue("a");

            Assert.IsNotNull(var);
            Assert.AreEqual(1, var);
        }
Exemplo n.º 11
0
        public void ImportSystemIONamespace()
        {
            ImportCommand importcmd = new ImportCommand("System.IO");

            Machine machine = new Machine();

            importcmd.Execute(machine.Environment);

            var result = machine.Environment.GetValue("System");

            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(Module));

            var ioresult = ((Module)result).GetValue("IO");

            Assert.IsNotNull(ioresult);
            Assert.IsInstanceOfType(ioresult, typeof(Module));

            var module = (Module)ioresult;

            Assert.IsNotNull(module.GetValue("FileInfo"));
            Assert.IsNotNull(module.GetValue("Directory"));
            Assert.IsNotNull(module.GetValue("DirectoryInfo"));
        }
Exemplo n.º 12
0
        public void HappyIntegration()
        {
            _command.ReadCompletedImports = () => new Dictionary <string, SyncEntity>()
            {
                { "123.Collection.Insert.json", new SyncEntity()
                  {
                      Imported = DateTime.Now
                  } }
            };
            _command.ReadFiles = (filter) => new FileInfo[] { new FileInfo("123.Collection.Insert.json"), new FileInfo("234.Collection.Insert.json"), new FileInfo("123.Collection.drop.json"),
                                                              new FileInfo("345.Collection.eval.js") };
            _command.Validate();
            _command.Execute();

            _mongoDatabaseMock.Verify();
            string fullLog = _consoleLog.ToString();

            // Error message not found
            Assert.True(fullLog.IndexOf("Error") < 0);

            /*
             * Found 2 files to import
             * Importing 123.Collection.drop.json to collection Collection, mode Drop
             * Dropping collection Collection
             * Collection Collection dropped
             * Importing 234.Collection.Insert.json to collection Collection, mode Insert
             * Import completed successfully
             */

            Assert.Contains("Found 4 files to import", fullLog);
            Assert.Contains("Skipping 123.Collection.Insert.json", fullLog);
            Assert.Contains("Dropping collection Collection", fullLog);
            Assert.Contains("Importing 234.Collection.Insert.json to collection Collection, mode Insert", fullLog);
            Assert.Contains("Importing 345.Collection.eval.js to collection Collection, mode Eval", fullLog);
            Assert.Contains("successfully", fullLog);
        }
Exemplo n.º 13
0
        public void Import(string path)
        {
            ImportCommand cmd = new ImportCommand(MainWindow, path);

            cmd.Execute();
        }
Exemplo n.º 14
0
		public void Import (string path) 
		{
			ImportCommand cmd = new ImportCommand (MainWindow, path);
			cmd.Execute ();
		}