예제 #1
0
        private void CheckedAndSubscribe(bool isChecked, NormalParam param)
        {
            if (isChecked)
            {
                subsManager.Subscribe(param);
            }
            else
            {
                subsManager.UnSubscribe(param);

                var ko           = KeepOddsManager.Instance.AddOrGetKeepOdds(param.Stage);
                var closeSportId = param.SocketParam.condition.sporttype.Select(o => IbcTools.ConvertToSportId(o + "")).ToList();
                matchManager.ForEach(me =>
                {
                    if (me.Stage == param.Stage && closeSportId.Contains(me.SportID))
                    {
                        ko.RemoveBySrcMatchId(me.SrcMatchID); if (me.Stage == 3)
                        {
                            LiveInfoManager.Instance.RemoveBySrcMatchId(me.SrcMatchID, me.Stage);
                        }
                        me.MatchDisappear(me.Stage, param.LimitMarketIdList, true);
                    }
                });
            }
        }
예제 #2
0
        private MatchEntity DealMatchInfo(JToken jtoken, NormalParam normalParam)
        {
            try
            {
                //解析比赛信息
                var pmi = new ParseMatchInfo();
                pmi.CompareSet(jtoken);
                int         sportId = 0;
                MatchEntity me;
                if (pmi.SportType != null)
                {
                    sportId = IbcTools.ConvertToSportId(pmi.SportType);
                    if (sportId == 0)
                    {
                        return(null);
                    }

                    var matchDate = GetTime(pmi.KickOffTime);
                    matchDate = matchDate.AddSeconds(-matchDate.Second);
                    var diffMinutes = matchDate.Minute % 5;
                    matchDate = matchDate.AddMinutes(5 - diffMinutes);
                    var home = string.IsNullOrEmpty(pmi.HomeTeamNameExtension) ? pmi.HomeTeamName : pmi.HomeTeamName + "[" + pmi.HomeTeamNameExtension + "]";
                    var away = string.IsNullOrEmpty(pmi.AwayTeamNameExtension) ? pmi.AwayTeamName : pmi.AwayTeamName + "[" + pmi.AwayTeamNameExtension + "]";
                    if (sportId == 1 && pmi.Isneutral == "1")
                    {
                        home = home + " (N)";
                    }

                    me = matchEntityManager.GetOrAdd(pmi.MatchId, pmi.LeagueName, home, away, matchDate, sportId);

                    me.CompareToStage(normalParam.Stage);
                }
                else
                {
                    me = matchEntityManager.Get(pmi.MatchId);
                }

                if (me == null)
                {
                    logger.Error("DealMatchInfo Cannot find srcMatchId = " + pmi.MatchId);
                    return(null);
                }

                //  if stage = 3
                if (normalParam.Stage == 3 && !me.IsSelfCreate && (me.SportID == 1 || me.SportID == 2))
                {
                    var lti = new LiveInfo();
                    lti.SportId                 = me.SportID;
                    lti.SrcMatchId              = pmi.MatchId;
                    lti.HomeScore               = string.IsNullOrEmpty(pmi.LiveHomeScore) ? (int?)null : Convert.ToInt32(pmi.LiveHomeScore);
                    lti.AwayScore               = string.IsNullOrEmpty(pmi.LiveAwayScore) ? (int?)null : Convert.ToInt32(pmi.LiveAwayScore);
                    lti.HomeRed                 = string.IsNullOrEmpty(pmi.HomeRed) ? (int?)null : Convert.ToInt32(pmi.HomeRed);
                    lti.AwayRed                 = string.IsNullOrEmpty(pmi.AwayRed) ? (int?)null : Convert.ToInt32(pmi.AwayRed);
                    lti.Csstatus                = pmi.Csstatus;
                    lti.Liveperiod              = pmi.Liveperiod;
                    lti.PhaseStartUtc           = pmi.Livetimer;
                    lti.PhaseStartUtcUpdateTime = string.IsNullOrEmpty(pmi.Livetimer) ? (DateTime?)null : DateTime.Now;

                    var ret = LiveInfoManager.Instance.AddOrUpdate(lti);

                    if (me.SportID == 1)
                    {
                        me.CompareToScore(ret.HomeScore.Value, ret.AwayScore.Value);
                        me.CompareToCard(ret.HomeRed.Value, ret.AwayRed.Value);
                    }
                    else if (me.SportID == 2)
                    {
                        if (!string.IsNullOrEmpty(pmi.LiveScore))
                        {
                            var bkScore   = JsonConvert.DeserializeObject <BasketballScore>(pmi.LiveScore);
                            var homeScore = Convert.ToInt32(bkScore.h1q) + Convert.ToInt32(bkScore.h2q) +
                                            Convert.ToInt32(bkScore.h3q) + Convert.ToInt32(bkScore.h4q);
                            var awayScore = Convert.ToInt32(bkScore.a1q) + Convert.ToInt32(bkScore.a2q) +
                                            Convert.ToInt32(bkScore.a3q) + Convert.ToInt32(bkScore.a4q);
                            me.CompareToScore(homeScore, awayScore);
                        }
                    }
                    me.CompareToTime(ret.Phase.Value, ret.LiveTime(LiveInfoManager.Instance.IbcDiffSyncTime));
                }

                JsonSerializerSettings jsetting = new JsonSerializerSettings();
                jsetting.NullValueHandling = NullValueHandling.Ignore;
                var str = JsonConvert.SerializeObject(pmi, jsetting);

                Console.WriteLine("match = " + str);
                return(me);
            }
            catch (Exception e)
            {
                logger.Error(e.ToString());
                return(null);
            }
        }