Ejemplo n.º 1
0
        private static void MetaSync(ThreadContext tc)
        {
            while (!tc.IsToStop)
            {

                if (StationRepository.IsPrematchEnabled)
                {
                    try
                    {
                        var stringsUpdateId = UpdateFileEntrySr.GetLastUpdate(eDataSyncCacheType.Metainfo);
                        var id = stringsUpdateId == null ? 0 : stringsUpdateId.DataSyncCacheID;

                        var updateline = WsdlRepository.GetMetainfo(StationRepository.StationNumber, id);
                        if (updateline != null && updateline.Length > 0)
                        {
                            ProviderHelper.UpdateDatabase(DateTime.Now, DalStationSettings.Instance.UseDatabaseForOthers, DataArrayToList(updateline));
                            LineSr.ProcessDataSqlUpdateSucceeded(eUpdateType.PreMatches, "SportRadar Metainfo Pre-Match Update.");
                        }

                        if (updateline != null && updateline.Length > 0)
                            continue;
                    }
                    catch (Exception)
                    {
                    }

                }

                var syncinterval = StationRepository.IsReady ? Convert.ToInt32(ConfigurationManager.AppSettings["METAINFO_SYNC_INTERVAL"]) : 1;

                Thread.Sleep(syncinterval * 1000);
            }
        }
Ejemplo n.º 2
0
        private static void StatisticsSync(ThreadContext tc)
        {
            while (!tc.IsToStop)
            {
                if (StationRepository.IsStatisticsEnabled)
                {
                    //get statistics
                    try
                    {
                        var stringsUpdateId = UpdateFileEntrySr.GetLastUpdate(eDataSyncCacheType.Statistic);
                        var id = stringsUpdateId == null ? 0 : stringsUpdateId.DataSyncCacheID;

                        var updateline = WsdlRepository.UpdateStatistics(StationRepository.StationNumber, id);
                        if (updateline != null && updateline.Length > 0)
                        {
                            ProviderHelper.UpdateDatabase(DateTime.Now, DalStationSettings.Instance.UseDatabaseForOthers, DataArrayToList(updateline));
                        }

                        if (updateline != null && updateline.Length > 0)
                        {
                            continue;
                        }
                    }
                    catch (Exception)
                    {
                    }
                }


                //get flags
                try
                {
                    var resourceUpdateId = UpdateFileEntrySr.GetLastUpdate(eDataSyncCacheType.Resources);
                    var id = resourceUpdateId == null ? 0 : resourceUpdateId.DataSyncCacheID;

                    var updateline = WsdlRepository.UpdateFlags(StationRepository.StationNumber, id);

                    if (updateline != null && updateline.Length > 0)
                    {
                        ProviderHelper.UpdateDatabase(DateTime.Now, DalStationSettings.Instance.UseDatabaseForOthers, DataArrayToList(updateline));
                        LineSr.ProcessDataSqlUpdateSucceeded(eUpdateType.PreMatches, "SportRadar Pre-Match Update.");
                    }
                }
                catch (Exception ex)
                {
                }

                var syncinterval = Convert.ToInt32(ConfigurationManager.AppSettings["STATIONPROPERTY_SYNC_INTERVAL"]);
                if (StationRepository.SyncInterval > 0)
                {
                    syncinterval = StationRepository.SyncInterval;
                }

                Thread.Sleep(syncinterval * 1000);
            }
        }
Ejemplo n.º 3
0
        private static void RemoveLiveMatches(eServerSourceType linetype) // DK - PreMatches means live that comes from LiveBetServer like Vfl, Vhc etc
        {
            m_logger.Warn("RemoveLiveMatches() been called.");

            LineSr.SyncRoutines(eUpdateType.LiveBet, "Connection lost. SportRadar LiveMarket is cleared.", DalStationSettings.Instance.UseDatabaseForLiveMatches, null, delegate(object obj)
            {
                return(LineSr.Instance.RemoveMatches(delegate(MatchLn match)
                {
                    if (match.SourceType == linetype && match.IsLiveBet.Value)
                    {
                        return true;
                    }

                    //Debug.Assert(false);
                    return false;
                }));
            });
            LineSr.ProcessDataSqlUpdateSucceeded(eUpdateType.LiveBet, "Connection lost. SportRadar LiveMarket is cleared.");
        }
