private void LoadMemberSettings() { _useShortProgramDesc = TvBLayer.GetSetting("TvMovieShortProgramDesc", "false").Value == "true"; _extendDescription = TvBLayer.GetSetting("TvMovieExtendDescription", "true").Value == "true"; _showRatings = TvBLayer.GetSetting("TvMovieShowRatings", "true").Value == "true"; _showAudioFormat = TvBLayer.GetSetting("TvMovieShowAudioFormat", "false").Value == "true"; _slowImport = TvBLayer.GetSetting("TvMovieSlowImport", "true").Value == "true"; _actorCount = Convert.ToInt32(TvBLayer.GetSetting("TvMovieLimitActors", "5").Value); _showLive = TvBLayer.GetSetting("TvMovieShowLive", "true").Value == "true"; _showRepeat = TvBLayer.GetSetting("TvMovieShowRepeating", "false").Value == "true"; _xmlFile = String.Format(@"{0}\TVMovieMapping.xml", PathManager.GetDataPath); }
/// <summary> /// Loops through all channel to find mappings and finally import EPG to MP's DB /// </summary> public void Import() { if (_canceled) { return; } List <Mapping> mappingList = GetMappingList(); if (mappingList == null || mappingList.Count < 1) { Log.Info("TVMovie: Cannot import from TV Movie database - no mappings found"); return; } DateTime ImportStartTime = DateTime.Now; Log.Debug("TVMovie: Importing database"); int maximum = 0; foreach (TVMChannel tvmChan in _tvmEpgChannels) { foreach (Mapping mapping in mappingList) { if (mapping.TvmEpgChannel == tvmChan.TvmEpgChannel) { maximum++; break; } } } Log.Debug("TVMovie: Calculating stations done"); // setting update time of epg import to avoid that the background thread triggers another import // if the process lasts longer than the timer's update check interval Setting setting = TvBLayer.GetSetting("TvMovieLastUpdate"); setting.Value = DateTime.Now.ToString(); setting.Persist(); Log.Debug("TVMovie: Mapped {0} stations for EPG import", Convert.ToString(maximum)); int counter = 0; _tvmEpgProgs.Clear(); // get all tv channels from MP DB via gentle.net IList <Channel> allChannels = Channel.ListAll(); foreach (TVMChannel station in _tvmEpgChannels) { if (_canceled) { return; } Log.Info("TVMovie: Searching time share mappings for station: {0}", station.TvmEpgDescription); // get all tv movie channels List <Mapping> channelNames = new List <Mapping>(); foreach (Mapping mapping in mappingList) { if (mapping.TvmEpgChannel == station.TvmEpgChannel) { channelNames.Add(mapping); } } if (channelNames.Count > 0) { try { string display = String.Empty; foreach (Mapping channelName in channelNames) { display += string.Format("{0} / ", channelName.Channel); } display = display.Substring(0, display.Length - 5); if (OnStationsChanged != null) { OnStationsChanged(counter, maximum, display); } counter++; Log.Info("TVMovie: Importing {3} time frame(s) for MP channel [{0}/{1}] - {2}", Convert.ToString(counter), Convert.ToString(maximum), display, Convert.ToString(channelNames.Count)); _tvmEpgProgs.Clear(); _programsCounter += ImportStation(station.TvmEpgChannel, channelNames, allChannels); ThreadPriority importPrio = _slowImport ? ThreadPriority.BelowNormal : ThreadPriority.AboveNormal; if (_slowImport) { Thread.Sleep(32); } // make a copy of this list because Insert it done in syncronized threads - therefore the object reference would cause multiple/missing entries List <Program> InsertCopy = new List <Program>(_tvmEpgProgs); int debugCount = TvBLayer.InsertPrograms(InsertCopy, DeleteBeforeImportOption.OverlappingPrograms, importPrio); Log.Info("TVMovie: Inserted {0} programs", debugCount); } catch (Exception ex) { Log.Info("TVMovie: Error inserting programs - {0}", ex.StackTrace); } } } Log.Debug("TVMovie: Waiting for database to be updated..."); TvBLayer.WaitForInsertPrograms(); Log.Debug("TVMovie: Database update finished."); if (OnStationsChanged != null) { OnStationsChanged(maximum, maximum, "Import done"); } if (!_canceled) { try { setting = TvBLayer.GetSetting("TvMovieLastUpdate"); setting.Value = DateTime.Now.ToString(); setting.Persist(); TimeSpan ImportDuration = (DateTime.Now - ImportStartTime); Log.Debug("TVMovie: Imported {0} database entries for {1} stations in {2} seconds", _programsCounter, counter, Convert.ToString(ImportDuration.TotalSeconds)); } catch (Exception) { Log.Info("TVMovie: Error updating the database with last import date"); } } GC.Collect(); }