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
using System;
using System.Collections.Specialized;
 
namespace Prow.Tasks
{
    internal static class TriggerStorageExtensions
    {
        /// <summary>
        /// 从持久化接口中加载任务触发器
        /// </summary>
        /// <param name="trigger"></param>
        /// <param name="scheduleName"></param>
        /// <param name="storage"></param>
        /// <param name="logger"></param>
        public static void Load(this ITrigger trigger, string scheduleName, IStorage storage, Action<string> logger)
        {
            if (storage != null)
            {
                if (!storage.Load(scheduleName, trigger) && storage.Exception != null) logger(storage.Exception.FormatException(new NameValueCollection()
                {
                    ["TaskName"] = scheduleName,
                    ["TriggerName"] = trigger.Name,
                    ["TriggerType"] = trigger.GetType().Name
                }));
            }
        }
 
        /// <summary>
        /// 保存任务触发器到持久化接口中
        /// </summary>
        /// <param name="trigger"></param>
        /// <param name="scheduleName"></param>
        /// <param name="storage"></param>
        /// <param name="logger"></param>
        public static void Save(this ITrigger trigger, string scheduleName, IStorage storage, Action<string> logger)
        {
            if (storage != null)
            {
                if (!storage.Save(scheduleName, trigger) && storage.Exception != null) logger(storage.Exception.FormatException(new NameValueCollection()
                {
                    ["TaskName"] = scheduleName,
                    ["TriggerName"] = trigger.Name,
                    ["TriggerType"] = trigger.GetType().Name
                }));
            }
        }
    }
}