Пример #1
0
        public ErrCode LoadEpgData(ref Dictionary <UInt64, EpgServiceAllEventInfo> serviceDic, EpgViewPeriod period = null, IEnumerable <ulong> keys = null)
        {
            ErrCode err = ReloadEpgData();

            if (err != ErrCode.CMD_SUCCESS)
            {
                return(err);
            }

            bool noCurrent = period != null && IsEpgLoaded && period.End <= EventTimeMinCurrent;
            bool noArc     = period == null || EventTimeBaseArc != DateTime.MaxValue && period.End <= EventTimeBaseArc;

            serviceDic = ServiceEventList.ToDictionary(item => item.Key,
                                                       item => new EpgServiceAllEventInfo(item.Value.serviceInfo
                                                                                          , noCurrent ? null : item.Value.eventList, noArc ? null : item.Value.eventArcList));

            var list = new List <EpgServiceEventInfo>();

            if (period != null && period.StartLoad < EventTimeBaseArc)
            {
                EpgViewPeriod prLoad = new EpgViewPeriod(period.StartLoad, CommonUtil.Min(period.End, EventTimeBaseArc));

                //DB更新の判定
                DateTime EventTimeBaseArcMin = Settings.Instance.EpgSettingList.Min(set => new EpgViewPeriodDef(set).DefPeriod.StartLoad);
                bool     addDB = prLoad.End > EventTimeBaseArcMin;
                if (addDB)
                {
                    prLoad.Start = Settings.Instance.PrebuildEpg ? CommonUtil.Min(EventTimeBaseArcMin, prLoad.Start) : prLoad.Start;
                    prLoad.End   = EventTimeBaseArc;
                }

                err = LoadEpgArcData(prLoad.Start, prLoad.End, ref list, addDB ? null : keys);
                if (err != ErrCode.CMD_SUCCESS)
                {
                    return(err);
                }

                //リモコンIDの登録、サービス名の補正
                ChSet5.SetRemoconID(list.Select(info => info.serviceInfo), true);
                CorrectServiceInfo(list);
                EpgServiceAllEventInfo.AddArcEpgServiceDictionary(serviceDic, list);

                //DB更新。EventTimeBaseArcが毎回固定でなくて良いなら、この回の取得を全てキャッシュする手もある。
                ReloadWork(UpdateNotifyItem.EpgDataAdd, addDB, false, ret =>
                {
                    EventTimeBaseArc = CommonUtil.Max(EventTimeBaseArcMin, prLoad.Start);
                    if (prLoad.Start < EventTimeBaseArcMin)
                    {
                        foreach (var info in list)
                        {
                            info.eventList = info.eventList.FindAll(d => d.start_time >= EventTimeBaseArc);
                        }
                    }
                    EpgServiceAllEventInfo.AddArcEpgServiceDictionary(ServiceEventList, list);
                    foreach (var data in list.SelectMany(info => info.eventList))
                    {
                        EventUIDList[data.CurrentPgUID()] = data;//通常あり得ないがUID被りは後優先。
                    }
                    return(ret);
                });
            }

            //必要なら期間を適用。未適用でもリストは再作成される。
            foreach (var info in serviceDic.Values)
            {
                info.eventList    = PeriodApplied(info.eventList, period.StrictLoad ? period : null);
                info.eventArcList = PeriodApplied(info.eventArcList, period.StrictLoad ? period : null);
            }

            //イベントリストが空の場合もあるが、そのまま返す。
            return(err);
        }