Files
ChanSort/source/ChanSort.Api/Model/DataRoot.cs

128 lines
4.0 KiB
C#
Raw Normal View History

2013-03-31 14:09:38 +02:00
using System.Collections.Generic;
using System.Text;
namespace ChanSort.Api
{
public class DataRoot
{
private readonly IDictionary<int, Satellite> satellites = new Dictionary<int, Satellite>();
private readonly IDictionary<int, Transponder> transponder = new Dictionary<int, Transponder>();
private readonly IDictionary<int, LnbConfig> lnbConfig = new Dictionary<int, LnbConfig>();
2013-03-31 14:09:38 +02:00
private readonly IList<ChannelList> channelLists = new List<ChannelList>();
private readonly StringBuilder warnings = new StringBuilder();
public StringBuilder Warnings { get { return this.warnings; } }
public IDictionary<int, Satellite> Satellites { get { return this.satellites; } }
public IDictionary<int, Transponder> Transponder { get { return this.transponder; } }
public IDictionary<int, LnbConfig> LnbConfig { get { return this.lnbConfig; } }
public IEnumerable<ChannelList> ChannelLists { get { return this.channelLists; } }
2013-03-31 14:09:38 +02:00
public bool IsEmpty { get { return this.channelLists.Count == 0; } }
public bool NeedsSaving { get; set; }
public Favorites SupportedFavorites { get; set; }
public bool SortedFavorites { get; set; }
public bool MixedSourceFavorites { get; set; }
public bool AllowGapsInFavNumbers { get; set; }
public bool ShowDeletedChannels { get; set; }
2013-03-31 14:09:38 +02:00
public DataRoot()
{
this.SupportedFavorites = Favorites.A | Favorites.B | Favorites.C | Favorites.D;
}
#region AddSatellite()
public virtual void AddSatellite(Satellite satellite)
{
this.satellites.Add(satellite.Id, satellite);
}
#endregion
#region AddTransponder()
public virtual void AddTransponder(Satellite sat, Transponder trans)
{
trans.Satellite = sat;
if (this.transponder.ContainsKey(trans.Id))
{
this.warnings.AppendFormat("Duplicate transponder data record for satellite #{0} with id {1}\r\n", sat?.Id, trans.Id);
2013-03-31 14:09:38 +02:00
return;
}
if (sat != null)
sat.Transponder.Add(trans.Id, trans);
2013-03-31 14:09:38 +02:00
this.transponder.Add(trans.Id, trans);
}
#endregion
#region AddLnbConfig()
public void AddLnbConfig(LnbConfig lnb)
{
this.lnbConfig.Add(lnb.Id, lnb);
}
#endregion
2013-03-31 14:09:38 +02:00
#region AddChannelList()
public virtual void AddChannelList(ChannelList list)
{
this.channelLists.Add(list);
2016-04-27 19:03:50 +02:00
this.MixedSourceFavorites |= list.IsMixedSourceFavoritesList;
2013-03-31 14:09:38 +02:00
}
#endregion
#region AddChannel()
public virtual void AddChannel(ChannelList list, ChannelInfo channel)
{
if (list == null)
{
warnings.AppendFormat("No list found to add channel '{0}'\r\n", channel);
return;
}
2013-03-31 14:09:38 +02:00
string warning = list.AddChannel(channel);
if (warning != null)
this.Warnings.AppendLine(warning);
}
#endregion
#region GetChannelList()
2013-04-03 23:26:09 +02:00
public ChannelList GetChannelList(SignalSource criteriaMask)
2013-03-31 14:09:38 +02:00
{
foreach (var list in this.channelLists)
{
2013-04-03 23:26:09 +02:00
uint searchMask = (uint)criteriaMask;
uint listMask = (uint) list.SignalSource;
if ((listMask & 0x000F & searchMask) != (searchMask & 0x000F)) // digital/analog
2013-04-03 23:26:09 +02:00
continue;
if ((listMask & 0x00F0 & searchMask) != (searchMask & 0x00F0)) // air/cable/sat/ip
2013-04-03 23:26:09 +02:00
continue;
if ((listMask & 0x0F00 & searchMask) != (searchMask & 0x0F00)) // tv/radio
2013-03-31 14:09:38 +02:00
continue;
2013-04-03 23:26:09 +02:00
if ((listMask & 0xF000) != (searchMask & 0xF000)) // preset list
2013-03-31 14:09:38 +02:00
continue;
2013-04-03 23:26:09 +02:00
return list;
2013-03-31 14:09:38 +02:00
}
2013-04-03 23:26:09 +02:00
return null;
2013-03-31 14:09:38 +02:00
}
#endregion
#region ApplyCurrentProgramNumbers()
public void ApplyCurrentProgramNumbers()
{
int c = 0;
if (this.MixedSourceFavorites || this.SortedFavorites)
{
for (int m = (int) this.SupportedFavorites; m != 0; m >>= 1)
++c;
}
foreach (var list in this.ChannelLists)
{
foreach (var channel in list.Channels)
{
for (int i=0; i<=c; i++)
channel.SetPosition(i, channel.GetOldPosition(i));
}
}
}
#endregion
2013-03-31 14:09:38 +02:00
}
}