1717// http://www.cas.eu
1818//</summary>
1919
20+ using CAS . Lib . CommonBus ;
2021using System ;
2122using System . ComponentModel ;
2223using System . Data ;
24+ using System . Linq ;
2325using System . Windows . Forms ;
2426
2527namespace CAS . CommServer . ProtocolHub . ConfigurationEditor . HMI
2628{
2729 internal class ActionBase
2830 {
29- protected static CAS . Lib . CommonBus . CommonBusControl m_CommonBusControl ;
30- internal static CAS . Lib . CommonBus . CommonBusControl SetCommonBusControl { set { m_CommonBusControl = value ; } }
31+ protected static CommonBusControl m_CommonBusControl ;
32+ internal static CommonBusControl SetCommonBusControl { set { m_CommonBusControl = value ; } }
3133 }
3234 /// <summary>
33- /// Abstract class to support operations on treeview node
35+ /// Abstract class to support operations on <see cref="TreeNode"/>
3436 /// </summary>
3537 /// <typeparam name="TRow">Object type</typeparam>
36- internal abstract class Action < TRow > : ActionBase , IAction where TRow : DataRow
38+ internal abstract class Action < TRow > : ActionBase , IAction where TRow : DataRow
3739 {
3840 #region private
39- private void Table_RowDeleted ( object sender , System . Data . DataRowChangeEventArgs e )
41+ private void Table_RowDeleted ( object sender , System . Data . DataRowChangeEventArgs e )
4042 {
41- System . Diagnostics . Debug . Assert ( ( m_Node != null ) && ( m_Parent != null ) && ! m_disposed ) ;
42- if ( e . Row != m_Parent )
43+ System . Diagnostics . Debug . Assert ( ( m_Node != null ) && ( m_Parent != null ) && ! m_disposed ) ;
44+ if ( e . Row != m_Parent )
4345 return ;
44- this . Dispose ( true ) ;
46+ this . Dispose ( true ) ;
4547 }
46- private void RemoveChildrens ( )
48+ private void RemoveChildren ( )
4749 {
48- foreach ( TreeNode cn in m_Node . Nodes )
49- ( ( IAction ) cn . Tag ) . Dispose ( ) ;
50+ foreach ( TreeNode cn in m_Node . Nodes . Cast < TreeNode > ( ) . ToList < TreeNode > ( ) )
51+ ( ( IAction ) cn . Tag ) . Dispose ( ) ;
5052 }
5153 private void RemoveEventHandler ( )
5254 {
53- if ( m_Parent == null )
55+ if ( m_Parent == null )
5456 return ;
55- m_Parent . Table . RowDeleted -= new DataRowChangeEventHandler ( Table_RowDeleted ) ;
57+ m_Parent . Table . RowDeleted -= new DataRowChangeEventHandler ( Table_RowDeleted ) ;
5658 }
5759 #endregion
5860 #region protected
@@ -67,7 +69,7 @@ private void RemoveEventHandler()
6769 /// Associate specified data row to this action
6870 /// </summary>
6971 /// <param name="row"></param>
70- protected Action ( TRow row )
72+ protected Action ( TRow row )
7173 {
7274 m_Parent = row ;
7375 }
@@ -76,14 +78,14 @@ protected Action( TRow row )
7678 /// </summary>
7779 ~ Action ( )
7880 {
79- Dispose ( false ) ;
81+ Dispose ( false ) ;
8082 }
8183 #endregion
8284 #region Properties
8385 /// <summary>
8486 /// Gets data row asscociated to this action
8587 /// </summary>
86- [ Browsable ( false ) ]
88+ [ Browsable ( false ) ]
8789 public TRow DataRow
8890 {
8991 get
@@ -93,19 +95,19 @@ public TRow DataRow
9395 }
9496 #endregion
9597 #region public
96- internal TreeNode AddActionTreeNode ( int pImageIndex , int pSelectedImageIndex )
98+ internal TreeNode AddActionTreeNode ( int pImageIndex , int pSelectedImageIndex )
9799 {
98100 m_Node . Tag = this ;
99101 m_Node . ImageIndex = pImageIndex ;
100102 m_Node . SelectedImageIndex = pSelectedImageIndex ;
101103 m_Node . Text = this . ToString ( ) ;
102104 return m_Node ;
103105 }
104- internal void AddActionTreeNode ( TreeNode pParentNode , int pImageIndex , int pSelectedImageIndex )
106+ internal void AddActionTreeNode ( TreeNode pParentNode , int pImageIndex , int pSelectedImageIndex )
105107 {
106- m_Node = AddActionTreeNode ( pImageIndex , pSelectedImageIndex ) ;
107- pParentNode . Nodes . Add ( m_Node ) ;
108- m_Parent . Table . RowDeleted += new System . Data . DataRowChangeEventHandler ( Table_RowDeleted ) ;
108+ m_Node = AddActionTreeNode ( pImageIndex , pSelectedImageIndex ) ;
109+ pParentNode . Nodes . Add ( m_Node ) ;
110+ m_Parent . Table . RowDeleted += new System . Data . DataRowChangeEventHandler ( Table_RowDeleted ) ;
109111 }
110112 #endregion
111113 #region IAction Members
@@ -116,7 +118,7 @@ internal void AddActionTreeNode( TreeNode pParentNode, int pImageIndex, int pSel
116118 /// <remarks>If we perform this action for PrortocolAndSerialWrapper we adds protocol and serial rows</remarks>
117119 public void AddObjectToTable ( )
118120 {
119- m_Parent . Table . Rows . Add ( m_Parent ) ;
121+ m_Parent . Table . Rows . Add ( m_Parent ) ;
120122 }
121123 /// <summary>
122124 /// cleanup after unfinished add operation
@@ -134,7 +136,7 @@ public virtual void AddUnfinishedCleanup()
134136 /// </summary>
135137 public virtual void CreateNodes ( )
136138 {
137- RemoveChildrens ( ) ;
139+ RemoveChildren ( ) ;
138140 m_Node . Nodes . Clear ( ) ;
139141 }
140142 /// <summary>
@@ -148,13 +150,13 @@ public virtual void DeleteObject()
148150 /// Pastes specified IAction object under this node
149151 /// </summary>
150152 /// <param name="objToPaste">Object to paste</param>
151- public abstract void PasteChildObject ( IAction objToPaste ) ;
153+ public abstract void PasteChildObject ( IAction objToPaste ) ;
152154 /// <summary>
153155 /// Checks if specified object can be pasted under this object
154156 /// </summary>
155157 /// <param name="objToPaste">Object to paste</param>
156158 /// <returns>True if specified object can be pasted hare</returns>
157- public abstract bool CanBePastedAsChild ( IAction objToPaste ) ;
159+ public abstract bool CanBePastedAsChild ( IAction objToPaste ) ;
158160 /// <summary>
159161 /// Checks if specified <see cref="IAction"/> object can be moved
160162 /// </summary>
@@ -164,7 +166,7 @@ public virtual void DeleteObject()
164166 /// Moves specified <see cref="IAction"/> object under this wrapper
165167 /// </summary>
166168 /// <param name="pObjToMove"><see cref="IAction"/> object to be moved</param>
167- public abstract void MoveChildObject ( IAction pObjToMove ) ;
169+ public abstract void MoveChildObject ( IAction pObjToMove ) ;
168170 /// <summary>
169171 /// Inform the object that some values have been changed.
170172 /// </summary>
@@ -175,7 +177,7 @@ public virtual void DeleteObject()
175177 /// Get the boolean value indicated that this object can be copy or not.
176178 /// By default it always returns true. If wrapper cannot be copy this property have to be overriten
177179 /// </summary>
178- [ BrowsableAttribute ( false ) ]
180+ [ BrowsableAttribute ( false ) ]
179181 public virtual bool CanBeCopied
180182 {
181183 get
@@ -187,7 +189,7 @@ public virtual bool CanBeCopied
187189 /// Get the boolean value indicated that this object can create child object or not.
188190 /// By default it always returns false. If wrapper cannot create child obj this property have to be overriten
189191 /// </summary>
190- [ BrowsableAttribute ( false ) ]
192+ [ BrowsableAttribute ( false ) ]
191193 public virtual bool CanCreateChild
192194 {
193195 get
@@ -199,7 +201,7 @@ public virtual bool CanCreateChild
199201 /// Get the boolean value indicated that this object can be deleted or not.
200202 /// By default it always returns true. If wrapper cannot be deleted this property have to be overriten
201203 /// </summary>
202- [ BrowsableAttribute ( false ) ]
204+ [ BrowsableAttribute ( false ) ]
203205 public virtual bool CanBeDeleted
204206 {
205207 get
@@ -214,8 +216,8 @@ public virtual bool CanBeDeleted
214216 /// </summary>
215217 public void Dispose ( )
216218 {
217- Dispose ( true ) ;
218- GC . SuppressFinalize ( this ) ;
219+ Dispose ( true ) ;
220+ GC . SuppressFinalize ( this ) ;
219221 }
220222 // Track whether Dispose has been called.
221223 private bool m_disposed = false ;
@@ -227,12 +229,12 @@ public void Dispose()
227229 /// objects. Only unmanaged resources can be disposed.
228230 /// </summary>
229231 /// <param name="pDisposing">If dsposing equals true, the method has been called directly or indirectly by a user's code</param>
230- protected virtual void Dispose ( bool pDisposing )
232+ protected virtual void Dispose ( bool pDisposing )
231233 {
232- if ( m_disposed || ! pDisposing )
234+ if ( m_disposed || ! pDisposing )
233235 return ;
234236 RemoveEventHandler ( ) ;
235- RemoveChildrens ( ) ;
237+ RemoveChildren ( ) ;
236238 m_Node . Remove ( ) ;
237239 m_Node = null ;
238240 m_disposed = true ;
0 commit comments