public void WaitsOrNot()
        {
            CommandLineProcessor p = new CommandLineProcessor();
            // File isn't used; just a dummy.
            FileInfo file = GetTestFile("BasicTextFile.txt");

            // ping command waits 1s between pings, so telling it to ping 3 times
            // guarantees the command will take at least 2s to run.  This is all
            // because there's no sleep command and this is what folks on
            // StackOverflow recommend.
            p.SetParameter("CommandLine", "ping -n 3 127.0.0.1");
            p.Init(RunInfo);
            Stopwatch sw = new Stopwatch();

            // Wait for this run to finish...
            p.SetParameter("WaitForTaskToFinish", true);
            sw.Start();
            ProcessingResult result = p.Process(file, MatchResultType.Yes, new string[0], new FileInfo[0],
                                                ProcessInput.OriginalFile, CancellationToken.None);

            sw.Stop();
            Assert.IsTrue(sw.ElapsedMilliseconds >= 2000);
            Assert.AreEqual(ProcessingResultType.Success, result.Type);
            // Don't wait for this run to finish...
            p.SetParameter("WaitForTaskToFinish", false);
            sw.Restart();
            result = p.Process(file, MatchResultType.Yes, new string[0], new FileInfo[0],
                               ProcessInput.OriginalFile, CancellationToken.None);
            sw.Stop();
            // Should have gotten started in less than a second, right?
            Assert.IsTrue(sw.ElapsedMilliseconds < 1000);
            Assert.AreEqual(ProcessingResultType.Success, result.Type);
            p.Cleanup();
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            var host = new ConsoleHost();
            host.WriteMessage("NSwag command line: v" + typeof(SwaggerInfo).Assembly.GetName().Version + "\n");
            host.WriteMessage("Visit http://NSwag.org for more information.\n");
            host.WriteMessage("Execute the 'help' command to show a list of all the available commands.\n");

            try
            {
                var processor = new CommandLineProcessor(host);

                processor.RegisterCommand<WebApiToSwaggerCommand>("webapi2swagger");

                processor.RegisterCommand<JsonSchemaToCSharpCommand>("jsonschema2csharp");
                processor.RegisterCommand<JsonSchemaToTypeScriptCommand>("jsonschema2typescript");
                
                processor.RegisterCommand<SwaggerToCSharpCommand>("swagger2csharp");
                processor.RegisterCommand<SwaggerToTypeScriptCommand>("swagger2typescript");

                processor.Process(args);
            }
            catch (Exception exception)
            {
                var savedForegroundColor = Console.ForegroundColor; 
                Console.ForegroundColor = ConsoleColor.Red;
                host.WriteMessage(exception.ToString());
                Console.ForegroundColor = savedForegroundColor;
            }

            if (Debugger.IsAttached)
            {
                Console.WriteLine("Press <any> key to exit...");
                Console.ReadKey();
            }
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            var host = new ConsoleHost();
            host.WriteMessage("NSwag command line: v" + typeof(SwaggerInfo).Assembly.GetName().Version + "\n");
            host.WriteMessage("Visit http://NSwag.org for more information.");
            host.WriteMessage("\n");

            try
            {
                var processor = new CommandLineProcessor(host);

                processor.RegisterCommand<CSharpCommand>("csharp");
                processor.RegisterCommand<TypeScriptCommand>("typescript");

                processor.Process(args);
            }
            catch (Exception exception)
            {
                var savedForegroundColor = System.Console.ForegroundColor;
                System.Console.ForegroundColor = ConsoleColor.Red;
                host.WriteMessage(exception.ToString());
                System.Console.ForegroundColor = savedForegroundColor;
            }

            if (Debugger.IsAttached)
                System.Console.ReadKey();
        }
