Skip to content

Commit 3132ae9

Browse files
committed
partial implementation of classes
1 parent 889ce07 commit 3132ae9

4 files changed

Lines changed: 244 additions & 1 deletion

File tree

SharpRepository.Repository/Aspects/RepositoryActionBaseAttribute.cs

Lines changed: 147 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,51 +14,194 @@ protected RepositoryActionBaseAttribute()
1414
public int Order { get; set; }
1515
public bool Enabled { get; set; }
1616

17+
18+
#region INIT
1719
public virtual void OnInitialized<T, TKey>(RepositoryActionContext<T, TKey> context) where T : class
1820
{
1921
}
2022

23+
public virtual void OnInitialized<T, TKey, TKey2>(RepositoryActionContext<T, TKey, TKey2> context) where T : class
24+
{
25+
}
26+
27+
public virtual void OnInitialized<T, TKey, TKey2, TKey3>(RepositoryActionContext<T, TKey, TKey2, TKey3> context) where T : class
28+
{
29+
}
30+
31+
public virtual void OnInitialized<T>(RepositoryActionContext<T> context) where T : class
32+
{
33+
}
34+
#endregion
35+
36+
#region ERROR
2137
public virtual void OnError<T, TKey>(RepositoryActionContext<T, TKey> context, Exception ex) where T : class
2238
{
2339
}
2440

41+
public virtual void OnError<T, TKey, TKey2>(RepositoryActionContext<T, TKey, TKey2> context, Exception ex) where T : class
42+
{
43+
}
44+
45+
public virtual void OnError<T, TKey, TKey2, TKey3>(RepositoryActionContext<T, TKey, TKey2, TKey3> context, Exception ex) where T : class
46+
{
47+
}
48+
49+
public virtual void OnError<T>(RepositoryActionContext<T> context, Exception ex) where T : class
50+
{
51+
}
52+
#endregion
53+
54+
#region ADD
2555
public virtual bool OnAddExecuting<T, TKey>(T entity, RepositoryActionContext<T, TKey> context) where T : class
2656
{
2757
return true;
2858
}
2959

60+
public virtual bool OnAddExecuting<T, TKey, TKey2>(T entity, RepositoryActionContext<T, TKey, TKey2> context) where T : class
61+
{
62+
return true;
63+
}
64+
public virtual bool OnAddExecuting<T, TKey, TKey2, TKey3>(T entity, RepositoryActionContext<T, TKey, TKey2, TKey3> context) where T : class
65+
{
66+
return true;
67+
}
68+
public virtual bool OnAddExecuting<T>(T entity, RepositoryActionContext<T> context) where T : class
69+
{
70+
return true;
71+
}
72+
3073
public virtual void OnAddExecuted<T, TKey>(T entity, RepositoryActionContext<T, TKey> context) where T : class
3174
{
3275
}
3376

77+
public virtual void OnAddExecuted<T, TKey, TKey2>(T entity, RepositoryActionContext<T, TKey, TKey2> context) where T : class
78+
{
79+
}
80+
81+
public virtual void OnAddExecuted<T, TKey, TKey2, TKey3>(T entity, RepositoryActionContext<T, TKey, TKey2, TKey3> context) where T : class
82+
{
83+
}
84+
85+
public virtual void OnAddExecuted<T>(T entity, RepositoryActionContext<T> context) where T : class
86+
{
87+
}
88+
#endregion
89+
90+
#region UPDATE
3491
public virtual bool OnUpdateExecuting<T, TKey>(T entity, RepositoryActionContext<T, TKey> context) where T : class
3592
{
3693
return true;
3794
}
95+
public virtual bool OnUpdateExecuting<T, TKey, TKey2>(T entity, RepositoryActionContext<T, TKey, TKey2> context) where T : class
96+
{
97+
return true;
98+
}
99+
public virtual bool OnUpdateExecuting<T, TKey, TKey2, TKey3>(T entity, RepositoryActionContext<T, TKey, TKey2, TKey3> context) where T : class
100+
{
101+
return true;
102+
}
103+
public virtual bool OnUpdateExecuting<T>(T entity, RepositoryActionContext<T> context) where T : class
104+
{
105+
return true;
106+
}
38107

