Exemple #1
0
        public void basic()
        {
            //Arrange
            var current_level = new nutility.InputClassReplLevel("UC-1", typeof(InputX));
            var tree          = new nutility.Tree <string, nutility.InputReplLevel> {
                Value = current_level
            };

            var input_lines = new[] { "new x1", "?" };
            var reader      = new StringReader(Common.asTextContent(input_lines));
            var writer      = new StringWriter();
            var repl        = new nutility.REPL {
                Reader = reader, Writer = writer
            };

            //Act
            repl.Loop(tree);

            //Assert
            Assert.IsTrue($"{writer}".Contains($"x1 ({typeof(InputX).FullName})"));
        }
Exemple #2
0
        public static void MainEntryPoint(string[] args, TextReader reader = null, TextWriter writer = null, int consoleWindowWidth = 20)
        {
            try
            {
                if (reader == null)
                {
                    reader = Console.In;
                }
                if (writer == null)
                {
                    writer = Console.Out;
                }
                if (Environment.UserInteractive)
                {
                    WriteLine($"Hello, {Environment.UserDomainName}\\{Environment.UserName} !!!");
                    Write($"PID: {System.Diagnostics.Process.GetCurrentProcess().Id} Thread: {System.Threading.Thread.CurrentThread.ManagedThreadId} Culture: {System.Threading.Thread.CurrentThread?.CurrentUICulture?.Name}, {System.Threading.Thread.CurrentThread?.CurrentCulture?.Name}\n");
                }

                /*if (!(args?.Any() == true) || args?.First().Contains("?") == true)
                 * {
                 * WriteLine($"Working with {GetHostProcessName()}:");
                 * nutility.Switch.ShowUsage(typeof(RootInput));
                 * }
                 * else*/
                {
                    var mvp = new nutility.InputClassReplLevel("MVP", typeof(RootInput));
                    var use_case_hierarchy_root = new nutility.Tree <string, nutility.InputReplLevel> {
                        Value = mvp
                    };
                    var uc2 = new nutility.InputClassReplLevel("UC2", typeof(InputUC2));
                    use_case_hierarchy_root[uc2.ID] = new nutility.Tree <string, nutility.InputReplLevel> {
                        Value = uc2, Parent = use_case_hierarchy_root
                    };
                    var uc3 = new nutility.InputClassReplLevel("UC3", typeof(InputUC3));
                    use_case_hierarchy_root[uc3.ID] = new nutility.Tree <string, nutility.InputReplLevel> {
                        Value = uc3, Parent = use_case_hierarchy_root
                    };

                    var repl = new nutility.REPL {
                        Reader = reader, Writer = writer, ConsoleWindowWidth = consoleWindowWidth
                    };
                    repl.Loop(use_case_hierarchy_root);
                }
            }
            catch (Exception ex)
            {
                for (int level = 0; ex != null; ex = ex.InnerException, ++level)
                {
                    writer.WriteLine($"\r\n[Level {level}] {ex.GetType().FullName}: {ex.Message} {ex.StackTrace}");
                }
            }

            string GetHostProcessName()
            {
                var result = Environment.GetCommandLineArgs()?.FirstOrDefault();

                if (!string.IsNullOrWhiteSpace(result))
                {
                    result = System.IO.Path.GetFileNameWithoutExtension(result);
                }
                return(result);
            }
        }