Esempio n. 4
0
        static void Main(string[] args)
        {
            var stopwatch = Stopwatch.StartNew();

            var assembly = Assembly.GetEntryAssembly();

            ConsoleUtilities.Write("DNT (DotNetTools, https://github.com/RSuter/DNT, v" + assembly.GetName().Version + ")\n");
            ConsoleUtilities.Write("Binary: " + assembly.Location + "\n\n");
            try
            {
                // MSBuildLocator takes care of finding the default MSBuild / Visual Studio instance
                // and setting up all necessary environment variables and paths for MSBuild.
                MSBuildLocator.RegisterDefaults();

                var processor = new CommandLineProcessor(new CoreConsoleHost());
                processor.RegisterCommandsFromAssembly(typeof(CommandBase).Assembly);
                processor.Process(args);
            }
            catch (Exception e)
            {
                ConsoleUtilities.WriteError(e.ToString());
            }
            ConsoleUtilities.WriteColor("\nElapsed time: " + stopwatch.Elapsed, ConsoleColor.DarkCyan);

            if (Debugger.IsAttached)
            {
                Console.ReadLine();
            }
        }
Esempio n. 5
0
        static void Main(string[] args)
        {
            if (Debugger.IsAttached)
            {
                Directory.SetCurrentDirectory("C:\\Data\\Projects\\Playground");
            }

            var stopwatch = Stopwatch.StartNew();

            var assembly = Assembly.GetEntryAssembly();

            ConsoleUtilities.Write("DNT (DotNetTools, https://github.com/RSuter/DNT, v" + assembly.GetName().Version + ")\n");
            ConsoleUtilities.Write("Binary: " + assembly.Location + "\n\n");
            try
            {
                SetMsBuildExePath();

                var processor = new CommandLineProcessor(new CoreConsoleHost());
                processor.RegisterCommandsFromAssembly(typeof(CommandBase).Assembly);
                processor.Process(args);
            }
            catch (Exception e)
            {
                ConsoleUtilities.WriteError(e.ToString());
            }
            ConsoleUtilities.WriteColor("\nElapsed time: " + stopwatch.Elapsed, ConsoleColor.DarkCyan);

            if (Debugger.IsAttached)
            {
                Console.ReadLine();
            }
        }
Esempio n. 6
0
        static int Main(string[] args)
        {
            var host = new ConsoleHost();

            host.WriteMessage("NSwag command line: NSwag toolchain v" + SwaggerService.ToolchainVersion + " (NJsonSchema v" + JsonSchema4.ToolchainVersion + ")\n");
            host.WriteMessage("Visit http://NSwag.org for more information.\n");

            if (args.Length == 0)
            {
                host.WriteMessage("Execute the 'help' command to show a list of all the available commands.\n");
            }

            try
            {
                var processor = new CommandLineProcessor(host);

                processor.RegisterCommand <NSwagDocumentCommand>("run");

                processor.RegisterCommand <AssemblyTypeToSwaggerCommand>("types2swagger");
                processor.RegisterCommand <WebApiToSwaggerCommand>("webapi2swagger");

                processor.RegisterCommand <JsonSchemaToCSharpCommand>("jsonschema2csclient");
                processor.RegisterCommand <JsonSchemaToTypeScriptCommand>("jsonschema2tsclient");

                processor.RegisterCommand <SwaggerToCSharpClientCommand>("swagger2csclient");
                processor.RegisterCommand <SwaggerToCSharpControllerCommand>("swagger2cscontroller");
                processor.RegisterCommand <SwaggerToTypeScriptClientCommand>("swagger2tsclient");

                var stopwatch = new Stopwatch();
                stopwatch.Start();
                var results = processor.Process(args);
                stopwatch.Stop();

                var output  = results.Last()?.Output;
                var service = output as SwaggerService;
                if (service != null)
                {
                    host.WriteMessage(service.ToJson());
                }
                else if (output != null)
                {
                    host.WriteMessage(output.ToString());
                }

                host.WriteMessage("\nDuration: " + stopwatch.Elapsed);
            }
            catch (Exception exception)
            {
                var savedForegroundColor = Console.ForegroundColor;
                Console.ForegroundColor = ConsoleColor.Red;
                host.WriteMessage(exception.ToString());
                Console.ForegroundColor = savedForegroundColor;

                WaitWhenDebuggerAttached();
                return(-1);
            }

            WaitWhenDebuggerAttached();
            return(0);
        }