39108
public virtual void OnUpdateExecuted<T, TKey>(T entity, RepositoryActionContext<T, TKey> context) where T : class
40109
{
41110
}
42111

112+
public virtual void OnUpdateExecuted<T, TKey, TKey2>(T entity, RepositoryActionContext<T, TKey, TKey2> context) where T : class
113+
{
114+
}
115+
116+
public virtual void OnUpdateExecuted<T, TKey, TKey2, TKey3>(T entity, RepositoryActionContext<T, TKey, TKey2, TKey3> context) where T : class
117+
{
118+
}
119+
120+
public virtual void OnUpdateExecuted<T>(T entity, RepositoryActionContext<T> context) where T : class
121+
{
122+
}
123+
#endregion
124+
125+
#region DELETE
43126
public virtual bool OnDeleteExecuting<T, TKey>(T entity, RepositoryActionContext<T, TKey> context) where T : class
44127
{
45128
return true;
46129
}
130+
public virtual bool OnDeleteExecuting<T, TKey, TKey2>(T entity, RepositoryActionContext<T, TKey, TKey2> context) where T : class
131+
{
132+
return true;
133+
}
134+
public virtual bool OnDeleteExecuting<T, TKey, TKey2, TKey3>(T entity, RepositoryActionContext<T, TKey, TKey2, TKey3> context) where T : class
135+
{
136+
return true;
137+
}
138+
public virtual bool OnDeleteExecuting<T>(T entity, RepositoryActionContext<T> context) where T : class
139+
{
140+
return true;
141+
}
47142

48143
public virtual void OnDeleteExecuted<T, TKey>(T entity, RepositoryActionContext<T, TKey> context) where T : class
49144
{
50145
}
146+
public virtual void OnDeleteExecuted<T, TKey, TKey2>(T entity, RepositoryActionContext<T, TKey, TKey2> context) where T : class
147+
{
148+
}
149+
public virtual void OnDeleteExecuted<T, TKey, TKey2, TKey3>(T entity, RepositoryActionContext<T, TKey, TKey2, TKey3> context) where T : class
150+
{
151+
}
152+
public virtual void OnDeleteExecuted<T>(T entity, RepositoryActionContext<T> context) where T : class
153+
{
154+
}
155+
#endregion DELETE
51156

157+
#region SAVE
52158
public virtual bool OnSaveExecuting<T, TKey>(RepositoryActionContext<T, TKey> context) where T : class
53159
{
54160
return true;
55161
}
162+
public virtual bool OnSaveExecuting<T, TKey, TKey2>(RepositoryActionContext<T, TKey, TKey2> context) where T : class
163+
{
164+
return true;
165+
}
166+
public virtual bool OnSaveExecuting<T, TKey, TKey2, TKey3>(RepositoryActionContext<T, TKey, TKey2, TKey3> context) where T : class
167+
{
168+
return true;
169+
}
170+
public virtual bool OnSaveExecuting<T>(RepositoryActionContext<T> context) where T : class
171+
{
172+
return true;
173+
}
56174

