1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
18 using System
.Collections
;
19 using System
.Collections
.Generic
;
21 public enum LifecycleStepType
28 /// Represents a collection of ordered lifecycle steps.
33 public class LifecycleStepCollection
: ICollection
35 private static object _syncRoot
= new object();
36 private List
<object> commissionSteps
;
37 private List
<object> decommissionSteps
;
40 /// Initializes a new instance of the <see cref="LifecycleStepCollection"/> class.
42 public LifecycleStepCollection()
44 commissionSteps
= new List
<object>();
45 decommissionSteps
= new List
<object>();
49 /// Returns all steps for the commission phase
51 /// <returns></returns>
52 public object[] GetCommissionSteps()
54 object[] steps
= new object[commissionSteps
.Count
];
55 commissionSteps
.CopyTo(steps
, 0);
60 /// Returns all steps for the decommission phase
62 /// <returns></returns>
63 public object[] GetDecommissionSteps()
65 object[] steps
= new object[decommissionSteps
.Count
];
66 decommissionSteps
.CopyTo(steps
, 0);
71 /// Gets a value indicating whether this instance has commission steps.
74 /// <c>true</c> if this instance has commission steps; otherwise, <c>false</c>.
76 public bool HasCommissionSteps
78 get { return commissionSteps.Count != 0; }
82 /// Gets a value indicating whether this instance has decommission steps.
85 /// <c>true</c> if this instance has decommission steps; otherwise, <c>false</c>.
87 public bool HasDecommissionSteps
89 get { return decommissionSteps.Count != 0; }
93 /// Adds a step to the commission or decomission phases.
95 /// <param name="type"></param>
96 /// <param name="stepImplementation"></param>
97 public void Add(LifecycleStepType type
, object stepImplementation
)
99 if (stepImplementation
== null) throw new ArgumentNullException("stepImplementation");
101 if (type
== LifecycleStepType
.Commission
)
103 commissionSteps
.Add(stepImplementation
);
107 decommissionSteps
.Add(stepImplementation
);
112 /// Copies the elements of
113 /// the <see cref="T:System.Collections.ICollection"/> to an <see cref="T:System.Array"/>, starting at a particular <see cref="T:System.Array"/> index.
115 /// <param name="array">The one-dimensional <see cref="T:System.Array"/> that is the destination of the elements copied from <see cref="T:System.Collections.ICollection"/>. The <see cref="T:System.Array"/> must have zero-based indexing.</param>
116 /// <param name="index">The zero-based index in <paramref name="array"/> at which copying begins.</param>
117 /// <exception cref="T:System.ArgumentNullException">
118 /// <paramref name="array"/> is <see langword="null"/>.</exception>
119 /// <exception cref="T:System.ArgumentOutOfRangeException">
120 /// <paramref name="index"/> is less than zero.</exception>
121 /// <exception cref="T:System.ArgumentException">
123 /// <paramref name="array"/> is multidimensional.</para>
124 /// <para>-or-</para>
126 /// <paramref name="index"/> is equal to or greater than the length of <paramref name="array"/>.</para>
127 /// <para>-or-</para>
128 /// <para>The number of elements in the source <see cref="T:System.Collections.ICollection"/> is greater than the available space from <paramref name="index"/> to the end of the destination <paramref name="array"/>.</para>
130 /// <exception cref="T:System.InvalidCastException">The type of the source <see cref="T:System.Collections.ICollection"/> cannot be cast automatically to the type of the destination <paramref name="array"/>.</exception>
131 public void CopyTo(Array array
, int index
)
133 throw new NotImplementedException();
137 /// Gets the number of
138 /// elements contained in the <see cref="T:System.Collections.ICollection"/>.
143 get { return commissionSteps.Count + decommissionSteps.Count; }
147 /// Gets an object that
148 /// can be used to synchronize access to the <see cref="T:System.Collections.ICollection"/>.
151 public object SyncRoot
153 get { return _syncRoot; }
158 /// indicating whether access to the <see cref="T:System.Collections.ICollection"/> is synchronized
162 public bool IsSynchronized
164 get { return false; }
168 /// Returns an enumerator that can iterate through a collection.
171 /// An <see cref="T:System.Collections.IEnumerator"/>
172 /// that can be used to iterate through the collection.
174 public IEnumerator
GetEnumerator()
176 List
<object> newList
= new List
<object>(commissionSteps
);
177 newList
.AddRange(decommissionSteps
);
178 return newList
.GetEnumerator();