public void RemoveAllAttendancesOfEvent(Event anEvent) { SqlBuilder sb = new SqlBuilder(StatementType.Delete, typeof(Attendance)); sb.AddConstraint(Operator.Equals, "id_event", anEvent.Id); SqlStatement stmt = sb.GetStatement(true); stmt.Execute(); }
public void RemoveAllAttendancesOfPerson(Person aPerson) { SqlBuilder sb = new SqlBuilder(StatementType.Delete, typeof(Attendance)); sb.AddConstraint(Operator.Equals, "id_person", aPerson.Id); SqlStatement stmt = sb.GetStatement(true); stmt.Execute(); }
public void OnActivated() { try { Application.DoEvents(); Cursor.Current = Cursors.WaitCursor; UpdateMenuAndTabs(); listView1.Items.Clear(); SqlBuilder sb = new SqlBuilder(StatementType.Select, typeof (GroupMap)); sb.AddConstraint(Operator.Equals, "idGroup", _channelGroup.IdGroup); sb.AddOrderByField(true, "sortOrder"); SqlStatement stmt = sb.GetStatement(true); IList<GroupMap> maps = ObjectFactory.GetCollection<GroupMap>(stmt.Execute()); foreach (GroupMap map in maps) { Channel channel = map.ReferencedChannel(); if (!channel.IsTv) { continue; } listView1.Items.Add(CreateItemForChannel(channel, map)); } bool isAllChannelsGroup = (_channelGroup.GroupName == TvConstants.TvGroupNames.AllChannels); removeChannelFromGroup.Enabled = !isAllChannelsGroup; mpButtonDel.Enabled = !isAllChannelsGroup; if (_channelGroup.GroupName != TvConstants.TvGroupNames.AllChannels) { labelPinCode.Visible = true; textBoxPinCode.Visible = true; textBoxPinCode.Text = _channelGroup.PinCode; } } catch (Exception exp) { Log.Error("OnActivated error: {0}", exp.Message); } finally { Cursor.Current = Cursors.Default; } }
private void CreateShareForm_Load(object sender, EventArgs e) { _channelNameLabel.Text = this.Channel.DisplayName; LoadGroups(); LinkedMediaPortalChannel linkedChannel = ChannelLinks.GetLinkedMediaPortalChannel(this.Channel); if (linkedChannel != null) { SqlBuilder sb = new SqlBuilder(StatementType.Select, typeof(TvDatabase.GroupMap)); sb.AddConstraint(Operator.Equals, "idChannel", linkedChannel.Id); SqlResult result = Broker.Execute(sb.GetStatement()); List<TvDatabase.GroupMap> groupMaps = (List<TvDatabase.GroupMap>) ObjectFactory.GetCollection(typeof(TvDatabase.GroupMap), result, new List<TvDatabase.GroupMap>()); if (groupMaps.Count > 0) { foreach (ListViewItem item in _groupsListView.Items) { if (item.Tag is int && (int)item.Tag == groupMaps[0].IdGroup) { item.Selected = true; _groupsListView.EnsureVisible(item.Index); break; } else { item.Selected = false; } } foreach (ListViewItem item in _channelsListView.Items) { ChannelItem channelItem = item.Tag as ChannelItem; if (channelItem.Channel.IdChannel == linkedChannel.Id) { item.Selected = true; _channelsListView.EnsureVisible(item.Index); break; } else { item.Selected = false; } } } } }
protected override void OnPageLoad() { Log.Debug("zaposd pageload"); // following line should stay. Problems with OSD not // appearing are already fixed elsewhere SqlBuilder sb = new SqlBuilder(StatementType.Select, typeof (Channel)); sb.AddConstraint(Operator.Equals, "istv", 1); sb.AddOrderByField(true, "sortOrder"); SqlStatement stmt = sb.GetStatement(true); ObjectFactory.GetCollection(typeof (Channel), stmt.Execute()); AllocResources(); // if (g_application.m_pPlayer) g_application.m_pPlayer.ShowOSD(false); ResetAllControls(); // make sure the controls are positioned relevant to the OSD Y offset m_bNeedRefresh = false; m_dateTime = DateTime.Now; channelNr = GetChannelNumber(); channelName = GetChannelName(); idChannel = GetIdChannel(); SetCurrentChannelLogo(); base.OnPageLoad(); GUIPropertyManager.SetProperty("#currentmodule", GUILocalizeStrings.Get(100000 + GetID)); }
/// <summary> /// Retreives the first found instance of a 'Once' typed schedule given its Channel,Title,Start and End Times /// </summary> /// <param name="idChannel">Channel id to look for</param> /// <param name="programName">Title we wanna look for</param> /// <param name="startTime">StartTime</param> /// <param name="endTime">EndTime</param> /// <returns>schedule instance or null</returns> public static Schedule RetrieveOnce(int idChannel, string programName, DateTime startTime, DateTime endTime) { //select * from 'foreigntable' SqlBuilder sb = new SqlBuilder(StatementType.Select, typeof (Schedule)); // sb.AddConstraint(Operator.Equals, "scheduleType", 0); sb.AddConstraint(Operator.Equals, "idChannel", idChannel); sb.AddConstraint(Operator.Equals, "programName", programName); sb.AddConstraint(Operator.Equals, "startTime", startTime); sb.AddConstraint(Operator.Equals, "endTime", endTime); // passing true indicates that we'd like a list of elements, i.e. that no primary key // constraints from the type being retrieved should be added to the statement SqlStatement stmt = sb.GetStatement(true); // execute the statement/query and create a collection of User instances from the result set IList<Schedule> getList = ObjectFactory.GetCollection<Schedule>(stmt.Execute()); if (getList.Count != 0) { return getList[0]; } return null; // TODO In the end, a GentleList should be returned instead of an arraylist //return new GentleList( typeof(ChannelMap), this ); }
/// <summary> /// Get a list of Conflicts referring to the current entity. /// </summary> public IList<Conflict> ConflictingSchedules() { //select * from 'foreigntable' SqlBuilder sb = new SqlBuilder(StatementType.Select, typeof (Conflict)); // where foreigntable.foreignkey = ourprimarykey sb.AddConstraint(Operator.Equals, "idConflictingSchedule", idSchedule); // passing true indicates that we'd like a list of elements, i.e. that no primary key // constraints from the type being retrieved should be added to the statement SqlStatement stmt = sb.GetStatement(true); // execute the statement/query and create a collection of User instances from the result set return ObjectFactory.GetCollection<Conflict>(stmt.Execute()); // TODO In the end, a GentleList should be returned instead of an arraylist //return new GentleList( typeof(CanceledSchedule), this ); }
/// <summary> /// Provides a wrapper for getting the channel by Name from the database. /// </summary> /// <param name="channelName">Channel Name.</param> /// <param name="idTvChannel">The id tv channel.</param> /// <returns>true if the channel name was found</returns> protected bool GetChannelByName(string channelName, out int idTvChannel) { //Channel fch = Channel.Retrieve( idTvChannel = -1; SqlBuilder sb = new SqlBuilder(StatementType.Select, typeof(Channel)); sb.AddConstraint(Operator.Equals, "displayName", channelName.ToString()); SqlStatement stmt = sb.GetStatement(true); System.Collections.IList chList = ObjectFactory.GetCollection(typeof(Channel), stmt.Execute()); if (chList.Count > 0) { idTvChannel = ((Channel)chList[0]).IdChannel; return true; } return false; }
public static Schedule FindNoEPGSchedule(Channel channel) { int idChannel = channel.IdChannel; //select * from 'foreigntable' SqlBuilder sb = new SqlBuilder(StatementType.Select, typeof (Schedule)); // sb.AddConstraint(Operator.Equals, "scheduleType", 0); sb.AddConstraint(Operator.Equals, "idChannel", idChannel); sb.AddConstraint(Operator.Equals, "idParentSchedule", -1); sb.AddConstraint(Operator.Equals, "series", false); // passing true indicates that we'd like a list of elements, i.e. that no primary key // constraints from the type being retrieved should be added to the statement SqlStatement stmt = sb.GetStatement(true); // execute the statement/query and create a collection of User instances from the result set IList<Schedule> getList = ObjectFactory.GetCollection<Schedule>(stmt.Execute()); if (getList.Count != 0) { return getList[0]; } return null; }
/// <summary> /// Retrieves an entity given it's filename. /// </summary> public static Recording Retrieve(string fileName) { // Return null if id is smaller than seed and/or increment for autokey if (string.IsNullOrEmpty(fileName)) { return null; } SqlBuilder sb = new SqlBuilder(StatementType.Select, typeof (Recording)); sb.AddConstraint(Operator.Equals, "fileName", fileName); SqlStatement stmt = sb.GetStatement(true); // execute the statement/query and create a collection of User instances from the result set IList<Recording> getList = ObjectFactory.GetCollection<Recording>(stmt.Execute()); if (getList.Count != 0) { return getList[0]; } return null; }
public override bool OnMessage(GUIMessage message) { switch (message.Message) { case GUIMessage.MessageType.GUI_MSG_WINDOW_DEINIT: // fired when OSD is hidden { //if (g_application.m_pPlayer) g_application.m_pPlayer.ShowOSD(true); // following line should stay. Problems with OSD not // appearing are already fixed elsewhere //for (int i = (int)Controls.Panel1; i < (int)Controls.Panel2; i++) //{ // HideControl(GetID, i); //} Dispose(); GUIPropertyManager.SetProperty("#currentmodule", GUIWindowManager.GetWindow(message.Param1).GetModuleName()); return true; } case GUIMessage.MessageType.GUI_MSG_WINDOW_INIT: // fired when OSD is shown { // following line should stay. Problems with OSD not // appearing are already fixed elsewhere SqlBuilder sb = new SqlBuilder(StatementType.Select, typeof (Channel)); sb.AddConstraint(Operator.Equals, "istv", 1); sb.AddOrderByField(true, "sortOrder"); SqlStatement stmt = sb.GetStatement(true); listTvChannels = ObjectFactory.GetCollection(typeof (Channel), stmt.Execute()); GUIPropertyManager.SetProperty("#currentmodule", GetModuleName()); previousProgram = null; AllocResources(); // if (g_application.m_pPlayer) g_application.m_pPlayer.ShowOSD(false); ResetAllControls(); // make sure the controls are positioned relevant to the OSD Y offset isSubMenuVisible = false; m_iActiveMenuButtonID = 0; m_iActiveMenu = 0; m_bNeedRefresh = false; m_dateTime = DateTime.Now; Reset(); FocusControl(GetID, (int)Controls.OSD_PLAY, 0); // set focus to play button by default when window is shown ShowPrograms(); QueueAnimation(AnimationType.WindowOpen); for (int i = (int)Controls.Panel1; i < (int)Controls.Panel2; i++) { ShowControl(GetID, i); } if (g_Player.Paused) { ToggleButton((int)Controls.OSD_PLAY, true); // make sure play button is down (so it shows the pause symbol) } else { ToggleButton((int)Controls.OSD_PLAY, false); // make sure play button is up (so it shows the play symbol) } m_delayInterval = MediaPortal.Player.Subtitles.SubEngine.GetInstance().DelayInterval; if (m_delayInterval > 0) m_subtitleDelay = MediaPortal.Player.Subtitles.SubEngine.GetInstance().Delay / m_delayInterval; m_delayIntervalAudio = PostProcessingEngine.GetInstance().AudioDelayInterval; if (m_delayIntervalAudio > 0) m_audioDelay = PostProcessingEngine.GetInstance().AudioDelay / m_delayIntervalAudio; g_Player.UpdateMediaInfoProperties(); GUIPropertyManager.SetProperty("#TV.View.HasTeletext", TVHome.Card.HasTeletext.ToString()); MediaPortal.Player.VideoStreamFormat videoFormat = g_Player.GetVideoFormat(); GUIPropertyManager.SetProperty("#Play.Current.TSBitRate", ((float)MediaPortal.Player.g_Player.GetVideoFormat().bitrate / 1024 / 1024).ToString("0.00", CultureInfo.InvariantCulture)); GUIPropertyManager.SetProperty("#Play.Current.VideoFormat.RawResolution", videoFormat.width.ToString() + "x" + videoFormat.height.ToString()); GUIPropertyManager.SetProperty("#TV.TuningDetails.FreeToAir", string.Empty); Channel chan = TVHome.Navigator.Channel; if (chan != null) { IList<TuningDetail> details = chan.ReferringTuningDetail(); if (details.Count > 0) { TuningDetail detail = null; switch (TVHome.Card.Type) { case TvLibrary.Interfaces.CardType.Analog: foreach (TuningDetail t in details) { if (t.ChannelType == 0) detail = t; } break; case TvLibrary.Interfaces.CardType.Atsc: foreach (TuningDetail t in details) { if (t.ChannelType == 1) detail = t; } break; case TvLibrary.Interfaces.CardType.DvbC: foreach (TuningDetail t in details) { if (t.ChannelType == 2) detail = t; } break; case TvLibrary.Interfaces.CardType.DvbS: foreach (TuningDetail t in details) { if (t.ChannelType == 3) detail = t; } break; case TvLibrary.Interfaces.CardType.DvbT: foreach (TuningDetail t in details) { if (t.ChannelType == 4) detail = t; } break; default: detail = details[0]; break; } GUIPropertyManager.SetProperty("#TV.TuningDetails.FreeToAir", detail.FreeToAir.ToString()); } } } return true; case GUIMessage.MessageType.GUI_MSG_SETFOCUS: goto case GUIMessage.MessageType.GUI_MSG_LOSTFOCUS; case GUIMessage.MessageType.GUI_MSG_LOSTFOCUS: { if (message.SenderControlId == 13) { return true; } } break; case GUIMessage.MessageType.GUI_MSG_CLICKED: { int iControl = message.SenderControlId; // get the ID of the control sending us a message if (iControl == btnChannelUp.GetID) { OnNextChannel(); } if (iControl == btnChannelDown.GetID) { OnPreviousChannel(); } if (!g_Player.IsTVRecording) { if (iControl == btnPreviousProgram.GetID) { Program prog = GetChannel().GetProgramAt(m_dateTime); if (prog != null) { prog = GetChannel().GetProgramAt( prog.StartTime.Subtract(new TimeSpan(0, 1, 0))); if (prog != null) { m_dateTime = prog.StartTime.AddMinutes(1); } } ShowPrograms(); } if (iControl == btnNextProgram.GetID) { Program prog = GetChannel().GetProgramAt(m_dateTime); if (prog != null) { prog = GetChannel().GetProgramAt(prog.EndTime.AddMinutes(+1)); if (prog != null) { m_dateTime = prog.StartTime.AddMinutes(1); } } ShowPrograms(); } } if (iControl >= (int)Controls.OSD_VOLUMESLIDER) // one of the settings (sub menu) controls is sending us a message { Handle_ControlSetting(iControl, message.Param1); } if (iControl == (int)Controls.OSD_PAUSE) { if (g_Player.Paused) { ToggleButton((int)Controls.OSD_PLAY, true); // make sure play button is down (so it shows the pause symbol) ToggleButton((int)Controls.OSD_FFWD, false); // pop the button back to it's up state ToggleButton((int)Controls.OSD_REWIND, false); // pop the button back to it's up state } else { ToggleButton((int)Controls.OSD_PLAY, false); // make sure play button is up (so it shows the play symbol) if (g_Player.Speed < 1) // are we not playing back at normal speed { ToggleButton((int)Controls.OSD_REWIND, true); // make sure out button is in the down position ToggleButton((int)Controls.OSD_FFWD, false); // pop the button back to it's up state } else { ToggleButton((int)Controls.OSD_REWIND, false); // pop the button back to it's up state if (g_Player.Speed == 1) { ToggleButton((int)Controls.OSD_FFWD, false); // pop the button back to it's up state } } } } if (iControl == (int)Controls.OSD_PLAY) { //TODO int iSpeed = g_Player.Speed; if (iSpeed != 1) // we're in ffwd or rewind mode { g_Player.Speed = 1; // drop back to single speed ToggleButton((int)Controls.OSD_REWIND, false); // pop all the relevant ToggleButton((int)Controls.OSD_FFWD, false); // buttons back to ToggleButton((int)Controls.OSD_PLAY, false); // their up state } else { g_Player.Pause(); // Pause/Un-Pause playback if (g_Player.Paused) { ToggleButton((int)Controls.OSD_PLAY, true); // make sure play button is down (so it shows the pause symbol) } else { ToggleButton((int)Controls.OSD_PLAY, false); // make sure play button is up (so it shows the play symbol) } } } if (iControl == (int)Controls.OSD_STOP) { if (isSubMenuVisible) // sub menu currently active ? { FocusControl(GetID, m_iActiveMenuButtonID, 0); // set focus to last menu button ToggleSubMenu(0, m_iActiveMenu); // hide the currently active sub-menu } //g_application.m_guiWindowFullScreen.m_bOSDVisible = false; // toggle the OSD off so parent window can de-init Log.Debug("TVOSD:stop"); if (TVHome.Card.IsRecording) { int id = TVHome.Card.RecordingScheduleId; if (id > 0) { TVHome.TvServer.StopRecordingSchedule(id); } } //GUIWindowManager.ShowPreviousWindow(); // go back to the previous window } if (iControl == (int)Controls.OSD_REWIND) { if (g_Player.Paused) { g_Player.Pause(); // Unpause playback } if (g_Player.Speed < 1) // are we not playing back at normal speed { ToggleButton((int)Controls.OSD_REWIND, true); // make sure out button is in the down position ToggleButton((int)Controls.OSD_FFWD, false); // pop the button back to it's up state } else { ToggleButton((int)Controls.OSD_REWIND, false); // pop the button back to it's up state if (g_Player.Speed == 1) { ToggleButton((int)Controls.OSD_FFWD, false); // pop the button back to it's up state } } } if (iControl == (int)Controls.OSD_FFWD) { if (g_Player.Paused) { g_Player.Pause(); // Unpause playback } if (g_Player.Speed > 1) // are we not playing back at normal speed { ToggleButton((int)Controls.OSD_FFWD, true); // make sure out button is in the down position ToggleButton((int)Controls.OSD_REWIND, false); // pop the button back to it's up state } else { ToggleButton((int)Controls.OSD_FFWD, false); // pop the button back to it's up state if (g_Player.Speed == 1) { ToggleButton((int)Controls.OSD_REWIND, false); // pop the button back to it's up state } } } if (iControl == (int)Controls.OSD_SKIPBWD) { if (_immediateSeekIsRelative) { g_Player.SeekRelativePercentage(-_immediateSeekValue); } else { g_Player.SeekRelative(-_immediateSeekValue); } ToggleButton((int)Controls.OSD_SKIPBWD, false); // pop the button back to it's up state } if (iControl == (int)Controls.OSD_SKIPFWD) { if (_immediateSeekIsRelative) { g_Player.SeekRelativePercentage(_immediateSeekValue); } else { g_Player.SeekRelative(_immediateSeekValue); } ToggleButton((int)Controls.OSD_SKIPFWD, false); // pop the button back to it's up state } if (iControl == (int)Controls.OSD_MUTE) { ToggleSubMenu(iControl, (int)Controls.OSD_SUBMENU_BG_VOL); // hide or show the sub-menu if (isSubMenuVisible) // is sub menu on? { int iValue = g_Player.Volume; GUISliderControl pSlider = GetControl((int)Controls.OSD_VOLUMESLIDER) as GUISliderControl; if (null != pSlider) { pSlider.Percentage = iValue; // Update our volume slider accordingly ... } ShowControl(GetID, (int)Controls.OSD_VOLUMESLIDER); // show the volume control ShowControl(GetID, (int)Controls.OSD_VOLUMESLIDER_LABEL); FocusControl(GetID, (int)Controls.OSD_VOLUMESLIDER, 0); // set focus to it } else // sub menu is off { FocusControl(GetID, (int)Controls.OSD_MUTE, 0); // set focus to the mute button } } if (iControl == (int)Controls.OSD_SUBTITLES) { ToggleSubMenu(iControl, (int)Controls.OSD_SUBMENU_BG_SUBTITLES); // hide or show the sub-menu if (isSubMenuVisible) { // set the controls values GUISliderControl pControl = (GUISliderControl)GetControl((int)Controls.OSD_SUBTITLE_DELAY); pControl.SpinType = GUISpinControl.SpinType.SPIN_CONTROL_TYPE_FLOAT; pControl.FloatInterval = 1; pControl.SetRange(-10, 10); SetSliderValue(-10, 10, m_subtitleDelay, (int)Controls.OSD_SUBTITLE_DELAY); SetCheckmarkValue(g_Player.EnableSubtitle, (int)Controls.OSD_SUBTITLE_ONOFF); // show the controls on this sub menu ShowControl(GetID, (int)Controls.OSD_SUBTITLE_DELAY); ShowControl(GetID, (int)Controls.OSD_SUBTITLE_DELAY_LABEL); ShowControl(GetID, (int)Controls.OSD_SUBTITLE_ONOFF); ShowControl(GetID, (int)Controls.OSD_SUBTITLE_LIST); FocusControl(GetID, (int)Controls.OSD_SUBTITLE_DELAY, 0); // set focus to the first control in our group PopulateSubTitles(); // populate the list control with subtitles for this video } } if (iControl == (int)Controls.OSD_BOOKMARKS) { //not used } if (iControl == (int)Controls.OSD_VIDEO) { ToggleSubMenu(iControl, (int)Controls.OSD_SUBMENU_BG_VIDEO); // hide or show the sub-menu if (isSubMenuVisible) // is sub menu on? { // set the controls values float fPercent = (float)(100 * (g_Player.CurrentPosition / g_Player.Duration)); SetSliderValue(0.0f, 100.0f, (float)fPercent, (int)Controls.OSD_VIDEOPOS); bool hasPostProc = g_Player.HasPostprocessing; if (hasPostProc) { IPostProcessingEngine engine = PostProcessingEngine.GetInstance(); SetCheckmarkValue(engine.EnablePostProcess, (int)Controls.OSD_VIDEO_POSTPROC_DEBLOCK_ONOFF); SetCheckmarkValue(engine.EnableResize, (int)Controls.OSD_VIDEO_POSTPROC_RESIZE_ONOFF); SetCheckmarkValue(engine.EnableCrop, (int)Controls.OSD_VIDEO_POSTPROC_CROP_ONOFF); SetCheckmarkValue(engine.EnableDeinterlace, (int)Controls.OSD_VIDEO_POSTPROC_DEINTERLACE_ONOFF); UpdatePostProcessing(); ShowControl(GetID, (int)Controls.OSD_VIDEO_POSTPROC_DEBLOCK_ONOFF); ShowControl(GetID, (int)Controls.OSD_VIDEO_POSTPROC_RESIZE_ONOFF); ShowControl(GetID, (int)Controls.OSD_VIDEO_POSTPROC_CROP_ONOFF); ShowControl(GetID, (int)Controls.OSD_VIDEO_POSTPROC_DEINTERLACE_ONOFF); ShowControl(GetID, (int)Controls.OSD_VIDEO_POSTPROC_CROP_VERTICAL); ShowControl(GetID, (int)Controls.OSD_VIDEO_POSTPROC_CROP_HORIZONTAL); ShowControl(GetID, (int)Controls.OSD_VIDEO_POSTPROC_CROP_VERTICAL_LABEL); ShowControl(GetID, (int)Controls.OSD_VIDEO_POSTPROC_CROP_HORIZONTAL_LABEL); } //SetCheckmarkValue(g_stSettings.m_bNonInterleaved, Controls.OSD_NONINTERLEAVED); //SetCheckmarkValue(g_stSettings.m_bNoCache, Controls.OSD_NOCACHE); //SetCheckmarkValue(g_stSettings.m_bFrameRateConversions, Controls.OSD_ADJFRAMERATE); UpdateGammaContrastBrightness(); // show the controls on this sub menu ShowControl(GetID, (int)Controls.OSD_VIDEOPOS); ShowControl(GetID, (int)Controls.OSD_VIDEOPOS_LABEL); ShowControl(GetID, (int)Controls.OSD_NONINTERLEAVED); ShowControl(GetID, (int)Controls.OSD_NOCACHE); ShowControl(GetID, (int)Controls.OSD_ADJFRAMERATE); ShowControl(GetID, (int)Controls.OSD_SATURATIONLABEL); ShowControl(GetID, (int)Controls.OSD_SATURATION); ShowControl(GetID, (int)Controls.OSD_SHARPNESSLABEL); ShowControl(GetID, (int)Controls.OSD_SHARPNESS); ShowControl(GetID, (int)Controls.OSD_BRIGHTNESS); ShowControl(GetID, (int)Controls.OSD_BRIGHTNESSLABEL); ShowControl(GetID, (int)Controls.OSD_CONTRAST); ShowControl(GetID, (int)Controls.OSD_CONTRASTLABEL); ShowControl(GetID, (int)Controls.OSD_GAMMA); ShowControl(GetID, (int)Controls.OSD_GAMMALABEL); FocusControl(GetID, (int)Controls.OSD_VIDEOPOS, 0); // set focus to the first control in our group } } if (iControl == (int)Controls.OSD_AUDIO) { ToggleSubMenu(iControl, (int)Controls.OSD_SUBMENU_BG_AUDIO); // hide or show the sub-menu if (isSubMenuVisible) // is sub menu on? { int iValue = g_Player.Volume; GUISliderControl pSlider = GetControl((int)Controls.OSD_AUDIOVOLUMESLIDER) as GUISliderControl; if (null != pSlider) { pSlider.Percentage = iValue; // Update our volume slider accordingly ... } // set the controls values GUISliderControl pControl = (GUISliderControl)GetControl((int)Controls.OSD_AVDELAY); pControl.SpinType = GUISpinControl.SpinType.SPIN_CONTROL_TYPE_FLOAT; pControl.SetRange(-20, 20); SetSliderValue(-20, 20, m_audioDelay, (int)Controls.OSD_AVDELAY); bool hasPostProc = g_Player.HasPostprocessing; if (hasPostProc) { GUIPropertyManager.SetProperty("#TvOSD.AudioVideoDelayPossible", "true"); pControl.FloatInterval = 1; } else { GUIPropertyManager.SetProperty("#TvOSD.AudioVideoDelayPossible", "false"); pControl.FloatValue = 0; m_audioDelay = 0; pControl.FloatInterval = 0; } // show the controls on this sub menu ShowControl(GetID, (int)Controls.OSD_AVDELAY); ShowControl(GetID, (int)Controls.OSD_AVDELAY_LABEL); ShowControl(GetID, (int)Controls.OSD_AUDIOSTREAM_LIST); ShowControl(GetID, (int)Controls.OSD_AUDIOVOLUMESLIDER); ShowControl(GetID, (int)Controls.OSD_AUDIOVOLUMESLIDER_LABEL); FocusControl(GetID, (int)Controls.OSD_AVDELAY, 0); // set focus to the first control in our group PopulateAudioStreams(); // populate the list control with audio streams for this video } } return true; } } return base.OnMessage(message); }
public Program GetProgramAt(DateTime date, string title) { //IFormatProvider mmddFormat = new CultureInfo(String.Empty, false); //DateTime startTime = DateTime.Now; SqlBuilder sb = new SqlBuilder(StatementType.Select, typeof (Program)); sb.AddConstraint(Operator.Equals, "Title", title); sb.AddConstraint(Operator.Equals, "idChannel", IdChannel); sb.AddConstraint(Operator.GreaterThan, "endTime", date); sb.AddConstraint(Operator.LessThanOrEquals, "startTime", date); sb.AddOrderByField(true, "startTime"); sb.SetRowLimit(1); SqlStatement stmt = sb.GetStatement(true); IList<Program> programs = ObjectFactory.GetCollection<Program>(stmt.Execute()); if (programs.Count == 0) { return null; } return programs[0]; }
private void UpdateNowAndNext() { if (_currentProgram != null) { if (DateTime.Now >= _currentProgram.StartTime && DateTime.Now <= _currentProgram.EndTime) { return; } } _currentProgram = null; _nextProgram = null; DateTime date = DateTime.Now; SqlBuilder sb = new SqlBuilder(StatementType.Select, typeof (Program)); sb.AddConstraint(Operator.Equals, "idChannel", IdChannel); sb.AddConstraint(Operator.GreaterThanOrEquals, "endTime", date); sb.AddOrderByField(true, "startTime"); sb.SetRowLimit(2); SqlStatement stmt = sb.GetStatement(true); IList<Program> programs = ObjectFactory.GetCollection<Program>(stmt.Execute()); if (programs.Count == 0) { return; } _currentProgram = programs[0]; if (_currentProgram.StartTime >= date) { _nextProgram = _currentProgram; _currentProgram = null; } else { if (programs.Count == 2) { _nextProgram = programs[1]; } } }
/// <summary> /// Get a list which contains token in the description /// </summary> private IList<Program> ContainsInGenre(string Token) { SqlBuilder sb = new SqlBuilder(StatementType.Select, typeof (Program)); sb.AddConstraint(Operator.Like, "genre", "%" + Token + "%"); SqlStatement stmt = sb.GetStatement(true); return ObjectFactory.GetCollection<Program>(stmt.Execute()); }
private void getTvServerChannels() { CBChannelGroup chGroup = (CBChannelGroup)GroupComboBox.SelectedItem; IList<Channel> Channels; if (chGroup != null && chGroup.idGroup != -1) { SqlBuilder sb1 = new SqlBuilder(Gentle.Framework.StatementType.Select, typeof (Channel)); SqlStatement stmt1 = sb1.GetStatement(true); SqlStatement ManualJoinSQL = new SqlStatement(stmt1.StatementType, stmt1.Command, String.Format( "select c.* from Channel c join {0}GroupMap g on c.idChannel=g.idChannel where c.{1} = 1 and g.idGroup = '{2}' order by g.sortOrder", IsTvMapping ? "" : "Radio", IsTvMapping ? "isTv" : "isRadio", chGroup.idGroup), typeof (Channel)); Channels = ObjectFactory.GetCollection<Channel>(ManualJoinSQL.Execute()); } else { SqlBuilder sb = new SqlBuilder(StatementType.Select, typeof (Channel)); sb.AddOrderByField(true, "sortOrder"); if (IsTvMapping) { sb.AddConstraint("isTv = 1"); } else { sb.AddConstraint("isRadio = 1"); } SqlStatement stmt = sb.GetStatement(true); Channels = ObjectFactory.GetCollection<Channel>(stmt.Execute()); } foreach (Channel chan in Channels) { if (!_channelMapping.ContainsKey(chan.DisplayName)) { ChannelMap channel = new ChannelMap(); channel.displayName = chan.DisplayName; _channelMapping.Add(chan.DisplayName, channel); } } }
public bool Import(string fileName, bool deleteBeforeImport, bool showProgress) { //System.Diagnostics.Debugger.Launch(); _errorMessage = ""; if (_isImporting == true) { _errorMessage = "already importing..."; return false; } _isImporting = true; bool result = false; XmlTextReader xmlReader = null; // remove old programs _status.Status = "Removing old programs"; _status.Channels = 0; _status.Programs = 0; _status.StartTime = DateTime.Now; _status.EndTime = new DateTime(1971, 11, 6); if (showProgress && ShowProgress != null) ShowProgress(_status); layer.RemoveOldPrograms(); /* // for each channel, get the last program's time Dictionary<int, DateTime> lastProgramForChannel = new Dictionary<int, DateTime>(); IList channels = Channel.ListAll(); foreach (Channel ch in channels) { SqlBuilder sb = new SqlBuilder(StatementType.Select, typeof(TvDatabase.Program)); sb.AddConstraint(Operator.Equals, "idChannel", ch.IdChannel); sb.AddOrderByField(false, "starttime"); sb.SetRowLimit(1); SqlStatement stmt = sb.GetStatement(true); IList programsInDbs = ObjectFactory.GetCollection(typeof(TvDatabase.Program), stmt.Execute()); DateTime lastProgram = DateTime.MinValue; if (programsInDbs.Count > 0) { TvDatabase.IProgram p = (TvDatabase.Program)programsInDbs[0]; lastProgram = p.EndTime; } lastProgramForChannel[ch.IdChannel] = lastProgram; }*/ //TVDatabase.SupressEvents = true; bool useTimeZone = layer.GetSetting("xmlTvUseTimeZone", "false").Value == "true"; int hours = Int32.Parse(layer.GetSetting("xmlTvTimeZoneHours", "0").Value); int mins = Int32.Parse(layer.GetSetting("xmlTvTimeZoneMins", "0").Value); int timeZoneCorrection = hours * 60 + mins; ArrayList Programs = new ArrayList(); Dictionary<int, ChannelPrograms> dChannelPrograms = new Dictionary<int, ChannelPrograms>(); try { Log.WriteFile("xmltv import {0}", fileName); // // Make sure the file exists before we try to do any processing // if (File.Exists(fileName)) { _status.Status = "Loading channel list"; _status.Channels = 0; _status.Programs = 0; _status.StartTime = DateTime.Now; _status.EndTime = new DateTime(1971, 11, 6); if (showProgress && ShowProgress != null) ShowProgress(_status); Dictionary<int, Channel> guideChannels = new Dictionary<int, Channel>(); IList<Channel> allChannels = Channel.ListAll(); int iChannel = 0; xmlReader = new XmlTextReader(fileName); #region import non-mapped channels by their display-name if (xmlReader.ReadToDescendant("tv")) { // get the first channel if (xmlReader.ReadToDescendant("channel")) { do { String id = xmlReader.GetAttribute("id"); if (id == null || id.Length == 0) { Log.Error(" channel#{0} doesnt contain an id", iChannel); } else { String displayName = null; XmlReader xmlChannel = xmlReader.ReadSubtree(); xmlChannel.ReadStartElement(); // read channel // now, xmlChannel is positioned on the first sub-element of <channel> while (!xmlChannel.EOF) { if (xmlChannel.NodeType == XmlNodeType.Element) { switch (xmlChannel.Name) { case "display-name": case "Display-Name": if (displayName == null) displayName = xmlChannel.ReadString(); else xmlChannel.Skip(); break; // could read more stuff here, like icon... default: // unknown, skip entire node xmlChannel.Skip(); break; } } else xmlChannel.Read(); } if (xmlChannel != null) { xmlChannel.Close(); xmlChannel = null; } if (displayName == null || displayName.Length == 0) { Log.Error(" channel#{0} xmlid:{1} doesnt contain an displayname", iChannel, id); } else { Channel chan = null; // a guide channel can be mapped to multiple tvchannels foreach (Channel ch in allChannels) { if (ch.ExternalId == id) { chan = ch; chan.ExternalId = id; } if (chan == null) { // no mapping found, ignore channel continue; } ChannelPrograms newProgChan = new ChannelPrograms(); newProgChan.Name = chan.DisplayName; newProgChan.ExternalId = chan.ExternalId; Programs.Add(newProgChan); Log.WriteFile(" channel#{0} xmlid:{1} name:{2} dbsid:{3}", iChannel, chan.ExternalId, chan.DisplayName, chan.IdChannel); if (!guideChannels.ContainsKey(chan.IdChannel)) { guideChannels.Add(chan.IdChannel, chan); dChannelPrograms.Add(chan.IdChannel, newProgChan); } } _status.Channels++; if (showProgress && ShowProgress != null) ShowProgress(_status); } } iChannel++; // get the next channel } while (xmlReader.ReadToNextSibling("channel")); } } //xmlReader.Close(); #endregion SqlBuilder sb = new SqlBuilder(StatementType.Select, typeof (Channel)); sb.AddOrderByField(true, "externalId"); sb.AddConstraint("externalId IS NOT null"); sb.AddConstraint(Operator.NotEquals, "externalId", ""); SqlStatement stmt = sb.GetStatement(true); allChannels = ObjectFactory.GetCollection<Channel>(stmt.Execute()); if (allChannels.Count == 0) { _isImporting = false; if (xmlReader != null) { xmlReader.Close(); xmlReader = null; } return true; } /////////////////////////////////////////////////////////////////////////// /* design: * 1. create a Dictionary<string,Channel> using the externalid as the key, * add all channels to this Dictionary * Note: channel -> guidechannel is a one-to-many relationship. * 2. Read all programs from the xml file * 3. Create a program for each mapped channel */ /////////////////////////////////////////////////////////////////////////// Dictionary<string, List<Channel>> allChannelMappingsByExternalId = new Dictionary<string, List<Channel>>(); string previousExternalId = null; // one-to-many so we need a collection of channels for each externalId List<Channel> eidMappedChannels = new List<Channel>(); for (int i = 0; i < allChannels.Count; i++) { Channel ch = (Channel)allChannels[i]; if (previousExternalId == null) { eidMappedChannels.Add(ch); previousExternalId = ch.ExternalId; } else if (ch.ExternalId == previousExternalId) { eidMappedChannels.Add(ch); } else { // got all channels for this externalId. Add the mappings allChannelMappingsByExternalId.Add(previousExternalId, eidMappedChannels); // new externalid, create a new List & add the channel to the new List eidMappedChannels = new List<Channel>(); eidMappedChannels.Add(ch); previousExternalId = ch.ExternalId; } if (i == allChannels.Count - 1) { allChannelMappingsByExternalId.Add(previousExternalId, eidMappedChannels); } } int programIndex = 0; _status.Status = "Loading TV programs"; if (showProgress && ShowProgress != null) ShowProgress(_status); Log.Debug("xmltvimport: Reading TV programs"); if (xmlReader != null) { xmlReader.Close(); xmlReader = null; } xmlReader = new XmlTextReader(fileName); if (xmlReader.ReadToDescendant("tv")) { // get the first programme if (xmlReader.ReadToDescendant("programme")) { #region read programme node do { ChannelPrograms channelPrograms = new ChannelPrograms(); String nodeStart = xmlReader.GetAttribute("start"); String nodeStop = xmlReader.GetAttribute("stop"); String nodeChannel = xmlReader.GetAttribute("channel"); String nodeTitle = null; String nodeCategory = null; String nodeDescription = null; String nodeEpisode = null; String nodeRepeat = null; String nodeEpisodeNum = null; String nodeEpisodeNumSystem = null; String nodeDate = null; String nodeStarRating = null; String nodeClassification = null; XmlReader xmlProg = xmlReader.ReadSubtree(); xmlProg.ReadStartElement(); // read programme // now, xmlProg is positioned on the first sub-element of <programme> while (!xmlProg.EOF) { if (xmlProg.NodeType == XmlNodeType.Element) { switch (xmlProg.Name) { case "title": if (nodeTitle == null) nodeTitle = xmlProg.ReadString(); else xmlProg.Skip(); break; case "category": if (nodeCategory == null) nodeCategory = xmlProg.ReadString(); else xmlProg.Skip(); break; case "desc": if (nodeDescription == null) nodeDescription = xmlProg.ReadString(); else xmlProg.Skip(); break; case "sub-title": if (nodeEpisode == null) nodeEpisode = xmlProg.ReadString(); else xmlProg.Skip(); break; case "previously-shown": if (nodeRepeat == null) nodeRepeat = xmlProg.ReadString(); else xmlProg.Skip(); break; case "episode-num": if (xmlProg.GetAttribute("system").Equals("xmltv_ns")) { nodeEpisodeNumSystem = xmlProg.GetAttribute("system"); nodeEpisodeNum = xmlProg.ReadString(); } else if (nodeEpisodeNum == null && xmlProg.GetAttribute("system").Equals("onscreen")) { nodeEpisodeNumSystem = xmlProg.GetAttribute("system"); nodeEpisodeNum = xmlProg.ReadString(); } else xmlProg.Skip(); break; case "date": if (nodeDate == null) nodeDate = xmlProg.ReadString(); else xmlProg.Skip(); break; case "star-rating": if (nodeStarRating == null) nodeStarRating = xmlProg.ReadInnerXml(); else xmlProg.Skip(); break; case "rating": if (nodeClassification == null) nodeClassification = xmlProg.ReadInnerXml(); else xmlProg.Skip(); break; default: // unknown, skip entire node xmlProg.Skip(); break; } } else xmlProg.Read(); } if (xmlProg != null) { xmlProg.Close(); xmlProg = null; } #endregion #region verify/convert values (programme) if (nodeStart != null && nodeChannel != null && nodeTitle != null && nodeStart.Length > 0 && nodeChannel.Length > 0 && nodeTitle.Length > 0) { string description = ""; string category = "-"; string serEpNum = ""; string date = ""; string seriesNum = ""; string episodeNum = ""; string episodeName = ""; string episodePart = ""; int starRating = -1; string classification = ""; string title = ConvertHTMLToAnsi(nodeTitle); long startDate = 0; if (nodeStart.Length >= 14) { if (Char.IsDigit(nodeStart[12]) && Char.IsDigit(nodeStart[13])) startDate = Int64.Parse(nodeStart.Substring(0, 14)); //20040331222000 else startDate = 100 * Int64.Parse(nodeStart.Substring(0, 12)); //200403312220 } else if (nodeStart.Length >= 12) { startDate = 100 * Int64.Parse(nodeStart.Substring(0, 12)); //200403312220 } long stopDate = startDate; if (nodeStop != null) { if (nodeStop.Length >= 14) { if (Char.IsDigit(nodeStop[12]) && Char.IsDigit(nodeStop[13])) stopDate = Int64.Parse(nodeStop.Substring(0, 14)); //20040331222000 else stopDate = 100 * Int64.Parse(nodeStop.Substring(0, 12)); //200403312220 } else if (nodeStop.Length >= 12) { stopDate = 100 * Int64.Parse(nodeStop.Substring(0, 12)); //200403312220 } } startDate = CorrectIllegalDateTime(startDate); stopDate = CorrectIllegalDateTime(stopDate); string timeZoneStart = ""; string timeZoneEnd = ""; if (nodeStart.Length > 14) { timeZoneStart = nodeStart.Substring(14); timeZoneStart = timeZoneStart.Trim(); timeZoneEnd = timeZoneStart; } if (nodeStop != null) { if (nodeStop.Length > 14) { timeZoneEnd = nodeStop.Substring(14); timeZoneEnd = timeZoneEnd.Trim(); } } // // add time correction // // correct program starttime DateTime dateTimeStart = longtodate(startDate); dateTimeStart = dateTimeStart.AddMinutes(timeZoneCorrection); if (useTimeZone) { int off = GetTimeOffset(timeZoneStart); int h = off / 100; // 220 -> 2, -220 -> -2 int m = off - (h * 100); // 220 -> 20, -220 -> -20 dateTimeStart = dateTimeStart.AddHours(-h); dateTimeStart = dateTimeStart.AddMinutes(-m); dateTimeStart = dateTimeStart.ToLocalTime(); } startDate = datetolong(dateTimeStart); if (nodeStop != null) { // correct program endtime DateTime dateTimeEnd = longtodate(stopDate); dateTimeEnd = dateTimeEnd.AddMinutes(timeZoneCorrection); if (useTimeZone) { int off = GetTimeOffset(timeZoneEnd); int h = off / 100; // 220 -> 2, -220 -> -2 int m = off - (h * 100); // 220 -> 20, -220 -> -20 dateTimeEnd = dateTimeEnd.AddHours(-h); dateTimeEnd = dateTimeEnd.AddMinutes(-m); dateTimeEnd = dateTimeEnd.ToLocalTime(); } stopDate = datetolong(dateTimeEnd); } else stopDate = startDate; //int channelId = -1; //string channelName = ""; if (nodeCategory != null) category = nodeCategory; if (nodeDescription != null) { description = ConvertHTMLToAnsi(nodeDescription); } if (nodeEpisode != null) { episodeName = ConvertHTMLToAnsi(nodeEpisode); if (title.Length == 0) title = nodeEpisode; } if (nodeEpisodeNum != null) { if (nodeEpisodeNumSystem != null) { // http://xml.coverpages.org/XMLTV-DTD-20021210.html if (nodeEpisodeNumSystem == "xmltv_ns") { serEpNum = ConvertHTMLToAnsi(nodeEpisodeNum.Replace(" ", "")); int dot1 = serEpNum.IndexOf(".", 0); int dot2 = serEpNum.IndexOf(".", dot1 + 1); seriesNum = serEpNum.Substring(0, dot1); episodeNum = serEpNum.Substring(dot1 + 1, dot2 - (dot1 + 1)); episodePart = serEpNum.Substring(dot2 + 1, serEpNum.Length - (dot2 + 1)); //xmltv_ns is theorically zero-based number will be increased by one seriesNum = CorrectEpisodeNum(seriesNum, 1); episodeNum = CorrectEpisodeNum(episodeNum, 1); episodePart = CorrectEpisodeNum(episodePart, 1); } else if (nodeEpisodeNumSystem == "onscreen") { // example: 'Episode #FFEE' serEpNum = ConvertHTMLToAnsi(nodeEpisodeNum); int num1 = serEpNum.IndexOf("#", 0); if (num1 > 0) { episodeNum = CorrectEpisodeNum(serEpNum.Substring(num1, serEpNum.Length - num1), 0); } else { if (serEpNum.IndexOf(":", 0) > 0) { episodeNum = CorrectEpisodeNum(serEpNum, 0); } else { Regex regEpisode = new Regex("(?<episode>\\d*)\\D*(?<series>\\d*)", RegexOptions.Compiled | RegexOptions.CultureInvariant | RegexOptions.Multiline | RegexOptions.Singleline | RegexOptions.IgnorePatternWhitespace | RegexOptions.ExplicitCapture); Match m = regEpisode.Match(serEpNum); if (m.Success) { episodeNum = CorrectEpisodeNum(m.Groups["episode"].Value, 0); seriesNum = CorrectEpisodeNum(m.Groups["series"].Value, 0); } else { episodeNum = CorrectEpisodeNum(serEpNum, 0); } } } } } else // fixing mantis bug 1486: XMLTV import doesn't take episode number from TVGuide.xml made by WebEPG { // example: '5' like WebEPG is creating serEpNum = ConvertHTMLToAnsi(nodeEpisodeNum.Replace(" ", "")); episodeNum = CorrectEpisodeNum(serEpNum, 0); } } if (nodeDate != null) { date = nodeDate; } if (nodeStarRating != null) { starRating = ParseStarRating(nodeStarRating); } if (nodeClassification != null) { classification = nodeClassification; } if (showProgress && ShowProgress != null && (_status.Programs % 100) == 0) ShowProgress(_status); #endregion #region create a program for every mapped channel List<Channel> mappedChannels; if (allChannelMappingsByExternalId.ContainsKey(nodeChannel)) { mappedChannels = allChannelMappingsByExternalId[nodeChannel]; if (mappedChannels != null && mappedChannels.Count > 0) { foreach (Channel chan in mappedChannels) { // get the channel program channelPrograms = dChannelPrograms[chan.IdChannel]; if (chan.IdChannel < 0) { continue; } title = title.Replace("\r\n", " "); title = title.Replace("\n\r", " "); title = title.Replace("\r", " "); title = title.Replace("\n", " "); title = title.Replace(" ", " "); description = description.Replace("\r\n", " "); description = description.Replace("\n\r", " "); description = description.Replace("\r", " "); description = description.Replace("\n", " "); description = description.Replace(" ", " "); episodeName = episodeName.Replace("\r\n", " "); episodeName = episodeName.Replace("\n\r", " "); episodeName = episodeName.Replace("\r", " "); episodeName = episodeName.Replace("\n", " "); episodeName = episodeName.Replace(" ", " "); Program prog = new Program(chan.IdChannel, longtodate(startDate), longtodate(stopDate), title, description, category, Program.ProgramState.None, System.Data.SqlTypes.SqlDateTime.MinValue.Value, seriesNum, episodeNum, episodeName, episodePart, starRating, classification, -1); channelPrograms.programs.Add(prog); programIndex++; //prog.Description = ConvertHTMLToAnsi(strDescription); //prog.StartTime = iStart; //prog.EndTime = iStop; //prog.Title = ConvertHTMLToAnsi(strTitle); //prog.Genre = ConvertHTMLToAnsi(strCategory); //prog.Channel = ConvertHTMLToAnsi(strChannelName); //prog.Date = strDate; //prog.Episode = ConvertHTMLToAnsi(strEpisode); //prog.Repeat = ConvertHTMLToAnsi(strRepeat); //prog.SeriesNum = ConvertHTMLToAnsi(strSeriesNum); //prog.EpisodeNum = ConvertHTMLToAnsi(strEpisodeNum); //prog.EpisodePart = ConvertHTMLToAnsi(strEpisodePart); //prog.StarRating = ConvertHTMLToAnsi(strStarRating); //prog.Classification = ConvertHTMLToAnsi(strClasification); _status.Programs++; } } } } // get the next programme } while (xmlReader.ReadToNextSibling("programme")); //if (xmlReader != null) xmlReader.Close(); #endregion #region sort & remove invalid programs. Save all valid programs Log.Debug("xmltvimport: Sorting TV programs"); _status.Programs = 0; _status.Status = "Sorting TV programs"; if (showProgress && ShowProgress != null) ShowProgress(_status); DateTime dtStartDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 0, 0, 0, 0); //dtStartDate=dtStartDate.AddDays(-4); foreach (ChannelPrograms progChan in Programs) { // empty, skip it if (progChan.programs.Count == 0) continue; progChan.programs.Sort(); progChan.programs.AlreadySorted = true; progChan.programs.FixEndTimes(); progChan.programs.RemoveOverlappingPrograms(); // be sure that we do not have any overlapping // get the id of the channel, just get the IdChannel of the first program int idChannel = progChan.programs[0].IdChannel; if (!deleteBeforeImport) { // retrieve all programs for this channel SqlBuilder sb2 = new SqlBuilder(StatementType.Select, typeof (Program)); sb2.AddConstraint(Operator.Equals, "idChannel", idChannel); sb2.AddOrderByField(false, "starttime"); SqlStatement stmt2 = sb2.GetStatement(true); ProgramList dbPrograms = new ProgramList(); ObjectFactory.GetCollection<Program>(stmt2.Execute(), dbPrograms); progChan.programs.RemoveOverlappingPrograms(dbPrograms, true); } for (int i = 0; i < progChan.programs.Count; ++i) { Program prog = progChan.programs[i]; // don't import programs which have already ended... if (prog.EndTime <= dtStartDate) { progChan.programs.RemoveAt(i); i--; continue; } DateTime start = prog.StartTime; DateTime end = prog.EndTime; DateTime airDate = System.Data.SqlTypes.SqlDateTime.MinValue.Value; try { airDate = prog.OriginalAirDate; if (airDate > System.Data.SqlTypes.SqlDateTime.MinValue.Value && airDate < System.Data.SqlTypes.SqlDateTime.MaxValue.Value) prog.OriginalAirDate = airDate; } catch (Exception) { Log.Info("XMLTVImport: Invalid year for OnAirDate - {0}", prog.OriginalAirDate); } if (prog.StartTime < _status.StartTime) _status.StartTime = prog.StartTime; if (prog.EndTime > _status.EndTime) _status.EndTime = prog.EndTime; _status.Programs++; if (showProgress && ShowProgress != null && (_status.Programs % 100) == 0) ShowProgress(_status); } Log.Info("XMLTVImport: Inserting {0} programs for {1}", progChan.programs.Count.ToString(), progChan.Name); layer.InsertPrograms(progChan.programs, deleteBeforeImport ? DeleteBeforeImportOption.OverlappingPrograms : DeleteBeforeImportOption.None, ThreadPriority.BelowNormal); } } #endregion //TVDatabase.RemoveOverlappingPrograms(); //TVDatabase.SupressEvents = false; if (programIndex > 0) { _errorMessage = "File imported successfully"; result = true; } else _errorMessage = "No programs found"; } } else { _errorMessage = "No xmltv file found"; _status.Status = _errorMessage; Log.Error("xmltv data file was not found"); } } catch (Exception ex) { _errorMessage = String.Format("Invalid XML file:{0}", ex.Message); _status.Status = String.Format("invalid XML file:{0}", ex.Message); Log.Error("XML tv import error loading {0} err:{1} \n {2}", fileName, ex.Message, ex.StackTrace); //TVDatabase.RollbackTransaction(); } Programs.Clear(); Programs = null; _isImporting = false; // TVDatabase.SupressEvents = false; if (xmlReader != null) { xmlReader.Close(); xmlReader = null; } return result; }
/// <summary> /// Update the Program in the database if it exists or add if it is new. /// </summary> /// <param name="mpProgram">The Program to add to the database</param> protected void UpdateProgram(Program mpProgram) { IFormatProvider mmddFormat = new System.Globalization.CultureInfo(String.Empty, false); SqlBuilder sb = new SqlBuilder(Gentle.Framework.StatementType.Select, typeof(Program)); // startTime < MyEndTime AND endTime > MyStartTime // OR == string sqlW1 = String.Format("(StartTime < '{0}' and EndTime > '{1}')", mpProgram.EndTime.ToString(tvLayer.GetDateTimeString(), mmddFormat), mpProgram.StartTime.ToString(tvLayer.GetDateTimeString(), mmddFormat)); string sqlW2 = String.Format("(StartTime = '{0}' and EndTime = '{1}')", mpProgram.StartTime.ToString(tvLayer.GetDateTimeString(), mmddFormat), mpProgram.EndTime.ToString(tvLayer.GetDateTimeString(), mmddFormat)); sb.AddConstraint(Operator.Equals, "idChannel", mpProgram.IdChannel); sb.AddConstraint(string.Format("({0} or {1}) ", sqlW1, sqlW2)); sb.AddOrderByField(true, "starttime"); SqlStatement stmt = sb.GetStatement(true); IList progList = ObjectFactory.GetCollection(typeof(Program), stmt.Execute()); if (progList.Count > 0) { bool bMatch = false; foreach (Program prog in progList) { if (!bMatch && prog.StartTime == mpProgram.StartTime && prog.EndTime == mpProgram.EndTime && prog.Title == mpProgram.Title) { //update - but only allow one match bMatch = true; prog.Classification = mpProgram.Classification; prog.Description = mpProgram.Description; prog.EpisodeNum = mpProgram.EpisodeNum; prog.Genre = mpProgram.Genre; prog.OriginalAirDate = mpProgram.OriginalAirDate; prog.SeriesNum = mpProgram.SeriesNum; prog.StarRating = mpProgram.StarRating; prog.Title = mpProgram.Title; prog.EpisodeName = mpProgram.EpisodeName; prog.Persist(); } else prog.Delete(); } if (!bMatch) mpProgram.Persist(); } else { mpProgram.Persist(); } }
/// <summary> /// Provides a wrapper for getting the channel by xmlTvId from the database. /// </summary> /// <param name="xmlTvId">xmlTvId aka ExternalID</param> /// <param name="idTvChannel">The id tv channel.</param> /// <param name="strTvChannel">The name tv channel.</param> /// <returns>true if the channel name was found</returns> protected bool LookupEPGMapping(string xmlTvId, out int idTvChannel, out string strTvChannel) { //Channel fch = Channel.Retrieve( idTvChannel = -1; strTvChannel = String.Empty; SqlBuilder sb = new SqlBuilder(StatementType.Select, typeof(Channel)); sb.AddConstraint(Operator.Equals, "externalId", xmlTvId.ToString()); SqlStatement stmt = sb.GetStatement(true); System.Collections.IList chList = ObjectFactory.GetCollection(typeof(Channel), stmt.Execute()); if (chList.Count > 0) { idTvChannel = ((Channel)chList[0]).IdChannel; strTvChannel = ((Channel)chList[0]).DisplayName; return true; } return false; }
public static Recording ActiveRecording(string title, int idChannel) { SqlBuilder sb = new SqlBuilder(StatementType.Select, typeof (Recording)); sb.AddConstraint(Operator.Equals, "isRecording", true); sb.AddConstraint(Operator.Equals, "title", title); sb.AddConstraint(Operator.Equals, "idChannel", idChannel); SqlStatement stmt = sb.GetStatement(true); // execute the statement/query and create a collection of User instances from the result set IList<Recording> getList = ObjectFactory.GetCollection<Recording>(stmt.Execute()); if (getList.Count != 0) { return getList[0]; } return null; }
public void ReLoad() { //System.Diagnostics.Debugger.Launch(); try { SetupDatabaseConnection(); Log.Info("get channels from database"); SqlBuilder sb = new SqlBuilder(StatementType.Select, typeof (Channel)); sb.AddConstraint(Operator.Equals, "isTv", 1); sb.AddOrderByField(true, "sortOrder"); SqlStatement stmt = sb.GetStatement(true); channels = ObjectFactory.GetCollection(typeof (Channel), stmt.Execute()); Log.Info("found:{0} tv channels", channels.Count); TvNotifyManager.OnNotifiesChanged(); m_groups.Clear(); TvBusinessLayer layer = new TvBusinessLayer(); RadioChannelGroup allRadioChannelsGroup = layer.GetRadioChannelGroupByName(TvConstants.RadioGroupNames.AllChannels); IList<Channel> radioChannels = layer.GetAllRadioChannels(); if (radioChannels != null) { if (radioChannels.Count > allRadioChannelsGroup.ReferringRadioGroupMap().Count) { foreach (Channel radioChannel in radioChannels) { layer.AddChannelToRadioGroup(radioChannel, allRadioChannelsGroup); } } } Log.Info("Done."); Log.Info("get all groups from database"); sb = new SqlBuilder(StatementType.Select, typeof (ChannelGroup)); sb.AddOrderByField(true, "groupName"); stmt = sb.GetStatement(true); IList<ChannelGroup> groups = ObjectFactory.GetCollection<ChannelGroup>(stmt.Execute()); IList<GroupMap> allgroupMaps = GroupMap.ListAll(); bool hideAllChannelsGroup = false; using ( Settings xmlreader = new MPSettings()) { hideAllChannelsGroup = xmlreader.GetValueAsBool("mytv", "hideAllChannelsGroup", false); } foreach (ChannelGroup group in groups) { if (group.GroupName == TvConstants.TvGroupNames.AllChannels) { foreach (Channel channel in channels) { if (channel.IsTv == false) { continue; } bool groupContainsChannel = false; foreach (GroupMap map in allgroupMaps) { if (map.IdGroup != group.IdGroup) { continue; } if (map.IdChannel == channel.IdChannel) { groupContainsChannel = true; break; } } if (!groupContainsChannel) { layer.AddChannelToGroup(channel, TvConstants.TvGroupNames.AllChannels); } } break; } } groups = ChannelGroup.ListAll(); foreach (ChannelGroup group in groups) { //group.GroupMaps.ApplySort(new GroupMap.Comparer(), false); if (hideAllChannelsGroup && group.GroupName.Equals(TvConstants.TvGroupNames.AllChannels) && groups.Count > 1) { continue; } m_groups.Add(group); } Log.Info("loaded {0} tv groups", m_groups.Count); //TVHome.Connected = true; } catch (Exception ex) { Log.Error("TVHome: Error in Reload"); Log.Error(ex); //TVHome.Connected = false; } }
/// <summary> /// Static method to retrieve all instances that are stored in the database in one call /// </summary> public static IList<Recording> ListAllActive() { SqlBuilder sb = new SqlBuilder(StatementType.Select, typeof (Recording)); sb.AddConstraint(Operator.Equals, "isRecording", true); SqlStatement stmt = sb.GetStatement(true); // execute the statement/query and create a collection of User instances from the result set return ObjectFactory.GetCollection<Recording>(stmt.Execute()); }
public override void OnSectionActivated() { mpListView1.BeginUpdate(); try { LoadLanguages(); TvBusinessLayer layer = new TvBusinessLayer(); Setting setting = layer.GetSetting("epgRadioStoreOnlySelected"); mpCheckBoxStoreOnlySelected.Checked = (setting.Value == "yes"); Dictionary<string, CardType> cards = new Dictionary<string, CardType>(); IList<Card> dbsCards = Card.ListAll(); foreach (Card card in dbsCards) { cards[card.DevicePath] = RemoteControl.Instance.Type(card.IdCard); } base.OnSectionActivated(); mpListView1.Items.Clear(); SqlBuilder sb = new SqlBuilder(StatementType.Select, typeof(Channel)); sb.AddOrderByField(true, "sortOrder"); SqlStatement stmt = sb.GetStatement(true); IList<Channel> channels = ObjectFactory.GetCollection<Channel>(stmt.Execute()); foreach (Channel ch in channels) { bool analog = false; bool dvbc = false; bool dvbt = false; bool dvbs = false; bool atsc = false; bool dvbip = false; bool hasFta = false; bool hasScrambled = false; if (ch.IsRadio == false) continue; if (ch.IsWebstream()) continue; IList<TuningDetail> tuningDetails = ch.ReferringTuningDetail(); foreach (TuningDetail detail in tuningDetails) { if (detail.FreeToAir) { hasFta = true; } if (!detail.FreeToAir) { hasScrambled = true; } } int imageIndex; if (hasFta && hasScrambled) { imageIndex = 2; } else if (hasScrambled) { imageIndex = 1; } else { imageIndex = 0; } ListViewItem item = mpListView1.Items.Add(ch.DisplayName, imageIndex); foreach (ChannelMap map in ch.ReferringChannelMap()) { if (cards.ContainsKey(map.ReferencedCard().DevicePath)) { CardType type = cards[map.ReferencedCard().DevicePath]; switch (type) { case CardType.Analog: analog = true; break; case CardType.DvbC: dvbc = true; break; case CardType.DvbT: dvbt = true; break; case CardType.DvbS: dvbs = true; break; case CardType.Atsc: atsc = true; break; case CardType.DvbIP: dvbip = true; break; } } } string line = ""; if (analog) { line += "Analog"; } if (dvbc) { if (line != "") line += ","; line += "DVB-C"; } if (dvbt) { if (line != "") line += ","; line += "DVB-T"; } if (dvbs) { if (line != "") line += ","; line += "DVB-S"; } if (atsc) { if (line != "") line += ","; line += "ATSC"; } if (dvbip) { if (line != "") line += ","; line += "DVB-IP"; } item.SubItems.Add(line); item.Checked = ch.GrabEpg; item.Tag = ch; } } finally { mpListView1.EndUpdate(); } }
public Instrument[] RetrieveAll() { SqlBuilder sb = new SqlBuilder(StatementType.Select, typeof(Instrument)); SqlStatement stmt = sb.GetStatement(true); Instrument[] instruments = (Instrument[])ObjectFactory.GetCollection(typeof(Instrument), stmt.Execute()); return instruments; }
private TvDatabase.Channel InternalGetChannelBy(ChannelType channelType, string columnName, object value, out bool duplicateChannelsFound) { SqlBuilder sb = new SqlBuilder(StatementType.Select, typeof(TvDatabase.Channel)); sb.AddConstraint(Operator.Equals, columnName, value); sb.AddConstraint(Operator.Equals, "visibleInGuide", true); if (channelType == ChannelType.Television) { sb.AddConstraint(Operator.Equals, "isTv", true); } else { sb.AddConstraint(Operator.Equals, "isRadio", true); } SqlResult result = Broker.Execute(sb.GetStatement()); if (result.Rows.Count == 1) { duplicateChannelsFound = false; IList channels = ObjectFactory.GetCollection(typeof(TvDatabase.Channel), result); return channels[0] as TvDatabase.Channel; } duplicateChannelsFound = (result.Rows.Count > 0); return null; }
/// <summary> /// Retreives the programs with a given title and starting between given Start and End Times /// </summary> /// <param name="title">Title we wanna look for</param> /// <param name="startTime">StartTime</param> /// <param name="endTime">EndTime</param> /// <param name="idChannel">The id of the channel</param> /// <returns></returns> public static IList<Schedule> RetrieveByTitleAndTimesInterval(string title, DateTime startTime, DateTime endTime, int idChannel) { //select * from 'foreigntable' SqlBuilder sb = new SqlBuilder(StatementType.Select, typeof (Schedule)); // where foreigntable.foreignkey = ourprimarykey sb.AddConstraint(Operator.Equals, "programName", title); sb.AddConstraint(Operator.GreaterThanOrEquals, "startTime", startTime); sb.AddConstraint(Operator.GreaterThanOrEquals, "endTime", endTime); sb.AddConstraint(Operator.Equals, "idChannel", idChannel); // passing true indicates that we'd like a list of elements, i.e. that no primary key // constraints from the type being retrieved should be added to the statement SqlStatement stmt = sb.GetStatement(true); // execute the statement/query and create a collection of User instances from the result set return ObjectFactory.GetCollection<Schedule>(stmt.Execute()); }
private void LoadDirectory() { GUIControl.ClearControl(GetID, listPriorities.GetID); SqlBuilder sb = new SqlBuilder(StatementType.Select, typeof (Schedule)); sb.AddOrderByField(false, "priority"); SqlStatement stmt = sb.GetStatement(true); IList itemlist = ObjectFactory.GetCollection(typeof (Schedule), stmt.Execute()); int total = 0; foreach (Schedule rec in itemlist) { if (rec.IsSerieIsCanceled(rec.StartTime, rec.IdChannel)) { continue; } GUIListItem item = new GUIListItem(); item.Label = String.Format("{0}.{1}", total, rec.ProgramName); item.TVTag = rec; string strLogo = Utils.GetCoverArt(Thumbs.TVChannel, rec.ReferencedChannel().DisplayName); if (string.IsNullOrEmpty(strLogo)) { strLogo = "defaultVideoBig.png"; } TvServer server = new TvServer(); VirtualCard card; if (server.IsRecordingSchedule(rec.IdSchedule, out card)) { if (rec.ScheduleType != (int)ScheduleRecordingType.Once) { item.PinImage = Thumbs.TvRecordingSeriesIcon; } else { item.PinImage = Thumbs.TvRecordingIcon; } } else if (rec.ReferringConflicts().Count > 0) { item.PinImage = Thumbs.TvConflictRecordingIcon; } item.ThumbnailImage = strLogo; item.IconImageBig = strLogo; item.IconImage = strLogo; listPriorities.Add(item); total++; } //set object count label GUIPropertyManager.SetProperty("#itemcount", Utils.GetObjectCountLabel(total)); GUIControl.SelectItemControl(GetID, listPriorities.GetID, m_iSelectedItem); }
private void comboBoxGroups_SelectedIndexChanged(object sender, EventArgs e) { ComboBoxExItem idItem = (ComboBoxExItem)comboBoxGroups.Items[comboBoxGroups.SelectedIndex]; mpComboBoxChannels.Items.Clear(); if (idItem.Id == -1) { SqlBuilder sb = new SqlBuilder(StatementType.Select, typeof (Channel)); sb.AddOrderByField(true, "sortOrder"); SqlStatement stmt = sb.GetStatement(true); IList<Channel> channels = ObjectFactory.GetCollection<Channel>(stmt.Execute()); foreach (Channel ch in channels) { if (ch.IsTv == false) continue; bool hasFta = false; bool hasScrambled = false; IList<TuningDetail> tuningDetails = ch.ReferringTuningDetail(); foreach (TuningDetail detail in tuningDetails) { if (detail.FreeToAir) { hasFta = true; } if (!detail.FreeToAir) { hasScrambled = true; } } int imageIndex; if (hasFta && hasScrambled) { imageIndex = 5; } else if (hasScrambled) { imageIndex = 4; } else { imageIndex = 3; } ComboBoxExItem item = new ComboBoxExItem(ch.DisplayName, imageIndex, ch.IdChannel); mpComboBoxChannels.Items.Add(item); } } else { ChannelGroup group = ChannelGroup.Retrieve(idItem.Id); IList<GroupMap> maps = group.ReferringGroupMap(); foreach (GroupMap map in maps) { Channel ch = map.ReferencedChannel(); if (ch.IsTv == false) continue; bool hasFta = false; bool hasScrambled = false; IList<TuningDetail> tuningDetails = ch.ReferringTuningDetail(); foreach (TuningDetail detail in tuningDetails) { if (detail.FreeToAir) { hasFta = true; } if (!detail.FreeToAir) { hasScrambled = true; } } int imageIndex; if (hasFta && hasScrambled) { imageIndex = 5; } else if (hasScrambled) { imageIndex = 4; } else { imageIndex = 3; } ComboBoxExItem item = new ComboBoxExItem(ch.DisplayName, imageIndex, ch.IdChannel); mpComboBoxChannels.Items.Add(item); } } if (mpComboBoxChannels.Items.Count > 0) mpComboBoxChannels.SelectedIndex = 0; }
public static Schedule RetrieveSpawnedSchedule(int parentScheduleId, DateTime startTime) { //select * from 'foreigntable' SqlBuilder sb = new SqlBuilder(StatementType.Select, typeof (Schedule)); sb.AddConstraint(Operator.Equals, "idParentSchedule", parentScheduleId); sb.AddConstraint(Operator.Equals, "startTime", startTime); // passing true indicates that we'd like a list of elements, i.e. that no primary key // constraints from the type being retrieved should be added to the statement SqlStatement stmt = sb.GetStatement(true); // execute the statement/query and create a collection of User instances from the result set IList<Schedule> getList = ObjectFactory.GetCollection<Schedule>(stmt.Execute()); if (getList.Count != 0) { return getList[0]; } else { //select * from 'foreigntable' sb = new SqlBuilder(StatementType.Select, typeof (Schedule)); sb.AddConstraint(Operator.Equals, "idParentSchedule", parentScheduleId); // passing true indicates that we'd like a list of elements, i.e. that no primary key // constraints from the type being retrieved should be added to the statement stmt = sb.GetStatement(true); // execute the statement/query and create a collection of User instances from the result set getList = ObjectFactory.GetCollection<Schedule>(stmt.Execute()); if (getList.Count != 0) { return getList[0]; } } return null; }
private void AddSelectedItemsToGroup(MPListView sourceListView) { if (_channelGroup == null) { return; } TvBusinessLayer layer = new TvBusinessLayer(); foreach (ListViewItem sourceItem in sourceListView.SelectedItems) { Channel channel = null; if (sourceItem.Tag is Channel) { channel = (Channel)sourceItem.Tag; } else if (sourceItem.Tag is RadioGroupMap) { channel = layer.GetChannel(((RadioGroupMap)sourceItem.Tag).IdChannel); } else { continue; } RadioGroupMap groupMap = null; layer.AddChannelToRadioGroup(channel, _channelGroup); //get the new group map and set the listitem tag SqlBuilder sb = new SqlBuilder(StatementType.Select, typeof (RadioGroupMap)); sb.AddConstraint(Operator.Equals, "idChannel", channel.IdChannel); sb.AddConstraint(Operator.Equals, "idGroup", _channelGroup.IdGroup); SqlStatement stmt = sb.GetStatement(true); groupMap = ObjectFactory.GetInstance<RadioGroupMap>(stmt.Execute()); foreach (ListViewItem item in listView1.Items) { if ((item.Tag as Channel) == channel) { item.Tag = groupMap; break; } } } }
public static IList<Schedule> FindOrphanedOnceSchedules() { SqlBuilder sb = new SqlBuilder(StatementType.Select, typeof (Schedule)); // DateTime now = DateTime.Now; sb.AddConstraint(Operator.Equals, "scheduleType", 0); sb.AddConstraint(Operator.LessThan, "endtime", now); // passing true indicates that we'd like a list of elements, i.e. that no primary key // constraints from the type being retrieved should be added to the statement SqlStatement stmt = sb.GetStatement(true); // execute the statement/query and create a collection of User instances from the result set IList<Schedule> getList = ObjectFactory.GetCollection<Schedule>(stmt.Execute()); IList<Schedule> newList = new List<Schedule>(); if (getList.Count > 0) { foreach (Schedule schedule in getList) { DateTime endPostTime = schedule.endTime.AddMinutes(schedule.postRecordInterval); if (endPostTime < now) { newList.Add(schedule); } } } return newList; }