Skip to content

Commit aef0ee0

Browse files
committed
Revamped DB hooking framework & added "load" hooking
1 parent 2c5de4e commit aef0ee0

35 files changed

Lines changed: 1480 additions & 875 deletions

src/Libraries/SmartStore.Core/Data/Hooks/DefaultHookHandler.cs

Lines changed: 284 additions & 284 deletions
Large diffs are not rendered by default.
Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
1-
using System;
1+
//using System;
22

3-
namespace SmartStore.Core.Data.Hooks
4-
{
5-
public class HookEntityMetadata
6-
{
7-
private EntityState _state;
3+
//namespace SmartStore.Core.Data.Hooks
4+
//{
5+
// public class HookEntityMetadata
6+
// {
7+
// private EntityState _state;
88

9-
public HookEntityMetadata(EntityState state)
10-
{
11-
_state = state;
12-
}
9+
// public HookEntityMetadata(EntityState state)
10+
// {
11+
// _state = state;
12+
// }
1313

14-
public EntityState State
15-
{
16-
get { return this._state; }
17-
set
18-
{
19-
if (_state != value)
20-
{
21-
this._state = value;
22-
HasStateChanged = true;
23-
}
24-
}
25-
}
14+
// public EntityState State
15+
// {
16+
// get { return this._state; }
17+
// set
18+
// {
19+
// if (_state != value)
20+
// {
21+
// this._state = value;
22+
// HasStateChanged = true;
23+
// }
24+
// }
25+
// }
2626

27-
public bool HasStateChanged
28-
{
29-
get;
30-
private set;
31-
}
32-
}
33-
}
27+
// public bool HasStateChanged
28+
// {
29+
// get;
30+
// private set;
31+
// }
32+
// }
33+
//}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System;
2+
3+
namespace SmartStore.Core.Data.Hooks
4+
{
5+
public class HookMetadata
6+
{
7+
/// <summary>
8+
/// The type of entity
9+
/// </summary>
10+
public Type HookedType { get; set; }
11+
12+
/// <summary>
13+
/// The type of the hook class itself
14+
/// </summary>
15+
public Type ImplType { get; set; }
16+
17+
public bool IsLoadHook { get; set; }
18+
19+
/// <summary>
20+
/// Whether the hook should run in any case, even if hooking has been turned off.
21+
/// </summary>
22+
public bool Important { get; set; }
23+
}
24+
}
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
using System;
2-
using System.Data.Entity.Infrastructure;
1+
//using System;
2+
//using System.Data.Entity.Infrastructure;
33

4-
namespace SmartStore.Core.Data.Hooks
5-
{
6-
public class HookedEntityEntry
7-
{
8-
public DbEntityEntry Entry { get; set; }
9-
public EntityState PreSaveState { get; set; }
10-
}
11-
}
4+
//namespace SmartStore.Core.Data.Hooks
5+
//{
6+
// public class HookedEntityEntry
7+
// {
8+
// public DbEntityEntry Entry { get; set; }
9+
// public EntityState PreSaveState { get; set; }
10+
// }
11+
//}
Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,41 @@
11

