Exemplo n.º 1
0
        // 删除
        public static bool RemoveDtuCache(string dtuID)
        {
            bool r = dtusCache.TryRemove(dtuID, out DTUInfo dtuInfo);

            if (r)
            {
                TraceManager.AppendInfo(dtuID + "注销下线");
            }
            return(r);
        }
Exemplo n.º 2
0
        private void RegisterDTU(DTUInfo dtu)
        {
            string setOnlineSQL = string.Format(@" update DTUBase set                                     
                                                    [是否使用] ={0},        
                                                    [是否在线] ={1},
                                                    [登录时间] = '{2}',
                                                    [最后注册时间] ='{3}',
                                                    [终端IP地址] ='{4}',
                                                    [终端端口] ={5},
                                                    [网关IP地址] ='{6}',
                                                    [网关端口] ={7} 
                                                    where [终端登录号码] = '{8}'",
                                                dtu.IsUsed, dtu.IsActive, dtu.ActiveTime,
                                                dtu.LastRegisterTime, dtu.TerminalIP, dtu.TerminalPort,
                                                dtu.GatewayIP, dtu.GatewayPort, dtu.ID);
            int rows = DBUtil.ExecuteNonQuery(setOnlineSQL, out string err);

            if (!string.IsNullOrEmpty(err))
            {
                TraceManager.AppendErrMsg(dtu.ID + "数据链路同步到数据库失败");
                return;
            }
            if (rows == 0)
            {
                TraceManager.AppendInfo(dtu.ID + "数据库没有该条链路信息");
                return;
            }
            if (rows > 0)
            {
                string    sqlQuery = string.Format(@"SELECT TOP 1 [ID]
                                  ,[名称]
                                  ,[描述]
                                  ,[DTU厂家]
                                  ,[DTU型号]
                                  ,[DTU工作方式]
                                  ,[通信协议] 
                              FROM DTUBase where 终端登录号码='{0}'; ", dtu.ID);
                DataTable dt       = DBUtil.ExecuteDataTable(sqlQuery, out err);
                if (!string.IsNullOrEmpty(err))
                {
                    TraceManager.AppendErrMsg(dtu.ID + "数据库同步链路的业务信息失败");
                    return;
                }
                DataRow dr = dt.Rows[0];// 只查询一行,在条件里面可以不用担心出错
                dtu.DBID        = DataUtil.ToInt(dr["ID"]);
                dtu.Name        = DataUtil.ToString(dr["名称"]);
                dtu.Description = DataUtil.ToString(dr["描述"]);
                dtu.FactoryName = DataUtil.ToString(dr["DTU厂家"]);
                dtu.Model       = DataUtil.ToString(dr["DTU型号"]);
                dtu.WorkType    = DataUtil.ToString(dr["DTU工作方式"]);
                dtu.Protocol    = DTUInfo.GetProtocol(DataUtil.ToString(dr["通信协议"]));

                DTUCacheManager.OperDTUCache(DTUCacheManager.OPeratingType.Add, dtu, null);
            }
        }
Exemplo n.º 3
0
        // 增删改调度及事件触发
        public static bool OperDTUCache(OPeratingType type, object target, DTUInfo souceDTU)
        {
            try
            {
                switch (type)
                {
                case OPeratingType.Add:
                {
                    DTUInfo dtu = target as DTUInfo;
                    Add(dtu);
                    TriggerAdd(dtu);
                    TraceManager.AppendInfo(dtu.ID + "上线");
                    return(true);
                }

                case OPeratingType.UpdateSocketInfo:
                {
                    DTUInfo targetDTU = target as DTUInfo;
                    UpdateSocketInfo(targetDTU, souceDTU);
                    TriggerUpdateSocInfo(targetDTU);
                    return(true);
                }

                case OPeratingType.UpdateBSInfoMulti:
                {
                    DTUInfo[] dtus = target as DTUInfo[];
                    if (UpdateBSInfo(dtus))
                    {
                        TriggerUpdateMulti(dtus);
                        return(true);
                    }
                    else
                    {
                        TraceManager.AppendErrMsg("DTU缓存更新业务对象失败");
                        return(false);
                    }
                }

                case OPeratingType.Delete:
                {
                    string dtuID = target as String;
                    if (RemoveDtuCache(dtuID))
                    {
                        TriggerDelOne(dtuID);
                        TraceManager.AppendInfo(dtuID + "下线");
                        return(true);
                    }
                    else
                    {
                        TraceManager.AppendErrMsg("DTU缓存移除对象失败");
                        return(false);
                    }
                }

                default:
                    return(false);
                }
            }
            catch (Exception e)
            {
                TraceManager.AppendErrMsg("DTU缓存字典操作出错:" + e.Message);
                return(false);
            }
        }
Exemplo n.º 4
0
        private static void Excute(GPRS_DATA_RECORD item)
        {
            switch (item.m_data_type)
            {
            case 0x01:      // 注册包
                GPRS_USER_INFO userInfo = new GPRS_USER_INFO();
                if (HDDTUAPI.get_user_info(item.m_userid, ref userInfo) == 0)
                {
                    DTUInfo sourceDTU = DTUInfo.ToDTUInfoForSoc(userInfo);
                    if (sourceDTU == null)
                    {
                        return;
                    }
                    DTUInfo targetDTU = DTUCacheManager.GetDTUInfo(item.m_userid);
                    if (targetDTU == null)
                    {
                        // 首次注册--在DBWorker从数据读取业务信息添加到缓存
                        DBWorker.Append(DBCommand.CreateDtuRegister(sourceDTU));
                    }
                    else
                    {
                        // 更新链路
                        DTUCacheManager.OperDTUCache(DTUCacheManager.OPeratingType.UpdateSocketInfo, targetDTU, sourceDTU);
                    }
                }
                break;

            case 0x02:      // 注销包
            {
                DTUCacheManager.OperDTUCache(DTUCacheManager.OPeratingType.Delete, item.m_userid, null);
            }
            break;

            case 0x04:      // 无效包
                TraceManager.AppendInfo(item.m_userid + "---接收无效的数据包");
                break;

            case 0x05:      // DTU已经接收到DSC发送的用户数据包
                TraceManager.AppendInfo(item.m_userid + "---已经接收到DSC发送的用户数据包");
                break;

            case 0x09:      // 数据包
            {
                //TraceManager.AppendInfo("DTU:" + item.m_userid + "接收了" +
                //                       ByteUtil.BytesToText(item.m_data_buf, item.m_data_len)
                //                       + "--共计" + item.m_data_len.ToString() + "个字节");

                DTUInfo dtu = DTUCacheManager.GetDTUInfo(item.m_userid);
                if (dtu == null)
                {
                    return;
                }
                dtu.Analysis(item.m_data_buf, item.m_data_len);
            }
            break;

            case 0x0d:
                TraceManager.AppendInfo(item.m_userid + "---参数设置成功");
                break;

            case 0x0b:
                TraceManager.AppendInfo(item.m_userid + "---参数查询成功");
                //  config.readconf();
                break;

            case 0x06:
                TraceManager.AppendInfo("---断开PPP连接成功");
                break;

            case 0x07:
                TraceManager.AppendInfo(item.m_userid + "---停止向DSC发送数据");
                break;

            case 0x08:
                TraceManager.AppendInfo("---允许向DSC发送数据");
                break;

            case 0x0A:
                TraceManager.AppendInfo("---丢弃用户数据");
                break;

            default:
                break;
            }
        }