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; } }