Esempio n. 7
0
 static void Main(string[] args)
 {
     var processor = new CommandLineProcessor(new ConsoleHost());
     processor.RegisterCommand<CloneCommand>("clone");
     processor.Process(args);
     Console.ReadKey();
 }
Esempio n. 8
0
        /// <summary>Processes the command line arguments.</summary>
        /// <param name="args">The arguments.</param>
        /// <returns>The result.</returns>
        public int Process(string[] args)
        {
            _host.WriteMessage("toolchain v" + SwaggerDocument.ToolchainVersion +
                               " (NJsonSchema v" + JsonSchema4.ToolchainVersion + ")\n");
            _host.WriteMessage("Visit http://NSwag.org for more information.\n");

            WriteBinDirectory();

            if (args.Length == 0)
            {
                _host.WriteMessage("Execute the 'help' command to show a list of all the available commands.\n");
            }

            try
            {
                var processor = new CommandLineProcessor(_host);

                processor.RegisterCommandsFromAssembly(typeof(SwaggerToCSharpControllerCommand).GetTypeInfo().Assembly);

                var stopwatch = new Stopwatch();
                stopwatch.Start();
                processor.Process(args);
                stopwatch.Stop();

                _host.WriteMessage("\nDuration: " + stopwatch.Elapsed + "\n");
            }
            catch (Exception exception)
            {
                _host.WriteError(exception.ToString());
                return(-1);
            }

            WaitWhenDebuggerAttached();
            return(0);
        }
Esempio n. 9
0
        static void Main(string[] args)
        {
            var host = new ConsoleHost();

            host.WriteMessage("NSwag command line: v" + typeof(SwaggerInfo).Assembly.GetName().Version + "\n");
            host.WriteMessage("Visit http://NSwag.org for more information.\n");

            if (args.Length == 0)
            {
                host.WriteMessage("Execute the 'help' command to show a list of all the available commands.\n");
            }

            try
            {
                var processor = new CommandLineProcessor(host);

                processor.RegisterCommand <AssemblyTypeToSwaggerCommand>("types2swagger");
                processor.RegisterCommand <WebApiToSwaggerCommand>("webapi2swagger");

                processor.RegisterCommand <JsonSchemaToCSharpCommand>("jsonschema2csclient");
                processor.RegisterCommand <JsonSchemaToTypeScriptCommand>("jsonschema2tsclient");

                processor.RegisterCommand <SwaggerToCSharpClientCommand>("swagger2csclient");
                processor.RegisterCommand <SwaggerToCSharpControllerCommand>("swagger2cscontroller");
                processor.RegisterCommand <SwaggerToTypeScriptClientCommand>("swagger2tsclient");

                var stopwatch = new Stopwatch();
                stopwatch.Start();
                var results = processor.Process(args);
                stopwatch.Stop();

                var output  = results.Last()?.Output;
                var service = output as SwaggerService;
                if (service != null)
                {
                    host.WriteMessage(service.ToJson());
                }
                else if (output != null)
                {
                    host.WriteMessage(output.ToString());
                }

                host.WriteMessage("\nDuration: " + stopwatch.Elapsed);
            }
            catch (Exception exception)
            {
                var savedForegroundColor = Console.ForegroundColor;
                Console.ForegroundColor = ConsoleColor.Red;
                host.WriteMessage(exception.ToString());
                Console.ForegroundColor = savedForegroundColor;
            }

            if (Debugger.IsAttached)
            {
                Console.WriteLine("Press <any> key to exit...");
                Console.ReadKey();
            }
        }
