Esempio n. 1
0
        public void Add(RpcServerContext context)
        {
            RpcClass <int, int> c = context.GetArgs <RpcClass <int, int> >();

            // Console.WriteLine("Rpc.Test1 {0} {1}", c.Value1, c.Value2);
            context.Return(c.Value1 + c.Value2);
        }
Esempio n. 2
0
        public void  ListFailedTransactions(RpcServerContext ctx)
        {
            if (_coordinator == null)
            {
                throw new Exception("Coordinator is Null");
            }
            string transName = ctx.GetArgs <string>();

            if (transName != _coordinator.TransName)
            {
                throw new Exception("TransName not Matched");
            }
            List <TccTransactionData>    dataList = (List <TccTransactionData>)_coordinator.GetFailedTransactions();
            RpcList <TccTransactionData> rpcList  = null;

            if (dataList != null && dataList.Count > 0)
            {
                rpcList = new RpcList <TccTransactionData>();
                foreach (TccTransactionData data in dataList)
                {
                    rpcList.Value.Add(data);
                }
            }
            ctx.Return <RpcList <TccTransactionData> >(rpcList);
        }
Esempio n. 3
0
        public void Register(RpcServerContext ctx)
        {
            //
            // 已经连接过的就返回失败
            if (ctx.Connection.Contexts["session"] != null)
            {
                ctx.ReturnError(RpcErrorCode.ConnectionBroken, null);
                return;
            }

            var args = ctx.GetArgs <DuplexDemoRegisterArgs>();

            if (args.UserName == "foo" && args.Passwd == "bar")
            {
                //
                // 注册成功, 建立session对象
                var session = new DuplexDemoSession()
                {
                    Id         = Guid.NewGuid().ToString(),
                    LastTime   = DateTime.Now,
                    Connection = ctx.Connection,
                };
                ctx.Connection.Contexts["session"] = session;
                lock (_syncRoot) {
                    _agents.Add(ctx.From, session);
                }
                ctx.Return();
            }
            else
            {
                ctx.ReturnError(RpcErrorCode.ConnectionFailed, new Exception("UserNotFound"));
            }
        }
Esempio n. 4
0
        public void KeepAlive(RpcServerContext ctx)
        {
            int seconds = ctx.GetArgs <int>();
            DuplexDemoSession session = (DuplexDemoSession)ctx.Connection.Contexts["session"];

            session.LastTime = DateTime.Now.AddSeconds(seconds);
            ctx.Return(0);              // 没意义
        }
Esempio n. 5
0
        public void AppendSystemLog(RpcServerContext context)
        {
            RpcList <SystemLogEvent> evts = context.GetArgs <RpcList <SystemLogEvent> >();

            foreach (SystemLogEvent evt in evts.Value)
            {
                Console.WriteLine(evt.ToString());
            }
            WaitEvent.Set();
            context.Return();
        }
Esempio n. 6
0
        public void Register(RpcServerContext ctx)
        {
            var token = (RpcDuplexConnectionToken)ctx.Connection.Contexts["Duplex"];

            if (token.Registerd)
            {
                ctx.Return(RpcErrorCode.ConnectionFailed);
                return;
            }
            else
            {
                token.ProcessRegister(ctx);
            }
        }
Esempio n. 7
0
        public void KeepAlive(RpcServerContext ctx)
        {
            var token = (RpcDuplexConnectionToken)ctx.Connection.Contexts["Duplex"];

            if (token != null && token.Registerd)
            {
                token.ProcessKeepalive(ctx);
            }
            else
            {
                ctx.Return(RpcErrorCode.ConnectionFailed);
                return;
            }
        }
Esempio n. 8
0
 public void Return(TResults ret)
 {
     InnerContext.Return <TResults>(ret);
 }
Esempio n. 9
0
 public void TestTimeout(RpcServerContext context)
 {
     Thread.Sleep(60000);
     context.Return();
 }
Esempio n. 10
0
 public void Array(RpcServerContext context)
 {
     byte[] a = context.GetArgs <byte[]>();
     context.Return(a);
 }
Esempio n. 11
0
        public void Default(RpcServerContext context)
        {
            RpcClass <int> a = new RpcClass <int>();

            context.Return(a);
        }
Esempio n. 12
0
 public void Null(RpcServerContext context)
 {
     context.Return <RpcClass <int> >(null);
 }
Esempio n. 13
0
        public void Mirror(RpcServerContext context)
        {
            var e = context.GetArgs <RpcClass <int> >();

            context.Return(e);
        }