mirror of
https://github.com/PredatH0r/ChanSort.git
synced 2026-03-06 12:10:42 +01:00
- moved all files to a "source" subdirectory to tidy up the GitHub project page
- started to write a readme.md
This commit is contained in:
260
source/ChanSort.Api/Model/ChannelInfo.cs
Normal file
260
source/ChanSort.Api/Model/ChannelInfo.cs
Normal file
@@ -0,0 +1,260 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace ChanSort.Api
|
||||
{
|
||||
public class ChannelInfo
|
||||
{
|
||||
private const int MAX_FAV_LISTS = 5;
|
||||
|
||||
private string uid;
|
||||
/// <summary>
|
||||
/// List of channels that have the same UID as this channel and were not added to the channel list directly
|
||||
/// </summary>
|
||||
public readonly List<ChannelInfo> Duplicates = new List<ChannelInfo>();
|
||||
|
||||
public virtual bool IsDeleted { get; set; }
|
||||
public SignalSource SignalSource { get; set; }
|
||||
public long RecordIndex { get; set; }
|
||||
public int RecordOrder { get; set; }
|
||||
public int OldProgramNr { get; set; }
|
||||
public int NewProgramNr { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string ShortName { get; set; }
|
||||
public Favorites Favorites { get; set; }
|
||||
public bool Skip { get; set; }
|
||||
public bool Lock { get; set; }
|
||||
public bool Hidden { get; set; }
|
||||
public bool? Encrypted { get; set; }
|
||||
public string ChannelOrTransponder { get; set; }
|
||||
public string Satellite { get; set; }
|
||||
public decimal FreqInMhz { get; set; }
|
||||
public char Polarity { get; set; }
|
||||
public int ServiceId { get; set; }
|
||||
public int VideoPid { get; set; }
|
||||
public int AudioPid { get; set; }
|
||||
public int OriginalNetworkId { get; set; }
|
||||
public int TransportStreamId { get; set; }
|
||||
public int Bouquet { get; set; }
|
||||
public string Provider { get; set; }
|
||||
public int SymbolRate { get; set; }
|
||||
public int ServiceType { get; set; }
|
||||
public string Debug { get; private set; }
|
||||
public string SatPosition { get; set; }
|
||||
public Transponder Transponder { get; set; }
|
||||
public IList<int> FavIndex { get; private set; }
|
||||
public int ProgramNrPreset { get; set; }
|
||||
|
||||
public bool IsNameModified { get; set; }
|
||||
|
||||
#region ctor()
|
||||
protected ChannelInfo()
|
||||
{
|
||||
this.NewProgramNr = -1;
|
||||
this.FavIndex = new List<int>(MAX_FAV_LISTS);
|
||||
for (int i = 0; i < MAX_FAV_LISTS; i++)
|
||||
this.FavIndex.Add(-1);
|
||||
this.Name = "";
|
||||
this.ShortName = "";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor for exiting TV channel
|
||||
/// </summary>
|
||||
public ChannelInfo(SignalSource source, int index, int oldProgNr, string name) : this()
|
||||
{
|
||||
this.SignalSource = source;
|
||||
this.RecordIndex = index;
|
||||
this.RecordOrder = index;
|
||||
this.NewProgramNr = -1;
|
||||
this.OldProgramNr = oldProgNr;
|
||||
this.Name = name;
|
||||
this.Encrypted = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor for reference list channels which no longer exist in TV list
|
||||
/// </summary>
|
||||
public ChannelInfo(SignalSource source, string uid, int newProgNr, string name) : this()
|
||||
{
|
||||
this.SignalSource = source;
|
||||
this.Uid = uid;
|
||||
this.RecordIndex = -1;
|
||||
this.RecordOrder = -1;
|
||||
this.OldProgramNr = -1;
|
||||
this.NewProgramNr = newProgNr;
|
||||
this.Name = name;
|
||||
this.Encrypted = null;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Uid
|
||||
public string Uid
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.uid == null)
|
||||
{
|
||||
if ((this.SignalSource & SignalSource.Digital) == 0)
|
||||
this.uid = "A-0-" + (int)(this.FreqInMhz*20) + "-0";
|
||||
else if ((this.SignalSource & SignalSource.Sat) != 0)
|
||||
this.uid = "S" + this.SatPosition + "-" + this.OriginalNetworkId + "-" + this.TransportStreamId + "-" + this.ServiceId;
|
||||
else
|
||||
this.uid = "C-" + this.OriginalNetworkId + "-" + this.TransportStreamId + "-" + this.ServiceId + "-" + this.ChannelOrTransponder;
|
||||
}
|
||||
return this.uid;
|
||||
}
|
||||
set { this.uid = value; }
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ToString(), Equals(), GetHashCode()
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
string nr = this.NewProgramNr != -1 ? this.NewProgramNr.ToString() : "@" + this.RecordIndex;
|
||||
return nr + ": " + this.Name;
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
//ChannelInfo that = obj as ChannelInfo;
|
||||
//return that != null && this.Uid == that.Uid && this.OldProgramNr == that.OldProgramNr;
|
||||
return ReferenceEquals(this, obj);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return this.Uid.GetHashCode() + this.OldProgramNr;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region NetworkName, NetworkOperator
|
||||
public string NetworkName
|
||||
{
|
||||
get
|
||||
{
|
||||
var network = LookupData.Instance.GetNetwork(this.OriginalNetworkId);
|
||||
return network == null ? null : network.Name;
|
||||
}
|
||||
}
|
||||
|
||||
public string NetworkOperator
|
||||
{
|
||||
get
|
||||
{
|
||||
var network = LookupData.Instance.GetNetwork(this.OriginalNetworkId);
|
||||
return network == null ? null : network.Operator;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ServiceTypeName
|
||||
public string ServiceTypeName { get { return LookupData.Instance.GetServiceTypeDescription(this.ServiceType); } }
|
||||
#endregion
|
||||
|
||||
#region GetFavString()
|
||||
public static string GetFavString(Favorites favorites)
|
||||
{
|
||||
string sep = "";
|
||||
string text = "";
|
||||
foreach (Favorites favMask in Enum.GetValues(typeof(Favorites)))
|
||||
{
|
||||
if ((favorites & favMask) != 0)
|
||||
{
|
||||
text += sep + favMask.ToString();
|
||||
sep = ",";
|
||||
}
|
||||
}
|
||||
return text;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ParseFavString()
|
||||
public static Favorites ParseFavString(string value)
|
||||
{
|
||||
Favorites favMask = 0;
|
||||
foreach (Favorites fav in Enum.GetValues(typeof (Favorites)))
|
||||
{
|
||||
foreach (char c in value)
|
||||
{
|
||||
if (c == fav.ToString()[0])
|
||||
{
|
||||
favMask |= fav;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return favMask;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region AddDebug()
|
||||
public void AddDebug(byte val)
|
||||
{
|
||||
if (this.Debug == null)
|
||||
this.Debug = val.ToString("x2");
|
||||
else
|
||||
this.Debug += " " + val.ToString("x2");
|
||||
}
|
||||
|
||||
public void AddDebug(ushort val)
|
||||
{
|
||||
if (this.Debug == null)
|
||||
this.Debug = val.ToString("x2");
|
||||
else
|
||||
this.Debug += " " + val.ToString("x4");
|
||||
}
|
||||
|
||||
public void AddDebug(byte[] data, int offset, int len)
|
||||
{
|
||||
for (int i = 0; i < len; i++)
|
||||
this.AddDebug(data[offset + i]);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region UpdateRawData()
|
||||
public virtual void UpdateRawData()
|
||||
{
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ChangeEncoding()
|
||||
public virtual void ChangeEncoding(System.Text.Encoding encoding)
|
||||
{
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region GetPosition(), SetPosition(), ChangePosition()
|
||||
|
||||
public int GetPosition(int subListIndex)
|
||||
{
|
||||
return subListIndex == 0 ? this.NewProgramNr : this.FavIndex[subListIndex - 1];
|
||||
}
|
||||
|
||||
public void SetPosition(int subListIndex, int newPos)
|
||||
{
|
||||
if (subListIndex == 0)
|
||||
this.NewProgramNr = newPos;
|
||||
else
|
||||
{
|
||||
this.FavIndex[subListIndex - 1] = newPos;
|
||||
int mask = 1 << (subListIndex - 1);
|
||||
if (newPos == -1)
|
||||
this.Favorites &= (Favorites)~mask;
|
||||
else
|
||||
this.Favorites |= (Favorites)mask;
|
||||
}
|
||||
}
|
||||
|
||||
internal void ChangePosition(int subListIndex, int delta)
|
||||
{
|
||||
if (subListIndex == 0)
|
||||
this.NewProgramNr += delta;
|
||||
else
|
||||
this.FavIndex[subListIndex - 1] += delta;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
160
source/ChanSort.Api/Model/ChannelList.cs
Normal file
160
source/ChanSort.Api/Model/ChannelList.cs
Normal file
@@ -0,0 +1,160 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace ChanSort.Api
|
||||
{
|
||||
public class ChannelList
|
||||
{
|
||||
private readonly SignalSource source;
|
||||
private readonly IList<ChannelInfo> channels = new List<ChannelInfo>();
|
||||
private readonly Dictionary<string, IList<ChannelInfo>> channelByUid = new Dictionary<string, IList<ChannelInfo>>();
|
||||
private readonly Dictionary<int, ChannelInfo> channelByProgNr = new Dictionary<int, ChannelInfo>();
|
||||
private readonly Dictionary<string, IList<ChannelInfo>> channelByName = new Dictionary<string, IList<ChannelInfo>>();
|
||||
private int insertProgramNr = 1;
|
||||
private int duplicateUidCount;
|
||||
private int duplicateProgNrCount;
|
||||
|
||||
public ChannelList(SignalSource source, string caption)
|
||||
{
|
||||
this.source = source;
|
||||
this.ShortCaption = caption;
|
||||
this.FirstProgramNumber = (source & SignalSource.Digital) != 0 ? 1 : 0;
|
||||
}
|
||||
|
||||
public string ShortCaption { get; private set; }
|
||||
public SignalSource SignalSource { get { return this.source; } }
|
||||
public IList<ChannelInfo> Channels { get { return this.channels; } }
|
||||
public int Count { get { return channels.Count; } }
|
||||
public int DuplicateUidCount { get { return duplicateUidCount; } }
|
||||
public int DuplicateProgNrCount { get { return duplicateProgNrCount; } }
|
||||
public bool ReadOnly { get; set; }
|
||||
public int MaxChannelNameLength { get; set; }
|
||||
public int PresetProgramNrCount { get; private set; }
|
||||
|
||||
#region Caption
|
||||
public string Caption
|
||||
{
|
||||
get
|
||||
{
|
||||
string cap = this.ShortCaption;
|
||||
int validChannelCount = this.Channels.Count(ch => ch.OldProgramNr != -1);
|
||||
return cap + " (" + validChannelCount + ")";
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region InsertProgramNumber
|
||||
public int InsertProgramNumber
|
||||
{
|
||||
get { return this.Count == 0 ? 1 : this.insertProgramNr; }
|
||||
set { this.insertProgramNr = Math.Max(this.FirstProgramNumber, value); }
|
||||
}
|
||||
#endregion
|
||||
|
||||
public int FirstProgramNumber { get; set; }
|
||||
|
||||
#region AddChannel()
|
||||
public string AddChannel(ChannelInfo ci)
|
||||
{
|
||||
IList<ChannelInfo> others;
|
||||
if (this.channelByUid.TryGetValue(ci.Uid, out others))
|
||||
++duplicateUidCount;
|
||||
else
|
||||
{
|
||||
others = new List<ChannelInfo>();
|
||||
this.channelByUid.Add(ci.Uid, others);
|
||||
}
|
||||
others.Add(ci);
|
||||
|
||||
string warning2 = null;
|
||||
bool isDupeProgNr = false;
|
||||
if (ci.OldProgramNr != -1)
|
||||
{
|
||||
ChannelInfo other;
|
||||
this.channelByProgNr.TryGetValue(ci.OldProgramNr, out other);
|
||||
if (other != null)
|
||||
{
|
||||
warning2 = string.Format(Resources.ChannelList_ProgramNrAssignedToMultipleChannels,
|
||||
this.ShortCaption, ci.OldProgramNr, other.RecordIndex, other.Name, ci.RecordIndex, ci.Name);
|
||||
++duplicateProgNrCount;
|
||||
isDupeProgNr = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!isDupeProgNr)
|
||||
this.channelByProgNr[ci.OldProgramNr] = ci;
|
||||
|
||||
var lowerName = (ci.Name ?? "").ToLower().Trim();
|
||||
var byNameList = this.channelByName.TryGet(lowerName);
|
||||
if (byNameList == null)
|
||||
{
|
||||
byNameList = new List<ChannelInfo>();
|
||||
this.channelByName[lowerName] = byNameList;
|
||||
}
|
||||
byNameList.Add(ci);
|
||||
|
||||
if (ci.ProgramNrPreset != 0)
|
||||
++this.PresetProgramNrCount;
|
||||
|
||||
this.channels.Add(ci);
|
||||
|
||||
return warning2;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region GetChannelByUid()
|
||||
public IList<ChannelInfo> GetChannelByUid(string uid)
|
||||
{
|
||||
IList<ChannelInfo> channel;
|
||||
this.channelByUid.TryGetValue(uid, out channel);
|
||||
return channel ?? new List<ChannelInfo>(0);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ToString()
|
||||
public override string ToString()
|
||||
{
|
||||
return this.Caption;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region GetChannelByName()
|
||||
public IEnumerable<ChannelInfo> GetChannelByName(string name)
|
||||
{
|
||||
var hits = this.channelByName.TryGet(name.ToLower().Trim());
|
||||
return hits ?? new List<ChannelInfo>();
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region GetChannelByNewProgNr()
|
||||
public IList<ChannelInfo> GetChannelByNewProgNr(int newProgNr)
|
||||
{
|
||||
return this.channels.Where(c => c.NewProgramNr == newProgNr).ToList();
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region GetChannelsByNewOrder()
|
||||
public IList<ChannelInfo> GetChannelsByNewOrder()
|
||||
{
|
||||
return this.channels.OrderBy(c => c.NewProgramNr).ToList();
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region RemoveChannel()
|
||||
public void RemoveChannel(ChannelInfo channel)
|
||||
{
|
||||
this.channels.Remove(channel);
|
||||
var list = this.channelByUid.TryGet(channel.Uid);
|
||||
if (list != null && list.Contains(channel))
|
||||
list.Remove(channel);
|
||||
list = this.channelByName.TryGet(channel.Name);
|
||||
if (list != null && list.Contains(channel))
|
||||
list.Remove(channel);
|
||||
var chan = this.channelByProgNr.TryGet(channel.OldProgramNr);
|
||||
if (ReferenceEquals(chan, channel))
|
||||
this.channelByProgNr.Remove(channel.OldProgramNr);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
112
source/ChanSort.Api/Model/DataRoot.cs
Normal file
112
source/ChanSort.Api/Model/DataRoot.cs
Normal file
@@ -0,0 +1,112 @@
|
||||
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>();
|
||||
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 ICollection<ChannelList> ChannelLists { get { return this.channelLists; } }
|
||||
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 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);
|
||||
return;
|
||||
}
|
||||
sat.Transponder.Add(trans.Id, trans);
|
||||
this.transponder.Add(trans.Id, trans);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region AddLnbConfig()
|
||||
public void AddLnbConfig(LnbConfig lnb)
|
||||
{
|
||||
this.lnbConfig.Add(lnb.Id, lnb);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region AddChannelList()
|
||||
public virtual void AddChannelList(ChannelList list)
|
||||
{
|
||||
this.channelLists.Add(list);
|
||||
}
|
||||
#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;
|
||||
}
|
||||
string warning = list.AddChannel(channel);
|
||||
if (warning != null)
|
||||
this.Warnings.AppendLine(warning);
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
#region GetChannelList()
|
||||
public ChannelList GetChannelList(SignalSource criteriaMask)
|
||||
{
|
||||
foreach (var list in this.channelLists)
|
||||
{
|
||||
uint searchMask = (uint)criteriaMask;
|
||||
uint listMask = (uint) list.SignalSource;
|
||||
|
||||
if ((listMask & 0x000F & searchMask) != (searchMask & 0x000F)) // digital/analog
|
||||
continue;
|
||||
if ((listMask & 0x00F0 & searchMask) != (searchMask & 0x00F0)) // air/cable/sat/ip
|
||||
continue;
|
||||
if ((listMask & 0x0F00 & searchMask) != (searchMask & 0x0F00)) // tv/radio
|
||||
continue;
|
||||
if ((listMask & 0xF000) != (searchMask & 0xF000)) // preset list
|
||||
continue;
|
||||
return list;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ApplyCurrentProgramNumbers()
|
||||
public void ApplyCurrentProgramNumbers()
|
||||
{
|
||||
foreach (var list in this.ChannelLists)
|
||||
{
|
||||
foreach (var channel in list.Channels)
|
||||
channel.NewProgramNr = channel.OldProgramNr;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
73
source/ChanSort.Api/Model/Enums.cs
Normal file
73
source/ChanSort.Api/Model/Enums.cs
Normal file
@@ -0,0 +1,73 @@
|
||||
using System;
|
||||
|
||||
namespace ChanSort.Api
|
||||
{
|
||||
#region enum SignalSource
|
||||
/// <summary>
|
||||
/// Bitmask for channel and list classification.
|
||||
/// An individual channel can only have one bit of each group set.
|
||||
/// A ChannelList can have multiple bits set to indicate which type of channels it can hold.
|
||||
/// </summary>
|
||||
[Flags]
|
||||
public enum SignalSource
|
||||
{
|
||||
// bit 1+2: analog/digital
|
||||
MaskAnalogDigital = 0x0003,
|
||||
Analog = 0x0001,
|
||||
Digital = 0x0002,
|
||||
|
||||
// bit 5+6+7+8: Antenna/Cable/Sat/IP
|
||||
MaskAntennaCableSat = 0x00F0,
|
||||
Antenna = 0x0010,
|
||||
Cable = 0x0020,
|
||||
Sat = 0x0040,
|
||||
IP = 0x0080,
|
||||
|
||||
// bit 9+10: TV/Radio
|
||||
MaskTvRadio = 0x0300,
|
||||
Tv = 0x0100,
|
||||
Radio = 0x0200,
|
||||
TvAndRadio = Tv | Radio,
|
||||
|
||||
// bit 13-16: Preset list selector (AstraHD+, Freesat, TivuSat, CanalDigitalSat, ... for Samsung)
|
||||
MaskProvider = 0xFC00,
|
||||
StandardSat = 0 << 12,
|
||||
AstraHdPlus = 1 << 12,
|
||||
Freesat = 2 << 12,
|
||||
TivuSat = 3 << 12,
|
||||
CanalDigital = 4 << 12,
|
||||
DigitalPlus = 5 << 12,
|
||||
CyfraPlus = 6 << 12,
|
||||
|
||||
StandardCable = 0 << 12,
|
||||
CablePrime = 1 << 12,
|
||||
|
||||
AnalogC = Analog + Cable,
|
||||
AnalogT = Analog + Antenna,
|
||||
AnalogCT = Analog + Cable + Antenna,
|
||||
DvbC = Digital + Cable,
|
||||
DvbT = Digital + Antenna,
|
||||
DvbCT = Digital + Cable + Antenna,
|
||||
DvbS = Digital + Sat,
|
||||
SatIP = Digital + Sat + IP,
|
||||
|
||||
CablePrimeD = Digital + Cable + CablePrime,
|
||||
HdPlusD = Digital + Sat + AstraHdPlus,
|
||||
FreesatD = Digital + Sat + Freesat,
|
||||
TivuSatD = Digital + Sat + TivuSat,
|
||||
CanalDigitalSatD = Digital + Sat + CanalDigital,
|
||||
DigitalPlusD = Digital + Sat + DigitalPlus,
|
||||
CyfraPlusD = Digital + Sat + CyfraPlus
|
||||
}
|
||||
#endregion
|
||||
|
||||
[Flags]
|
||||
public enum Favorites : byte { A = 0x01, B = 0x02, C = 0x04, D = 0x08, E = 0x10 }
|
||||
|
||||
public enum UnsortedChannelMode
|
||||
{
|
||||
AppendInOrder=0,
|
||||
AppendAlphabetically=1,
|
||||
MarkDeleted=2
|
||||
}
|
||||
}
|
||||
7
source/ChanSort.Api/Model/LnbConfig.cs
Normal file
7
source/ChanSort.Api/Model/LnbConfig.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace ChanSort.Api
|
||||
{
|
||||
public class LnbConfig
|
||||
{
|
||||
public int Id { get; protected set; }
|
||||
}
|
||||
}
|
||||
231
source/ChanSort.Api/Model/LookupData.cs
Normal file
231
source/ChanSort.Api/Model/LookupData.cs
Normal file
@@ -0,0 +1,231 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
|
||||
namespace ChanSort.Api
|
||||
{
|
||||
public class LookupData
|
||||
{
|
||||
private readonly IDictionary<int, NetworkInfo> networks = new Dictionary<int, NetworkInfo>();
|
||||
private readonly IDictionary<int, int> transponderNrByFreqInMhz = new Dictionary<int, int>();
|
||||
private readonly IDictionary<int, int> transponderFreqInMhzByNr = new Dictionary<int, int>();
|
||||
private readonly IDictionary<int, string> serviceTypeDescriptions = new Dictionary<int, string>();
|
||||
private readonly IDictionary<int, int> dvbtFreqInMhzByTransponder = new Dictionary<int, int>();
|
||||
|
||||
public static readonly LookupData Instance = new LookupData();
|
||||
|
||||
private LookupData()
|
||||
{
|
||||
this.LoadDataFromCsvFile();
|
||||
}
|
||||
|
||||
#region GetNetwork()
|
||||
public NetworkInfo GetNetwork(int networkId)
|
||||
{
|
||||
NetworkInfo network;
|
||||
this.networks.TryGetValue((ushort)networkId, out network);
|
||||
return network;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region GetTransponderNumber(), GetTransponderFrequency()
|
||||
public int GetTransponderNumber(int frequencyInMhz)
|
||||
{
|
||||
int number;
|
||||
bool found = this.transponderNrByFreqInMhz.TryGetValue(frequencyInMhz, out number) ||
|
||||
this.transponderNrByFreqInMhz.TryGetValue(frequencyInMhz - 1, out number) ||
|
||||
this.transponderNrByFreqInMhz.TryGetValue(frequencyInMhz + 1, out number) ||
|
||||
this.transponderNrByFreqInMhz.TryGetValue(frequencyInMhz - 2, out number) ||
|
||||
this.transponderNrByFreqInMhz.TryGetValue(frequencyInMhz + 2, out number);
|
||||
return found ? number : 0;
|
||||
}
|
||||
|
||||
public int GetTransponderFrequency(int transponderNr)
|
||||
{
|
||||
return this.transponderNrByFreqInMhz.TryGet(transponderNr);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region GetServiceTypeDescription()
|
||||
public string GetServiceTypeDescription(int serviceType)
|
||||
{
|
||||
string descr;
|
||||
this.serviceTypeDescriptions.TryGetValue(serviceType, out descr);
|
||||
return descr;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region LoadDataFromCsvFile()
|
||||
public void LoadDataFromCsvFile()
|
||||
{
|
||||
this.networks.Clear();
|
||||
this.transponderFreqInMhzByNr.Clear();
|
||||
this.transponderNrByFreqInMhz.Clear();
|
||||
this.serviceTypeDescriptions.Clear();
|
||||
this.dvbtFreqInMhzByTransponder.Clear();
|
||||
|
||||
string file = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "lookup.csv");
|
||||
if (!File.Exists(file))
|
||||
return;
|
||||
using (var reader = new StreamReader(file, System.Text.Encoding.UTF8))
|
||||
{
|
||||
string line;
|
||||
while ((line = reader.ReadLine()) != null)
|
||||
{
|
||||
var fields = CsvFile.Parse(line, ';');
|
||||
if (fields.Count == 0)
|
||||
continue;
|
||||
switch (fields[0].ToLower())
|
||||
{
|
||||
case "onid": this.ParseNetwork(fields); break;
|
||||
case "dvbt": this.ParseDvbtTransponder(fields); break;
|
||||
case "transp": this.ParseTransponder(fields); break;
|
||||
case "servicetype": this.ParseServiceType(fields); break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region AddNetwork()
|
||||
private void AddNetwork(NetworkInfo network)
|
||||
{
|
||||
this.networks[network.OriginalNetworkId] = network;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region AddTransponderMapping()
|
||||
private void AddTransponderMapping(int transponderNr, int frequencyInMhz)
|
||||
{
|
||||
this.transponderNrByFreqInMhz[frequencyInMhz] = transponderNr;
|
||||
this.transponderFreqInMhzByNr[transponderNr] = frequencyInMhz;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region AddDvbtTransponderMapping()
|
||||
private void AddDvbtTransponderMapping(int transponderNr, int frequencyInMhz)
|
||||
{
|
||||
this.dvbtFreqInMhzByTransponder[transponderNr] = frequencyInMhz;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region AddServiceType()
|
||||
public void AddServiceType(int serviceType, string description)
|
||||
{
|
||||
this.serviceTypeDescriptions[serviceType] = description;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ParseNetwork()
|
||||
private void ParseNetwork(IList<string> fields)
|
||||
{
|
||||
if (fields.Count < 3)
|
||||
return;
|
||||
int start = ParseNumber(fields[1]);
|
||||
int end = ParseNumber(fields[2]);
|
||||
if (start == 0 || end == 0 || start > end)
|
||||
return;
|
||||
for (int onid = start; onid <= end; onid++)
|
||||
{
|
||||
var network = new NetworkInfo();
|
||||
network.OriginalNetworkId = onid;
|
||||
if (fields.Count >= 4)
|
||||
network.Name = fields[3];
|
||||
if (fields.Count >= 5)
|
||||
network.Operator = fields[4];
|
||||
this.AddNetwork(network);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ParseNumber()
|
||||
private int ParseNumber(string nr)
|
||||
{
|
||||
int number;
|
||||
if (nr.StartsWith("0x"))
|
||||
int.TryParse(nr.Substring(2), System.Globalization.NumberStyles.HexNumber, System.Globalization.NumberFormatInfo.InvariantInfo, out number);
|
||||
else
|
||||
int.TryParse(nr, System.Globalization.NumberStyles.Integer, System.Globalization.NumberFormatInfo.InvariantInfo, out number);
|
||||
return number;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ParseTransponder()
|
||||
private void ParseTransponder(IList<string> fields)
|
||||
{
|
||||
if (fields.Count < 3)
|
||||
return;
|
||||
int nr, freq;
|
||||
int.TryParse(fields[1], out nr);
|
||||
int.TryParse(fields[2], out freq);
|
||||
if (nr == 0 || freq == 0)
|
||||
return;
|
||||
this.AddTransponderMapping(nr, freq);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ParseTransponder()
|
||||
private void ParseDvbtTransponder(IList<string> fields)
|
||||
{
|
||||
if (fields.Count < 3)
|
||||
return;
|
||||
int nr, freq;
|
||||
int.TryParse(fields[1], out nr);
|
||||
int.TryParse(fields[2], out freq);
|
||||
if (nr == 0 || freq == 0)
|
||||
return;
|
||||
this.AddDvbtTransponderMapping(nr, freq);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ParseServiceType()
|
||||
private void ParseServiceType(IList<string> fields)
|
||||
{
|
||||
if (fields.Count < 3) return;
|
||||
int serviceType = this.ParseNumber(fields[1]);
|
||||
if (serviceType <= 0) return;
|
||||
this.AddServiceType(serviceType, fields[2]);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region IsRadioOrTv()
|
||||
public SignalSource IsRadioOrTv(int dvbServiceType)
|
||||
{
|
||||
switch (dvbServiceType)
|
||||
{
|
||||
case 0x01: // SD MPEG1
|
||||
case 0x11: // MPEG2-HD
|
||||
case 0x16: // H264/AVC-SD
|
||||
case 0x19: // H264/AVC-HD
|
||||
case 0x1F: // UHD
|
||||
return SignalSource.Tv;
|
||||
case 0x02:
|
||||
case 0x0A:
|
||||
return SignalSource.Radio;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region GetDvbtTransponder()
|
||||
public int GetDvbtTransponder(decimal freq)
|
||||
{
|
||||
return (int)(freq - 106)/8;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region GetDvbtFrequencyForTransponder()
|
||||
public decimal GetDvbtFrequenyForTransponder(int transponder)
|
||||
{
|
||||
return transponder * 8 + 106;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region GetDvbtFrequencyForChannel()
|
||||
public decimal GetDvbtFrequenyForChannel(int channel)
|
||||
{
|
||||
return channel * 8 + 306;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
9
source/ChanSort.Api/Model/NetworkInfo.cs
Normal file
9
source/ChanSort.Api/Model/NetworkInfo.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace ChanSort.Api
|
||||
{
|
||||
public class NetworkInfo
|
||||
{
|
||||
public int OriginalNetworkId { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Operator { get; set; }
|
||||
}
|
||||
}
|
||||
28
source/ChanSort.Api/Model/Satellite.cs
Normal file
28
source/ChanSort.Api/Model/Satellite.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace ChanSort.Api
|
||||
{
|
||||
public class Satellite
|
||||
{
|
||||
private readonly int id;
|
||||
private readonly IDictionary<int, Transponder> transponder = new Dictionary<int, Transponder>();
|
||||
|
||||
public int Id { get { return this.id; } }
|
||||
public string Name { get; set; }
|
||||
public string OrbitalPosition { get; set; }
|
||||
public IDictionary<int, Transponder> Transponder { get { return this.transponder; } }
|
||||
|
||||
public Satellite(int id)
|
||||
{
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public LnbConfig LnbConfig { get; set; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
22
source/ChanSort.Api/Model/Transponder.cs
Normal file
22
source/ChanSort.Api/Model/Transponder.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
namespace ChanSort.Api
|
||||
{
|
||||
public class Transponder
|
||||
{
|
||||
private readonly int id;
|
||||
|
||||
public int Id { get { return id; } }
|
||||
public Satellite Satellite { get; set; }
|
||||
public decimal FrequencyInMhz { get; set; }
|
||||
public int Number { get; set; }
|
||||
public virtual int SymbolRate { get; set; }
|
||||
public char Polarity { get; set; }
|
||||
public int OriginalNetworkId { get; set; }
|
||||
public int TransportStreamId { get; set; }
|
||||
|
||||
public Transponder(int id)
|
||||
{
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user