-
Notifications
You must be signed in to change notification settings - Fork 0
/
WorkflowStateFilterDisabler.cs
86 lines (70 loc) · 1.67 KB
/
WorkflowStateFilterDisabler.cs
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
using System;
using System.Collections.Generic;
using System.Threading;
using Sitecore.Web;
namespace scLabs.PreProdPreview
{
public class WorkflowStateFilterDisabler : IDisposable
{
#region Fields
private static object _lock = new object();
private string _oldValue;
protected static List<ThreadStart> _onLeave = new List<ThreadStart>();
private const string ItemsKey = "WorkflowStateFilterDisabler";
private int m_disposed;
#endregion
#region ctor
public WorkflowStateFilterDisabler()
{
lock (_lock)
{
_oldValue = WebUtil.GetItemsString(ItemsKey);
WebUtil.SetItemsValue(ItemsKey, "1");
}
}
#endregion
#region Properties
public static bool IsActive
{
get { return (WebUtil.GetItemsString(ItemsKey) == "1"); }
}
#endregion
#region Events
public static event ThreadStart OnLeave
{
add
{
lock (_lock)
{
_onLeave.Add(value);
}
}
remove
{
lock (_lock)
{
_onLeave.Remove(value);
}
}
}
#endregion
#region Methods
public void Dispose()
{
if (Interlocked.CompareExchange(ref m_disposed, 1, 0) == 0)
{
WebUtil.SetItemsValue(ItemsKey, _oldValue);
}
if (IsActive) return;
lock (_lock)
{
if (IsActive) return;
foreach (var start in _onLeave)
{
start();
}
}
}
#endregion
}
}