示例#1
0
        void ActionPrefix(out Process proc, string locality)
        {
            Process nextproc = new NilProcess(); proc = null; Action action = null;

            if (la.kind == 17 || la.kind == 19 || la.kind == 20)
            {
                Action(out action, locality);
                if (la.kind == 13)
                {
                    Get();
                    ActionPrefix(out nextproc, locality);
                }
                proc = new ActionPrefix(action, nextproc); CopyPos(proc, action, t);
            }
            else if (la.kind == 14)
            {
                Get();
                Process(out proc, locality);
                Expect(15);
            }
            else if (la.kind == 16)
            {
                Get();
                proc = new NilProcess(); SetPos(proc, t);
            }
            else
            {
                SynErr(27);
            }
        }
示例#2
0
        /// <summary>异步调用</summary>
        /// <param name="resultType"></param>
        /// <param name="action"></param>
        /// <param name="args"></param>
        /// <param name="flag"></param>
        /// <returns></returns>
        public override Task <Object> InvokeAsync(Type resultType, String action, Object args = null, Byte flag = 0)
        {
            if (!ActionPrefix.IsNullOrEmpty() && !action.Contains("/"))
            {
                action = ActionPrefix + "/" + action;
            }

            return(base.InvokeAsync(resultType, action, args, flag));
        }
示例#3
0
        /// <summary>异步调用</summary>
        /// <param name="action"></param>
        /// <param name="args"></param>
        /// <returns></returns>
        public override Task <TResult> InvokeAsync <TResult>(String action, Object args = null)
        {
            if (!ActionPrefix.IsNullOrEmpty() && !action.Contains("/"))
            {
                action = ActionPrefix + "/" + action;
            }

            return(base.InvokeAsync <TResult>(action, args));
        }
示例#4
0
        /// <summary>连接后自动登录</summary>
        /// <param name="client">客户端</param>
        /// <param name="force">强制登录</param>
        protected override async Task <Object> OnLoginAsync(ISocketClient client, Boolean force)
        {
            if (Logined && !force)
            {
                return(null);
            }

            Logined = false;

            var user = UserName;
            var pass = Password;

            //if (user.IsNullOrEmpty()) return null;
            //if (user.IsNullOrEmpty()) throw new ArgumentNullException(nameof(user), "用户名不能为空!");
            //if (pass.IsNullOrEmpty()) throw new ArgumentNullException(nameof(pass), "密码不能为空!");
            if (!pass.IsNullOrEmpty())
            {
                pass = pass.MD5();
            }

            var arg = new
            {
                user,
                pass,
            };

            // 克隆一份,避免修改原始数据
            var dic = arg.ToDictionary();

            dic.Merge(GetLoginInfo(), false);

            var act = "Login";

            if (!ActionPrefix.IsNullOrEmpty())
            {
                act = ActionPrefix + "/" + act;
            }

            var rs = await base.InvokeWithClientAsync <Object>(client, act, dic);

            var inf = rs.ToJson();

            XTrace.WriteLine("登录{0}成功!{1}", Servers.FirstOrDefault(), inf);

            Logined = true;

            Info = rs as IDictionary <String, Object>;

            if (_timer == null)
            {
                _timer = new TimerX(DoPing, null, 10_000, 30_000);
            }

            return(rs);
        }
示例#5
0
        /// <summary>连接后自动登录</summary>
        /// <param name="client">客户端</param>
        /// <param name="force">强制登录</param>
        protected override async Task <Object> OnLoginAsync(ISocketClient client, Boolean force)
        {
            if (Logined && !force)
            {
                return(null);
            }

            Logined = false;

            var user = UserName;
            var pass = Password;

            //if (user.IsNullOrEmpty()) return null;
            if (user.IsNullOrEmpty())
            {
                throw new ArgumentNullException(nameof(user), "用户名不能为空!");
            }
            //if (pass.IsNullOrEmpty()) throw new ArgumentNullException(nameof(pass), "密码不能为空!");

            var asmx = AssemblyX.Entry;

            var arg = new
            {
                user,
                pass = pass.MD5(),
            };

            // 克隆一份,避免修改原始数据
            var dic = arg.ToDictionary();

            dic.Merge(Parameters, false);

            var act = "Login";

            if (!ActionPrefix.IsNullOrEmpty())
            {
                act = ActionPrefix + "/" + act;
            }

            var rs = await base.InvokeWithClientAsync <Object>(client, act, dic);

            var inf = rs.ToJson();

            if (Setting.Current.Debug)
            {
                XTrace.WriteLine("登录{0}成功!{1}", Servers.FirstOrDefault(), inf);
            }

            Logined = true;

            return(Info = rs as IDictionary <String, Object>);
        }
