Пример #1
0
        public void RemoveSession(LazynetHandlerContext ctx)
        {
            string address = ctx.GetAddress();
            string id      = EncryptionHelper.GetMD5Hash(address);

            this.SessionManager.RemoveSession(id);
        }
Пример #2
0
        public LazynetSession GetSessionByCtx(LazynetHandlerContext ctx)
        {
            string address = ctx.GetAddress();
            string id      = EncryptionHelper.GetMD5Hash(address);

            return(this.SessionManager.GetSession(id));
        }
Пример #3
0
        public void Read(LazynetHandlerContext ctx, string msg)
        {
            this.Context.Log(LazynetLogLevel.Debug, "===recv data is " + msg);
            var message = SerializeHelper.Deserialize <LazynetMessage>(msg);

            this.CallService(ctx, message);
        }
Пример #4
0
 public void DisConnect(LazynetHandlerContext ctx)
 {
     this.CallService(ctx, new LazynetMessage()
     {
         RouteUrl   = "/System/DisConnect",
         Parameters = null
     });
 }
Пример #5
0
        public void Read(LazynetHandlerContext ctx, string msg)
        {
            this.Context.Log(LazynetLogLevel.Debug, "===recv data is " + msg);
            var message = SerializeHelper.Deserialize <LazynetMessage>(msg);

            message.Parameters.Insert(0, ctx);
            this.Context.Call(message);
        }
Пример #6
0
 public void Exception(LazynetHandlerContext ctx, Exception exception)
 {
     this.CallService(ctx, new LazynetMessage()
     {
         RouteUrl   = "/System/Exception",
         Parameters = new List <object> {
             exception
         }
     });
 }
Пример #7
0
 public void AddNode(string name, LazynetHandlerContext ctx)
 {
     if (string.IsNullOrEmpty(name) ||
         ctx == null)
     {
         this.Logger.Error(" name is empty or ctx is null, so add node fail ");
         return;
     }
     this.Nodes.Add(name, ctx);
 }
Пример #8
0
        public void SendMessage(LazynetHandlerContext ctx, string routeUrl, LuaTable args)
        {
            LazynetMessage message = new LazynetMessage();

            message.RouteUrl = routeUrl;
            foreach (var item in args)
            {
                message.Parameters.Add(item.Value);
            }
            ctx.WriteAndFlushAsync(SerializeHelper.Serialize(message));
        }
Пример #9
0
 public void DisConnect(LazynetHandlerContext ctx)
 {
     this.CallService(new LazynetMessage()
     {
         RouteUrl   = "/System/DisConnect",
         Parameters = new List <object>()
         {
             ctx
         }
     });
 }
Пример #10
0
 public void DisConnect(LazynetHandlerContext ctx)
 {
     this.Context.Call(new LazynetMessage()
     {
         RouteUrl   = LazynetActionConstant.NodeDisconnect,
         Parameters = new List <object>()
         {
             ctx
         }
     });
 }
Пример #11
0
 public void Exception(LazynetHandlerContext ctx, Exception ex)
 {
     this.Context.CallAction(new LazynetMessage()
     {
         RouteUrl   = "/InteriorServer/Exception",
         Parameters = new List <object>()
         {
             ctx
         }
     });
 }
 public void DisConnect(LazynetHandlerContext ctx)
 {
     this.Context.CallAction(new LazynetMessage()
     {
         RouteUrl   = "/ExternalServer/DisConnect",
         Parameters = new List <object>()
         {
             ctx
         }
     });
 }
 public void Exception(LazynetHandlerContext ctx, Exception ex)
 {
     this.Context.CallAction(new LazynetMessage()
     {
         RouteUrl   = "/ExternalServer/Exception",
         Parameters = new List <object>()
         {
             ctx,
             ex.ToString()
         }
     });
 }
