forked from JMS-1/DVB.NET---VCR.NET
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSourceGroup.cs
More file actions
113 lines (99 loc) · 3.84 KB
/
SourceGroup.cs
File metadata and controls
113 lines (99 loc) · 3.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
using System;
using System.Xml.Serialization;
using System.Collections.Generic;
namespace JMS.DVB
{
/// <summary>
/// Instanzen dieser Klasse beschreiben eine ganze Gruppe von möglichen Quellen,
/// die von einer Hardware gleichzeitig angeboten werden können. Sie entsprechend
/// den <i>Transpondern</i> in der DVB Notation.
/// </summary>
[Serializable]
public abstract class SourceGroup
{
/// <summary>
/// Die Frequenz in kHz, über die diese Gruppe empfangen werden kann.
/// </summary>
public uint Frequency { get; set; }
/// <summary>
/// Alle Quellen, die über die Gruppe zur Verfügung stehen.
/// </summary>
[XmlArray( "Stations" )]
[XmlArrayItem( typeof( Station ) )]
public readonly List<SourceIdentifier> Sources = new List<SourceIdentifier>();
/// <summary>
/// Initialisiert eine neue Beschreibung.
/// </summary>
protected SourceGroup()
{
}
/// <summary>
/// Vergleicht diese Quellgruppe (Transponder) mit einer anderen.
/// </summary>
/// <param name="group">Die andere Quellgruppe.</param>
/// <param name="legacy">Gesetzt, wenn ein partieller Vergleich erfolgen soll.</param>
/// <returns>Gesetzt, wenn die Gruppen identisch sind.</returns>
protected abstract bool OnCompare( SourceGroup group, bool legacy );
/// <summary>
/// Meldet, ob alle benötigten Parameter gesetzt sind.
/// </summary>
public abstract bool IsComplete { get; }
/// <summary>
/// Vergleicht diese Quellgruppe (Transponder) mit einer anderen.
/// </summary>
/// <param name="group">Die andere Quellgruppe.</param>
/// <returns>Gesetzt, wenn die Gruppen identisch sind.</returns>
public bool CompareTo( SourceGroup group )
{
// Forward
return CompareTo( group, false );
}
/// <summary>
/// Vergleicht diese Quellgruppe (Transponder) mit einer anderen.
/// </summary>
/// <param name="group">Die andere Quellgruppe.</param>
/// <param name="legacy">Gesetzt, wenn ein partieller Vergleich erfolgen soll.</param>
/// <returns>Gesetzt, wenn die Gruppen identisch sind.</returns>
public bool CompareTo( SourceGroup group, bool legacy )
{
// By identity
if (ReferenceEquals( group, null ))
return false;
if (ReferenceEquals( group, this ))
return true;
// Wrong type
if (group.GetType() != GetType())
return false;
// Forward
return OnCompare( group, legacy );
}
/// <summary>
/// Wandelt eine Textdarstellung einer Gruppe von Quellen in eine
/// Gruppeninstanz um.
/// </summary>
/// <returns>Die rekonstruierte Instanz.</returns>
/// <exception cref="FormatException">Es wurde keine gültige Textdarstellung angegeben.</exception>
public static T FromString<T>( string text ) where T : SourceGroup
{
// None
if (string.IsNullOrEmpty( text ))
return null;
// Helper
T group;
// Dispatch known types
if (text.StartsWith( "DVB-C" ))
group = CableGroup.Parse( text ) as T;
else if (text.StartsWith( "DVB-T" ))
group = TerrestrialGroup.Parse( text ) as T;
else if (text.StartsWith( "DVB-S" ))
group = SatelliteGroup.Parse( text ) as T;
else
group = null;
// Invalid
if (null == group)
throw new FormatException( text );
// Report
return group;
}
}
}