57175
public virtual void OnSaveExecuted<T, TKey>(RepositoryActionContext<T, TKey> context) where T : class
58176
{
59177
}
178+
public virtual void OnSaveExecuted<T, TKey, TKey2>(RepositoryActionContext<T, TKey, TKey2> context) where T : class
179+
{
180+
}
181+
public virtual void OnSaveExecuted<T, TKey, TKey2, TKey3>(RepositoryActionContext<T, TKey, TKey2, TKey3> context) where T : class
182+
{
183+
}
184+
public virtual void OnSaveExecuted<T>(RepositoryActionContext<T> context) where T : class
185+
{
186+
}
187+
#endregion
188+
189+
#region GET
190+
public virtual bool OnGetExecuting<T, TKey, TResult>(RepositoryGetContext<T, TKey, TResult> context) where T : class
191+
{
192+
return true;
193+
}
194+
195+
public virtual bool OnGetExecuting<T, TKey, TKey2, TResult>(RepositoryGetContext<T, TKey, TKey2, TResult> context) where T : class
196+
{
197+
return true;
198+
}
199+
200+
public virtual bool OnGetExecuting<T, TKey, TKey2, TKey3, TResult>(RepositoryGetContext<T, TKey, TKey2, TKey3, TResult> context) where T : class
201+
{
202+
return true;
203+
}
60204

61-
/* Queries */
62205
public virtual bool OnGetExecuting<T, TKey, TResult>(RepositoryGetContext<T, TKey, TResult> context) where T : class
63206
{
64207
return true;
@@ -76,7 +219,9 @@ public virtual bool OnGetAllExecuting<T, TKey, TResult>(RepositoryQueryMultipleC
76219
public virtual void OnGetAllExecuted<T, TKey, TResult>(RepositoryQueryMultipleContext<T, TKey, TResult> context) where T : class
77220
{
78221
}
222+
#endregion
79223

224+
#region FIND
80225
public virtual bool OnFindExecuting<T, TKey, TResult>(RepositoryQuerySingleContext<T, TKey, TResult> context) where T : class
81226
{
82227
return true;
@@ -94,5 +239,6 @@ public virtual bool OnFindAllExecuting<T, TKey, TResult>(RepositoryQueryMultiple
94239
public virtual void OnFindAllExecuted<T, TKey, TResult>(RepositoryQueryMultipleContext<T, TKey, TResult> context) where T : class
95240
{
96241
}
242+
#endregion
97243
}
98244
}

SharpRepository.Repository/Aspects/RepositoryActionContext.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,34 @@ public RepositoryActionContext(IRepository<T, TKey> repository)
99

1010
public IRepository<T, TKey> Repository { get; set; }
1111
}
12+
13+
public class RepositoryActionContext<T, TKey, TKey2> where T : class
14+
{
15+
public RepositoryActionContext(ICompoundKeyRepository<T, TKey, TKey2> repository)
16+
{
17+
Repository = repository;
18+
}
19+
20+
public ICompoundKeyRepository<T, TKey, TKey2> Repository { get; set; }
21+
}
22+
23+
public class RepositoryActionContext<T, TKey, TKey2, TKey3> where T : class
24+
{
25+
public RepositoryActionContext(ICompoundKeyRepository<T, TKey, TKey2, TKey3> repository)
26+
{
27+
Repository = repository;
28+
}
29+
30+
public ICompoundKeyRepository<T, TKey, TKey2, TKey3> Repository { get; set; }
31+
}
32+
33+
public class RepositoryActionContext<T> where T : class
34+
{
35+
public RepositoryActionContext(ICompoundKeyRepository<T> repository)
36+
{
37+
Repository = repository;
38+
}
39+
40+
public ICompoundKeyRepository<T> Repository { get; set; }
41+
}
1242
}

SharpRepository.Repository/Aspects/RepositoryGetContext.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.Linq.Expressions;
34

