Beispiel #1
0
 public void Clear()
 {
     this._curSceneQueue.Clear();
     this._highPriorityQueue.Clear();
     this._nextSceneQueue.Clear();
     this._lowQueue.Clear();
     _curSceneFailQueue.Clear();
     _highPriorityFailQueue.Clear();
     _nextSceneFailQueue.Clear();
     _lowFailQueue.Clear();
     _allFailQueue.Clear();
 }
Beispiel #2
0
 public void Clear()
 {
     if (this.InvokeRequired)
     {
         Invoke(new MethodInvoker(Clear));
         return;
     }
     listView1.Items.Clear();
     syncQueue.Clear();
 }
            void Update()
            {
                if (!_hasSyncItems)
                {
                    return;
                }
                lock (SyncLock) {
                    _syncBuffer.AddRange(SyncQueue);
                    SyncQueue.Clear();
                }

                foreach (var a in _syncBuffer)
                {
                    ExecuteSyncMethod(a);
                }
                _syncBuffer.Clear();
            }
Beispiel #4
0
        private static void ReaderThread(ThreadContext tc)
        {
            RemoveLiveMatches(eServerSourceType.BtrPre);
            RemoveLiveMatches(eServerSourceType.BtrLive);

            DateTime dtLastReceived = DateTime.Now;

            bool bDisabled       = false;
            bool bRemoved        = false;
            var  lineReseiveCopy = "";

            while (m_bRunning && !tc.IsToStop)
            {
                m_dtConnected = DateTime.Now;

                try
                {
                    string sServerMessage = "";

                    while (m_bRunning && !tc.IsToStop && m_liveClient.IsAlive)
                    {
                        lineReseiveCopy = LinesToReceive;

                        //if (m_liveClient.HaveData)
                        sServerMessage = m_liveClient.ReadLine();
                        ExcpHelper.ThrowIf(string.IsNullOrEmpty(sServerMessage), "Received Empty Message");

                        m_logger.Debug("received live message " + sServerMessage.Length);
                        m_liveClient.WriteLine(lineReseiveCopy);


                        if (sServerMessage == LIVEBET_MSG_HELLO || sServerMessage == LIVEBET_MSG_EMPTY)
                        {
                            m_logger.DebugFormat("Received '{0}'", sServerMessage);
                            dtLastReceived          = DateTime.Now;
                            LineSr.LiveBetConnected = true;
                        }
                        else
                        {
                            try
                            {
                                var originalLength = sServerMessage.Length;
                                if (sServerMessage.StartsWith(COMPRESSED))
                                {
                                    string sPrefix = sServerMessage.Substring(0, COMPRESSED_MASK_SIZE);

                                    string sSize = sPrefix.Substring(COMPRESSED.Length);

                                    int  iCompressedMessageSize = 0;
                                    bool bSizeParsed            = int.TryParse(sSize, out iCompressedMessageSize);
                                    Debug.Assert(bSizeParsed && iCompressedMessageSize > 0);
                                    //Debug.Assert(iCompressedMessageSize + COMPRESSED_MASK_SIZE == sServerMessage.Length);

                                    sServerMessage = TextUtil.DecompressBase64String(sServerMessage.Substring(COMPRESSED_MASK_SIZE));
                                }

                                int startIndex = sServerMessage.IndexOf('<');

                                ExcpHelper.ThrowIf(startIndex < 0, "Cannot find start xml point '<'");
                                sServerMessage = sServerMessage.Substring(startIndex);

                                TimeSpan tsDuration = DateTime.Now - m_dtConnected;

                                LineContainer lc = LineContainer.FromXml(sServerMessage);

                                ExcpHelper.ThrowIf <NullReferenceException>(lc == null, "LineContainer is Null");
                                //lc.Duration = tsDuration;
                                m_sqMessages.Enqueue(lc);

                                int iQueueCount = m_sqMessages.Count;

                                ExcpHelper.ThrowIf(iQueueCount > DalStationSettings.Instance.LiveErrorQueueSize, "Live Client Queue size ({0}) is too big.", iQueueCount);

                                if (iQueueCount > DalStationSettings.Instance.LiveWarnQueueSize)
                                {
                                    m_logger.Warn("Live Client Queue size = " + iQueueCount);
                                }

                                dtLastReceived = DateTime.Now;
                                bDisabled      = false;
                                bRemoved       = false;
                                string sType = lc.Attributes.ContainsKey("line") ? lc.Attributes["line"] : "none";

                                m_logger.DebugFormat("Enqueueing message {0} (Total messages in queue {1}; Connected {2}; Duration {3},type {4},length {5},compressedLength {6})", lc.GetDocId(), m_sqMessages.Count, m_dtConnected, tsDuration, sType, sServerMessage.Length, originalLength);
                            }
                            catch (Exception excp)
                            {
                                m_logger.Warn(ExcpHelper.FormatException(excp, "Could not process incoming server message (Size={0})", sServerMessage.Length));
                                throw;
                            }
                        }

                        LineSr.LiveBetConnected = true;
                        Thread.Sleep(10);
                    }
                }
                catch (Exception excp)
                {
                    m_logger.Error(excp.Message, excp);

                    m_sqMessages.Clear();
                    m_logger.Excp(excp, "Connection to server lost after importing time ({0}) ms bacause of {1}", DateTime.Now - m_dtConnected, excp.GetType());
                    LineSr.LiveBetConnected = false;
                }

                if (dtLastReceived + LIVE_TIME_OUT_TO_DISABLE < DateTime.Now && !bDisabled)
                {
                    LineSr.SyncRoutines(eUpdateType.LiveBet, "Connection lost. SportRadar LiveMarket is disabled.", DalStationSettings.Instance.UseDatabaseForLiveMatches, null, delegate(object obj)
                    {
                        LineSr.Instance.DisableLiveMatches(eServerSourceType.BtrLive);
                        return(false);
                    });


                    LineSr.ProcessDataSqlUpdateSucceeded(eUpdateType.LiveBet, "Connection lost. SportRadar LiveMarket is cleared.");

                    bDisabled = true;
                }
                else if (dtLastReceived + LIVE_TIME_OUT_TO_REMOVE < DateTime.Now && !bRemoved)
                {
                    m_logger.ErrorFormat("Removing all live matches because last message ('{0}') were too long time ago (TimeOut='{1}')", new Exception(), dtLastReceived, LIVE_TIME_OUT_TO_REMOVE);
                    RemoveLiveMatches(eServerSourceType.BtrPre);
                    RemoveLiveMatches(eServerSourceType.BtrLive);
                    bRemoved = true;
                }

                Thread.Sleep(10);

                EnsureConnection();
            }
        }