Ejemplo n.º 4
0
        private static void WorkerThread(ThreadContext tc)
        {
            while (m_bRunning) //(!m_bImportError)
            {
                try
                {
                    int counter         = 0;
                    int iLiveQueueCount = m_sqMessages.Count;

                    if (!m_liveClient.IsAlive)
                    {
                        m_sqMessages.Clear();
                    }
                    else if (iLiveQueueCount > 0)
                    {
                        while (m_sqMessages.Count > 0)
                        {
                            counter++;

                            LineContainer lc = m_sqMessages.Dequeue();

                            eFileSyncResult fsr = eFileSyncResult.Failed;
                            Debug.Assert(lc != null);

                            try
                            {
                                string     sSrcTime  = lc.Attributes["srctime"];
                                DateTimeSr dtSrcTime = DateTimeSr.FromString(sSrcTime);
                                string     sSrcDelay = (DateTime.UtcNow - dtSrcTime.UtcDateTime).ToString();

                                string     sTime = lc.Attributes["time"];
                                DateTimeSr dt    = DateTimeSr.FromString(sTime);
                                TimeSpan   ts    = DateTime.UtcNow - dt.UtcDateTime;

                                string sType = lc.Attributes.ContainsKey("line") ? lc.Attributes["line"] : "none";

                                m_logger.InfoFormat("Queue={0} Delay={1} Size={2}", iLiveQueueCount, ts, lc.OriginalXml.Length);

                                if (ConfigurationManager.AppSettings["betradar_xml_files"] != null)
                                {
                                    SaveXml(lc, "Live");
                                }


                                fsr = LineSr.SyncRoutines(eUpdateType.LiveBet, string.Format("Host='{0}' Connected={1}; SrcDelay={2}; Delay={3}; Line={4}", m_sHost, DateTime.Now - m_dtConnected, sSrcDelay, ts, sType), DalStationSettings.Instance.UseDatabaseForLiveMatches, null, delegate(object objParam)
                                                          { return(ProviderHelperNew.MergeFromLineContainer(lc)); });
                            }
                            catch (Exception excp)
                            {
                                fsr = eFileSyncResult.Failed;
                                m_logger.Excp(excp, "WorkerThread() ERROR for {0}", lc);
                            }


                            if (fsr == eFileSyncResult.Failed)
                            {
                                m_liveClient.Disconnect();
                                RemoveLiveMatches(eServerSourceType.BtrPre);
                                RemoveLiveMatches(eServerSourceType.BtrLive);
                            }
                        }
                        LineSr.ProcessDataSqlUpdateSucceeded(eUpdateType.LiveBet, string.Format("liveUpdate {0} messages", counter));
                    }
                }
                catch (Exception excp)
                {
                    m_logger.Excp(excp, "WorkerThread() general ERROR");
                }

                Thread.Sleep(10);
            }
        }
Ejemplo n.º 5
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();
            }
        }
