Skip to content

Commit c098355

Browse files
author
Jeff Treuting
committed
Clean up and consolidate Specification code
Fixes #51
1 parent 59d6750 commit c098355

27 files changed

Lines changed: 1202 additions & 1327 deletions
Lines changed: 129 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -1,129 +1,129 @@
1-
using System;
2-
using System.Runtime.Caching;
3-
using Microsoft.ApplicationServer.Caching;
4-
using SharpRepository.Repository.Caching;
5-
6-
// Reference: http://stackoverflow.com/questions/4739548/appfabric-caching-examples-using-c-sharp
7-
8-
namespace SharpRepository.Caching.AppFabric
9-
{
10-
/// <summary>
11-
/// Uses AppFabric Caching as the caching provider. <a href="http://msdn.microsoft.com/en-us/library/ff383731(v=azure.10).aspx">Get more info on AppFabric Caching</a>
12-
/// </summary>
13-
public class AppFabricCachingProvider : ICachingProvider
14-
{
15-
protected DataCacheFactory CacheFactory { get; set;}
16-
protected DataCache Cache { get; set; }
17-
18-
private static readonly object LockObject = new object();
19-
20-
/// <summary>
21-
/// Initializes a new instance of the <see cref="AppFabricCachingProvider"/> class.
22-
/// </summary>
23-
/// <param name="cacheName">Name of the cache.</param>
24-
public AppFabricCachingProvider(string cacheName = null)
25-
: this(new DataCacheFactory(), cacheName)
26-
{
27-
}
28-
29-
/// <summary>
30-
/// Initializes a new instance of the <see cref="AppFabricCachingProvider"/> class.
31-
/// </summary>
32-
/// <param name="configuration">The AbbFabric Caching configuration.</param>
33-
/// <param name="cacheName">Name of the cache.</param>
34-
public AppFabricCachingProvider(DataCacheFactoryConfiguration configuration, string cacheName = null)
35-
: this(new DataCacheFactory(configuration), cacheName)
36-
{
37-
if (configuration == null) throw new ArgumentNullException("configuration");
38-
}
39-
40-
/// <summary>
41-
/// Initializes a new instance of the <see cref="AppFabricCachingProvider"/> class.
42-
/// </summary>
43-
/// <param name="cacheFactory">The cache factory.</param>
44-
/// <param name="cacheName">Name of the cache.</param>
45-
public AppFabricCachingProvider(DataCacheFactory cacheFactory, string cacheName = null)
46-
{
47-
if (cacheFactory == null) throw new ArgumentNullException("cacheFactory");
48-
49-
CacheFactory = cacheFactory;
50-
51-
// TODO: don't know enough about AppFabric to know if we should use the GetDefaultCache() if no cache name provided, or if we should use our own name like SharpRepository
52-
Cache = String.IsNullOrEmpty(cacheName) ? cacheFactory.GetDefaultCache() : cacheFactory.GetCache(cacheName);
53-
}
54-
55-
public void Set<T>(string key, T value, CacheItemPriority priority = CacheItemPriority.Default, int? cacheTime = null)
56-
{
57-
if (String.IsNullOrEmpty(key)) throw new ArgumentNullException("key");
58-
59-
if (!cacheTime.HasValue)
60-
{
61-
Cache.Put(key, value);
62-
}
63-
else
64-
{
65-
Cache.Put(key, value, TimeSpan.FromSeconds(cacheTime.Value));
66-
}
67-
}
68-
69-
public void Clear(string key)
70-
{
71-
if (String.IsNullOrEmpty(key)) throw new ArgumentNullException("key");
72-
73-
Cache.Remove(key);
74-
}
75-
76-
public bool Exists(string key)
77-
{
78-
if (String.IsNullOrEmpty(key)) throw new ArgumentNullException("key");
79-
80-
return Cache.Get(key) != null;
81-
}
82-
83-
public bool Get<T>(string key, out T value)
84-
{
85-
if (String.IsNullOrEmpty(key)) throw new ArgumentNullException("key");
86-
87-
value = default(T);
88-
89-
try
90-
{
91-
var item = Cache.Get(key);
92-
if (item == null)
93-
return false;
94-
95-
value = (T)item;
96-
}
97-
catch (Exception)
98-
{
99-
return false;
100-
}
101-
102-
return true;
103-
}
104-
105-
public int Increment(string key, int defaultValue, int value, CacheItemPriority priority = CacheItemPriority.Default)
106-
{
107-
if (String.IsNullOrEmpty(key)) throw new ArgumentNullException("key");
108-
109-
lock (LockObject)
110-
{
111-
int current;
112-
if (!Get(key, out current))
113-
{
114-
current = defaultValue;
115-
}
116-
117-
var newValue = current + value;
118-
Set(key, newValue, priority);
119-
return newValue;
120-
}
121-
}
122-
123-
public void Dispose()
124-
{
125-
Cache = null;
126-
CacheFactory.Dispose();
127-
}
128-
}
129-
}
1+
using System;
2+
using System.Runtime.Caching;
3+
using Microsoft.ApplicationServer.Caching;
4+
using SharpRepository.Repository.Caching;
5+
6+
// Reference: http://stackoverflow.com/questions/4739548/appfabric-caching-examples-using-c-sharp
7+
8+
namespace SharpRepository.Caching.AppFabric
9+
{
10+
/// <summary>
11+
/// Uses AppFabric Caching as the caching provider. <a href="http://msdn.microsoft.com/en-us/library/ff383731(v=azure.10).aspx">Get more info on AppFabric Caching</a>
12+
/// </summary>
13+
public class AppFabricCachingProvider : ICachingProvider
14+
{
15+
protected DataCacheFactory CacheFactory { get; set;}
16+
protected DataCache Cache { get; set; }
17+
18+
private static readonly object LockObject = new object();
19+
20+
/// <summary>
21+
/// Initializes a new instance of the <see cref="AppFabricCachingProvider"/> class.
22+
/// </summary>
23+
/// <param name="cacheName">Name of the cache.</param>
24+
public AppFabricCachingProvider(string cacheName = null)
25+
: this(new DataCacheFactory(), cacheName)
26+
{
27+
}
28+
29+
/// <summary>
30+
/// Initializes a new instance of the <see cref="AppFabricCachingProvider"/> class.
31+
/// </summary>
32+
/// <param name="configuration">The AbbFabric Caching configuration.</param>
33+
/// <param name="cacheName">Name of the cache.</param>
34+
public AppFabricCachingProvider(DataCacheFactoryConfiguration configuration, string cacheName = null)
35+
: this(new DataCacheFactory(configuration), cacheName)
36+
{
37+
if (configuration == null) throw new ArgumentNullException("configuration");
38+
}
39+
40+
/// <summary>
41+
/// Initializes a new instance of the <see cref="AppFabricCachingProvider"/> class.
42+
/// </summary>
43+
/// <param name="cacheFactory">The cache factory.</param>
44+
/// <param name="cacheName">Name of the cache.</param>
45+
public AppFabricCachingProvider(DataCacheFactory cacheFactory, string cacheName = null)
46+
{
47+
if (cacheFactory == null) throw new ArgumentNullException("cacheFactory");
48+
49+
CacheFactory = cacheFactory;
50+
51+
// TODO: don't know enough about AppFabric to know if we should use the GetDefaultCache() if no cache name provided, or if we should use our own name like SharpRepository
52+
Cache = String.IsNullOrEmpty(cacheName) ? cacheFactory.GetDefaultCache() : cacheFactory.GetCache(cacheName);
53+
}
54+
55+
public void Set<T>(string key, T value, CacheItemPriority priority = CacheItemPriority.Default, int? cacheTime = null)
56+
{
57+
if (String.IsNullOrEmpty(key)) throw new ArgumentNullException("key");
58+
59+
if (!cacheTime.HasValue)
60+
{
61+
Cache.Put(key, value);
62+
}
63+
else
64+
{
65+
Cache.Put(key, value, TimeSpan.FromSeconds(cacheTime.Value));
66+
}
67+
}
68+
69+
public void Clear(string key)
70+
{
71+
if (String.IsNullOrEmpty(key)) throw new ArgumentNullException("key");
72+
73+
Cache.Remove(key);
74+
}
75+
76+
public bool Exists(string key)
77+
{
78+
if (String.IsNullOrEmpty(key)) throw new ArgumentNullException("key");
79+
80+
return Cache.Get(key) != null;
81+
}
82+
83+
public bool Get<T>(string key, out T value)
84+
{
85+
if (String.IsNullOrEmpty(key)) throw new ArgumentNullException("key");
86+
87+
value = default(T);
88+
89+
try
90+
{
91+
var item = Cache.Get(key);
92+
if (item == null)
93+
return false;
94+
95+
value = (T)item;
96+
}
97+
catch (Exception)
98+
{
99+
return false;
100+
}
101+
102+
return true;
103+
}
104+
105+
public int Increment(string key, int defaultValue, int value, CacheItemPriority priority = CacheItemPriority.Default)
106+
{
107+
if (String.IsNullOrEmpty(key)) throw new ArgumentNullException("key");
108+
109+
lock (LockObject)
110+
{
111+
int current;
112+
if (!Get(key, out current))
113+
{
114+
current = defaultValue;
115+
}
116+
117+
var newValue = current + value;
118+
Set(key, newValue, priority);
119+
return newValue;
120+
}
121+
}
122+
123+
public void Dispose()
124+
{
125+
Cache = null;
126+
CacheFactory.Dispose();
127+
}
128+
}
129+
}
Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,36 @@
1-
using System.Reflection;
2-
using System.Runtime.CompilerServices;
3-
using System.Runtime.InteropServices;
4-
5-
// General Information about an assembly is controlled through the following
6-
// set of attributes. Change these attribute values to modify the information
7-
// associated with an assembly.
8-
[assembly: AssemblyTitle("SharpRepository.Caching.AppFabric")]
9-
[assembly: AssemblyDescription("")]
10-
[assembly: AssemblyConfiguration("")]
11-
[assembly: AssemblyCompany("")]
12-
[assembly: AssemblyProduct("SharpRepository.Caching.AppFabric")]
13-
[assembly: AssemblyCopyright("Copyright © 2012")]
14-
[assembly: AssemblyTrademark("")]
15-
[assembly: AssemblyCulture("")]
16-
17-
// Setting ComVisible to false makes the types in this assembly not visible
18-
// to COM components. If you need to access a type in this assembly from
19-
// COM, set the ComVisible attribute to true on that type.
20-
[assembly: ComVisible(false)]
21-
22-
// The following GUID is for the ID of the typelib if this project is exposed to COM
23-
[assembly: Guid("9a62addf-9f66-455b-91cb-b7a6b409682c")]
24-
25-
// Version information for an assembly consists of the following four values:
26-
//
27-
// Major Version
28-
// Minor Version
29-
// Build Number
30-
// Revision
31-
//
32-
// You can specify all the values or you can default the Build and Revision Numbers
33-
// by using the '*' as shown below:
34-
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("1.0.0.0")]
36-
[assembly: AssemblyFileVersion("1.0.0.0")]
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("SharpRepository.Caching.AppFabric")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("SharpRepository.Caching.AppFabric")]
13+
[assembly: AssemblyCopyright("Copyright © 2012")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("9a62addf-9f66-455b-91cb-b7a6b409682c")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]

0 commit comments

Comments
 (0)