1 namespace System.Workflow.Activities
2 {
3     using System;
4     using System.Text;
5     using System.Reflection;
6     using System.Collections;
7     using System.Collections.Generic;
8     using System.Collections.ObjectModel;
9     using System.CodeDom;
10     using System.ComponentModel;
11     using System.ComponentModel.Design;
12     using System.Drawing.Design;
13     using System.Drawing;
14     using System.Drawing.Drawing2D;
15     using System.Diagnostics;
16     using System.IO;
17     using System.Windows.Forms;
18     using System.Workflow.ComponentModel;
19     using System.Workflow.ComponentModel.Design;
20     using System.Runtime.Serialization;
21 
22 
23     internal partial class StateDesigner : FreeformActivityDesigner
24     {
25         #region ContainedDesignersParser class
26         /// <summary>
27         /// Helper class to sort the contained designers
28         /// </summary>
29         private class ContainedDesignersParser
30         {
31             List<StateInitializationDesigner> _stateInitializationDesigners = new List<StateInitializationDesigner>();
32             List<StateFinalizationDesigner> _stateFinalizationDesigners = new List<StateFinalizationDesigner>();
33             List<EventDrivenDesigner> _eventDrivenDesigners = new List<EventDrivenDesigner>();
34             List<StateDesigner> _leafStateDesigners = new List<StateDesigner>();
35             List<StateDesigner> _stateDesigners = new List<StateDesigner>();
36             List<ActivityDesigner> _ordered;
ContainedDesignersParser(ReadOnlyCollection<ActivityDesigner> containedDesigners)37             internal ContainedDesignersParser(ReadOnlyCollection<ActivityDesigner> containedDesigners)
38             {
39                 foreach (ActivityDesigner designer in containedDesigners)
40                 {
41                     StateInitializationDesigner stateInitializationDesigner = designer as StateInitializationDesigner;
42                     if (stateInitializationDesigner != null)
43                     {
44                         _stateInitializationDesigners.Add(stateInitializationDesigner);
45                         continue;
46                     }
47                     StateFinalizationDesigner stateFinalizationDesigner = designer as StateFinalizationDesigner;
48                     if (stateFinalizationDesigner != null)
49                     {
50                         _stateFinalizationDesigners.Add(stateFinalizationDesigner);
51                         continue;
52                     }
53                     EventDrivenDesigner eventDrivenDesigner = designer as EventDrivenDesigner;
54                     if (eventDrivenDesigner != null)
55                     {
56                         _eventDrivenDesigners.Add(eventDrivenDesigner);
57                         continue;
58                     }
59 
60                     StateDesigner stateDesigner = designer as StateDesigner;
61                     if (stateDesigner != null)
62                     {
63                         if (StateMachineHelpers.IsLeafState((StateActivity)designer.Activity))
64                             _leafStateDesigners.Add(stateDesigner);
65                         else
66                             _stateDesigners.Add(stateDesigner);
67 
68                         continue;
69                     }
70                 }
71             }
72 
73             public List<ActivityDesigner> Ordered
74             {
75                 get
76                 {
77                     if (_ordered == null)
78                     {
79                         _ordered = new List<ActivityDesigner>();
80                         _ordered.AddRange(_stateInitializationDesigners.ToArray());
81                         _ordered.AddRange(_eventDrivenDesigners.ToArray());
82                         _ordered.AddRange(_stateFinalizationDesigners.ToArray());
83                         _ordered.AddRange(_leafStateDesigners.ToArray());
84                         _ordered.AddRange(_stateDesigners.ToArray());
85                     }
86                     return _ordered;
87                 }
88             }
89 
90             public List<StateInitializationDesigner> StateInitializationDesigners
91             {
92                 get
93                 {
94                     return _stateInitializationDesigners;
95                 }
96             }
97 
98             public List<StateFinalizationDesigner> StateFinalizationDesigners
99             {
100                 get
101                 {
102                     return _stateFinalizationDesigners;
103                 }
104             }
105 
106             public List<EventDrivenDesigner> EventDrivenDesigners
107             {
108                 get
109                 {
110                     return _eventDrivenDesigners;
111                 }
112             }
113 
114             public List<StateDesigner> LeafStateDesigners
115             {
116                 get
117                 {
118                     return _leafStateDesigners;
119                 }
120             }
121 
122             public List<StateDesigner> StateDesigners
123             {
124                 get
125                 {
126                     return _stateDesigners;
127                 }
128             }
129         }
130         #endregion
131     }
132 }
133