1 namespace System.Workflow.Activities
2 {
3     using System;
4     using System.Text;
5     using System.Reflection;
6     using System.Collections;
7     using System.CodeDom;
8     using System.ComponentModel;
9     using System.ComponentModel.Design;
10     using System.Drawing;
11     using System.Drawing.Drawing2D;
12     using System.Workflow.ComponentModel;
13     using System.Workflow.ComponentModel.Design;
14     using System.Workflow.ComponentModel.Compiler;
15     using System.Workflow.Activities.Common;
16 
17     #region Class HandleExternalEventActivityDesigner
18     [ActivityDesignerTheme(typeof(EventSinkDesignerTheme))]
19     internal class HandleExternalEventActivityDesigner : ActivityDesigner
20     {
PreFilterProperties(IDictionary properties)21         protected override void PreFilterProperties(IDictionary properties)
22         {
23             base.PreFilterProperties(properties);
24 
25             object corrRefProperty = properties["CorrelationToken"];
26 
27             HandleExternalEventActivity eventSink = Activity as HandleExternalEventActivity;
28 
29             AddRemoveCorrelationToken(eventSink.InterfaceType, properties, corrRefProperty);
30 
31             Type type = eventSink.InterfaceType;
32             if (type == null)
33                 return;
34 
35             AddRemoveCorrelationToken(type, properties, corrRefProperty);
36 
37             eventSink.GetParameterPropertyDescriptors(properties);
38         }
39 
AddRemoveCorrelationToken(Type interfaceType, IDictionary properties, object corrRefProperty)40         private void AddRemoveCorrelationToken(Type interfaceType, IDictionary properties, object corrRefProperty)
41         {
42             if (interfaceType != null)
43             {
44                 object[] corrProvAttribs = interfaceType.GetCustomAttributes(typeof(CorrelationProviderAttribute), false);
45                 object[] corrParamAttribs = interfaceType.GetCustomAttributes(typeof(CorrelationParameterAttribute), false);
46                 if (corrProvAttribs.Length != 0 || corrParamAttribs.Length != 0)
47                 {
48                     if (!properties.Contains("CorrelationToken"))
49                         properties.Add("CorrelationToken", corrRefProperty);
50                     return;
51                 }
52             }
53             if (properties.Contains("CorrelationToken"))
54                 properties.Remove("CorrelationToken");
55         }
56 
OnActivityChanged(ActivityChangedEventArgs e)57         protected override void OnActivityChanged(ActivityChangedEventArgs e)
58         {
59             base.OnActivityChanged(e);
60 
61             if (e.Member != null)
62             {
63                 if (e.Member.Name == "InterfaceType")
64                 {
65                     if (Activity.Site != null)
66                     {
67                         Type interfaceType = e.NewValue as Type;
68                         if (interfaceType != null)
69                             new ExternalDataExchangeInterfaceTypeFilterProvider(Activity.Site).CanFilterType(interfaceType, true);
70 
71                         HandleExternalEventActivity eventSinkActivity = e.Activity as HandleExternalEventActivity;
72                         PropertyDescriptorUtils.SetPropertyValue(Activity.Site, TypeDescriptor.GetProperties(Activity)["EventName"], Activity, String.Empty);
73 
74                         IExtendedUIService extUIService = (IExtendedUIService)Activity.Site.GetService(typeof(IExtendedUIService));
75                         if (extUIService == null)
76                             throw new Exception(SR.GetString(SR.General_MissingService, typeof(IExtendedUIService).FullName));
77                     }
78                 }
79                 else if ((e.Member.Name == "EventName")
80                     && e.Activity is HandleExternalEventActivity)
81                 {
82                     (e.Activity as HandleExternalEventActivity).ParameterBindings.Clear();
83                 }
84 
85                 if (e.Member.Name == "InterfaceType" || e.Member.Name == "EventName" || e.Member.Name == "CorrelationToken")
86                     TypeDescriptor.Refresh(e.Activity);
87             }
88         }
89     }
90     #endregion
91 
92     #region EventSinkDesignerTheme
93     internal sealed class EventSinkDesignerTheme : ActivityDesignerTheme
94     {
EventSinkDesignerTheme(WorkflowTheme theme)95         public EventSinkDesignerTheme(WorkflowTheme theme)
96             : base(theme)
97         {
98             this.ForeColor = Color.FromArgb(0xFF, 0x00, 0x00, 0x00);
99             this.BorderColor = Color.FromArgb(0xFF, 0x9C, 0xAE, 0x73);
100             this.BorderStyle = DashStyle.Solid;
101             this.BackColorStart = Color.FromArgb(0xFF, 0xF5, 0xFB, 0xE1);
102             this.BackColorEnd = Color.FromArgb(0xFF, 0xD6, 0xEB, 0x84);
103             this.BackgroundStyle = LinearGradientMode.Horizontal;
104         }
105     }
106     #endregion
107 }
108