45
namespace SharpRepository.Repository.Aspects
@@ -9,6 +10,24 @@ public RepositoryGetContext(IRepository<T, TKey> repository, TKey id) : base(rep
910
{
1011
}
1112
}
13+
public class RepositoryGetContext<T, TKey, TKey2> : RepositoryGetContext<T, TKey, TKey2, T> where T : class
14+
{
15+
public RepositoryGetContext(ICompoundKeyRepository<T, TKey, TKey2> repository, TKey id) : base(repository, id)
16+
{
17+
}
18+
}
19+
public class RepositoryGetContext<T, TKey, TKey2, TKey3> : RepositoryGetContext<T, TKey, TKey2, TKey3, T> where T : class
20+
{
21+
public RepositoryGetContext(ICompoundKeyRepository<T, TKey, TKey2, TKey3> repository, TKey id, TKey2 id2, TKey3 id3) : base(repository, id, id2, id3)
22+
{
23+
}
24+
}
25+
public class RepositoryGetContext<T> : RepositoryGetContext<T, T> where T : class
26+
{
27+
public RepositoryGetContext(IRepository<T> repository, IEnumerable<object> ids) : base(repository, ids)
28+
{
29+
}
30+
}
1231

1332
public class RepositoryGetContext<T, TKey, TResult> : RepositoryActionContext<T, TKey> where T : class
1433
{
@@ -29,4 +48,24 @@ public bool HasResult
2948

3049
public Expression<Func<T, TResult>> Selector { get; set; }
3150
}
51+
52+
public class RepositoryGetContext<T, TKey, TKey2, TResult> : RepositoryActionContext<T, TKey, TKey2> where T : class
53+
{
54+
public RepositoryGetContext(IRepository<T, TKey> repository, TKey id, TKey2 id2, Expression<Func<T, TResult>> selector = null)
55+
: base(repository)
56+
{
57+
Id = id;
58+
Selector = selector;
59+
}
60+
61+
public TKey Id { get; set; }
62+
public TResult Result { get; set; }
63+
64+
public bool HasResult
65+
{
66+
get { return Result != null && !Result.Equals(default(TResult)); }
67+
}
68+
69+
public Expression<Func<T, TResult>> Selector { get; set; }
70+
}
3271
}

SharpRepository.Repository/CompoundKeyRepositoryBase.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Generic;
33
using System.Linq;
44
using System.Linq.Expressions;
5+
using SharpRepository.Repository.Aspects;
56
using SharpRepository.Repository.Caching;
67
using SharpRepository.Repository.FetchStrategies;
78
using SharpRepository.Repository.Queries;
@@ -34,8 +35,15 @@ public override IBatch<T> BeginBatch()
3435
protected CompoundKeyRepositoryBase(ICompoundKeyCachingStrategy<T> cachingStrategy = null)
3536
{
3637
CachingStrategy = cachingStrategy ?? new NoCompoundKeyCachingStrategy<T>();
38+
39+
_repositoryActionContext = new RepositoryActionContext<T>(this);
40+
41+
RunAspect(aspect => aspect.OnInitialized(_repositoryActionContext));
3742
}
3843

44+
private readonly RepositoryActionContext<T> _repositoryActionContext;
45+
private readonly Dictionary<string, RepositoryActionBaseAttribute> _aspects;
46+
3947
public ICompoundKeyCachingStrategy<T> CachingStrategy
4048
{
4149
get { return _cachingStrategy; }
@@ -46,6 +54,26 @@ public ICompoundKeyCachingStrategy<T> CachingStrategy
4654
}
4755
}
4856

57+
private bool RunAspect(Func<RepositoryActionBaseAttribute, bool> action)
58+
{
59+
return _aspects.Values
60+
.Where(a => a.Enabled)
61+
.OrderBy(a => a.Order)
62+
.All(action);
63+
}
64+
65+
private void RunAspect(Action<RepositoryActionBaseAttribute> action)
66+
{
67+
var aspects = _aspects.Values
68+
.Where(a => a.Enabled)
69+
.OrderBy(a => a.Order);
70+
71+
foreach (var attribute in aspects)
72+
{
73+
action(attribute);
74+
}
75+
}
76+
4977
public override IEnumerable<T> GetAll(IQueryOptions<T> queryOptions, IFetchStrategy<T> fetchStrategy)
5078
{
5179
return _queryManager.ExecuteGetAll(

0 commit comments

Comments
 (0)