示例#6
0
        /// <summary>调用</summary>
        /// <typeparam name="TResult"></typeparam>
        /// <param name="action"></param>
        /// <param name="args"></param>
        /// <param name="cookie">附加参数,位于顶级</param>
        /// <returns></returns>
        public virtual async Task <TResult> InvokeAsync <TResult>(String action, Object args = null, IDictionary <String, Object> cookie = null)
        {
            var ss = Client;

            if (ss == null)
            {
                return(default(TResult));
            }

            // 未登录且设置了用户名,并且当前不是登录,则异步登录
            if (!Logined && !UserName.IsNullOrEmpty() && action != "Login")
            {
                await LoginAsync();
            }

            var act = action;

            if (!ActionPrefix.IsNullOrEmpty() && !act.Contains("/"))
            {
                act = ActionPrefix.EnsureEnd("/") + act;
            }

            LastInvoke = DateTime.Now;
            try
            {
                return(await ApiHostHelper.InvokeAsync <TResult>(this, this, act, args, cookie ?? Cookie));
            }
            catch (ApiException ex)
            {
                // 重新登录后再次调用
                if (ex.Code == 401)
                {
                    Logined = false;
                    // 如果当前不是登录,且设置了用户名,尝试自动登录
                    if (action != "Login" && !UserName.IsNullOrEmpty())
                    {
                        await LoginAsync();

                        return(await ApiHostHelper.InvokeAsync <TResult>(this, this, act, args, cookie ?? Cookie));
                    }
                }

                throw;
            }
            // 截断任务取消异常,避免过长
            catch (TaskCanceledException)
            {
                throw new TaskCanceledException(action + "超时取消");
            }
        }
示例#7
0
        void ActionPrefix(out Process proc)
        {
            ActionPrefix ap = null; ActionPrefix prev = null; ActionPrefix first = null; Process nextProc = null; ProcessConstant pc; proc = null; Action act = null;

            while (la.kind == 3 || la.kind == 5 || la.kind == 6)
            {
                Token startAction = la;
                Action(out act);
                ap = new ActionPrefix(act, null); SetStartPos(ap, startAction); if (first == null)
                {
                    first = ap;
                }
                if (prev != null)
                {
                    prev.Process = ap;
                }
                prev = ap;
                SetPos(act, startAction, t);
                Expect(16);
            }
            if (la.kind == 10)
            {
                Get();
                Process(out nextProc);
                Expect(12);
                nextProc.ParenCount++;
            }
            else if (la.kind == 17)
            {
                Get();
                nextProc = new NilProcess(); SetPos(nextProc, t);
            }
            else if (la.kind == 1)
            {
                ProcessConstantInvoke(out pc);
                nextProc = pc;
            }
            else if (la.kind == 18)
            {
                BranchProcess(out nextProc);
            }
            else
            {
                SynErr(42);
            }
            if (first == null)
            {
                proc = nextProc;
            }
            else
            {
                ap.Process = nextProc; proc = first;
            };
            if (la.kind == 21)
            {
                PreProcessActions ppa = null;
                Relabelling(out ppa);
                nextProc.PreProcessActions = ppa;
            }
            if (la.kind == 24)
            {
                ActionRestrictions ar = null;
                Restriction(out ar);
                nextProc.ActionRestrictions = ar;
            }
        }
 //Processes
 public virtual void Visit(ActionPrefix node)
 {
 }
示例#9
0
 public virtual string Format(ActionPrefix ap)
 {
     return(SurroundWithParens(Format(ap.Action) + "." + Format(ap.Process), ap.ParenCount));
 }
        //Processes
        public override void Visit(ActionPrefix node)
        {
            List <string> children = PopChildren();

            Return(CheckProc(children[2] + " . " + children[3], children));
        }