Esempio n. 10
0
        //LiteDB connection
        //static LiteDatabase db = new LiteDatabase(@"Users.db");
        static void Main(string[] args)
        {
            var processor = new CommandLineProcessor(new ConsoleHost(!args.Contains("/noninteractive")));

            //var processor = new CommandLineProcessor(new ConsoleHost());
            processor.RegisterCommand <InsertCommand>("insert");
            processor.RegisterCommand <ListCommand>("list");
            processor.Process(args);
            //Console.ReadKey();
        }
        public void When_first_argument_is_existing_command_name_then_command_is_executed()
        {
            //// Arrange
            var resolver = new MyDependencyResolver(); 
            var processor = new CommandLineProcessor(new ConsoleHost(), resolver);
            processor.RegisterCommand<MyCommand>("test");

            //// Act
            var command = (MyCommand)processor.Process(new string[] { "test" });

            //// Assert
            Assert.IsNotNull(command);
        }
Esempio n. 12
0
        /// <summary>Processes the command line arguments.</summary>
        /// <param name="args">The arguments.</param>
        /// <returns>The result.</returns>
        public int Process(string[] args)
        {
            var architecture = IntPtr.Size == 4 ? " (x86)" : " (x64)";

            _host.WriteMessage("toolchain v" + SwaggerDocument.ToolchainVersion + " (NJsonSchema v" + JsonSchema4.ToolchainVersion + ")" + architecture + "\n");
            _host.WriteMessage("Visit http://NSwag.org for more information.\n");

            var binDirectory = DynamicApis.PathGetDirectoryName(((dynamic)typeof(NSwagCommandProcessor).GetTypeInfo().Assembly).CodeBase.Replace("file:///", string.Empty));

            _host.WriteMessage("NSwag bin directory: " + binDirectory + "\n");

            if (args.Length == 0)
            {
                _host.WriteMessage("Execute the 'help' command to show a list of all the available commands.\n");
            }

            try
            {
                var processor = new CommandLineProcessor(_host);

                processor.RegisterCommandsFromAssembly(_assemblyLoaderAssembly);
                processor.RegisterCommandsFromAssembly(typeof(SwaggerToCSharpControllerCommand).GetTypeInfo().Assembly);

                var stopwatch = new Stopwatch();
                stopwatch.Start();
                var results = processor.Process(args);
                stopwatch.Stop();

                var output   = results.Last()?.Output;
                var document = output as SwaggerDocument;
                if (document != null)
                {
                    _host.WriteMessage(document.ToJson());
                }
                else if (output != null)
                {
                    _host.WriteMessage(output.ToString());
                }

                _host.WriteMessage("\nDuration: " + stopwatch.Elapsed);
            }
            catch (Exception exception)
            {
                _host.WriteError(exception.ToString());
                return(-1);
            }

            WaitWhenDebuggerAttached();
            return(0);
        }
Esempio n. 13
0
        public void When_no_dependency_resolver_is_present_static_ctor_is_not_used()
        {
            //// Arrange
            var processor = new CommandLineProcessor(new ConsoleHost());

            processor.RegisterCommand <CommandWithStaticCtor>("test");

            //// Act
            var result  = processor.Process(new[] { "test" });
            var command = result.Last().Command as CommandWithStaticCtor;

            //// Assert
            Assert.NotNull(command);
        }
        public void RunsCommandLine()
        {
            CommandLineProcessor p = new CommandLineProcessor();

            p.SetParameter("CommandLine", $"copy \"{{FullName}}\" \"{CurrentTestResultsDirectoryPath}\"");
            p.SetParameter("WaitForTaskToFinish", true);
            p.Init(RunInfo);
            FileInfo         file   = GetTestFile("BasicTextFile.txt");
            ProcessingResult result = p.Process(file, MatchResultType.Yes, new string[0], new FileInfo[0],
                                                ProcessInput.OriginalFile, CancellationToken.None);

            Assert.AreEqual(ProcessingResultType.Success, result.Type);
            p.Cleanup();
        }
Esempio n. 15
0
        public void When_first_argument_is_existing_command_name_then_command_is_executed()
        {
            //// Arrange
            var resolver  = new MyDependencyResolver();
            var processor = new CommandLineProcessor(new ConsoleHost(), resolver);

            processor.RegisterCommand <MyCommand>("test");

            //// Act
            var result  = processor.Process(new[] { "test" });
            var command = result.Last().Command as MyCommand;

            //// Assert
            Assert.NotNull(command);
        }
