-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSessionSimpleDbDomainCollection.cs
More file actions
116 lines (106 loc) · 3.48 KB
/
SessionSimpleDbDomainCollection.cs
File metadata and controls
116 lines (106 loc) · 3.48 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
114
115
116
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using Cucumber.SimpleDb.Transport;
namespace Cucumber.SimpleDb.Session
{
internal sealed class SessionSimpleDbDomainCollection : ISimpleDbDomainCollection
{
private Dictionary<string, ISimpleDbDomain> _domains;
private IInternalContext _session;
internal SessionSimpleDbDomainCollection(IInternalContext session)
{
_session = session;
}
public int Count
{
get
{
if (_domains == null)
{
PopulateDomains();
}
return this._domains.Count;
}
}
public ISimpleDbDomain this[string name]
{
get
{
if (string.IsNullOrEmpty(name))
{
throw new ArgumentNullException("name");
}
if (_domains != null)
{
if (_domains.ContainsKey(name))
{
return _domains[name];
}
}
else
{
return new ProxySimpleDbDomain(name, this._domains, _session);
}
throw new KeyNotFoundException(
string.Format("A domain named '{0}' does not exist",
name));
}
}
public ISimpleDbDomain Add(string name)
{
if (string.IsNullOrEmpty(name))
{
throw new ArgumentNullException("name");
}
_session.Service.CreateDomain (name);
if (_domains != null)
{
_domains.Add (name, new ProxySimpleDbDomain (name, _domains, _session));
}
return this [name];
}
public bool HasDomain(string name)
{
if (string.IsNullOrEmpty(name))
{
throw new ArgumentNullException("name");
}
if (_domains == null)
{
PopulateDomains();
}
return _domains.ContainsKey(name);
}
public IEnumerator<ISimpleDbDomain> GetEnumerator()
{
if (_domains == null)
{
PopulateDomains();
}
return this._domains.Select(kvp => kvp.Value).GetEnumerator();
}
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
{
return this.GetEnumerator();
}
private void PopulateDomains()
{
_domains = new Dictionary<string, ISimpleDbDomain>(StringComparer.OrdinalIgnoreCase);
XElement result = null;
string nextPageToken = null;
do
{
result = _session.Service.ListDomains(nextPageToken).Element(SdbNs + "ListDomainsResult");
foreach (var domainNode in result.Elements(SdbNs + "DomainName"))
{
_domains.Add(domainNode.Value, new ProxySimpleDbDomain(domainNode.Value, _domains, _session));
}
nextPageToken = result.Elements(SdbNs + "NextToken").Select(x => x.Value).FirstOrDefault();
} while (!string.IsNullOrEmpty(nextPageToken));
}
private readonly static XNamespace SdbNs = "http://sdb.amazonaws.com/doc/2009-04-15/";
}
}