/// <summary> /// 番組情報の再描画処理 /// </summary> private void ReloadProgramViewItemForSearch() { try { epgProgramView.ClearInfo(); timeList.Clear(); programList.Clear(); nowViewTimer.Stop(); serviceList.Clear(); //番組情報の検索 List<EpgSearchKeyInfo> keyList = new List<EpgSearchKeyInfo>(); keyList.Add(setViewInfo.SearchKey); List<EpgEventInfo> list = new List<EpgEventInfo>(); cmd.SendSearchPg(keyList, ref list); //サービス毎のリストに変換 Dictionary<UInt64, EpgServiceEventInfo> serviceEventList = new Dictionary<UInt64, EpgServiceEventInfo>(); foreach (EpgEventInfo eventInfo in list) { UInt64 id = CommonManager.Create64Key(eventInfo.original_network_id, eventInfo.transport_stream_id, eventInfo.service_id); EpgServiceEventInfo serviceInfo = null; if (serviceEventList.ContainsKey(id) == false) { if (ChSet5.Instance.ChList.ContainsKey(id) == false) { //サービス情報ないので無効 continue; } serviceInfo = new EpgServiceEventInfo(); serviceInfo.serviceInfo = CommonManager.ConvertChSet5To(ChSet5.Instance.ChList[id]); serviceEventList.Add(id, serviceInfo); } else { serviceInfo = serviceEventList[id]; } serviceInfo.eventList.Add(eventInfo); } foreach (UInt64 id in viewCustServiceList) { if (serviceEventList.ContainsKey(id) == true) { EpgServiceInfo serviceInfo = serviceEventList[id].serviceInfo; if (serviceList.Exists(i => i.ONID == serviceInfo.ONID && i.TSID == serviceInfo.TSID && i.SID == serviceInfo.SID) == false) { serviceList.Add(serviceInfo); } } } //必要番組の抽出と時間チェック List<EpgServiceInfo> primeServiceList = new List<EpgServiceInfo>(); int mergePos = 0; int mergeNum = 0; int servicePos = -1; for (int i = 0; i < serviceList.Count; i++) { //TSIDが同じでSIDが逆順に登録されているときは併合する int spanCheckNum = 1; if (--mergePos < i - mergeNum) { EpgServiceInfo curr = serviceList[i]; for (mergePos = i; mergePos + 1 < serviceList.Count; mergePos++) { EpgServiceInfo next = serviceList[mergePos + 1]; if (next.ONID != curr.ONID || next.TSID != curr.TSID || next.SID >= curr.SID) { break; } curr = next; } mergeNum = mergePos + 1 - i; servicePos++; //正順のときは貫きチェックするサービス数を調べる for (; mergeNum == 1 && i + spanCheckNum < serviceList.Count; spanCheckNum++) { EpgServiceInfo next = serviceList[i + spanCheckNum]; if (next.ONID != curr.ONID || next.TSID != curr.TSID) { break; } else if (next.SID < curr.SID) { spanCheckNum--; break; } curr = next; } primeServiceList.Add(serviceList[mergePos]); } EpgServiceInfo serviceInfo = serviceList[mergePos]; UInt64 id = CommonManager.Create64Key(serviceInfo.ONID, serviceInfo.TSID, serviceInfo.SID); foreach (EpgEventInfo eventInfo in serviceEventList[id].eventList) { if (eventInfo.StartTimeFlag == 0) { //開始未定は除外 continue; } //ジャンル絞り込み if (this.viewCustContentKindList.Count > 0) { bool find = false; if (eventInfo.ContentInfo != null) { if (eventInfo.ContentInfo.nibbleList.Count > 0) { foreach (EpgContentData contentInfo in eventInfo.ContentInfo.nibbleList) { UInt16 ID1 = (UInt16)(((UInt16)contentInfo.content_nibble_level_1) << 8 | 0xFF); UInt16 ID2 = (UInt16)(((UInt16)contentInfo.content_nibble_level_1) << 8 | contentInfo.content_nibble_level_2); if (this.viewCustContentKindList.ContainsKey(ID1) == true) { find = true; break; } else if (this.viewCustContentKindList.ContainsKey(ID2) == true) { find = true; break; } } } } if (find == false) { //ジャンル見つからないので除外 continue; } } //イベントグループのチェック int widthSpan = 1; if (eventInfo.EventGroupInfo != null) { bool spanFlag = false; foreach (EpgEventData data in eventInfo.EventGroupInfo.eventDataList) { if (serviceInfo.ONID == data.original_network_id && serviceInfo.TSID == data.transport_stream_id && serviceInfo.SID == data.service_id) { spanFlag = true; break; } } if (spanFlag == false) { //サービス2やサービス3の結合されるべきもの continue; } else { //横にどれだけ貫くかチェック int count = 1; while (mergeNum == 1 ? count < spanCheckNum : count < mergeNum - (mergeNum+i-mergePos-1)/2) { EpgServiceInfo nextInfo = serviceList[mergeNum == 1 ? i + count : mergePos - count]; bool findNext = false; foreach (EpgEventData data in eventInfo.EventGroupInfo.eventDataList) { if (nextInfo.ONID == data.original_network_id && nextInfo.TSID == data.transport_stream_id && nextInfo.SID == data.service_id) { widthSpan++; findNext = true; } } if (findNext == false) { break; } count++; } } } ProgramViewItem viewItem = new ProgramViewItem(eventInfo); viewItem.Height = ((eventInfo.DurationFlag == 0 ? 300 : eventInfo.durationSec) * Settings.Instance.MinHeight) / 60; viewItem.Width = Settings.Instance.ServiceWidth * widthSpan / mergeNum; viewItem.LeftPos = Settings.Instance.ServiceWidth * (servicePos + (double)((mergeNum+i-mergePos-1)/2) / mergeNum); //viewItem.TopPos = (eventInfo.start_time - startTime).TotalMinutes * Settings.Instance.MinHeight; programList.Add(viewItem); //日付チェック DateTime EndTime; if (eventInfo.DurationFlag == 0) { //終了未定 EndTime = eventInfo.start_time.AddSeconds(30 * 10); } else { EndTime = eventInfo.start_time.AddSeconds(eventInfo.durationSec); } //必要時間リストの構築 DateTime chkStartTime = new DateTime(eventInfo.start_time.Year, eventInfo.start_time.Month, eventInfo.start_time.Day, eventInfo.start_time.Hour, 0, 0); while (chkStartTime <= EndTime) { if (timeList.ContainsKey(chkStartTime) == false) { timeList.Add(chkStartTime, new List<ProgramViewItem>()); } chkStartTime = chkStartTime.AddHours(1); } } } //必要時間のチェック if (viewCustNeedTimeOnly == false) { //番組のない時間帯を追加 for (int i = 1; i < timeList.Count; i++) { if (timeList.Keys[i] > timeList.Keys[i - 1].AddHours(1)) { timeList.Add(timeList.Keys[i - 1].AddHours(1), new List<ProgramViewItem>()); } } //番組の表示位置設定 foreach (ProgramViewItem item in programList) { item.TopPos = (item.EventInfo.start_time - timeList.Keys[0]).TotalMinutes * Settings.Instance.MinHeight; } } else { //番組の表示位置設定 foreach (ProgramViewItem item in programList) { DateTime chkStartTime = new DateTime(item.EventInfo.start_time.Year, item.EventInfo.start_time.Month, item.EventInfo.start_time.Day, item.EventInfo.start_time.Hour, 0, 0); if (timeList.ContainsKey(chkStartTime) == true) { int index = timeList.IndexOfKey(chkStartTime); item.TopPos = (index * 60 + (item.EventInfo.start_time - chkStartTime).TotalMinutes) * Settings.Instance.MinHeight; } } } if (Settings.Instance.MinimumHeight > 0) { //最低表示行数を適用 programList.Sort((x, y) => Math.Sign(x.LeftPos - y.LeftPos) * 2 + Math.Sign(x.TopPos - y.TopPos)); double minimum = (Settings.Instance.FontSizeTitle + 2) * Settings.Instance.MinimumHeight; double lastLeft = double.MinValue; double lastBottom = 0; foreach (ProgramViewItem item in programList) { if (lastLeft != item.LeftPos) { lastLeft = item.LeftPos; lastBottom = double.MinValue; } item.Height = Math.Max(item.Height, minimum); if (item.TopPos < lastBottom) { item.Height = Math.Max(item.TopPos + item.Height - lastBottom, minimum); item.TopPos = lastBottom; } lastBottom = item.TopPos + item.Height; } } //必要時間リストと時間と番組の関連づけ foreach (ProgramViewItem item in programList) { int index = Math.Max((int)(item.TopPos / (60 * Settings.Instance.MinHeight)), 0); while (index < Math.Min((int)((item.TopPos + item.Height) / (60 * Settings.Instance.MinHeight)) + 1, timeList.Count)) { timeList.Values[index++].Add(item); } } epgProgramView.SetProgramList( programList, timeList, primeServiceList.Count() * Settings.Instance.ServiceWidth, timeList.Count * 60 * Settings.Instance.MinHeight); List<DateTime> dateTimeList = new List<DateTime>(); foreach (var item in timeList) { dateTimeList.Add(item.Key); } timeView.SetTime(dateTimeList, viewCustNeedTimeOnly, false); dateView.SetTime(dateTimeList); serviceView.SetService(primeServiceList); ReDrawNowLine(); } catch (Exception ex) { MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); } }
public static string Generate(DateTime StartTime, int MaxHour, List<ulong> ServiceKeys = null, int MinSize = 5, bool SetBgColor = true, bool IncludeNotEpg = false, bool EpgCapOnly = true, EpgSearchKeyInfo Search = null) { DateTime Start = ConvertDateTime(StartTime.AddSeconds(StartTime.Second * -1).AddMinutes(StartTime.Minute * -1)); DateTime End = Start.AddHours(MaxHour); StringBuilder sb = new StringBuilder(); StringBuilder sb1 = new StringBuilder(); sb1.Append("<div id=\"epg\">\n"); sb1.Append("<div id=\"header\">\n"); sb1.Append("<div class=\"time\">時間</div>\n"); //Select Item var Out = new Dictionary<EpgServiceInfo, List<EventInfoItem>>(); var List = new Dictionary<ulong, EpgServiceEventInfo>(); List<EpgServiceEventInfo> list = new List<EpgServiceEventInfo>(); ErrCode ret = (ErrCode)CommonManager.Instance.CtrlCmd.SendEnumPgAll(ref list); if (ret == ErrCode.CMD_SUCCESS) { foreach (EpgServiceEventInfo info in list) { UInt64 id = CommonManager.Create64Key( info.serviceInfo.ONID, info.serviceInfo.TSID, info.serviceInfo.SID); List.Add(id, info); } } else { return ""; } list.Clear(); list = null; if (Search != null) { Start = DateTime.MinValue; End = DateTime.MaxValue; List<EpgEventInfo> Events = new List<EpgEventInfo>(); var Res = CommonManager.Instance.CtrlCmd.SendSearchPg(new List<EpgSearchKeyInfo>() { Search }, ref Events); if ((ErrCode)Res != ErrCode.CMD_SUCCESS || Events.Count == 0) return ""; foreach (var item in List) { item.Value.eventList.Clear(); } foreach (var item in Events) { var Key = CommonManager.Create64Key(item.original_network_id, item.transport_stream_id, item.service_id); if (List.ContainsKey(Key)) { List[Key].eventList.Add(item); } else { if (!CommonManager.Instance.DB.ServiceEventList.ContainsKey(Key)) return ""; List[Key] = new EpgServiceEventInfo(); List[Key].serviceInfo = CommonManager.Instance.DB.ServiceEventList[Key].serviceInfo; List[Key].eventList = new List<EpgEventInfo>(); List[Key].eventList.Add(item); } } } foreach (var a in List) { if (a.Value.eventList.Count == 0) continue; if (ServiceKeys != null && ServiceKeys.Count != 0 && !ServiceKeys.Contains(a.Key)) continue; if (EpgCapOnly && (!ChSet5.Instance.ChList.ContainsKey(a.Key) || ChSet5.Instance.ChList[a.Key].EpgCapFlag != 1)) continue; if (Search == null) { var Events = a.Value.eventList .Where(x => x.ShortInfo != null) .Where(b => b.start_time < End && b.start_time.AddSeconds(b.durationSec) > Start) .OrderBy(d => d.start_time); Debug.Print("{0}: {1}", a.Value.serviceInfo.service_name, Events.Count()); if (Events.Count() == 0) continue; Out.Add( a.Value.serviceInfo, Events .Select(e => new EventInfoItem(e)) .ToList() ); } else { Out.Add( a.Value.serviceInfo, a.Value.eventList .Select(e => new EventInfoItem(e)) .ToList() ); } } SortedList<long, DateTime> TimeList = new SortedList<long, DateTime>(); foreach (var Item3 in Out.Values) { foreach (var Item2 in Item3) { var TempDate = ConvertDateTime(Item2.Start); var TempDate2 = ConvertDateTime(Item2.End); if (TempDate < Start) TempDate = Start; if (TempDate2 > End) TempDate2 = End; for (; TempDate < TempDate2; ) { long Unix = UnixTime.ToUnixTime(TempDate); TimeList[Unix] = TempDate; TempDate = TempDate.AddHours(1); } } } sb.Append("</div>\n<div id=\"body\">\n"); //Print Time sb.Append("<div id=\"timeline\" class=\"list\">\n"); for (int i = 0; i < TimeList.Values.Count; i++) { DateTime Temp = TimeList.Values[i]; string Text = (TimeList.Values.Count(s => s < Temp && s > Temp.AddHours(-1 * Temp.Hour)) == 0) ? "<p>" + Temp.Month + "/" + Temp.Day + "</p>" + Temp.Hour : Temp.Hour.ToString(); sb.AppendFormat("<div style=\"height:{1}px;top:{2}px;\">{0}</div>\n", Text, MinSize * 60, MinSize * 60 * i); } sb.Append("</div>\n"); //Print EPG foreach (var Item in Out) { StringBuilder sb2 = new StringBuilder(); sb2.AppendFormat("<div class=\"list\" ts=\"{0}\" on=\"{1}\" s=\"{2}\">", Item.Key.TSID, Item.Key.ONID, Item.Key.SID); if (Item.Value == null || Item.Value.Count == 0) { if (!IncludeNotEpg) continue; } else { DateTime OldTime = Start; int ItemCount = 0; foreach (var Event in Item.Value) { //Debug.Print("EPG Header {0}", Item.Key.service_name); if (Event.Short == null || !Event.StartFlg) continue; DateTime EventStart = Event.Start, EventEnd = Event.End; long Size = 0; OldTime = EventEnd; if (EventStart < Start) EventStart = Start; if (EventEnd > End) EventEnd = End; Size = (UnixTime.ToUnixTime(EventEnd) - UnixTime.ToUnixTime(EventStart)) / 60 * MinSize; if (Size <= 0) continue; string StartTimeStr = Event.Start.ToString("HH:mm"); var EventName = String.Format("{0} <span title=\"{1}\">{1}</span>\n<p>{2}</p>\n", StartTimeStr, HttpUtility.HtmlEncode(Event.Short.event_name), HttpUtility.HtmlEncode(Event.Short.text_char)); DateTime Time1 = ConvertDateTime(EventStart); long Top = 0; foreach (var Time2 in TimeList.Values) { if (Time1 == ConvertDateTime(Time2)) break; Top += MinSize * 60; } Top += ((UnixTime.ToUnixTime(EventStart) - UnixTime.ToUnixTime(Start)) % 3600) / 60 * MinSize; var Reserve = CommonManager.Instance.DB.ReserveList.Values.Where(s => s.EventID == Event.EID && s.ServiceID == Event.SID && s.TransportStreamID == Event.TSID && s.OriginalNetworkID == Event.ONID); string AddClass = (Reserve.Count() > 0) ? (Reserve.First().RecSetting.RecMode == 5 ? " disable-reserve" : " reserved") : ""; if (SetBgColor) { if (Event.Content != null && Event.Content.nibbleList != null && Event.Content.nibbleList.Count != 0 && Setting.Instance.ContentToColorTable .Count(s => s.ContentLevel1 == Event.Content.nibbleList[0].content_nibble_level_1) > 0) sb2.AppendFormat("<div class=\"event{4} ct-{6}\" e=\"{0}\" style=\"top:{3}px;min-height:{2}px;max-height:{2}px;z-index:{5};\">{1}</div>\n", Event.EID, EventName, Size, Top, AddClass, ItemCount, Event.Content.nibbleList[0].content_nibble_level_1); else sb2.AppendFormat("<div class=\"event{4}\" e=\"{0}\" style=\"top:{3}px;min-height:{2}px;max-height:{2}px;z-index:{5};\">{1}</div>\n", Event.EID, EventName, Size, Top, AddClass, ItemCount); } else { sb2.AppendFormat("<div class=\"event{4}\" e=\"{0}\" style=\"top:{3}px;min-height:{2}px;max-height:{2}px;z-index:{5};\">{1}</div>\n", Event.EID, EventName, Size, Top, AddClass, ItemCount); } ItemCount++; } sb.Append(sb2.ToString()); if (Item.Key.remote_control_key_id == 0) sb1.AppendFormat("<div>{0}<p>{1}</p></div>", Item.Key.service_name, Item.Key.network_name + " " + Item.Key.SID); else sb1.AppendFormat("<div>{0}<p>{1}</p></div>", Item.Key.service_name, Item.Key.remote_control_key_id); } sb.Append("</div>"); } sb.Append("</div>"); return sb1.ToString() + sb.ToString(); }
private void ReloadProgramViewItemForSearch() { try { if (lastChkSID != null && listBox_service.ItemsSource != null) { lastChkSID.Clear(); foreach (ServiceItem info in serviceList) { if (info.IsSelected == true) { lastChkSID.Add(info.ID, info.ID); } } } listBox_service.ItemsSource = null; serviceList.Clear(); //番組情報の検索 List<EpgSearchKeyInfo> keyList = new List<EpgSearchKeyInfo>(); keyList.Add(setViewInfo.SearchKey); List<EpgEventInfo> list = new List<EpgEventInfo>(); cmd.SendSearchPg(keyList, ref list); //サービス毎のリストに変換 serviceEventList.Clear(); foreach (EpgEventInfo eventInfo in list) { UInt64 id = CommonManager.Create64Key(eventInfo.original_network_id, eventInfo.transport_stream_id, eventInfo.service_id); EpgServiceEventInfo serviceInfo = null; if (serviceEventList.ContainsKey(id) == false) { if (ChSet5.Instance.ChList.ContainsKey(id) == false) { //サービス情報ないので無効 continue; } serviceInfo = new EpgServiceEventInfo(); serviceInfo.serviceInfo = CommonManager.ConvertChSet5To(ChSet5.Instance.ChList[id]); serviceEventList.Add(id, serviceInfo); } else { serviceInfo = serviceEventList[id]; } serviceInfo.eventList.Add(eventInfo); } foreach (UInt64 id in viewCustServiceList) { if (serviceEventList.ContainsKey(id) == true) { ServiceItem item = new ServiceItem(); item.ServiceInfo = serviceEventList[id].serviceInfo; item.IsSelected = true; if (lastChkSID != null) { if (lastChkSID.ContainsKey(id) == false) { item.IsSelected = false; } } serviceList.Add(item); } } if (lastChkSID == null) { lastChkSID = new Dictionary<ulong, ulong>(); } listBox_service.ItemsSource = serviceList; UpdateEventList(); } catch (Exception ex) { MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); } }
/// <summary> /// 番組情報の再描画処理 /// </summary> private void ReloadProgramViewItemForSearch() { try { epgProgramView.ClearInfo(); timeList.Clear(); dayList.Clear(); programList.Clear(); searchEventList.Clear(); nowViewTimer.Stop(); //番組情報の検索 List<EpgSearchKeyInfo> keyList = new List<EpgSearchKeyInfo>(); keyList.Add(setViewInfo.SearchKey); List<EpgEventInfo> list = new List<EpgEventInfo>(); cmd.SendSearchPg(keyList, ref list); //サービス毎のリストに変換 foreach (EpgEventInfo eventInfo in list) { UInt64 id = CommonManager.Create64Key(eventInfo.original_network_id, eventInfo.transport_stream_id, eventInfo.service_id); EpgServiceEventInfo serviceInfo = null; if (searchEventList.ContainsKey(id) == false) { if (ChSet5.Instance.ChList.ContainsKey(id) == false) { //サービス情報ないので無効 continue; } serviceInfo = new EpgServiceEventInfo(); serviceInfo.serviceInfo = CommonManager.ConvertChSet5To(ChSet5.Instance.ChList[id]); searchEventList.Add(id, serviceInfo); } else { serviceInfo = searchEventList[id]; } serviceInfo.eventList.Add(eventInfo); } //必要サービスの抽出 int selectIndex = 0; UInt64 selectID = 0; if (comboBox_service.SelectedItem != null) { ComboBoxItem item = comboBox_service.SelectedItem as ComboBoxItem; EpgServiceInfo serviceInfo = item.DataContext as EpgServiceInfo; selectID = CommonManager.Create64Key(serviceInfo.ONID, serviceInfo.TSID, serviceInfo.SID); } comboBox_service.Items.Clear(); foreach (UInt64 id in viewCustServiceList) { if (searchEventList.ContainsKey(id) == false) { //サービス情報ないので無効 continue; } ComboBoxItem item = new ComboBoxItem(); item.Content = searchEventList[id].serviceInfo.service_name; item.DataContext = searchEventList[id].serviceInfo; int index = comboBox_service.Items.Add(item); if (selectID == id || selectID == 0) { selectIndex = index; selectID = id; } } comboBox_service.SelectedIndex = selectIndex; //UpdateProgramView(); } catch (Exception ex) { MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); } }
private void ReloadProgramViewItemForSearch() { try { if (lastChkSID != null && listBox_service.ItemsSource != null) { lastChkSID.Clear(); foreach (ServiceItem info in serviceList) { if (info.IsSelected == true) { lastChkSID.Add(info.ID, info.ID); } } } listBox_service.ItemsSource = null; serviceList.Clear(); //番組情報の検索 List <EpgSearchKeyInfo> keyList = new List <EpgSearchKeyInfo>(); keyList.Add(setViewInfo.SearchKey); List <EpgEventInfo> list = new List <EpgEventInfo>(); cmd.SendSearchPg(keyList, ref list); //サービス毎のリストに変換 serviceEventList.Clear(); foreach (EpgEventInfo eventInfo in list) { UInt64 id = CommonManager.Create64Key(eventInfo.original_network_id, eventInfo.transport_stream_id, eventInfo.service_id); EpgServiceEventInfo serviceInfo = null; if (serviceEventList.ContainsKey(id) == false) { if (ChSet5.Instance.ChList.ContainsKey(id) == false) { //サービス情報ないので無効 continue; } serviceInfo = new EpgServiceEventInfo(); serviceInfo.serviceInfo = CommonManager.ConvertChSet5To(ChSet5.Instance.ChList[id]); serviceEventList.Add(id, serviceInfo); } else { serviceInfo = serviceEventList[id]; } serviceInfo.eventList.Add(eventInfo); } foreach (UInt64 id in viewCustServiceList) { if (serviceEventList.ContainsKey(id) == true) { ServiceItem item = new ServiceItem(); item.ServiceInfo = serviceEventList[id].serviceInfo; item.IsSelected = true; if (lastChkSID != null) { if (lastChkSID.ContainsKey(id) == false) { item.IsSelected = false; } } serviceList.Add(item); } } if (lastChkSID == null) { lastChkSID = new Dictionary <ulong, ulong>(); } listBox_service.ItemsSource = serviceList; UpdateEventList(); } catch (Exception ex) { MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); } }