示例#1
0
        public static bool Wait <T1>(T1 task, CancellationTokenSource cancel = null)
            where T1 : Task
        {
            var wm = @"|/-\";
            var i  = 0;

            Console.CursorVisible = false;
            while (!task.IsCompleted)
            {
                Thread.Sleep(400);
                if (Console.KeyAvailable)
                {
                    Console.ReadKey(true);
                    Console.CursorVisible = true;
                    if (Prompt.GetYesNo("\rCancel Request?", false))
                    {
                        cancel.Cancel();
                        BaseCmd.Error("Request Cancelled!");
                        break;
                    }
                    Console.CursorVisible = false;
                }
                Console.Write('\r' + wm[i].ToString());
                i = (i + 1) % 4;
            }
            Console.CursorVisible = true;
            return(task.IsCompleted);
        }
示例#2
0
 public static void Load(string fname)
 {
     try
     {
         using (StreamReader sr = File.OpenText(fname))
         {
             var list = JsonSerializer.Deserialize <List <T> >(sr.ReadToEnd(), new JsonSerializerOptions
             {
                 Converters =
                 {
                     new ServerJsonConverter(),
                     new AIS.ActionJsonConverter(),
                     new AIS.GridActionJsonConverter()
                 }
             });
             if (list != null && list.Count > 0)
             {
                 List    = list;
                 Current = List.First();
             }
             else
             {
                 BaseCmd.Warning("No data to load!");
             }
         }
     }
     catch (Exception e)
     {
         BaseCmd.Error(e.Message);
     }
 }
示例#3
0
 public void Submit()
 {
     if (ServerCtx.Current is null)
     {
         BaseCmd.Error("No Server Context!");
     }
     else if (ServerCtx.Current.Server.AuthResponse is null)
     {
         BaseCmd.Error("{0} not connected!", ServerCtx.Current.Id);
     }
     else
     {
         var cancel = new CancellationTokenSource();
         try
         {
             var t = ServerCtx.Current.Server.RequestAsync <JsonElement>(Request, cancel);
             if (Wait(t, cancel))
             {
                 Responses.Add(new Response <T1>()
                 {
                     Request = Request, Result = t.Result
                 });
                 BaseCmd.Success("Responses {0}.", Responses.Count);
             }
         }
         catch (Exception ex)
         {
             BaseCmd.Error("Request failed!\n{0}", ex.Message);
         }
     }
 }
示例#4
0
 public static void Save(string fname)
 {
     if (!File.Exists(fname) || Prompt.GetYesNo("Do you want to overwrite existing file?", false))
     {
         try
         {
             using (StreamWriter sw = File.CreateText(fname))
             {
                 sw.Write(JsonSerializer.Serialize(List));
             }
         }
         catch (Exception e)
         {
             BaseCmd.Error(e.Message);
         }
     }
 }
示例#5
0
        public static void Main(string[] args)
        {
            ServerCmd.AddCmd();
            FormCmd.AddCmd();
            StackFormCmd.AddCmd();
            DataCmd.AddCmd();
            WatchListCmd.AddCmd();
            PreferenceCmd.AddCmd();
            OutFileCmd.AddCmd();
            HelpCmd.AddCmd();
            ClearCmd.AddCmd();
            QuitCmd.AddCmd();
            var startupMsg = "Celin's AIS Command Shell";

            InteractivePrompt.Prompt = BaseCmd.PromptTx;
            InteractivePrompt.Run(
                ((strCmd, listCmd, completion) =>
            {
                var resume = true;
                if (strCmd.Length > 0)
                {
                    var command = BaseCmd.Find(completion[0]);
                    if (command != null)
                    {
                        resume = -1 != command.Execute(completion.Skip(1).ToArray());
                    }
                    else
                    {
                        command = BaseCmd.Context is null ? null : BaseCmd.Find(BaseCmd.Context.Cmd);
                        if (command != null)
                        {
                            command.Execute(completion.ToArray());
                        }
                        else
                        {
                            Console.WriteLine("{0}: command not found! Type 'help' for available commands.", completion[0]);
                        }
                    }
                }
                InteractivePrompt.Prompt = BaseCmd.PromptTx;
                return(resume);
            }), startupMsg);
        }
示例#6
0
 void DisplayCmd(BaseCmd cmd, ref int spaces)
 {
 }