private void Xmhelper_errorMessageEvent(Socket soc, WeaveBase.WeaveSession _0x01, string message)
 {
     if (ErrorMge != null)
     {
         ErrorMge(0, message);
     }
 }
 public bool SendRoot <T>(byte command, String Request, T Root, int Querycount)
 {
     WeaveBase.WeaveSession b = new WeaveBase.WeaveSession();
     b.Request = Request;
     b.Token   = this.Tokan;
     b.SetRoot <T>(Root);
     b.Querycount = Querycount;
     return(send(command, b.Getjson()));
 }
 public bool SendParameter <T>(byte command, String Request, T Parameter, int Querycount)
 {
     WeaveBase.WeaveSession b = new WeaveBase.WeaveSession();
     b.Request = Request;
     b.Token   = this.Tokan;
     b.SetParameter <T>(Parameter);
     b.Querycount = Querycount;
     return(send(command, b.Getjson()));
 }
 public bool SendDtu(Socket soc, byte[] Root, String ip, int port)
 {
     WeaveBase.WeaveSession b = new WeaveBase.WeaveSession();
     b.Request = "dtu";
     b.Token   = ip + "|" + port;
     b.SetRoot <byte[]>(Root);
     b.Querycount = 0;
     return(Send(soc, 0x00, b.Getjson()));
 }
Exemple #5
0
        /// <summary>
        /// 错误返回事件
        /// </summary>
        public void Init(String data, Socket soc)
        {
            WeaveSession _0x01 = Newtonsoft.Json.JsonConvert.DeserializeObject <WeaveSession>(data);
            //json 转 对象,我用的第三方的DLL,你用这里能用的就行了
            string message = "";

            try
            {
                if (_0x01 != null && _0x01.Token != "")
                {
                    int count            = listmode.Count;
                    WeaveModelData[] mds = new WeaveModelData[count];
                    listmode.CopyTo(mds);
                    foreach (WeaveModelData md in mds)
                    {
                        if (md.Request == _0x01.Request)
                        {
                            if (md.rd2 != null && md.dtu == true)
                            {
                                WeaveRequestDataDtuDelegate rdh = new WeaveRequestDataDtuDelegate(md.rd2);
                                byte[] b = Newtonsoft.Json.JsonConvert.DeserializeObject <byte[]>(_0x01.Root); //对象转BYTE[]
                                rdh(soc, b, _0x01.Token.Split('|')[0], Convert.ToInt32(_0x01.Token.Split('|')[1]));
                                if (md.type == "once")
                                {
                                    listmode.Remove(md);
                                }
                            }
                            if (md.rd != null && md.dtu == false)
                            {
                                //md.rd(soc, _0x01);
                                WeaveRequestDataDelegate rdh = new WeaveRequestDataDelegate(md.rd);
                                rdh(soc, _0x01);
                                if (md.type == "once")
                                {
                                    listmode.Remove(md);
                                }
                            }
                        }
                    }
                    //根据具体功能不同,代码不同
                    //if (RequestDataEvent != null)
                    //    RequestDataEvent(soc, _0x01,_0x01.Request);
                }
            }
            catch (Exception ex)
            {
                _0x01.Parameter = ex.Message;
                message         = Newtonsoft.Json.JsonConvert.SerializeObject(_0x01);
                WeaveErrorMessageEvent(soc, _0x01, ex.Message);
            }
        }
 public bool Send(Socket soc, byte command, WeaveBase.WeaveSession b)
 {
     foreach (WeaveTcpToken itp in WeaveTcpTokenList)
     {
         if (itp.P2Server.Port == ((System.Net.IPEndPoint)soc.LocalEndPoint).Port)
         {
             if (itp.PortType == WeavePortTypeEnum.Bytes)
             {
                 return(itp.P2Server.Send(soc, command, itp.BytesDataparsing.Get_Byte(b)));
             }
         }
     }
     return(false);
 }
        public bool SendRoot <T>(Socket soc, byte command, String Request, T Root, int Querycount, String Tokan)
        {
            WeaveBase.WeaveSession b = new WeaveBase.WeaveSession();
            b.Request = Request;
            b.Token   = Tokan;
            b.SetRoot <T>(Root);
            b.Querycount = Querycount;
            bool sendok = Send(soc, command, b);

            if (!sendok)
            {
                return(Send(soc, command, b.Getjson()));
            }
            return(sendok);
        }
Exemple #8
0
        protected void ReloadFliesway(object obj)
        {
            try
            {
                foreach (WayItem ci in WayItemS)
                {
                    ci.Client.stop();
                }
                WayItemS.Clear();
                XmlDocument xml = new XmlDocument();
                xml.Load("nodeway.xml");
                foreach (XmlNode xn in xml.FirstChild.ChildNodes)
                {
                    WayItem ci = new WayItem();
                    ci.Ip     = xn.Attributes["ip"].Value;
                    ci.Port   = Convert.ToInt32(xn.Attributes["port"].Value);
                    ci.Token  = (xn.Attributes["token"].Value);
                    ci.Client = new P2Pclient(false);
                    ci.Client.receiveServerEvent += Client_receiveServerEvent;
                    ci.Client.timeoutobjevent    += Client_timeoutobjevent;

                    ci.Client.ErrorMge += Client_ErrorMge;
                    if (ci.Client.start(ci.Ip, ci.Port, false))
                    {
                        WeaveBase.WeaveSession oxff = new WeaveBase.WeaveSession();
                        oxff.Request = "token";
                        oxff.Root    = ci.Token;
                        ci.Client.send(0xff, oxff.Getjson());
                        WayItemS.Add(ci);
                    }
                    else
                    {
                        if (EventMylog != null)
                        {
                            EventMylog("从网关连接失败", "从网关:" + ci.Ip + ":节点连接失败,抛弃此节点");
                        }
                    }
                }
                System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(getwaynum));
            }
            catch (Exception ex)
            {
                if (EventMylog != null)
                {
                    EventMylog("加载异常", ex.Message);
                }
            }
        }
Exemple #9
0
 public void getwaynum(object obj)
 {
     while (true)
     {
         try
         {
             int       count  = WayItemS.Count;
             WayItem[] coobjs = new WayItem[count];
             WayItemS.CopyTo(0, coobjs, 0, count);
             foreach (WayItem wi in coobjs)
             {
                 WeaveBase.WeaveSession oxff = new WeaveBase.WeaveSession();
                 oxff.Request = "getnum";
                 oxff.Root    = wi.Token;
                 wi.Client.send(0xff, oxff.Getjson());
             }
         }
         catch { }
         System.Threading.Thread.Sleep(2000);
     }
 }
 public abstract void WeaveBaseErrorMessageEvent(Socket soc, WeaveBase.WeaveSession _0x01, string message);