Beispiel #1
0
 void SuperSocket_DataReceived(object sender, WebSocket4Net.DataReceivedEventArgs e)
 {
     try
     {
         var code = SerializaHelper.DeSerialize <CodeBase>(e.Data);
         if (code == null)
         {
             ShowMsg("无法处理的未知消息类型");
         }
         //消息分发处理
         var interFaces = this.GetType().GetInterfaces().Where(iface => iface.Name == "IHandleMessage`1");
         foreach (var interFace in interFaces)
         {
             var codeType = code.GetType();
             var argTypes = interFace.GetGenericArguments();
             if (argTypes != null && argTypes.Length == 1 && argTypes[0].Name == codeType.Name)
             {
                 System.Reflection.MethodInfo methodInfo = interFace.GetMethod("HandleMessage");
                 var result = methodInfo.Invoke(this, new object[] { code });
             }
         }
     }
     catch (Exception ex)
     {
     }
 }
Beispiel #2
0
        public void SuperSocket_DataReceived(object sender, WebSocket4Net.DataReceivedEventArgs e)
        {
            var code = SerializaHelper.DeSerialize <CodeBase>(e.Data);

            if (code == null)
            {
                Mediator.ShowMsg("无法处理的未知消息类型");
            }
            if (code.Name == "Regist")
            {
                var registCode = code as RegistCode;
                File.WriteAllText(Path.Combine(Application.StartupPath, "appLicense.txt"), registCode.License);
                if (!registCode.isLegal)
                {
                    Invoke(new MethodInvoker(() =>
                    {
                        this.Title            = "身份验证过期!,请重新激活此软件";
                        this.BtnText          = "确定";
                        this.CancelBtnVisible = true;
                        this.btnCancel.Click += (a, b) => { System.Environment.Exit(0); };
                    }));
                }
                else
                {
                    Invoke(new MethodInvoker(() =>
                    {
                        //this.Title = "身份验证通过...";
                        //this.BtnText = "确定";
                        //this.CancelBtnVisible = true;
                        this.Close();
                    }));
                }
            }
        }
Beispiel #3
0
 void SuperSocket_DataReceived(object sender, WebSocket4Net.DataReceivedEventArgs e)
 {
     try
     {
         var code = SerializaHelper.DeSerialize <CodeBase>(e.Data);
         if (code == null)
         {
             Mediator.ShowMsg("无法处理的未知消息类型");
         }
         //消息分发处理
         for (int i = 0; i < Application.OpenForms.Count; i++)
         {
             var from       = Application.OpenForms[i];
             var interFaces = from.GetType().GetInterfaces().Where(iface => iface.Name == "IHandleMessage`1");
             // var interFace = from.GetType().GetInterface("IHandleMessage`1");
             foreach (var interFace in interFaces)
             {
                 var codeType = code.GetType();
                 var argTypes = interFace.GetGenericArguments();
                 if (argTypes != null && argTypes.Length == 1 && argTypes[0].Name == codeType.Name)
                 {
                     System.Reflection.MethodInfo methodInfo = interFace.GetMethod("HandleMessage");
                     var result = methodInfo.Invoke(from, new object[] { code });
                 }
             }
         }
     }
     catch
     {
     }
 }