-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathViewSteps.cs
107 lines (97 loc) · 2.86 KB
/
ViewSteps.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
using System;
using System.Collections.Concurrent;
using System.Threading;
namespace Inversion.Process {
/// <summary>
/// A collection of view step objects representing
/// the steps taken in a view generating pipeline.
/// </summary>
/// <remarks>
/// This is currently badly implemented as a concurrent stack,
/// and needs to change. This needs to become a synchronised
/// collection.
/// </remarks>
public class ViewSteps : ConcurrentStack<ViewStep>, IDisposable {
private readonly ReaderWriterLockSlim _lock = new ReaderWriterLockSlim();
private bool _isDisposed;
/// <summary>
/// Determines whether or not there are any
/// steps.
/// </summary>
public bool HasSteps {
get {
try {
_lock.EnterReadLock();
return base.Count > 0;
} finally {
_lock.ExitReadLock();
}
}
}
/// <summary>
/// The last step in the current pipeline.
/// </summary>
public ViewStep Last {
get {
try {
_lock.EnterReadLock();
ViewStep last;
base.TryPeek(out last);
return last;
} finally {
_lock.ExitReadLock();
}
}
}
/// <summary>
/// Releases all resources maintained by the current context instance.
/// </summary>
public void Dispose() {
this.Dispose(true);
GC.SuppressFinalize(this);
}
/// <summary>
/// Disposal that allows for partitioning of
/// clean-up of managed and unmanaged resources.
/// </summary>
/// <param name="disposing"></param>
/// <remarks>
/// This is looking conceited and should probably be removed.
/// I'm not even sure I can explain a use case for it in terms
/// of an Inversion context.
/// </remarks>
protected virtual void Dispose(bool disposing) {
if (!_isDisposed) {
if (disposing) {
// managed resource clean-up
_lock.Dispose();
}
// unmanaged resource clean-up
// ... nothing to do
// call dispose on base class, and clear data
// base.Dispose(disposing);
// mark disposing as done
_isDisposed = true;
}
}
/// <summary>
/// Creates a new view step and pushes it onto the
/// stack of view steps to be processed.
/// </summary>
/// <param name="name">The name of the view step to be created.</param>
/// <param name="contentType">The content type that the new view step represents.</param>
/// <param name="content">The actual content of the new view step.</param>
public void CreateStep(string name, string contentType, string content) {
this.Push(new ViewStep(name, contentType, content));
}
/// <summary>
/// Creates a new view step and pushes it onto the
/// stack of view steps to be processed.
/// </summary>
/// <param name="name">The name of the view step to be created.</param>
/// <param name="model">The actual model of the new view step.</param>
public void CreateStep(string name, IData model) {
this.Push(new ViewStep(name, model));
}
}
}