Skip to content

Commit 3729680

Browse files
committed
Cleaning code
1 parent a48ef1d commit 3729680

File tree

335 files changed

+5358
-4537
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

335 files changed

+5358
-4537
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
namespace DataCommander.Foundation
2+
{
3+
using System;
4+
using System.Diagnostics.Contracts;
5+
6+
/// <summary>
7+
///
8+
/// </summary>
9+
/// <typeparam name="TArgument"></typeparam>
10+
public sealed class ArgumentEqualsSelection<TArgument> where TArgument : IEquatable<TArgument>
11+
{
12+
private readonly TArgument argument;
13+
private bool selected;
14+
15+
/// <summary>
16+
///
17+
/// </summary>
18+
/// <param name="argument"></param>
19+
public ArgumentEqualsSelection(TArgument argument)
20+
{
21+
this.argument = argument;
22+
}
23+
24+
/// <summary>
25+
///
26+
/// </summary>
27+
/// <param name="other"></param>
28+
/// <param name="action"></param>
29+
/// <returns></returns>
30+
public ArgumentEqualsSelection<TArgument> IfArgumentEquals(TArgument other, Action action)
31+
{
32+
Contract.Requires<ArgumentNullException>(action != null);
33+
34+
if (!this.selected)
35+
{
36+
this.selected = this.argument.Equals(other);
37+
if (this.selected)
38+
{
39+
action();
40+
}
41+
}
42+
43+
return this;
44+
}
45+
46+
/// <summary>
47+
///
48+
/// </summary>
49+
/// <param name="action"></param>
50+
public void Else(Action action)
51+
{
52+
Contract.Requires<ArgumentNullException>(action != null);
53+
54+
if (!this.selected)
55+
{
56+
action();
57+
}
58+
}
59+
}
60+
}
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
namespace DataCommander.Foundation
2+
{
3+
using System;
4+
using System.Diagnostics.Contracts;
5+
6+
/// <summary>
7+
///
8+
/// </summary>
9+
/// <typeparam name="TArgument"></typeparam>
10+
public sealed class ArgumentIsSelection<TArgument> where TArgument : class
11+
{
12+
private readonly TArgument argument;
13+
private bool selected;
14+
15+
/// <summary>
16+
///
17+
/// </summary>
18+
/// <param name="argument"></param>
19+
public ArgumentIsSelection(TArgument argument)
20+
{
21+
this.argument = argument;
22+
}
23+
24+
/// <summary>
25+
///
26+
/// </summary>
27+
/// <typeparam name="TArgumentAs"></typeparam>
28+
/// <param name="action"></param>
29+
/// <returns></returns>
30+
public ArgumentIsSelection<TArgument> IfArgumentIs<TArgumentAs>(Action<TArgumentAs> action) where TArgumentAs : class
31+
{
32+
Contract.Requires<ArgumentNullException>(action != null);
33+
34+
if (!this.selected)
35+
{
36+
var argumentAs = this.argument as TArgumentAs;
37+
this.selected = argumentAs != null;
38+
if (this.selected)
39+
{
40+
action(argumentAs);
41+
}
42+
}
43+
44+
return this;
45+
}
46+
47+
/// <summary>
48+
///
49+
/// </summary>
50+
/// <param name="action"></param>
51+
/// <returns></returns>
52+
public ArgumentIsSelection<TArgument> IfArgumentIsNull(Action action)
53+
{
54+
Contract.Requires<ArgumentNullException>(action != null);
55+
56+
if (!this.selected)
57+
{
58+
this.selected = this.argument == null;
59+
if (this.selected)
60+
{
61+
action();
62+
}
63+
}
64+
65+
return this;
66+
}
67+
68+
/// <summary>
69+
///
70+
/// </summary>
71+
/// <param name="condition"></param>
72+
/// <param name="action"></param>
73+
/// <returns></returns>
74+
public ArgumentIsSelection<TArgument> If(Func<bool> condition, Action action)
75+
{
76+
Contract.Requires<ArgumentNullException>(action != null);
77+
78+
if (!this.selected)
79+
{
80+
this.selected = condition();
81+
if (this.selected)
82+
{
83+
action();
84+
}
85+
}
86+
87+
return this;
88+
}
89+
90+
/// <summary>
91+
///
92+
/// </summary>
93+
/// <param name="action"></param>
94+
public void Else(Action action)
95+
{
96+
Contract.Requires<ArgumentNullException>(action != null);
97+
98+
if (!this.selected)
99+
{
100+
action();
101+
}
102+
}
103+
}
104+
}

