zhaolei
2020-11-20 921de2254ff5712a44ed8575ee8efe34252f6603
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
#if !NET45
using Microsoft.Extensions.DependencyInjection;
#endif
using PetaPoco;
using System;
 
namespace Prow.Data
{
    /// <summary>
    /// IDatabase Logger 扩展
    /// </summary>
    public static class DatabaseExtensions
    {
#if !NET45
        /// <summary>
        /// IDatabase 实例数据库脚本执行前回调方法
        /// </summary>
        /// <param name="db"></param>
        /// <param name="executedCallback"></param>
        public static void OnCommandExecuted(this IDatabase db, Action<IServiceProvider> executedCallback)
        {
            db.CommandExecuted += (sender, args) => executedCallback?.Invoke(DatabaseServiceCollectionExtensions.ServiceProvider);
        }
 
        /// <summary>
        /// IDatabase 实例数据库脚本执行后回调方法
        /// </summary>
        /// <param name="db"></param>
        /// <param name="executingCallback"></param>
        public static void OnCommandExecuting(this IDatabase db, Action<IServiceProvider> executingCallback)
        {
            db.CommandExecuting += (sender, args) => executingCallback?.Invoke(DatabaseServiceCollectionExtensions.ServiceProvider);
        }
#else
        /// <summary>
        /// IDatabase 实例数据库脚本执行前回调方法
        /// </summary>
        /// <param name="db"></param>
        /// <param name="executedCallback"></param>
        public static void OnCommandExecuted(this IDatabase db, Action executedCallback)
        {
            db.CommandExecuted += (sender, args) => executedCallback?.Invoke();
        }
 
        /// <summary>
        /// IDatabase 实例数据库脚本执行后回调方法
        /// </summary>
        /// <param name="db"></param>
        /// <param name="executingCallback"></param>
        public static void OnCommandExecuting(this IDatabase db, Action executingCallback)
        {
            db.CommandExecuting += (sender, args) => executingCallback?.Invoke();
        }
#endif
    }
}