コード例 #1
0
        static void Main(string[] args)
        {
            var screen = new ScreenConfig(8, 8);
            var debug  = new DebugConfig(updateTime: 0.15f, maxLogSize: 20);
            var config = ConfigurationLoader.Load(ArgumentSet.Parse(args));
            var root   = new CompositionRoot(
                screen,
                debug,
                config,
                () => new ReadConsoleReadInputSystem(),
                new Func <ISystem>[] {
                () => new ConsoleTriggerSystem(debug),
                () => new ConsoleClearSystem(),
                () => new ConsoleRenderSystem(screen),
                () => new ConsoleLogSystem()
            },
                () => new FinishFrameRealTimeSystem(),
                () => new DeviceRenderSystem(screen, new DeviceRenderConfig(172)));

            var(entities, systems) = root.Create();
            systems.Init(entities);
            systems.UpdateLoop(entities);
            Console.WriteLine($"Your score is: {entities.GetFirstComponent<ScoreState>()?.TotalScore}");
            Console.WriteLine($"Time: {entities.GetFirstComponent<TimeState>().UnscaledTotalTime:0.00}");
            if (config.IsReplayRecord)
            {
                var replay = entities.GetFirstComponent <InputRecordState>();
                replay.Save(config.NewReplayPath);
            }
        }
コード例 #2
0
        public void GetByName_should_throw_KeyNotFoundException_if_name_doesnt_exist()
        {
            //  arrange
            var         args = new[] { "blah" };
            ArgumentSet set  = ArgumentSet.Parse(args);

            //  act
            Assert.Throws <KeyNotFoundException>(() => set.GetByName("help"));
        }
コード例 #3
0
        public void Parse_should_match_dash_names()
        {
            //  arrange
            var args = new[] { "-help", "migrate" };

            //  act
            ArgumentSet set = ArgumentSet.Parse(args);

            //  assert
            Assert.IsTrue(set.ContainsName("help"));
        }
コード例 #4
0
        public void Parse_should_validate_properties()
        {
            //  arrange
            ArgumentSet args = ArgumentSet.Parse(new[] { "-v", "1" });
            var         opts = new MockCommandArgs();

            //  act
            opts.Parse(args);

            //  assert
            Assert.IsFalse(opts.IsValid);
        }
コード例 #5
0
        public void Validation_should_succeed_if_MigrationName_has_value()
        {
            //  arrange
            var argSet = ArgumentSet.Parse(new string[] { "-n", "my_migration_name" });
            var args   = new GenerateScriptCommandArgs();

            //  act
            args.Parse(argSet);

            //  assert
            Assert.IsTrue(args.IsValid);
        }
コード例 #6
0
        public void ContainsName_should_return_true_if_name_exists()
        {
            //  arrange
            var         args = new[] { "-help", "migrate" };
            ArgumentSet set  = ArgumentSet.Parse(args);

            //  act
            bool exists = set.ContainsName("help");

            //  assert
            Assert.IsTrue(exists);
        }
コード例 #7
0
        public void ContainsName_should_be_case_insensitive()
        {
            //  arrange
            var         args = new[] { "-HELP", "migrate" };
            ArgumentSet set  = ArgumentSet.Parse(args);

            //  act
            bool exists = set.ContainsName("help");

            //  assert
            Assert.IsTrue(exists);
        }
コード例 #8
0
        public void Validation_should_succeed_if_Connection_has_value()
        {
            //  arrange
            var argSet = ArgumentSet.Parse(new string[] { "-c", "my_connection" });
            var args   = new DatabaseCommandArguments();

            //  act
            args.Parse(argSet);

            //  assert
            Assert.IsTrue(args.IsValid);
        }
コード例 #9
0
        public void Parse_should_set_property_values_to_matching_named_arguments()
        {
            //  arrange
            ArgumentSet args = ArgumentSet.Parse(new[] { "-connection", "joshua", "-v", "123" });
            var         opts = new MockCommandArgs();

            //  act
            opts.Parse(args);

            //  assert
            Assert.AreEqual("joshua", opts.Connection);
            Assert.AreEqual(123, opts.TargetVersion);
        }
コード例 #10
0
        public void Parse_should_match_multiple_named_arguments_and_values()
        {
            //  arrange
            var args = new[] { "-help", "migrate", "-c", "connection" };

            //  act
            ArgumentSet set = ArgumentSet.Parse(args);

            //  assert
            Assert.AreEqual(2, set.NamedArgs.Count());
            Assert.AreEqual("migrate", set.GetByName("help"));
            Assert.AreEqual("connection", set.GetByName("c"));
        }
コード例 #11
0
        public void Parse_should_find_named_arguments_with_no_value()
        {
            //  arrange
            var args = new[] { "-help", "-me" };

            //  act
            ArgumentSet set = ArgumentSet.Parse(args);

            //  assert
            Assert.AreEqual(2, set.NamedArgs.Count());
            Assert.AreEqual(null, set.GetByName("help"));
            Assert.AreEqual(null, set.GetByName("me"));
        }
