tanghai пре 7 година
родитељ
комит
c8c66bc312
2 измењених фајлова са 68 додато и 50 уклоњено
  1. 36 43
      Server/Model/Component/ConsoleComponent.cs
  2. 32 7
      Server/Model/Component/ReplComponent.cs

+ 36 - 43
Server/Model/Component/ConsoleComponent.cs

@@ -40,6 +40,41 @@ namespace ETModel
                     
                     line = line.Trim();
 
+                    if (this.Mode != "")
+                    {
+                        bool isExited = true;
+                        switch (this.Mode)
+                        {
+                            case ConsoleMode.Repl:
+                            {
+                                ReplComponent replComponent = this.GetComponent<ReplComponent>();
+                                if (replComponent == null)
+                                {
+                                    Console.WriteLine($"no command: {line}!");
+                                    break;
+                                }
+                            
+                                try
+                                {
+                                    isExited = await replComponent.Run(line, this.CancellationTokenSource.Token);
+                                }
+                                catch (Exception e)
+                                {
+                                    Console.WriteLine(e);
+                                }
+
+                                break;
+                            }
+                        }
+
+                        if (isExited)
+                        {
+                            this.Mode = "";
+                        }
+
+                        continue;
+                    }
+
                     switch (line)
                     {
                         case "reload": 
@@ -63,50 +98,8 @@ namespace ETModel
                                 Console.WriteLine(e);
                             }
                             break;
-                        case "exit":
-                            switch (this.Mode)
-                            {
-                                case ConsoleMode.Repl:
-                                    this.RemoveComponent<ReplComponent>();
-                                    break;
-                            }
-
-                            this.Mode = ConsoleMode.None;
-                            break;
-                        case "reset":
-                            switch (this.Mode)
-                            {
-                                case ConsoleMode.Repl:
-                                    this.RemoveComponent<ReplComponent>();
-                                    this.AddComponent<ReplComponent>();
-                                    break;
-                            }
-                            break;
                         default:
-                            switch (this.Mode)
-                            {
-                                case ConsoleMode.Repl:
-                                {
-                                    ReplComponent replComponent = this.GetComponent<ReplComponent>();
-                                    if (replComponent == null)
-                                    {
-                                        Console.WriteLine($"no command: {line}!");
-                                        break;
-                                    }
-                            
-                                    try
-                                    {
-                                        await replComponent.Run(line, this.CancellationTokenSource.Token);
-                                    }
-                                    catch (Exception e)
-                                    {
-                                        Console.WriteLine(e);
-                                    }
-
-                                    break;
-                                }
-                            }
-
+                            Console.WriteLine($"no such command: {line}");
                             break;
                     }
                 }

+ 32 - 7
Server/Model/Component/ReplComponent.cs

@@ -22,15 +22,40 @@ namespace ETModel
         public ScriptOptions ScriptOptions;
         public ScriptState ScriptState;
 
-        public async ETTask Run(string line, CancellationToken cancellationToken)
+        public async ETTask<bool> Run(string line, CancellationToken cancellationToken)
         {
-            if (this.ScriptState == null)
+            switch (line)
             {
-                this.ScriptState = await CSharpScript.RunAsync(line, this.ScriptOptions, cancellationToken: cancellationToken);
-            }
-            else
-            {
-                this.ScriptState = await this.ScriptState.ContinueWithAsync(line, cancellationToken: cancellationToken);
+                case "exit":
+                {
+                    this.Entity.RemoveComponent<ReplComponent>();
+                    return true;
+                }
+                case "reset":
+                {
+                    this.ScriptState = null;
+                    return false;
+                }
+                default:
+                {
+                    try
+                    {
+                        if (this.ScriptState == null)
+                        {
+                            this.ScriptState = await CSharpScript.RunAsync(line, this.ScriptOptions, cancellationToken: cancellationToken);
+                        }
+                        else
+                        {
+                            this.ScriptState = await this.ScriptState.ContinueWithAsync(line, cancellationToken: cancellationToken);
+                        }
+                    }
+                    catch (Exception e)
+                    {
+                        Console.WriteLine(e);
+                    }
+
+                    return false;
+                }
             }
         }