Пример #14
0
 public void Exception(LazynetHandlerContext ctx, Exception exception)
 {
     this.Context.Call(new LazynetMessage()
     {
         RouteUrl   = LazynetActionConstant.NodeException,
         Parameters = new List <object>()
         {
             ctx,
             exception.ToString()
         }
     });
 }
Пример #15
0
        public void AddSession(LazynetHandlerContext ctx)
        {
            string address = ctx.GetAddress();
            string id      = EncryptionHelper.GetMD5Hash(address);

            this.SessionDict.Add(id, new LazynetSession()
            {
                Address         = address,
                ID              = id,
                ConnectDateTime = DateTime.Now,
                Context         = ctx
            });
        }
        public void Read(LazynetHandlerContext ctx, string msg)
        {
            var sessionMessage = SerializeHelper.Deserialize <LazynetSessionMessage>(msg);
            var message        = new LazynetMessage();

            message.RouteUrl   = "/ExternalServer/Read";
            message.Parameters = new List <object>()
            {
                ctx,
                sessionMessage.ServerName,
                sessionMessage.RouteUrl,
            };
            message.Parameters.AddRange(sessionMessage.Parameters);
            this.Context.CallAction(message);
        }
Пример #17
0
        public void Read(LazynetHandlerContext ctx, string msg)
        {
            // 转发消息
            var message        = SerializeHelper.Deserialize <LazynetMessage>(msg);
            var messageWrapper = new LazynetMessage();

            messageWrapper.RouteUrl   = "/InteriorServer/Read";
            messageWrapper.Parameters = new List <object>();
            messageWrapper.Parameters.Add(ctx);
            messageWrapper.Parameters.Add(message.RouteUrl);
            foreach (var item in message.Parameters)
            {
                messageWrapper.Parameters.Add(item);
            }
            this.Context.CallAction(messageWrapper);
        }
Пример #18
0
        public void Add(string name, LazynetHandlerContext ctx)
        {
            var findNode = this.Nodes
                           .Where(it => it.Name == name)
                           .FirstOrDefault();

            if (findNode == null)
            {
                this.Nodes.Add(new LazynetNode()
                {
                    Address         = ctx.GetAddress(),
                    ConnectDateTime = DateTime.Now,
                    Context         = ctx,
                    ID   = EncryptionHelper.GetMD5Hash(ctx.GetAddress()),
                    Name = name
                });
            }
        }
Пример #19
0
 private void CallService(LazynetHandlerContext ctx, LazynetMessage message)
 {
     try
     {
         this.Context.CurrentContext = ctx;
         Stopwatch sw = new Stopwatch();
         sw.Start();
         this.Context.ActionProxy.Call(message);
         sw.Stop();
         if (sw.Elapsed.TotalSeconds >= 3)
         {
             this.Context.Log(LazynetLogLevel.Warn, message.RouteUrl + " action run slow ");
         }
     }
     catch (Exception ex)
     {
         this.Context.Log(LazynetLogLevel.Error, ex.ToString());
     }
 }
Пример #20
0
        public void SendMessage(LazynetHandlerContext ctx, string routeUrl, LuaTable args)
        {
            if (ctx == null)
            {
                var method = new StackFrame(1).GetMethod();
                this.Log(LazynetLogLevel.Warn, method.Name + ": ctx is null ");
                return;
            }
            LazynetMessage message = new LazynetMessage();

            message.RouteUrl = routeUrl;
            foreach (var item in args)
            {
                message.Parameters.Add(item.Value);
            }
            string msg = SerializeHelper.Serialize(message);

            this.Log(LazynetLogLevel.Debug, "===send data is " + msg);
            ctx.WriteAndFlushAsync(msg);
        }
Пример #21
0
 public void AddSession(LazynetHandlerContext ctx)
 {
     this.SessionManager.AddSession(ctx);
 }
Пример #22
0
        public void RemoveNode(LazynetHandlerContext ctx)
        {
            string id = EncryptionHelper.GetMD5Hash(ctx.GetAddress());

            this.Nodes.RemoveByID(id);
        }