Пример #1
0
 public void CheckComunication()
 {
     List<RealSignalRequest> ids = new List<RealSignalRequest>();
     RealSignalRequest rsr = new RealSignalRequest();
     rsr.Idx = 1;
     rsr.Id = 1;
     ids.Add(rsr);
     RealHostRequestItem di = new RealHostRequestItem(String.Empty, Guid.NewGuid(), DistributeTypeEnum.Signal);
     guid = di.DistributeId;
     Byte[] buffer = GetRequestBytes(ids, di);
     SendData(buffer);
 }
Пример #2
0
        /// <summary>
        /// 数据订阅方法,调用此方法来进行数据订阅。
        /// </summary>
        public bool Distribute(int DBHostIdx,int Idx)
        {
            //PageLogger.RecordDebugLog(String.Format("Distribute Signal DBHostIdx : {0} Idx : {1}", DBHostIdx, Idx));

            //获取实时服务器Id
            string realHostID = TCacheHostDetailDAL.Instance.GetCacheHostIdByDbHostId(DBHostIdx);
            RealHostRequestItem rhri=null;
            foreach (RealHostRequestItem o in m_CacheHostDistribute.Keys)
            {
                if (o.realHostID == realHostID)
                {
                    rhri = o;
                    break;
                }
            }
            if (rhri == null)
            {
                rhri = new RealHostRequestItem(realHostID, Guid.NewGuid(), DistributeTypeEnum.Signal);
                if (!m_CacheHostDistribute.ContainsKey(rhri))
                    m_CacheHostDistribute.Add(rhri, new List<DistributeItem>());
            }
                        
            DistributeItem nDi = new DistributeItem(DBHostIdx, Idx);
            nDi.realHostID = realHostID;
            List<RealSignalRequest> rsrs = new List<RealSignalRequest>();
            RealSignalRequest rsr = new RealSignalRequest();
            rsr.Idx = nDi.DBHostIdx;
            rsr.Id = nDi.Idx;
            rsrs.Add(rsr);
            nDi.ids = rsrs;

            bool hasExit = false;
            foreach (DistributeItem di in m_CacheHostDistribute[rhri])
            {
                if (di.DBHostIdx == DBHostIdx && di.Idx == Idx)
                {
                    di.LastVisit = DateTime.Now;
                    hasExit = true;
                    break;
                }
            }
            if (!hasExit)
            {
                m_CacheHostDistribute[rhri].Add(nDi);
                rhri.IdsModified = true;                
            }                       
            return true;
        }
Пример #3
0
 private void reSendData(RealHostRequestItem rhri)
 {           
     List<RealSignalRequest> rsrs = new List<RealSignalRequest>();
     foreach (DistributeItem dbi in m_CacheHostDistribute[rhri])
     {
         rsrs.AddRange(dbi.ids);
     }
     if (CommunicationManager.Instance.SignalSockets.ContainsKey(rhri.realHostID))
     {
         rhri.IdsModified = false;
         CommunicationManager.Instance.SignalSockets[rhri.realHostID].GetSignals(rsrs, rhri);
     }
 }
Пример #4
0
 public bool Equals(RealHostRequestItem o)
 {
     return o.realHostID == realHostID;
 }
Пример #5
0
 public bool Equals(RealHostRequestItem t1, RealHostRequestItem t2)
 {
     return t1.realHostID == t2.realHostID;
 }
Пример #6
0
 public void GetSignals(List<RealSignalRequest> ids, RealHostRequestItem di)
 {
     Byte[] buffer = GetRequestBytes(ids, di);
     SendData(buffer);           
 }
Пример #7
0
        /// <summary>
        /// 得到请求的内容
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        public Byte[] GetRequestContent(List<RealSignalRequest> ids, RealHostRequestItem di)
        {
            int contentLenBeforCompress = 8 * (ids.Count);
            Byte[] contentAHead = new Byte[39 + 1 + 4];

            guid = Guid.NewGuid();
            Encoding.ASCII.GetBytes("{" + di.DistributeId.ToString() + "}").CopyTo(contentAHead, 0);
            int communicationMode = int.Parse(ConfigurationManager.AppSettings["CommunicationMode"]);
            BitConverter.GetBytes(communicationMode).CopyTo(contentAHead, 39);
            BitConverter.GetBytes(contentLenBeforCompress).CopyTo(contentAHead, 40);

            Byte[] buffer = new Byte[contentLenBeforCompress];
            int i = 0;
            foreach (RealSignalRequest id in ids)
            {
                BitConverter.GetBytes(id.Id).CopyTo(buffer, i);
                i += 4;
                BitConverter.GetBytes(id.Idx).CopyTo(buffer, i);
                i += 4;
            }

            Byte[] contentCompressed = ZLibProvider.CompressBytes(buffer);
            Byte[] contetAll = new Byte[contentCompressed.Length + 44];
            Array.Copy(contentAHead, 0, contetAll, 0, contentAHead.Length);
            Array.Copy(contentCompressed, 0, contetAll, contentAHead.Length, contentCompressed.Length);
            return contetAll;
        }
Пример #8
0
 /// <summary>
 /// 得到请求包
 /// </summary>
 /// <param name="ids"></param>
 /// <returns></returns>
 public Byte[] GetRequestBytes(List<RealSignalRequest> ids, RealHostRequestItem di)
 {
     Byte[] buffer = GetRequestContent(ids, di);            
     buffer = AppendRequestHeader(buffer);
     return buffer;
 }