DataCommander.Foundation/Caching/CacheEntry.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ namespace DataCommander.Foundation.Caching
77
internal sealed class CacheEntry
88
{
99
public ICacheItem CacheItem = null;
10-
public Boolean Initialized = false;
10+
public bool Initialized = false;
1111
public DateTime AbsoluteExpiration = default( DateTime );
12-
public Object Value = null;
12+
public object Value = null;
1313
public Lock Lock = new Lock();
1414
}
1515
}

DataCommander.Foundation/Caching/CacheItem.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public static class CacheItem
1616
/// <param name="getValue"></param>
1717
/// <param name="slidingExpiration"></param>
1818
/// <returns></returns>
19-
public static CacheItem<T> Create<T>( String key, Func<T> getValue, TimeSpan slidingExpiration )
19+
public static CacheItem<T> Create<T>( string key, Func<T> getValue, TimeSpan slidingExpiration )
2020
{
2121
return new CacheItem<T>( key, getValue, slidingExpiration );
2222
}

DataCommander.Foundation/Caching/CacheItemGeneric.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ namespace DataCommander.Foundation.Caching
1010
/// <typeparam name="T"></typeparam>
1111
public sealed class CacheItem<T> : ICacheItem
1212
{
13-
private readonly String key;
13+
private readonly string key;
1414
private readonly TimeSpan slidingExpiration;
1515
private readonly Func<T> getValue;
1616
private T value;
1717

18-
internal CacheItem( String key, Func<T> getValue, TimeSpan slidingExpiration )
18+
internal CacheItem( string key, Func<T> getValue, TimeSpan slidingExpiration )
1919
{
2020
Contract.Requires( key != null );
2121
Contract.Requires( getValue != null );
@@ -39,7 +39,7 @@ public T Value
3939

4040
#region ICacheItem Members
4141

42-
String ICacheItem.Key
42+
string ICacheItem.Key
4343
{
4444
get
4545
{
@@ -55,7 +55,7 @@ TimeSpan ICacheItem.SlidingExpiration
5555
}
5656
}
5757

58-
Object ICacheItem.GetValue()
58+
object ICacheItem.GetValue()
5959
{
6060
T value = this.getValue();
6161
this.value = value;

DataCommander.Foundation/Caching/ICache.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ public interface ICache : IDisposable
2626
/// <param name="key"></param>
2727
/// <param name="value"></param>
2828
/// <returns></returns>
29-
Boolean TryGetValue( String key, out Object value );
29+
bool TryGetValue( string key, out object value );
3030

3131
/// <summary>
3232
///
3333
/// </summary>
3434
/// <param name="key"></param>
35-
void Remove( String key );
35+
void Remove( string key );
3636
}
3737
}
3838
#endif

DataCommander.Foundation/Caching/ICacheItem.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public interface ICacheItem
1111
/// <summary>
1212
///
1313
/// </summary>
14-
String Key
14+
string Key
1515
{
1616
get;
1717
}
@@ -28,7 +28,7 @@ TimeSpan SlidingExpiration
2828
///
2929
/// </summary>
3030
/// <returns></returns>
31-
Object GetValue();
31+
object GetValue();
3232
}
3333
}
3434
#endif

