示例#1
0
 public virtual void Dispose()
 {
     Store.Clear();
 }
        protected void StartRouting(string name, Dictionary <int, string> functions, bool nameToPhrase = true)
        {
            int  function = 0;
            bool restart  = false;

            while (true)
            {
                string data = GenerateChoices(functions, nameToPhrase);
                Console.Write(string.Format(@"
Select a {0} from the List

    {1}

Enter Your Choice (0: Exit{2}) : ", name, data, IsMain ? " | r: Restart" : ""));

                string l = Console.ReadLine();
                if (IsMain && l.ToLower() == "r")
                {
                    restart = true;
                    break;
                }
                if (!int.TryParse(l, out function) || function > Functions.Count || (function < 1 && function != 0))
                {
                    Console.WriteLine("Invalid Choice");
                    continue;
                }

                if (function == 0)
                {
                    break;
                }


                MethodInfo info = GetType().GetMethod(Functions[function]);
                OnMethodSelected(Functions[function]);
                CurrentMethod = Functions[function];


                try
                {
                    using (var sc = Shell.GetScope())
                    {
                        _scope = sc;
                        ConsoleShell.CurrentScope = _scope;
                        info.Invoke(this, new object[] { });
                        ConsoleShell.CurrentScope = null;
                    }
                }
                catch (Exception ex)
                {
                    ConsoleShell.CurrentScope = null;
                    writer.WriteException(ex);
                }
                store.Clear();
            }
            if (restart)
            {
                Console.WriteLine();
                Console.WriteLine("Restarting...");
                Process.Start(new ProcessStartInfo
                {
                    FileName        = "dotnet",
                    Arguments       = "run",
                    UseShellExecute = true,
                    CreateNoWindow  = false
                });
            }
        }