コード例 #12
0
        public void Parse_should_set_property_values_by_position_of_anonymous_arguments()
        {
            //  arrange
            ArgumentSet args = ArgumentSet.Parse(new[] { "joshua", "2" });
            var         opts = new MockCommandArgs();

            //  act
            opts.Parse(args);

            //  assert
            Assert.AreEqual("joshua", opts.Connection);
            Assert.AreEqual(2, opts.TargetVersion);
        }
コード例 #13
0
        public void Validation_should_fail_if_Connection_is_null_or_empty()
        {
            //  arrange
            var argSet = ArgumentSet.Parse(new string[] { string.Empty });
            var args   = new DatabaseCommandArguments();

            //  act
            args.Parse(argSet);

            //  assert
            Assert.IsFalse(args.IsValid);
            Assert.AreEqual(1, args.Errors.Count());
        }
コード例 #14
0
        public void Parse_should_override_anonymous_arguments_with_named_arguments()
        {
            //  arrange
            ArgumentSet args = ArgumentSet.Parse(new[] { "joshua", "2", "-connection", "david", "-v", "123" });
            var         opts = new MockCommandArgs();

            //  act
            opts.Parse(args);

            //  assert
            Assert.AreEqual("david", opts.Connection);
            Assert.AreEqual(123, opts.TargetVersion);
        }
コード例 #15
0
        public void Validation_should_fail_if_MigrationName_is_null_or_empty()
        {
            //  arrange
            var argSet = ArgumentSet.Parse(new string[] { string.Empty });
            var args   = new GenerateScriptCommandArgs();

            //  act
            args.Parse(argSet);

            //  assert
            Assert.IsFalse(args.IsValid);
            Assert.AreEqual(1, args.Errors.Count());
        }
コード例 #16
0
        public void Parse_should_validate_arguments_and_add_error_messages_to_collection()
        {
            //  arrange
            ArgumentSet args = ArgumentSet.Parse(new[] { "-v", "0" });
            var         opts = new MockCommandArgs();

            //  act
            opts.Parse(args);

            //  assert
            Assert.AreEqual(2, opts.Errors.Count());
            Assert.AreEqual("Connection is required", opts.Errors.First());
            Assert.AreEqual("Target version must be between 1 and 5", opts.Errors.Last());
        }
コード例 #17
0
        public void GetByName_should_return_value_of_argument_with_given_name()
        {
            //  arrange
            var         args = new[] { "-help", "migrate" };
            ArgumentSet set  = ArgumentSet.Parse(args);

            //  act
            string value = set.GetByName("help");

            //  assert
            const string expectedValue = "migrate";

            Assert.AreEqual(expectedValue, value);
        }
コード例 #18
0
        public void Parse_should_find_anonymous_arguments_between_named_arguments()
        {
            //  arrange
            var args = new[] { "-help", "migrate", "joshua", "david", "-c", "connection" };

            //  act
            ArgumentSet set = ArgumentSet.Parse(args);

            //  assert
            Assert.AreEqual(2, set.NamedArgs.Count());
            Assert.AreEqual(2, set.AnonymousArgs.Count());
            Assert.AreEqual("joshua", set.AnonymousArgs.First());
            Assert.AreEqual("david", set.AnonymousArgs.Skip(1).First());
        }
コード例 #19
0
        public void Run_should_throw_InvalidOperationException_if_args_are_not_valid()
        {
            //  arrange
            var cmd = new MockCommand1();

            cmd.Log = new MockLog1();
            ArgumentSet argSet = ArgumentSet.Parse(new[] { "blah" });
            var         args   = new MockCommandArgs();

            args.Parse(argSet);

            //  act
            var ex = Assert.Throws <InvalidOperationException>(() => cmd.Run(args));

            Assert.AreEqual("Argument validation failed. Arguments are invalid.", ex.Message);
        }
コード例 #20
0
 public void Parse_should_throw_ArgumentNullException_if_args_param_is_null()
 {
     //  act
     Assert.Throws <ArgumentNullException>(() => ArgumentSet.Parse(null));
 }