DataCommander.Foundation/Caching/MemoryCache.cs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,20 @@ public sealed class MemoryCache : ICache
2020
{
2121
private static readonly ILog log = LogFactory.Instance.GetCurrentTypeLog();
2222
private readonly IndexableCollection<CacheEntry> entries;
23-
private readonly UniqueIndex<String, CacheEntry> keyIndex;
23+
private readonly UniqueIndex<string, CacheEntry> keyIndex;
2424
private readonly NonUniqueIndex<DateTime, CacheEntry> absoluteExpirationIndex;
2525
private readonly LimitedConcurrencyLevelTaskScheduler scheduler;
2626
private readonly Timer timer;
27-
private Boolean disposed;
27+
private bool disposed;
2828

2929
/// <summary>
3030
///
3131
/// </summary>
3232
/// <param name="maximumConcurrencyLevel"></param>
3333
/// <param name="timerPeriod"></param>
34-
public MemoryCache( Int32 maximumConcurrencyLevel, TimeSpan timerPeriod )
34+
public MemoryCache( int maximumConcurrencyLevel, TimeSpan timerPeriod )
3535
{
36-
this.keyIndex = new UniqueIndex<String, CacheEntry>(
36+
this.keyIndex = new UniqueIndex<string, CacheEntry>(
3737
"key",
3838
entry => GetKeyResponse.Create( true, entry.CacheItem.Key ),
3939
SortOrder.None );
@@ -69,13 +69,13 @@ void ICache.Add( ICacheItem item )
6969
entry = new CacheEntry
7070
{
7171
CacheItem = item,
72-
AbsoluteExpiration = OptimizedDateTime.Now + item.SlidingExpiration
72+
AbsoluteExpiration = LocalTime.Default.Now + item.SlidingExpiration
7373
};
7474

7575
this.entries.Add( entry );
7676
}
7777

78-
Object value = item.GetValue();
78+
object value = item.GetValue();
7979
entry.Value = value;
8080
entry.Initialized = true;
8181
}
@@ -97,7 +97,7 @@ void ICache.AddOrGetExisiting( ICacheItem item )
9797
entry = new CacheEntry
9898
{
9999
CacheItem = item,
100-
AbsoluteExpiration = OptimizedDateTime.Now + item.SlidingExpiration
100+
AbsoluteExpiration = LocalTime.Default.Now + item.SlidingExpiration
101101
};
102102

103103
this.entries.Add( entry );
@@ -114,7 +114,7 @@ void ICache.AddOrGetExisiting( ICacheItem item )
114114
if (!entry.Initialized)
115115
{
116116
var stopwatch = Stopwatch.StartNew();
117-
Object value = item.GetValue();
117+
object value = item.GetValue();
118118
stopwatch.Stop();
119119
entry.Value = value;
120120
entry.Initialized = true;
@@ -124,10 +124,10 @@ void ICache.AddOrGetExisiting( ICacheItem item )
124124
}
125125
}
126126

127-
Boolean ICache.TryGetValue( String key, out Object value )
127+
bool ICache.TryGetValue( string key, out object value )
128128
{
129129
CacheEntry entry;
130-
Boolean contains = this.keyIndex.TryGetValue( key, out entry );
130+
bool contains = this.keyIndex.TryGetValue( key, out entry );
131131

132132
if (contains)
133133
{
@@ -141,7 +141,7 @@ Boolean ICache.TryGetValue( String key, out Object value )
141141
return contains;
142142
}
143143

144-
void ICache.Remove( String key )
144+
void ICache.Remove( string key )
145145
{
146146
lock (this.entries)
147147
{
@@ -182,12 +182,12 @@ public void Dispose()
182182
}
183183
}
184184

185-
private void TimerCallback( Object state )
185+
private void TimerCallback( object state )
186186
{
187187
if (this.entries.Count > 0 && !disposed)
188188
{
189189
var enumerable = (ICollection<CacheEntry>)this.absoluteExpirationIndex;
190-
DateTime now = OptimizedDateTime.Now;
190+
DateTime now = LocalTime.Default.Now;
191191
ICollection<CacheEntry> expiredEntries;
192192

193193
lock (this.entries)
@@ -215,19 +215,19 @@ private void Update( CacheEntry entry )
215215
{
216216
var item = entry.CacheItem;
217217
var stopwatch = Stopwatch.StartNew();
218-
Object value = item.GetValue();
218+
object value = item.GetValue();
219219
stopwatch.Stop();
220220
log.Trace( "Update, item.GetValue(), key: {0}, elapsed: {1}", item.Key, stopwatch.Elapsed );
221221

222222
var collection = (ICollection<CacheEntry>)this.absoluteExpirationIndex;
223223

224224
lock (this.entries)
225225
{
226-
Boolean succeeded = collection.Remove( entry );
226+
bool succeeded = collection.Remove( entry );
227227
Contract.Assert( succeeded, "collection.Remove( entry )" );
228228

229229
entry.Value = value;
230-
entry.AbsoluteExpiration = OptimizedDateTime.Now + item.SlidingExpiration;
230+
entry.AbsoluteExpiration = LocalTime.Default.Now + item.SlidingExpiration;
231231

232232
collection.Add( entry );
233233
}

DataCommander.Foundation/Collections/BitVector64.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public UInt64 Value
3535
/// <summary>
3636
///
3737
/// </summary>
38-
public Boolean this[Int32 index]
38+
public bool this[int index]
3939
{
4040
get
4141
{
@@ -62,9 +62,9 @@ public Boolean this[Int32 index]
6262
///
6363
/// </summary>
6464
/// <returns></returns>
65-
public override String ToString()
65+
public override string ToString()
6666
{
67-
String value = this.data.ToString("X");
67+
string value = this.data.ToString("X");
6868
value = value.PadLeft(16, '0');
6969
return value;
7070
}

0 commit comments

Comments
 (0)