private void ThreadFunctionImportTVGuide(object aparam) { SetStandbyAllowed(false); try { ThreadParams param = (ThreadParams)aparam; Setting setting; TvBusinessLayer layer = new TvBusinessLayer(); string destination = layer.GetSetting("webepgDestination", "db").Value; string webepgDirectory = PathManager.GetDataPath; string configFile = webepgDirectory + @"\WebEPG\WebEPG.xml"; //int numChannels = 0, numPrograms = 0; //string errors = ""; try { Log.Write("plugin:webepg importing"); Log.Info("WebEPG: Using directory {0}", webepgDirectory); IEpgDataSink epgSink; if (destination == "db") { bool deleteBeforeImport = Convert.ToBoolean(layer.GetSetting("webepgDeleteBeforeImport", "true").Value); //// Allow for deleting of all existing programs before adding the new ones. //// Already imported programs might have incorrect data depending on the grabber & setup //// f.e when grabbing programs many days ahead //if (deleteBeforeImport && ! deleteOnlyOverlapping) //{ // SqlBuilder sb = new SqlBuilder(StatementType.Delete, typeof(Program)); // SqlStatement stmt = sb.GetStatement(); // stmt.Execute(); //} epgSink = new DatabaseEPGDataSink(deleteBeforeImport); Log.Info("Writing to TVServer database"); } else { string xmltvDirectory = string.Empty; if (destination == "xmltv") { xmltvDirectory = layer.GetSetting("webepgDestinationFolder", string.Empty).Value; } if (xmltvDirectory == string.Empty) { // Do not use XmlTvImporter.DefaultOutputFolder to avoid reference to XmlTvImport xmltvDirectory = layer.GetSetting("xmlTv", PathManager.GetDataPath + @"\xmltv").Value; } Log.Info("Writing to tvguide.xml in {0}", xmltvDirectory); // Open XMLTV output file if (!Directory.Exists(xmltvDirectory)) { Directory.CreateDirectory(xmltvDirectory); } epgSink = new XMLTVExport(xmltvDirectory); } WebEPG epg = new WebEPG(configFile, epgSink, webepgDirectory); if (param.showProgress != null) { epg.ShowProgress += param.showProgress; } epg.Import(); if (param.showProgress != null) { epg.ShowProgress -= param.showProgress; } setting = layer.GetSetting("webepgResultLastImport", ""); setting.Value = DateTime.Now.ToString(); setting.Persist(); setting = layer.GetSetting("webepgResultChannels", ""); setting.Value = epg.ImportStats.Channels.ToString(); setting.Persist(); setting = layer.GetSetting("webepgResultPrograms", ""); setting.Value = epg.ImportStats.Programs.ToString(); setting.Persist(); setting = layer.GetSetting("webepgResultStatus", ""); setting.Value = epg.ImportStats.Status; setting.Persist(); //Log.Write("Xmltv: imported {0} channels, {1} programs status:{2}", numChannels, numPrograms, errors); } catch (Exception ex) { Log.Error(@"plugin:webepg import failed"); Log.Write(ex); } setting = layer.GetSetting("webepgResultLastImport", ""); setting.Value = DateTime.Now.ToString(); setting.Persist(); } finally { Log.WriteFile(@"plugin:webepg import done"); _workerThreadRunning = false; SetStandbyAllowed(true); } }
protected void StartImport(WebEPG.ShowProgressHandler showProgress) { if (_workerThreadRunning) return; _workerThreadRunning = true; ThreadParams param = new ThreadParams(); param.showProgress = showProgress; Thread workerThread = new Thread(new ParameterizedThreadStart(ThreadFunctionImportTVGuide)); workerThread.Name = "WebEPGImporter"; workerThread.IsBackground = true; workerThread.Priority = ThreadPriority.Lowest; workerThread.Start(param); }
private void ShowImportProgress(WebEPG.Stats status) { this.Invoke(new ShowStatusHandler(ShowStatus), new object[] {status}); }
/// <summary> /// Forces the import of the tvguide. Usable when testing the grabber /// </summary> public void ForceImport(WebEPG.ShowProgressHandler showProgress) { StartImport(showProgress); }
private void ShowStatus(WebEPG.Stats status) { labelLastImport.Text = status.StartTime.ToString(); labelChannels.Text = status.Channels.ToString(); labelPrograms.Text = status.Programs.ToString(); labelStatus.Text = status.Status; TvBusinessLayer layer = new TvBusinessLayer(); Setting setting = layer.GetSetting("webepgResultLastImport", ""); setting.Value = status.StartTime.ToString(); setting.Persist(); setting = layer.GetSetting("webepgResultChannels", ""); setting.Value = status.Channels.ToString(); setting.Persist(); setting = layer.GetSetting("webepgResultPrograms", ""); setting.Value = status.Programs.ToString(); setting.Persist(); setting = layer.GetSetting("webepgResultStatus", ""); setting.Value = status.Status; setting.Persist(); }