Ejemplo n.º 6
0
        private static void PreMatchSync(ThreadContext tc)
        {
            try
            {
                var arrUpdateRecords = WsdlRepository.GetLatestConfidenceFactorsUpdate(StationNumber);

                ProviderHelper.UpdateDatabase(DateTime.Now, DalStationSettings.Instance.UseDatabaseForOthers, DataArrayToList(arrUpdateRecords));
            }
            catch (Exception e)
            {
            }

            while (!tc.IsToStop)
            {
                int?iTotal = 0;

                try
                {
                    if (true)
                    {
                        /*
                         * using (StreamReader streamReader = new StreamReader(@"C:\Library\Data.xml", Encoding.UTF8))
                         * {
                         *  string sXml = streamReader.ReadToEnd();
                         *
                         *  SportRadarLineContainer srlc = SportRadarLineContainer.FromXmlString(sXml);
                         *
                         *  LineSr.SyncRoutines(eUpdateType.PreMatches, "Test", "None", null, delegate(object obj)
                         *  {
                         *      ProviderHelper.MergeFromSportRadarLineContainer(srlc);
                         *  });
                         * }
                         */

                        while (!StationRepository.IsReady)
                        {
                            Thread.Sleep(1000);
                        }

                        valueForm vf = null;
                        BsmHubConfigurationResponse bhcr = null;

                        string sStationNumber = StationNumber;

                        var            stringsUpdateId = UpdateFileEntrySr.GetLastUpdate(eDataSyncCacheType.String);
                        var            id = stringsUpdateId == null ? 0 : stringsUpdateId.DataSyncCacheID;
                        UpdateRecord[] arrUpdateRecords = WsdlRepository.UpdateLocalization(sStationNumber, id);
                        ProviderHelper.UpdateDatabase(DateTime.Now, DalStationSettings.Instance.UseDatabaseForOthers, DataArrayToList(arrUpdateRecords));
                        if (arrUpdateRecords != null && arrUpdateRecords.Length > 0)
                        {
                            DataCopy.UpdateLanguages();
                        }
                        // Lock Offer
                        long[] arrLockedTournamentIds = null;
                        long[] arrLockedOddIds        = WsdlRepository.GetLockedOffer(sStationNumber, out arrLockedTournamentIds);

                        // Sync Locked Odds
                        LineSr.Instance.LockedObjects.SyncLockedOdds(arrLockedOddIds);
                        int counter = 0;
                        do
                        {
                            var lastUpdateId = UpdateFileEntrySr.GetLastUpdate(eDataSyncCacheType.Match);
                            id = lastUpdateId == null ? 0 : lastUpdateId.DataSyncCacheID;
                            arrUpdateRecords = WsdlRepository.UpdateLine(sStationNumber, id, DateTime.MinValue, out iTotal);

                            if (iTotal > 0 && arrUpdateRecords != null)
                            {
                                iTotal = iTotal + arrUpdateRecords.Length;
                            }
                            DataCopy.UpdateProgressBar(iTotal);

                            ProviderHelper.UpdateDatabase(DateTime.Now, DalStationSettings.Instance.UseDatabaseForPreMatches, DataArrayToList(arrUpdateRecords));
                            LineSr.ProcessDataSqlUpdateSucceeded(eUpdateType.PreMatches, "SportRadar Pre-Match Update.");
                        } while (iTotal > 0 && counter++ < 100);

                        /*
                         * // Sync Locked Groups
                         * SyncList<long> lLockedGroupIds = new SyncList<long>();
                         *
                         * // Tournament IDs to Group IDs
                         * foreach (long lTournamentId in arrLockedTournamentIds)
                         * {
                         *  GroupLn group = LineSr.Instance.AllObjects.Groups.SafelyGetGroupByKeyName(GroupLn.GROUP_TYPE_GROUP_T, lTournamentId);
                         *
                         *  if (group != null)
                         *  {
                         *      lLockedGroupIds.SafelyAdd(group.GroupId);
                         *  }
                         * }
                         *
                         * LineSr.Instance.LockedObjects.SyncLockedGroups(lLockedGroupIds);
                         */
                    }
                }
                catch (Exception excp)
                {
                }
                var syncinterval = Convert.ToInt32(ConfigurationManager.AppSettings["STATIONPROPERTY_SYNC_INTERVAL"]);
                if (StationRepository.SyncInterval > 0)
                {
                    syncinterval = StationRepository.SyncInterval;
                }
                if (iTotal > 0)
                {
                    syncinterval = 0;
                }
                Thread.Sleep(syncinterval * 1000);
            }
        }