/*
         * internal void Add(ConsoleDebug.ActionResult action, string cline, string cl, bool uwp = false, string description = null)
         * {
         *  Commands.Add(CCommand.New(action, cline, cl, uwp, description));
         * }
         * internal void SAdd(ConsoleDebug.ActionResult action, string cline, string cl, bool uwp = false, string description = null)
         * {
         *  Commands.Add(CCommand.SNew(action, cline, cl, uwp, description));
         * }
         */
        public void WaitCommand(string cline)
        {
            bool normal = true;

            if (string.IsNullOrEmpty(cline))
            {
                normal = false;
            }

            if (normal)
            {
                if (cline[0] == ' ')
                {
                    for (var i = 1; i != cline.Length; i++)
                    {
                        if (cline[i] != ' ')
                        {
                            cline = cline.Remove(0, i);
                            break;
                        }
                    }
                }
                if (string.IsNullOrEmpty(cline))
                {
                    normal = false;
                }
            }

            bool finded = false;

            if (normal)
            {
                string clinesp = cline;
                //var spacep = clinesp.Length - 1;
                for (var i = clinesp.Length - 1; i != 0; i--)
                {
                    if (clinesp[i] == ' ')
                    {
                        clinesp = clinesp.Remove(i, 1);
                    }
                    else
                    {
                        break;
                    }
                }
                string c      = clinesp;
                var    clines = CommandActions.GetLine(clinesp);
                if (!Params.IsNull())
                {
                    Params.Clear();
                }
                if (clines.Length > 1)
                {
                    Params = new ExtraArray <CParameter>(CParameter.FromLine(clinesp).ToArray().AsMemory());

                    var cc = clinesp.Split(' ');
                    c = cc[0];
                }
                foreach (var item in GetCCommandList())
                {
                    if (item.CommandLine == c)
                    {
                        finded = true;
                        if (Params.Count == item.Params.Length)
                        {
                            InvokeAction(item);
                        }
                        else
                        {
                            if (item.Params.Length > 0 && !item.UseWithoutParams)
                            {
                                var ot = $"";
                                foreach (var item1 in item.Params)
                                {
                                    ot += $" <{item1}>";
                                }
                                Beep(800, 100);
                                LogFramework.WriteNewLog($"Instruction of {item.CommandLine}:{ot}.", CClass, this, null, LogEnums.ResultCode.WarnMethod);
                            }
                            else if (item.Params.Length > 0 && item.UseWithoutParams)
                            {
                                InvokeAction(item);
                            }
                            else
                            {
                                Beep(800, 100);
                                LogFramework.WriteNewLog($"{item.CommandLine}: using without parameters.", CClass, this, null, LogEnums.ResultCode.WarnMethod);
                            }
                        }
                    }
                }
            }
            if (!finded)
            {
                LogFramework.WriteNewLog("Unknown command.", CClass, this, null, LogEnums.ResultCode.ErrorMethod);
                Beep(85, 300);
            }
        }
Example #2
0
 public CallBack(string name)
 {
     Name          = name;
     Subscriptions = new ExtraArray <CallBackSub <TCallBack> >(Array.Empty <CallBackSub <TCallBack> >());
 }