1 '---------------------------------------------------------------------
2 ' This file is part of the Windows Workflow Foundation SDK Code Samples.
4 ' Copyright (C) Microsoft Corporation. All rights reserved.
6 ' This source code is intended only as a supplement to Microsoft
7 ' Development Tools and/or on-line documentation. See these other
8 ' materials for detailed information regarding Microsoft code samples.
10 ' THIS CODE AND INFORMATION ARE PROVIDED AS IS WITHOUT WARRANTY OF ANY
11 ' KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
12 ' IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
14 '---------------------------------------------------------------------
16 Imports System
.ComponentModel
17 Imports System
.ComponentModel
.Design
19 Imports System
.Workflow
.ComponentModel
20 Imports System
.Workflow
.ComponentModel
.Compiler
21 Imports System
.Workflow
.ComponentModel
.Design
22 Imports System
.Globalization
24 #Region
"IdentifierCreationService"
25 Friend NotInheritable Class IdentifierCreationService
26 Implements IIdentifierCreationService
27 Dim serviceProvider
As IServiceProvider
= Nothing
29 Friend Sub New(ByVal serviceProvider
As IServiceProvider
)
30 Me.serviceProvider
= serviceProvider
33 Sub ValidateIdentifier(ByVal activity
As Activity
, ByVal identifier
As String) Implements IIdentifierCreationService
.ValidateIdentifier
34 If identifier Is
Nothing Then
35 Throw
New ArgumentNullException("identifier")
37 If activity Is
Nothing Then
38 Throw
New ArgumentNullException("activity")
42 If (activity
.Name
.ToLower(CultureInfo
.InvariantCulture
).Equals(identifier
.ToLower(CultureInfo
.InvariantCulture
))) Then
46 Dim identifiers
As New ArrayList()
47 Dim rootActivity
As Activity
= GetRootActivity(activity
)
48 identifiers
.AddRange(GetIdentifiersInCompositeActivity(TryCast(rootActivity
, CompositeActivity
)))
50 If identifiers
.BinarySearch(identifier
.ToLower(CultureInfo
.InvariantCulture
), StringComparer
.OrdinalIgnoreCase
) >= 0 Then
51 Throw
New ArgumentException(String.Format("Duplicate Component Identifier {0}", identifier
))
55 Sub EnsureUniqueIdentifiers(ByVal parentActivity
As CompositeActivity
, ByVal childActivities
As ICollection
) Implements IIdentifierCreationService
.EnsureUniqueIdentifiers
56 If parentActivity Is
Nothing Then
57 Throw
New ArgumentNullException("parentActivity")
59 If childActivities Is
Nothing Then
60 Throw
New ArgumentNullException("childActivities")
63 Dim allActivities
As New ArrayList()
65 Dim activities
As New Queue(childActivities
)
66 While (activities
.Count
> 0)
67 Dim activity
As Activity
= CType(activities
.Dequeue(), Activity
)
68 If (TypeOf activity Is CompositeActivity
) Then
69 For Each child
As Activity
In (CType(activity
, CompositeActivity
)).Activities
70 activities
.Enqueue(child
)
74 ' If we are moving activities, we need not regenerate their identifiers
75 If (CType(activity
, IComponent
)).Site IsNot
Nothing Then
78 allActivities
.Add(activity
)
81 ' get the root activity
82 Dim rootActivity
As CompositeActivity
= TryCast(GetRootActivity(parentActivity
), CompositeActivity
)
83 Dim identifiers
As New ArrayList() ' all the identifiers in the workflow
84 identifiers
.AddRange(GetIdentifiersInCompositeActivity(rootActivity
))
86 For Each activity
As Activity
In allActivities
87 Dim finalIdentifier
As String = activity
.Name
89 ' now loop until we find a identifier that hasn't been used.
90 Dim baseIdentifier
As String = GetBaseIdentifier(activity
)
91 Dim index
As Integer = 0
94 While finalIdentifier Is
Nothing Or finalIdentifier
.Length
= 0 Or identifiers
.BinarySearch(finalIdentifier
.ToLower(CultureInfo
.InvariantCulture
), StringComparer
.OrdinalIgnoreCase
) >= 0
96 finalIdentifier
= String.Format("{0}{1}", baseIdentifier
, index
)
99 ' add new identifier to collection
100 identifiers
.Add(finalIdentifier
)
101 activity
.Name
= finalIdentifier
105 Shared
Function GetIdentifiersInCompositeActivity(ByVal compositeActivity
As CompositeActivity
) As IList
106 Dim identifiers
As New ArrayList()
107 If compositeActivity IsNot
Nothing Then
108 identifiers
.Add(compositeActivity
.Name
)
109 Dim allChildren
As IList(Of Activity
) = GetAllNestedActivities(compositeActivity
)
110 For Each activity
As Activity
In allChildren
111 identifiers
.Add(activity
.Name
)
114 Return ArrayList
.ReadOnly(identifiers
)
117 Private Shared
Function GetBaseIdentifier(ByVal activity
As Activity
) As String
118 Dim baseIdentifier
As String = activity
.GetType().Name
119 Dim b
As New StringBuilder(baseIdentifier
.Length
)
120 For i
As Integer = 0 To baseIdentifier
.Length
- 1
121 If (Char
.IsUpper(baseIdentifier(i
)) And (i
= 0 Or i
= baseIdentifier
.Length
- 1 Or Char
.IsUpper(baseIdentifier(i
+ 1)))) Then
122 b
.Append(Char
.ToLower(baseIdentifier(i
), CultureInfo
.InvariantCulture
))
124 b
.Append(baseIdentifier
.Substring(i
))
130 Shared
Function GetRootActivity(ByVal activity
As Activity
) As Activity
131 If activity Is
Nothing Then
132 Throw
New ArgumentException("activity")
135 While activity
.Parent IsNot
Nothing
136 activity
= activity
.Parent
142 Shared
Function GetAllNestedActivities(ByVal compositeActivity
As CompositeActivity
) As Activity()
143 If compositeActivity Is
Nothing Then
144 Throw
New ArgumentNullException("compositeActivity")
147 Dim nestedActivities
As New ArrayList()
148 Dim compositeActivities
As New Queue()
149 compositeActivities
.Enqueue(compositeActivity
)
150 While compositeActivities
.Count
> 0
151 Dim compositeActivity2
As CompositeActivity
= CType(compositeActivities
.Dequeue(), CompositeActivity
)
153 For Each activity
As Activity
In compositeActivity2
.Activities
154 nestedActivities
.Add(activity
)
155 If TypeOf activity Is CompositeActivity
Then
156 compositeActivities
.Enqueue(activity
)
160 For Each activity
As Activity
In compositeActivity2
.EnabledActivities
161 If Not (nestedActivities
.Contains(activity
)) Then
162 nestedActivities
.Add(activity
)
163 If TypeOf activity Is CompositeActivity
Then
164 compositeActivities
.Enqueue(activity
)
169 Return CType(nestedActivities
.ToArray(GetType(Activity
)), Activity())
175 #Region
"WorkflowCompilerOptionsService"
176 Friend Class WorkflowCompilerOptionsService
177 Implements IWorkflowCompilerOptionsService
183 #Region
"IWorkflowCompilerOptionsService Members"
184 Public ReadOnly
Property RootNamespace() As String Implements IWorkflowCompilerOptionsService
.RootNamespace
190 Public ReadOnly
Property Language() As String Implements IWorkflowCompilerOptionsService
.Language
196 Public ReadOnly
Property CheckTypes() As Boolean Implements IWorkflowCompilerOptionsService
.CheckTypes
198 Throw
New Exception("The method or operation is not implemented.")
206 #Region
"Class EventBindingService"
207 Friend Class EventBindingService
208 Implements IEventBindingService
213 Public Function CreateUniqueMethodName(ByVal component
As IComponent
, ByVal e
As EventDescriptor
) As String Implements IEventBindingService
.CreateUniqueMethodName
217 Public Function GetCompatibleMethods(ByVal e
As EventDescriptor
) As ICollection Implements IEventBindingService
.GetCompatibleMethods
218 Return New ArrayList()
221 Public Function GetEvent(ByVal propertyDescriptor
As PropertyDescriptor
) As EventDescriptor Implements IEventBindingService
.GetEvent
222 Return iif(TypeOf propertyDescriptor Is EventPropertyDescriptor
, (CType(propertyDescriptor
, EventPropertyDescriptor
)).EventDescriptor
, Nothing)
225 Public Function GetEventProperties(ByVal events
As EventDescriptorCollection
) As PropertyDescriptorCollection Implements IEventBindingService
.GetEventProperties
226 Dim descriptors() As PropertyDescriptor
= Nothing
227 Return New PropertyDescriptorCollection(descriptors
, True)
230 Public Function GetEventProperty(ByVal e
As EventDescriptor
) As PropertyDescriptor Implements IEventBindingService
.GetEventProperty
231 Return New EventPropertyDescriptor(e
)
234 Public Function ShowCode() As Boolean Implements IEventBindingService
.ShowCode
238 Public Function ShowCode(ByVal lineNumber
As Integer) As Boolean Implements IEventBindingService
.ShowCode
242 Public Function ShowCode(ByVal component
As IComponent
, ByVal e
As EventDescriptor
) As Boolean Implements IEventBindingService
.ShowCode
246 Private Class EventPropertyDescriptor
247 Inherits PropertyDescriptor
249 Dim eventDescriptorValue
As EventDescriptor
251 Public ReadOnly
Property EventDescriptor() As EventDescriptor
253 Return Me.eventDescriptorValue
258 Public Sub New(ByVal eventDescriptor
As EventDescriptor
)
259 MyBase
.New(eventDescriptor
, Nothing)
260 Me.eventDescriptorValue
= eventDescriptor
263 Public Overrides ReadOnly
Property ComponentType() As Type
265 Return Me.eventDescriptorValue
.ComponentType
269 Public Overrides ReadOnly
Property PropertyType() As Type
271 Return Me.eventDescriptorValue
.EventType
275 Public Overrides ReadOnly
Property IsReadOnly() As Boolean
281 Public Overrides
Function CanResetValue(ByVal Component
As Object) As Boolean
285 Public Overrides
Function GetValue(ByVal component
As Object) As Object
289 Public Overrides
Sub ResetValue(ByVal component
As Object)
292 Public Overrides
Sub SetValue(ByVal component
As Object, ByVal value
As Object)
295 Public Overrides
Function ShouldSerializeValue(ByVal component
As Object) As Boolean