2-
namespace SmartStore.Core.Data.Hooks
3-
{
4-
public interface IHook
5-
{
6-
void HookObject(object entity, HookEntityMetadata metadata);
2+
//namespace SmartStore.Core.Data.Hooks
3+
//{
4+
// public interface IHook
5+
// {
6+
// void HookObject(object entity, HookEntityMetadata metadata);
77

8-
/// <summary>
9-
/// Indicates whether the hook instance can be processed for the given <see cref="EntityState"/>
10-
/// </summary>
11-
/// <param name="state">The state of the entity</param>
12-
/// <returns><c>true</c> when the hook should be processed, <c>false</c> otherwise</returns>
13-
bool CanProcess(EntityState state);
8+
// /// <summary>
9+
// /// Indicates whether the hook instance can be processed for the given <see cref="EntityState"/>
10+
// /// </summary>
11+
// /// <param name="state">The state of the entity</param>
12+
// /// <returns><c>true</c> when the hook should be processed, <c>false</c> otherwise</returns>
13+
// bool CanProcess(EntityState state);
1414

15-
/// <summary>
16-
/// Called after all entities in the current unit of work has been hooked
17-
/// </summary>
18-
void OnCompleted();
19-
}
15+
// /// <summary>
16+
// /// Called after all entities in the current unit of work has been hooked
17+
// /// </summary>
18+
// void OnCompleted();
19+
// }
2020

21-
/// <summary>
22-
/// A hook that is executed after an action.
23-
/// </summary>
24-
public interface IPostActionHook : IHook
25-
{
26-
}
21+
// /// <summary>
22+
// /// A hook that is executed after an action.
23+
// /// </summary>
24+
// public interface IPostActionHook : IHook
25+
// {
26+
// }
2727

28-
/// <summary>
29-
/// A hook that is executed before an action.
30-
/// </summary>
31-
public interface IPreActionHook : IHook
32-
{
33-
/// <summary>
34-
/// Gets a value indicating whether the hook is only used after successful validation.
35-
/// </summary>
36-
/// <value>
37-
/// <c>true</c> if requires validation; otherwise, <c>false</c>.
38-
/// </value>
39-
bool RequiresValidation { get; }
40-
}
41-
}
28+
// /// <summary>
29+
// /// A hook that is executed before an action.
30+
// /// </summary>
31+
// public interface IPreActionHook : IHook
32+
// {
33+
// /// <summary>
34+
// /// Gets a value indicating whether the hook is only used after successful validation.
35+
// /// </summary>
36+
// /// <value>
37+
// /// <c>true</c> if requires validation; otherwise, <c>false</c>.
38+
// /// </value>
39+
// bool RequiresValidation { get; }
40+
// }
41+
//}
Lines changed: 56 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,56 @@
1-
using System;
2-
using System.Collections.Generic;
3-
4-
namespace SmartStore.Core.Data.Hooks
5-
{
6-
public class HookMetadata
7-
{
8-
/// <summary>
9-
/// The type of entity
10-
/// </summary>
11-
public Type HookedType { get; set; }
12-
13-
/// <summary>
14-
/// The type of the hook class itself
15-
/// </summary>
16-
public Type ImplType { get; set; }
17-
18-
/// <summary>
19-
/// Whether the hook should run in any case, even if hooking has been turned off.
20-
/// </summary>
21-
public bool Important { get; set; }
22-
}
23-
24-
public interface IHookHandler
25-
{
26-
bool HasImportantPreHooks();
27-
bool HasImportantPostHooks();
28-
29-
/// <summary>
30-
/// Triggers all pre action hooks
31-
/// </summary>
32-
/// <param name="entries">Entries</param>
33-
/// <param name="requiresValidation"></param>
34-
/// <param name="importantHooksOnly"></param>
35-
/// <returns><c>true</c> if the state of any entry changed</returns>
36-
bool TriggerPreActionHooks(IEnumerable<HookedEntityEntry> entries, bool requiresValidation, bool importantHooksOnly);
37-
38-
/// <summary>
39-
/// Triggers all post action hooks
40-
/// </summary>
41-
/// <param name="entries">Entries</param>
42-
/// <param name="importantHooksOnly"></param>
43-
void TriggerPostActionHooks(IEnumerable<HookedEntityEntry> entries, bool importantHooksOnly);
44-
}
45-
46-
public sealed class NullHookHandler : IHookHandler
47-
{
48-
private readonly static IHookHandler s_instance = new NullHookHandler();
49-
50-
public static IHookHandler Instance
51-
{
52-
get { return s_instance; }
53-
}
54-
55-
public bool HasImportantPostHooks()
56-
{
57-
return false;
58-
}
59-
60-
public bool HasImportantPreHooks()
61-
{
62-
return false;
63-
}
64-
65-
public void TriggerPostActionHooks(IEnumerable<HookedEntityEntry> entries, bool importantHooksOnly)
66-
{
67-
}
68-
69-
public bool TriggerPreActionHooks(IEnumerable<HookedEntityEntry> entries, bool requiresValidation, bool importantHooksOnly)
70-
{
71-
return false;
72-
}
73-
}
74-
}
1+
//using System;
2+
//using System.Collections.Generic;
3+
4+
//namespace SmartStore.Core.Data.Hooks
5+
//{
6+
// public interface IHookHandler
7+
// {
8+
// bool HasImportantPreHooks();
9+
// bool HasImportantPostHooks();
10+
11+
// /// <summary>
12+
// /// Triggers all pre action hooks
13+
// /// </summary>
14+
// /// <param name="entries">Entries</param>
15+
// /// <param name="requiresValidation"></param>
16+
// /// <param name="importantHooksOnly"></param>
17+
// /// <returns><c>true</c> if the state of any entry changed</returns>
18+
// bool TriggerPreActionHooks(IEnumerable<HookedEntityEntry> entries, bool requiresValidation, bool importantHooksOnly);
19+
20+
// /// <summary>
21+
// /// Triggers all post action hooks
22+
// /// </summary>
23+
// /// <param name="entries">Entries</param>
24+
// /// <param name="importantHooksOnly"></param>
25+
// void TriggerPostActionHooks(IEnumerable<HookedEntityEntry> entries, bool importantHooksOnly);
26+
// }
27+
28+
// public sealed class NullHookHandler : IHookHandler
29+
// {
30+
// private readonly static IHookHandler s_instance = new NullHookHandler();
31+
32+
// public static IHookHandler Instance
33+
// {
34+
// get { return s_instance; }
35+
// }
36+
37+
// public bool HasImportantPostHooks()
38+
// {
39+
// return false;
40+
// }
41+
42+
// public bool HasImportantPreHooks()
43+
// {
44+
// return false;
45+
// }
46+
47+
// public void TriggerPostActionHooks(IEnumerable<HookedEntityEntry> entries, bool importantHooksOnly)
48+
// {
49+
// }
50+
51+
// public bool TriggerPreActionHooks(IEnumerable<HookedEntityEntry> entries, bool requiresValidation, bool importantHooksOnly)
52+
// {
53+
// return false;
54+
// }
55+
// }
56+
//}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System;
2+
3+
namespace SmartStore.Core.Data.Hooks
4+
{
5+
public abstract class DbLoadHook<TEntity> : IDbLoadHook
6+
{
7+
public virtual void OnLoaded(BaseEntity entity)
8+
{
9+
}
10+
}
11+
}

0 commit comments

Comments
 (0)