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
;
20 public enum LifecycleStepType
27 /// Represents a collection of ordered lifecycle steps.
30 public class LifecycleStepCollection
: ICollection
32 private IList commissionSteps
;
33 private IList decommissionSteps
;
36 /// Initializes a new instance of the <see cref="LifecycleStepCollection"/> class.
38 public LifecycleStepCollection()
40 commissionSteps
= new ArrayList();
41 decommissionSteps
= new ArrayList();
45 /// Returns all steps for the commission phase
47 /// <returns></returns>
48 public object[] GetCommissionSteps()
50 object[] steps
= new object[commissionSteps
.Count
];
51 commissionSteps
.CopyTo(steps
, 0);
56 /// Returns all steps for the decommission phase
58 /// <returns></returns>
59 public object[] GetDecommissionSteps()
61 object[] steps
= new object[decommissionSteps
.Count
];
62 decommissionSteps
.CopyTo(steps
, 0);
67 /// Gets a value indicating whether this instance has commission steps.
70 /// <c>true</c> if this instance has commission steps; otherwise, <c>false</c>.
72 public bool HasCommissionSteps
74 get { return commissionSteps.Count != 0; }
78 /// Gets a value indicating whether this instance has decommission steps.
81 /// <c>true</c> if this instance has decommission steps; otherwise, <c>false</c>.
83 public bool HasDecommissionSteps
85 get { return decommissionSteps.Count != 0; }
89 /// Adds a step to the commission or decomission phases.
91 /// <param name="type"></param>
92 /// <param name="stepImplementation"></param>
93 public void Add(LifecycleStepType type
, object stepImplementation
)
95 if (stepImplementation
== null) throw new ArgumentNullException("stepImplementation");
97 if (type
== LifecycleStepType
.Commission
)
99 commissionSteps
.Add(stepImplementation
);
103 decommissionSteps
.Add(stepImplementation
);
108 /// Copies the elements of
109 /// the <see cref="T:System.Collections.ICollection"/> to an <see cref="T:System.Array"/>, starting at a particular <see cref="T:System.Array"/> index.
111 /// <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>
112 /// <param name="index">The zero-based index in <paramref name="array"/> at which copying begins.</param>
113 /// <exception cref="T:System.ArgumentNullException">
114 /// <paramref name="array"/> is <see langword="null"/>.</exception>
115 /// <exception cref="T:System.ArgumentOutOfRangeException">
116 /// <paramref name="index"/> is less than zero.</exception>
117 /// <exception cref="T:System.ArgumentException">
119 /// <paramref name="array"/> is multidimensional.</para>
120 /// <para>-or-</para>
122 /// <paramref name="index"/> is equal to or greater than the length of <paramref name="array"/>.</para>
123 /// <para>-or-</para>
124 /// <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>
126 /// <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>
127 public void CopyTo(Array array
, int index
)
129 throw new NotImplementedException();
133 /// Gets the number of
134 /// elements contained in the <see cref="T:System.Collections.ICollection"/>.
139 get { return commissionSteps.Count + decommissionSteps.Count; }
143 /// Gets an object that
144 /// can be used to synchronize access to the <see cref="T:System.Collections.ICollection"/>.
147 public object SyncRoot
149 get { return commissionSteps.SyncRoot; }
154 /// indicating whether access to the <see cref="T:System.Collections.ICollection"/> is synchronized
158 public bool IsSynchronized
160 get { return commissionSteps.IsSynchronized; }
164 /// Returns an enumerator that can iterate through a collection.
167 /// An <see cref="T:System.Collections.IEnumerator"/>
168 /// that can be used to iterate through the collection.
170 public IEnumerator
GetEnumerator()
172 ArrayList newList
= new ArrayList(commissionSteps
);
173 newList
.AddRange(decommissionSteps
);
174 return newList
.GetEnumerator();