-
Notifications
You must be signed in to change notification settings - Fork 0
/
RegistrationGroup.cs
43 lines (35 loc) · 1.41 KB
/
RegistrationGroup.cs
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
namespace IsbnTools
{
public class RegistrationGroup
{
private RegistrationGroup(UccPrefix uccPrefix, string groupIdentifier, string agency, ICollection<Range> rules)
{
UccPrefix = uccPrefix;
GroupIdentifier = groupIdentifier;
Agency = agency;
Rules = rules;
}
public UccPrefix UccPrefix { get; private set; }
public string GroupIdentifier { get; private set; }
public string Agency { get; private set; }
public ICollection<Range> Rules { get; private set; }
public static RegistrationGroup FromXml(XElement groupElement, RangeMessage rangeMessage)
{
var prefix = (string) groupElement.Element("Prefix");
var agency = (string) groupElement.Element("Agency");
string[] parts = prefix.Split('-');
string uccPrefix = parts[0];
string groupIdentifier = parts[1];
List<Range> rules = groupElement.Element("Rules").Elements("Rule").Select(Range.FromXml).ToList();
return new RegistrationGroup(rangeMessage.FindUccPrefix(uccPrefix), groupIdentifier, agency, rules);
}
public override string ToString()
{
return UccPrefix + GroupIdentifier;
}
}
}