コード例 #21
0
        static async Task StartMain(string[] args)
        {
            var @params = new ArgumentSet();

            @params.AddLinkedFlags("f:p", "format-plain");

            @params.AddOption("d:package", "packages/");
            @params.AddOption("d:install", "tools/");
            @params.AddOption("d:build", null);
            @params.AddOption("version", "*");
            @params.AddOption("repo", "*");

            @params.Parse(args);

            var repo = new MasterRepository();

            MasterRepository.Register(new GnuRepository());


            if ("list".Equals(@params[0], StringComparison.CurrentCultureIgnoreCase))
            {
                IEnumerable <Object> output;

                if ("packages".Equals(@params[1], StringComparison.CurrentCultureIgnoreCase))
                {
                    if (!String.IsNullOrWhiteSpace(@params[2]))
                    {
                        output = await repo.QueryPackages(@params[2]);
                    }
                    else
                    {
                        output = await repo.QueryPackages();
                    }
                }
                else if ("products".Equals(@params[1], StringComparison.CurrentCultureIgnoreCase))
                {
                    output = await repo.QueryProducts();
                }
                else if ("installed".Equals(@params[1], StringComparison.CurrentCultureIgnoreCase))
                {
                    throw new NotImplementedException();
                }
                else
                {
                    Console.WriteLine("[ERROR] Unknown command");
                    throw new Exception();
                }

                if ([email protected]("f:p"))
                {
                    Console.WriteLine("\n{0}:", @params[1]);
                    foreach (Object obj in output)
                    {
                        Console.WriteLine(" - " + obj.ToString());
                    }
                }
                else
                {
                    foreach (Object obj in output)
                    {
                        Console.WriteLine(obj.ToString());
                    }
                }
            }
            else if ("download".Equals(@params[0], StringComparison.CurrentCultureIgnoreCase))
            {
            }


            /*Package lastestBinutils = (from pkg in await repo.QueryPackages("binutils")
             *                     orderby pkg.Version select pkg).FirstOrDefault();
             *
             * var installer = new Installers.BinutilsInstaller();
             *
             * await Task.WhenAll(installer.InstallPackage(lastestBinutils, @params));*/

            using (Archive arch = new Archive(@"J:\Users\James\Downloads\binutils-2.24.tar.gz"))
            {
                arch.ExtractToDirectory(Directory.CreateDirectory("test").FullName);
            }
        }
コード例 #22
0
ファイル: Program.cs プロジェクト: eway-crm/dotnetmigrations
        /// <summary>
        /// Primary Program Execution
        /// </summary>
        private void Run(string[] args)
        {
            string      executableName = Process.GetCurrentProcess().ProcessName + ".exe";
            ArgumentSet allArguments   = ArgumentSet.Parse(args);

            var helpWriter = new CommandHelpWriter(_logger);

            bool showHelp = allArguments.ContainsName("help");

            string commandName = showHelp
                                     ? allArguments.GetByName("help")
                                     : allArguments.AnonymousArgs.FirstOrDefault();

            ICommand command = null;

            if (commandName != null)
            {
                command = _commandRepo.GetCommand(commandName);
            }

            if (command == null)
            {
                if (showHelp)
                {
                    //  no command name was found, show the list of available commands
                    WriteAppUsageHelp(executableName);
                    helpWriter.WriteCommandList(_commandRepo.Commands);
                }
                else
                {
                    //  invalid command name was given
                    _logger.WriteError("'{0}' is not a DotNetMigrations command.", commandName);
                    _logger.WriteLine(string.Empty);
                    _logger.WriteError("See '{0} -help' for a list of available commands.", executableName);
                }
            }

            if (showHelp && command != null)
            {
                //  show help for the given command
                helpWriter.WriteCommandHelp(command, executableName);
            }
            else if (command != null)
            {
                command.Log = _logger;

                var        commandArgumentSet = ArgumentSet.Parse(args.Skip(1).ToArray());
                IArguments commandArgs        = command.CreateArguments();
                commandArgs.Parse(commandArgumentSet);

                if (commandArgs.IsValid)
                {
                    var timer = new Stopwatch();
                    timer.Start();

                    try
                    {
                        command.Run(commandArgs);
                    }
                    catch (Exception ex)
                    {
                        //_logger.WriteLine(string.Empty);

                        if (_logFullErrors)
                        {
                            _logger.WriteError(ex.ToString());
                        }
                        else
                        {
                            WriteShortErrorMessages(ex);
                        }

                        if (Debugger.IsAttached)
                        {
                            throw;
                        }
                    }
                    finally
                    {
                        timer.Stop();

                        _logger.WriteLine(string.Empty);
                        _logger.WriteLine(string.Format("Command duration was {0}.",
                                                        decimal.Divide(timer.ElapsedMilliseconds, 1000).ToString(
                                                            "0.0000s")));
                    }
                }
                else
                {
                    //  argument validation failed, show errors
                    WriteValidationErrors(command.CommandName, commandArgs.Errors);
                    _logger.WriteLine(string.Empty);
                    helpWriter.WriteCommandHelp(command, executableName);
                }
            }

            if (_keepConsoleOpen)
            {
                Console.WriteLine();
                Console.WriteLine("  > Uh-oh. It looks like you didn't run me from a console.");
                Console.WriteLine("  > Did you double-click me?");
                Console.WriteLine("  > I don't like to be clicked.");
                Console.WriteLine("  > Please open a command prompt and run me by typing " + executableName + ".");
                Console.WriteLine();
                Console.WriteLine("Press any key to exit...");
                Console.Read();
            }
        }