コード例 #1
0
 private void StartConsumeThread(TopCometStreamRequest cometReq)
 {
     IStreamImplementation stream = null;
     try
     {
         stream = this.GetMsgStreamImpl(cometReq);
         if (cometReq.GetConnectListener() != null)
         {
             cometReq.GetConnectListener().OnConnect();
         }
     }
     catch (TopCometSysErrorException exception)
     {
         this.bstop = true;
         this.logger.Error(exception.Message);
         if (cometReq.GetConnectListener() != null)
         {
             cometReq.GetConnectListener().OnSysErrorException(exception);
         }
     }
     catch (Exception exception2)
     {
         this.bstop = true;
         this.logger.Error(exception2.Message);
         if (cometReq.GetConnectListener() != null)
         {
             cometReq.GetConnectListener().OnConnectError(exception2);
         }
     }
     this.lastStartConsumeThread = DateTime.Now.Ticks;
     new Thread(delegate {
         this.TopCometStreamConsume(this.lastStartConsumeThread, ref this.bstop, stream, cometReq.GetConnectListener());
     }) { Name = "top-stream-consume-thread" + cometReq.GetConnectId() }.Start();
 }
コード例 #2
0
 public IStreamImplementation GetMsgStreamImpl(TopCometStreamRequest cometReq)
 {
     if (cometReq != null)
     {
         cometReq.GetConnectListener().OnBeforeConnect();
     }
     TopDictionary parameters = new TopDictionary();
     parameters.Add("app_key", cometReq.GetAppkey());
     if (!string.IsNullOrEmpty(cometReq.GetUserId()))
     {
         parameters.Add("user", cometReq.GetUserId());
     }
     if (!string.IsNullOrEmpty(cometReq.GetConnectId()))
     {
         parameters.Add("id", cometReq.GetConnectId());
     }
     parameters.Add("timestamp", DateTime.Now.Ticks);
     IDictionary<string, string> otherParam = cometReq.GetOtherParam();
     if ((otherParam != null) && (otherParam.Count > 0))
     {
         IEnumerator<KeyValuePair<string, string>> enumerator = otherParam.GetEnumerator();
         while (enumerator.MoveNext())
         {
             KeyValuePair<string, string> current = enumerator.Current;
             KeyValuePair<string, string> pair2 = enumerator.Current;
             parameters.Add(current.Key, pair2.Value);
         }
     }
     string str = null;
     try
     {
         str = TopUtils.SignTopRequest(parameters, cometReq.GetSecret(), true);
         if (string.IsNullOrEmpty(str))
         {
             throw new Exception("Get sign error");
         }
     }
     catch (Exception exception)
     {
         throw exception;
     }
     parameters.Add("sign", str);
     HttpResponse response = new HttpClient(this.conf, parameters).Post();
     return (this.currentStreamImpl = new MessageStreamImpl(this.msgConsumeFactory, response, this.cometMessageListener, this));
 }