This repository has been archived by the owner on Jul 7, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 360
/
MembaseClientSection.cs
169 lines (147 loc) · 5.28 KB
/
MembaseClientSection.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
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Net;
using System.Web.Configuration;
using Enyim.Caching.Configuration;
using Enyim.Caching.Memcached;
namespace Membase.Configuration
{
/// <summary>
/// Configures the <see cref="T:MembaseClient"/>. This class cannot be inherited.
/// </summary>
public class MembaseClientSection : ConfigurationSection, IMembaseClientConfiguration
{
[ConfigurationProperty("servers", IsRequired = true)]
public ServersElement Servers
{
get { return (ServersElement)base["servers"]; }
set { base["servers"] = value; }
}
/// <summary>
/// Gets or sets the configuration of the socket pool.
/// </summary>
[ConfigurationProperty("socketPool", IsRequired = false)]
public SocketPoolElement SocketPool
{
get { return (SocketPoolElement)base["socketPool"]; }
set { base["socketPool"] = value; }
}
/// <summary>
/// Gets or sets the <see cref="T:Enyim.Caching.Memcached.IMemcachedNodeLocator"/> which will be used to assign items to Memcached nodes.
/// </summary>
[ConfigurationProperty("locator", IsRequired = false)]
public ProviderElement<IMemcachedNodeLocator> NodeLocator
{
get { return (ProviderElement<IMemcachedNodeLocator>)base["locator"]; }
set { base["locator"] = value; }
}
/// <summary>
/// Gets or sets the <see cref="T:Enyim.Caching.Memcached.IMemcachedKeyTransformer"/> which will be used to convert item keys for Memcached.
/// </summary>
[ConfigurationProperty("keyTransformer", IsRequired = false)]
public ProviderElement<IMemcachedKeyTransformer> KeyTransformer
{
get { return (ProviderElement<IMemcachedKeyTransformer>)base["keyTransformer"]; }
set { base["keyTransformer"] = value; }
}
/// <summary>
/// Gets or sets the <see cref="T:Enyim.Caching.Memcached.ITranscoder"/> which will be used serialize or deserialize items.
/// </summary>
[ConfigurationProperty("transcoder", IsRequired = false)]
public ProviderElement<ITranscoder> Transcoder
{
get { return (ProviderElement<ITranscoder>)base["transcoder"]; }
set { base["transcoder"] = value; }
}
/// <summary>
/// Gets or sets the <see cref="T:Enyim.Caching.Memcached.IPerformanceMonitor"/> which will be used monitor the performance of the client.
/// </summary>
[ConfigurationProperty("performanceMonitor", IsRequired = false)]
public FactoryElement<IMembasePerformanceMonitorFactory> PerformanceMonitorFactory
{
get { return (FactoryElement<IMembasePerformanceMonitorFactory>)base["performanceMonitor"]; }
set { base["performanceMonitor"] = value; }
}
/// <summary>
/// Called after deserialization.
/// </summary>
protected override void PostDeserialize()
{
WebContext hostingContext = base.EvaluationContext.HostingContext as WebContext;
if (hostingContext != null && hostingContext.ApplicationLevel == WebApplicationLevel.BelowApplication)
{
throw new InvalidOperationException("The " + this.SectionInformation.SectionName + " section cannot be defined below the application level.");
}
}
#region [ interface ]
IList<Uri> IMembaseClientConfiguration.Urls
{
get { return this.Servers.Urls.ToUriCollection(); }
}
ISocketPoolConfiguration IMembaseClientConfiguration.SocketPool
{
get { return this.SocketPool; }
}
IMemcachedKeyTransformer IMembaseClientConfiguration.CreateKeyTransformer()
{
return this.KeyTransformer.CreateInstance() ?? new DefaultKeyTransformer();
}
IMemcachedNodeLocator IMembaseClientConfiguration.CreateNodeLocator()
{
return this.NodeLocator.CreateInstance() ?? new KetamaNodeLocator();
}
ITranscoder IMembaseClientConfiguration.CreateTranscoder()
{
return this.Transcoder.CreateInstance() ?? new DefaultTranscoder();
}
IPerformanceMonitor IMembaseClientConfiguration.CreatePerformanceMonitor()
{
var pmf = this.PerformanceMonitorFactory;
if (pmf.ElementInformation.IsPresent)
{
var f = pmf.CreateInstance();
if (f != null)
return f.Create(this.Servers.Bucket);
}
return null;
}
string IMembaseClientConfiguration.Bucket
{
get { return this.Servers.Bucket; }
}
string IMembaseClientConfiguration.BucketPassword
{
get { return this.Servers.BucketPassword; }
}
int IMembaseClientConfiguration.RetryCount
{
get { return this.Servers.RetryCount; }
}
TimeSpan IMembaseClientConfiguration.RetryTimeout
{
get { return this.Servers.RetryTimeout; }
}
#endregion
}
}
#region [ License information ]
/* ************************************************************
*
* Copyright (c) 2010 Attila Kiskó, enyim.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* ************************************************************/
#endregion