Esempio n. 16
0
        public static void MainEntry(ProgressReporterFactory zProgressReporterFactory,
                                     string[] args)
        {
            var commandLineProcessor = new CommandLineProcessor(
                new CommandLineParser().Parse(args),
                zProgressReporterFactory)
            {
                CommandLineUtil = new CommandLineUtil()
            };

            if (!commandLineProcessor.Process())
            {
#if !MONO_BUILD
                Win32.ShowConsole(Application.ExecutablePath, false);
#endif
                Application.Run(new CardMakerMDI());
            }
        }
Esempio n. 17
0
        /// <summary>Processes the command line arguments.</summary>
        /// <param name="args">The arguments.</param>
        /// <returns>The result.</returns>
        public int Process(string[] args)
        {
            var architecture = IntPtr.Size == 4 ? " (x86)" : " (x64)";
            _host.WriteMessage("toolchain v" + SwaggerDocument.ToolchainVersion + " (NJsonSchema v" + JsonSchema4.ToolchainVersion + ")" + architecture + "\n");
            _host.WriteMessage("Visit http://NSwag.org for more information.\n");

            var binDirectory = DynamicApis.PathGetDirectoryName(((dynamic)typeof(NSwagCommandProcessor).GetTypeInfo().Assembly).CodeBase.Replace("file:///", string.Empty));
            _host.WriteMessage("NSwag bin directory: " + binDirectory + "\n");

            if (args.Length == 0)
                _host.WriteMessage("Execute the 'help' command to show a list of all the available commands.\n");

            try
            {
                var processor = new CommandLineProcessor(_host);

                processor.RegisterCommandsFromAssembly(_assemblyLoaderAssembly);
                processor.RegisterCommandsFromAssembly(typeof(SwaggerToCSharpControllerCommand).GetTypeInfo().Assembly);

                var stopwatch = new Stopwatch();
                stopwatch.Start();
                var results = processor.Process(args);
                stopwatch.Stop();

                var output = results.Last()?.Output;
                var document = output as SwaggerDocument;
                if (document != null)
                    _host.WriteMessage(document.ToJson());
                else if (output != null)
                    _host.WriteMessage(output.ToString());

                _host.WriteMessage("\nDuration: " + stopwatch.Elapsed);
            }
            catch (Exception exception)
            {
                _host.WriteError(exception.ToString());
                return -1;
            }

            WaitWhenDebuggerAttached();
            return 0;
        }
Esempio n. 18
0
        static void Main(string[] args)
        {
            var host = new ConsoleHost();

            host.WriteMessage("NSwag command line: v" + typeof(SwaggerInfo).Assembly.GetName().Version + "\n");
            host.WriteMessage("Visit http://NSwag.org for more information.\n");
            host.WriteMessage("Execute the 'help' command to show a list of all the available commands.\n");

            try
            {
                var processor = new CommandLineProcessor(host);

                processor.RegisterCommand <WebApiToSwaggerCommand>("webapi2swagger");

                processor.RegisterCommand <JsonSchemaToCSharpCommand>("jsonschema2csclient");
                processor.RegisterCommand <JsonSchemaToTypeScriptCommand>("jsonschema2tsclient");

                processor.RegisterCommand <SwaggerToCSharpClientCommand>("swagger2csclient");
                processor.RegisterCommand <SwaggerToCSharpWebApiControllerCommand>("swagger2cscontroller");
                processor.RegisterCommand <SwaggerToTypeScriptCommand>("swagger2tsclient");

                processor.Process(args);
            }
            catch (Exception exception)
            {
                var savedForegroundColor = Console.ForegroundColor;
                Console.ForegroundColor = ConsoleColor.Red;
                host.WriteMessage(exception.ToString());
                Console.ForegroundColor = savedForegroundColor;
            }

            if (Debugger.IsAttached)
            {
                Console.WriteLine("Press <any> key to exit...");
                Console.ReadKey();
            }
        }