33
44using  System . Collections . Generic ; 
55using  System . Runtime . Serialization ; 
6- using  System . Linq ; 
7- using  System . ComponentModel ; 
6+ using  System . Linq ; 
7+ using  System . Runtime . InteropServices . ComTypes ; 
88
99namespace  Moryx . Workplans 
1010{ 
@@ -95,85 +95,92 @@ public static Workplan Restore(List<IConnector> connectors, List<IWorkplanStep>
9595            return  new  Workplan ( connectors ,  steps ) ; 
9696        } 
9797
98-         /// <summary> 
99-         /// Compare two workplans 
100-         /// </summary> 
101-         /// <param name="obj"></param> 
102-         /// <returns></returns> 
103-         public  override  bool  Equals ( object  obj ) 
98+         public  static bool  noteSameFollowringSteps ( Workplan  workplan ,  Workplan  newWorkplan  , IWorkplanStep  step ,  IWorkplanStep  newStep ,  List < IWorkplanStep >  needToCheck ,  List < IWorkplanStep >  newNeedToCheck ,  List < IWorkplanStep >  isChecked ) 
10499        { 
105- 
106-             if  ( ! ( obj  is  Workplan ) ) 
107-             { 
108-                 return  false ; 
109-             } 
110-             Workplan  newPlan  =  ( Workplan ) obj ; 
111- 
112-             var  start  =  this . Connectors . First ( x =>  x . Name . Equals ( "Start" ) ) ; 
113-             var  end  =  this . Connectors . First ( x =>  x . Name . Equals ( "End" ) ) ; 
114-             var  failed  =  this . Connectors . First ( x =>  x . Name . Equals ( "Failed" ) ) ; 
115- 
116-             var  newStart  =  newPlan . Connectors . First ( x =>  x . Name . Equals ( "Start" ) ) ; 
117-             var  newEnd  =  newPlan . Connectors . First ( x =>  x . Name . Equals ( "End" ) ) ; 
118-             var  newFailed  =  newPlan . Connectors . First ( x =>  x . Name . Equals ( "Failed" ) ) ; 
119- 
120-             var  step  =  this . Steps . First ( x =>  x . Inputs . Any ( y =>  y . Equals ( start ) ) ) ; 
121-             var  newStep  =  newPlan . Steps . First ( x =>  x . Inputs . Any ( y =>  y . Equals ( newStart ) ) ) ; 
122- 
123-             List < IWorkplanStep >  needToCheck  =  new  List < IWorkplanStep > ( ) ; 
124-             List < IWorkplanStep >  newNeedToCheck  =  new  List < IWorkplanStep > ( ) ; 
125- 
126-             List < IWorkplanStep >  check  =  new  List < IWorkplanStep > ( ) ; 
127- 
128-             needToCheck . Add ( step ) ; 
129-             newNeedToCheck . Add ( newStep ) ; 
130- 
131-             while  ( needToCheck . Count  !=  0  &&  newNeedToCheck . Count  !=  0 ) 
100+             
101+             for  ( int  a  =  0 ;  a  <  step . Outputs . Length ;  a ++ ) 
132102            { 
103+                 var  connector  =  step . Outputs [ a ] ; 
104+                 var  newConnector  =  newStep . Outputs [ a ] ; 
133105
134- 
135-                 for  ( int  a  =  0 ;  a  <  step . Outputs . Length ;  a ++ ) 
106+                 if  ( connector . Id  ==  newConnector . Id ) 
136107                { 
137108
138-                     var  connector  =  step . Outputs [ a ] ; 
139-                     var  newConnector  =  newStep . Outputs [ a ] ; 
140- 
141-                     bool  isNotEndConnector  =  ( connector  !=  end  &&  newConnector  !=  newEnd ) ; 
142-                     bool  isNotFailedConnector  =  ( connector  !=  failed  &&  newConnector  !=  newFailed ) ; 
109+                     bool  isNotEndConnector  =  ! ( connector . Classification . Equals ( NodeClassification . End ) )  &&  ! ( newConnector . Classification . Equals ( NodeClassification . End ) ) ; 
110+                     bool  isNotFailedConnector  =  ! ( connector . Classification . Equals ( NodeClassification . Failed ) )  &&  ! ( newConnector . Classification . Equals ( NodeClassification . Failed ) ) ; 
143111
144112                    if  ( isNotEndConnector  &&  isNotFailedConnector ) 
145113                    { 
146-                         var  follower  =  this . Steps . FirstOrDefault ( x =>  x . Inputs . Any ( y =>  y . Equals ( connector ) ) ) ; 
147-                         var  newFollower  =  newPlan . Steps . FirstOrDefault ( x =>  x . Inputs . Any ( y =>  y . Equals ( newConnector ) ) ) ; 
114+                         var  follower  =  workplan . Steps . FirstOrDefault ( x =>  x . Inputs . Any ( y =>  y . Equals ( connector ) ) ) ; 
115+                         var  newFollower  =  newWorkplan . Steps . FirstOrDefault ( x =>  x . Inputs . Any ( y =>  y . Equals ( newConnector ) ) ) ; 
116+ 
117+                         bool  isAlreadyChecked  =  ( isChecked . Contains ( follower )  ||  isChecked . Contains ( newFollower ) ) ; 
148118
149-                         bool  isAlreadyChecked  =  ( check . Contains ( follower )  ||  check . Contains ( newFollower ) ) ; 
150- 
151119                        if  ( ! ( isAlreadyChecked ) ) 
152120                        { 
153121                            needToCheck . Add ( follower ) ; 
154122                            newNeedToCheck . Add ( newFollower ) ; 
155123                        } 
156124                    } 
157-                     else  if  ( connector . Classification  !=  newConnector . Classification ) 
158-                     { 
159-                         return  false ; 
160-                     } 
161125                } 
126+                 else 
127+                 { 
128+                     return  false ; 
129+                 } 
130+             } 
131+             return  true ; 
132+         } 
133+ 
134+         /// <summary> 
135+         /// Compare two workplans 
136+         /// </summary> 
137+         /// <param name="workplan"></param> 
138+         /// <param name="newWorkplan"></param> 
139+         /// <returns></returns> 
140+         public  static bool  Equals ( Workplan  workplan ,  Workplan  newWorkplan ) 
141+         { 
142+ 
143+             //var start = workplan.Connectors.First(x => x.Classification.Equals(NodeClassification.Start)); 
144+             //var end = workplan.Connectors.First(x => x.Classification.Equals(NodeClassification.End)); 
145+             //var failed = workplan.Connectors.First(x => x.Classification.Equals(NodeClassification.Failed)); 
146+ 
147+             //var newStart = newWorkplan.Connectors.First(x => x.Classification.Equals(NodeClassification.Start)); 
148+             //var newEnd = newWorkplan.Connectors.First(x => x.Classification.Equals(NodeClassification.End)); 
149+             //var newFailed = newWorkplan.Connectors.First(x => x.Classification.Equals(NodeClassification.Failed)); 
162150
151+             var  step  =  workplan . Steps . First ( x =>  x . Inputs . Any ( y =>  y . Classification . Equals ( NodeClassification . Start ) ) ) ; 
152+             var  newStep  =  newWorkplan . Steps . First ( x =>  x . Inputs . Any ( y =>  y . Classification . Equals ( NodeClassification . Start ) ) ) ; 
163153
154+             List < IWorkplanStep >  needToCheck  =  new  List < IWorkplanStep > ( )  {  step  } ; 
155+             List < IWorkplanStep >  newNeedToCheck  =  new  List < IWorkplanStep > ( )  {  newStep  } ; 
156+ 
157+             List < IWorkplanStep >  isChecked  =  new  List < IWorkplanStep > ( ) ; 
158+ 
159+             while  ( needToCheck . Count  !=  0  &&  newNeedToCheck . Count  !=  0 ) 
160+             { 
161+                 //noteAllFollowringSteps(workplan, newWorkplan, step, newStep, needToCheck, newNeedToCheck, isChecked); 
164162
165163                bool  isSameStep  =  ( step . GetType ( )  ==  newStep . GetType ( ) ) ; 
166164                if  ( isSameStep ) 
167165                { 
168-                     needToCheck . Remove ( step ) ; 
169-                     newNeedToCheck . Remove ( newStep ) ; 
170166
171-                     check . Add ( step ) ; 
167+                     bool  sameConnections  =  noteSameFollowringSteps ( workplan ,  newWorkplan ,  step ,  newStep ,  needToCheck ,  newNeedToCheck ,  isChecked ) ; 
168+                     if  ( sameConnections ) 
169+                     { 
170+                         needToCheck . Remove ( step ) ; 
171+                         newNeedToCheck . Remove ( newStep ) ; 
172+ 
173+                         isChecked . Add ( step ) ; 
172174
173-                     if  ( needToCheck . Count  !=  0  &&  newNeedToCheck . Count  !=  0 ) 
175+                         if  ( needToCheck . Count  !=  0  &&  newNeedToCheck . Count  !=  0 ) 
176+                         { 
177+                             step  =  needToCheck [ 0 ] ; 
178+                             newStep  =  newNeedToCheck [ 0 ] ; 
179+                         } 
180+                     } 
181+                     else 
174182                    { 
175-                         step  =  needToCheck [ 0 ] ; 
176-                         newStep  =  newNeedToCheck [ 0 ] ; 
183+                         return  false ; 
177184                    } 
178185                } 
179186                else 
@@ -184,8 +191,7 @@ public override bool Equals(object obj)
184191
185192            return  true ; 
186193        } 
187-             
188-             
194+           
189195
190196    } 
191197} 
0 commit comments