1 //----------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation. All rights reserved.
3 //----------------------------------------------------------------
4 namespace System.Activities.Core.Presentation
7 using System.Activities.Presentation;
8 using System.Activities.Presentation.Metadata;
9 using System.Activities.Presentation.PropertyEditing;
10 using System.Activities.Presentation.View;
11 using System.Activities.Statements;
12 using System.ComponentModel;
15 using System.Windows.Threading;
17 partial class InteropDesigner
19 private static Func<Type, bool> filter;
20 private static string interopTypeAssemblyQualifiedName = null;
22 public InteropDesigner()
24 this.InitializeComponent();
27 public static Func<Type, bool> Filter
31 if (InteropDesigner.filter == null)
33 // We will build type name for System.Workflow.ComponentModel.Activity
34 string typeName = typeof(Activity).AssemblyQualifiedName;
35 typeName = typeName.Replace("System.Activities", "System.Workflow.ComponentModel");
37 Type activityType = GetTypeByQualifiedName(typeName);
38 if (activityType != null)
40 //Interop.Body has to be a 3.5 Activity
41 InteropDesigner.filter = (type) => activityType.IsAssignableFrom(type);
45 return InteropDesigner.filter;
49 public static string InteropTypeAssemblyQualifiedName
53 if (interopTypeAssemblyQualifiedName == null)
55 // Construct the type name dynamically to avoid hardcoding the version number and public key token.
56 // The constructed type name should look like: "System.Activities.Statements.Interop, System.Workflow.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
57 interopTypeAssemblyQualifiedName = typeof(Parallel).AssemblyQualifiedName.Replace("Parallel", "Interop").Replace("System.Activities,", "System.Workflow.Runtime,");
60 return interopTypeAssemblyQualifiedName;
64 protected override void OnModelItemChanged(object newItem)
66 base.OnModelItemChanged(newItem);
67 this.ModelItem.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(OnModelItemPropertyChanged);
70 private void OnModelItemPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
72 if (e.PropertyName == "ActivityType")
74 //Whenever ActivityType property changes, the activity will generate a new set of
75 // dynamic properties. the property browser will not pick up the changes till
76 // we select some other modelitem and then select this back.
77 // modelItem.root is theone that will be always available.
79 this.Dispatcher.BeginInvoke(DispatcherPriority.SystemIdle, (Action)(() =>
81 Selection.SelectOnly(this.Context, this.ModelItem.Root);
83 this.Dispatcher.BeginInvoke(DispatcherPriority.SystemIdle, (Action)(() =>
85 Selection.SelectOnly(this.Context, this.ModelItem);
91 public static void RegisterMetadata(AttributeTableBuilder builder)
93 Type activityType = GetTypeByQualifiedName(InteropDesigner.InteropTypeAssemblyQualifiedName);
95 //activityType will be null in ClientSKU since System.Workflow.Runtime.dll is not a part of clientSKU.
96 if (activityType != null)
98 builder.AddCustomAttributes(activityType, new DesignerAttribute(typeof(InteropDesigner)));
99 builder.AddCustomAttributes(
102 new EditorOptionAttribute { Name = TypePropertyEditor.BrowseTypeDirectly, Value = true });
103 builder.AddCustomAttributes(
106 new EditorOptionAttribute { Name = TypePropertyEditor.Filter, Value = Filter });
107 builder.AddCustomAttributes(
110 new RefreshPropertiesAttribute(RefreshProperties.All));
111 builder.AddCustomAttributes(activityType, new ActivityDesignerOptionsAttribute { AllowDrillIn = false });
115 // Gets a System.Type object using the type's assembly qualified name.
116 // Non-fatal exceptions are ----ed.
117 private static Type GetTypeByQualifiedName(string assemblyQualifiedName)
119 Fx.Assert(assemblyQualifiedName != null, "assemblyQualifiedName cannot be null.");
123 Type type = Type.GetType(assemblyQualifiedName);