Exemple #1
0
        internal static void ConvertToTextExpressionImports(VisualBasicSettings settings, out IList <string> importedNamespace, out IList <AssemblyReference> references)
        {
            importedNamespace = new Collection <string>();
            List <string> assemblyNames = new List <string>();

            foreach (VisualBasicImportReference visualbasicImport in settings.ImportReferences)
            {
                if (!BlackListedAssemblies.Contains(visualbasicImport.Assembly))
                {
                    if (importedNamespace.IndexOf(visualbasicImport.Import) == -1)
                    {
                        importedNamespace.Add(visualbasicImport.Import);
                    }

                    string displayName = visualbasicImport.Assembly.Split(',')[0];
                    if (assemblyNames.IndexOf(displayName) == -1)
                    {
                        assemblyNames.Add(displayName);
                    }
                }
            }

            references = new Collection <AssemblyReference>();
            foreach (string assemblyName in assemblyNames)
            {
                AssemblyReference reference = new AssemblyReference
                {
                    AssemblyName = new AssemblyName(assemblyName)
                };

                references.Add(reference);
            }
        }
        internal static void ConvertToTextExpressionImports(VisualBasicSettings settings, out IList<string> importedNamespace, out IList<AssemblyReference> references)
        {
            importedNamespace = new Collection<string>();
            List<string> assemblyNames = new List<string>();
            foreach (VisualBasicImportReference visualbasicImport in settings.ImportReferences)
            {
                if (!BlackListedAssemblies.Contains(visualbasicImport.Assembly))
                {
                    if (importedNamespace.IndexOf(visualbasicImport.Import) == -1)
                    {
                        importedNamespace.Add(visualbasicImport.Import);
                    }

                    string displayName = visualbasicImport.Assembly.Split(',')[0];
                    if (assemblyNames.IndexOf(displayName) == -1)
                    {
                        assemblyNames.Add(displayName);
                    }
                }
            }

            references = new Collection<AssemblyReference>();
            foreach (string assemblyName in assemblyNames)
            {
                AssemblyReference reference = new AssemblyReference
                {
                    AssemblyName = new AssemblyName(assemblyName)
                };

                references.Add(reference);
            }
        }
Exemple #3
0
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            string sourceString = value as string;

            if (sourceString != null)
            {
                if (sourceString.Equals(VisualBasicSettingsValueSerializer.ImplementationVisualBasicSettingsValue))
                {
                    // this is the VBSettings for the internal implementation
                    // suppress its Xaml serialization
                    VisualBasicSettings settings = CollectXmlNamespacesAndAssemblies(context);
                    if (settings != null)
                    {
                        settings.SuppressXamlSerialization = true;
                    }
                    return(settings);
                }

                if (!(sourceString.Equals(String.Empty) || sourceString.Equals(VisualBasicSettingsValueSerializer.VisualBasicSettingsValue)))
                {
                    throw FxTrace.Exception.AsError(new InvalidOperationException(SR.InvalidVisualBasicSettingsValue));
                }

                return(CollectXmlNamespacesAndAssemblies(context));
            }
            return(base.ConvertFrom(context, culture, value));
        }
        /// <summary>
        /// The add imports.
        /// </summary>
        /// <param name="activity">
        /// The activity.
        /// </param>
        /// <returns>
        /// </returns>
        internal static Activity AddImports(Activity activity)
        {
            var settings = new VisualBasicSettings();

            settings.ImportReferences.Add(
                new VisualBasicImportReference
            {
                Assembly = "Microsoft.ApplicationServer.Http", Import = "Microsoft.ApplicationServer.Http"
            });
            settings.ImportReferences.Add(
                new VisualBasicImportReference
            {
                Assembly = "Microsoft.ApplicationServer.Http",
                Import   = "Microsoft.ApplicationServer.Http.Dispatcher"
            });
            settings.ImportReferences.Add(
                new VisualBasicImportReference {
                Assembly = "System", Import = "System.Net"
            });
            settings.ImportReferences.Add(
                new VisualBasicImportReference {
                Assembly = "Microsoft.Net.Http", Import = "System.Net.Http"
            });
            VisualBasic.SetSettings(activity, settings);
            return(activity);
        }
        public static Activity RecompileVisualBasicReference(ActivityWithResult visualBasicReference,
            out Type returnType,
            out SourceExpressionException compileError,
            out VisualBasicSettings vbSettings)
        {
            ITextExpression textExpression = visualBasicReference as ITextExpression;
            if (textExpression == null || textExpression.Language != VisualBasicHelper.Language)
            {
                // the argument must be of type VisualBasicReference<>
                throw FxTrace.Exception.AsError(new ArgumentException());
            }
            string expressionText = textExpression.ExpressionText;
            LocationReferenceEnvironment environment = visualBasicReference.GetParentEnvironment();

            IList<string> namespaces;
            IList<string> referencedAssemblies;
            GetAllImportReferences(visualBasicReference, out namespaces, out referencedAssemblies);

            return CreatePrecompiledVisualBasicReference(
                null,
                expressionText,
                namespaces,
                referencedAssemblies,
                environment,
                out returnType,
                out compileError,
                out vbSettings);
        }
        public override void SetValue(object component, object value)
        {
            NamespaceList namespaceList = value as NamespaceList;

            if (namespaceList != null)
            {
                if (namespaceList is VisualBasicNamespaceList)
                {
                    VisualBasicNamespaceList visualBasicNamespaces = namespaceList as VisualBasicNamespaceList;
                    VisualBasicSettings      settings = new VisualBasicSettings();
                    settings.ImportReferences.UnionWith(visualBasicNamespaces.VisualBasicImports);
                    NamespaceHelper.SetVisualBasicSettings(component, settings);
                }
                else
                {
                    Fx.Assert(namespaceList is TextExpressionNamespaceList, "The namespace list must be either of VisualBaiscSettings or TextExpression attached properties.");
                    TextExpressionNamespaceList textExpressionNamespace = namespaceList as TextExpressionNamespaceList;
                    NamespaceHelper.SetTextExpressionNamespaces(
                        component,
                        textExpressionNamespace.TextExpressionNamespaces,
                        textExpressionNamespace.TextExpressionReferences);
                }
            }
            else
            {
                this.ResetValue(component);
            }
        }
        static void InvokeActivity(string serializedActivity)
        {
            var stringReader = new StringReader(serializedActivity);
            var xamlXmlReader = new XamlXmlReader(stringReader, new XamlXmlReaderSettings
                {
                    LocalAssembly = Assembly.GetExecutingAssembly()
                });
            var xamlReader = ActivityXamlServices.CreateReader(xamlXmlReader);
            var activity = ActivityXamlServices.Load(xamlReader, new ActivityXamlServicesSettings
                {
                    CompileExpressions = true
                });

            var settings = new VisualBasicSettings();
            settings.ImportReferences.Add(new VisualBasicImportReference
                {
                    Assembly = typeof (HttpClient).Assembly.GetName().Name,
                    Import = typeof (HttpClient).Namespace
                });
            VisualBasic.SetSettings(activity, settings);

            WorkflowInvoker.Invoke(activity, new Dictionary<string, object>
                {
                    {"HttpClient", new HttpClient()}
                });
        }
Exemple #8
0
 public static void SetSettingsForImplementation(object target, VisualBasicSettings value)
 {
     if (value != null)
     {
         value.SuppressXamlSerialization = true;
     }
     SetSettings(target, value);
 }
Exemple #9
0
        private static void ConvertNamespaces(object root, EditingContext context)
        {
            VisualBasicSettings       settings = VisualBasic.GetSettings(root);
            IList <AssemblyReference> references;
            IList <string>            importedNamespaces = NamespaceHelper.GetTextExpressionNamespaces(root, out references);
            FrameworkName             targetFramework    = WorkflowDesigner.GetTargetFramework(context);

            if (targetFramework.IsLessThan45())
            {
                if (settings == null)
                {
                    if ((importedNamespaces != null) && (importedNamespaces.Count > 0))
                    {
                        NamespaceHelper.ConvertToVBSettings(
                            importedNamespaces,
                            references,
                            context,
                            out settings);
                    }
                    else
                    {
                        settings = new VisualBasicSettings();
                    }

                    NamespaceHelper.SetVisualBasicSettings(root, settings);
                    NamespaceHelper.SetTextExpressionNamespaces(root, null, null);
                }

                IDebuggableWorkflowTree debuggableWorkflowTree = root as IDebuggableWorkflowTree;
                if (debuggableWorkflowTree != null)
                {
                    Activity rootActivity = debuggableWorkflowTree.GetWorkflowRoot();
                    if (rootActivity != null)
                    {
                        NamespaceHelper.SetVisualBasicSettings(rootActivity, settings);
                        NamespaceHelper.SetTextExpressionNamespaces(rootActivity, null, null);
                    }
                }
            }
            else
            {
                if ((importedNamespaces == null) || (importedNamespaces.Count == 0))
                {
                    if (settings != null)
                    {
                        NamespaceHelper.ConvertToTextExpressionImports(settings, out importedNamespaces, out references);
                        NamespaceHelper.SetTextExpressionNamespaces(root, importedNamespaces, references);
                        NamespaceHelper.SetVisualBasicSettings(root, null);
                    }
                    else
                    {
                        NamespaceHelper.SetTextExpressionNamespaces(root, new Collection <string>(), new Collection <AssemblyReference>());
                    }
                }
            }
        }
        public override string ConvertToString(object value, IValueSerializerContext context)
        {
            VisualBasicSettings settings = value as VisualBasicSettings;

            if (settings != null && settings.SuppressXamlSerialization)
            {
                return(ImplementationVisualBasicSettingsValue);
            }
            return(VisualBasicSettingsValue);
        }
Exemple #11
0
        public override string ConvertToString(object value, IValueSerializerContext context)
        {
            VisualBasicSettings settings = value as VisualBasicSettings;

            if ((settings != null) && settings.SuppressXamlSerialization)
            {
                return("Assembly references and imported namespaces for internal implementation");
            }
            return("Assembly references and imported namespaces serialized as XML namespaces");
        }
Exemple #12
0
        public override bool CanConvertToString(object value, IValueSerializerContext context)
        {
            VisualBasicSettings settings = value as VisualBasicSettings;

            if (settings != null)
            {
                settings.GenerateXamlReferences(context);
            }
            return(true);
        }
        private static void ConvertNamespaces(object root, EditingContext context)
        {
            VisualBasicSettings settings = VisualBasic.GetSettings(root);
            IList<AssemblyReference> references;
            IList<string> importedNamespaces = NamespaceHelper.GetTextExpressionNamespaces(root, out references);
            FrameworkName targetFramework = WorkflowDesigner.GetTargetFramework(context);
            if (targetFramework.IsLessThan45())
            {
                if (settings == null)
                {
                    if ((importedNamespaces != null) && (importedNamespaces.Count > 0))
                    {
                        NamespaceHelper.ConvertToVBSettings(
                            importedNamespaces,
                            references,
                            context,
                            out settings);
                    }
                    else
                    {
                        settings = new VisualBasicSettings();
                    }

                    NamespaceHelper.SetVisualBasicSettings(root, settings);
                    NamespaceHelper.SetTextExpressionNamespaces(root, null, null);
                }

                IDebuggableWorkflowTree debuggableWorkflowTree = root as IDebuggableWorkflowTree;
                if (debuggableWorkflowTree != null)
                {
                    Activity rootActivity = debuggableWorkflowTree.GetWorkflowRoot();
                    if (rootActivity != null)
                    {
                        NamespaceHelper.SetVisualBasicSettings(rootActivity, settings);
                        NamespaceHelper.SetTextExpressionNamespaces(rootActivity, null, null);
                    }                 
                }
            }
            else
            {
                if ((importedNamespaces == null) || (importedNamespaces.Count == 0))
                {
                    if (settings != null)
                    {
                        NamespaceHelper.ConvertToTextExpressionImports(settings, out importedNamespaces, out references);
                        NamespaceHelper.SetTextExpressionNamespaces(root, importedNamespaces, references);
                        NamespaceHelper.SetVisualBasicSettings(root, null);
                    }
                    else
                    {
                        NamespaceHelper.SetTextExpressionNamespaces(root, new Collection<string>(), new Collection<AssemblyReference>());
                    }
                }
            }
        }
Exemple #14
0
 internal static void SetVisualBasicSettings(object root, VisualBasicSettings settings)
 {
     if (NamespaceHelper.ShouldUsePropertiesForImplementation(root))
     {
         VisualBasic.SetSettingsForImplementation(root, settings);
     }
     else
     {
         VisualBasic.SetSettings(root, settings);
     }
 }
 internal static void SetVisualBasicSettings(object root, VisualBasicSettings settings)
 {
     if (NamespaceHelper.ShouldUsePropertiesForImplementation(root))
     {
         VisualBasic.SetSettingsForImplementation(root, settings);                
     }
     else
     {
         VisualBasic.SetSettings(root, settings);
     }
 }
        public override object GetValue(object component)
        {
            VisualBasicSettings       settings = VisualBasic.GetSettings(component);
            IList <AssemblyReference> references;
            IList <string>            namespaces = NamespaceHelper.GetTextExpressionNamespaces(component, out references);

            if ((namespaces != null) && ((namespaces.Count > 0) || ((namespaces.Count == 0) && (settings == null))))
            {
                return(new TextExpressionNamespaceList(namespaces, references));
            }
            else
            {
                Fx.Assert(settings != null, "Either VB settings or new TextExpression attached properties should be set");
                return(new VisualBasicNamespaceList(settings.ImportReferences));
            }
        }
Exemple #17
0
        /// <summary>
        /// Adds a setting to the activity provided which ensures visual basic-style declarations are interpreted correctly
        /// </summary>
        internal static void AddVbSetting(Activity activity)
        {
            var settings = new VisualBasicSettings
            {
                ImportReferences =
                {
                    new VisualBasicImportReference
                    {
                        Assembly = typeof(Person).Assembly.GetName().Name,
                        Import   = typeof(Person).Namespace
                    }
                }
            };

            VisualBasic.SetSettings(activity, settings);
        }
Exemple #18
0
        static DynamicActivity GetDynamicActivity(ActivityBuilder activityDefinition)
        {
            DynamicActivity result = new DynamicActivity
            {
                Name = activityDefinition.Name
            };

            foreach (DynamicActivityProperty property in activityDefinition.Properties)
            {
                result.Properties.Add(property);
            }
            foreach (Attribute attrib in activityDefinition.Attributes)
            {
                result.Attributes.Add(attrib);
            }
            foreach (Constraint constraint in activityDefinition.Constraints)
            {
                result.Constraints.Add(constraint);
            }
            result.Implementation = () => activityDefinition.Implementation;

            VisualBasicSettings vbsettings = VisualBasic.GetSettings(activityDefinition);

            if (vbsettings != null)
            {
                VisualBasic.SetSettings(result, vbsettings);
            }

            IList <string> namespacesForImplementation = TextExpression.GetNamespacesForImplementation(activityDefinition);

            if (namespacesForImplementation.Count > 0)
            {
                TextExpression.SetNamespacesForImplementation(result, namespacesForImplementation);
            }

            IList <AssemblyReference> referencesForImplementation = TextExpression.GetReferencesForImplementation(activityDefinition);

            if (referencesForImplementation.Count > 0)
            {
                TextExpression.SetReferencesForImplementation(result, referencesForImplementation);
            }

            return(result);
        }
        /// <summary>
        /// Get Visual Basic settings containing importings of assemblies and namespaces.
        /// </summary>
        public VisualBasicSettings GetVisualBasicSettings()
        {
            VisualBasicSettings vbs = new VisualBasicSettings();

            foreach (var arg in Arguments.Keys)
            {
                Type importType = arg.ArgumentType;
                if (importType == null)
                {
                    continue;
                }

                while (importType != null && importType != typeof(object))
                {
                    string ns = importType.Namespace;
                    if (vbs.ImportReferences.Count((i) => i.Import.Equals(ns)) == 0)
                    {
                        VisualBasicImportReference theReference = new VisualBasicImportReference
                        {
                            Assembly = importType.Assembly.FullName,
                            Import   = ns
                        };
                        vbs.ImportReferences.Add(theReference);
                    }
                    importType = importType.BaseType;
                }

                foreach (Type interfaceType in arg.ArgumentType.GetInterfaces())
                {
                    string interfaceNs = interfaceType.Namespace;
                    if (vbs.ImportReferences.Count((i) => i.Import.Equals(interfaceNs)) == 0)
                    {
                        VisualBasicImportReference interfaceReference = new VisualBasicImportReference
                        {
                            Assembly = interfaceType.Assembly.FullName,
                            Import   = interfaceNs
                        };
                        vbs.ImportReferences.Add(interfaceReference);
                    }
                }
            }
            return(vbs);
        }
Exemple #20
0
 /// <summary>
 /// The add imports.
 /// </summary>
 /// <param name="activity">
 /// The activity.
 /// </param>
 /// <returns>
 /// </returns>
 internal static Activity AddImports(Activity activity)
 {
     var settings = new VisualBasicSettings();
     settings.ImportReferences.Add(
         new VisualBasicImportReference
             {
                Assembly = "Microsoft.ApplicationServer.Http", Import = "Microsoft.ApplicationServer.Http"
             });
     settings.ImportReferences.Add(
         new VisualBasicImportReference
             {
                 Assembly = "Microsoft.ApplicationServer.Http",
                 Import = "Microsoft.ApplicationServer.Http.Dispatcher"
             });
     settings.ImportReferences.Add(
         new VisualBasicImportReference { Assembly = "System", Import = "System.Net" });
     settings.ImportReferences.Add(
         new VisualBasicImportReference { Assembly = "Microsoft.Net.Http", Import = "System.Net.Http" });
     VisualBasic.SetSettings(activity, settings);
     return activity;
 }
Exemple #21
0
        static void OnRootPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            ModelItem rootModel = sender as ModelItem;

            Fx.Assert(rootModel != null, "sender item could not be null");
            ModelProperty changedProperty = rootModel.Properties[e.PropertyName];

            if (changedProperty == null)
            {
                return;
            }

            object changedPropertyValue = changedProperty.ComputedValue;

            if (changedPropertyValue == null)
            {
                return;
            }

            Fx.Assert(rootModel.GetCurrentValue().GetType() == WorkflowServiceType, "This handler should only be attached when the root is WorkflowService");
            IDebuggableWorkflowTree root = rootModel.GetCurrentValue() as IDebuggableWorkflowTree;
            Activity rootActivity        = root.GetWorkflowRoot();

            if (rootActivity == changedPropertyValue)
            {
                if (WorkflowDesigner.GetTargetFramework(rootModel.GetEditingContext()).IsLessThan45())
                {
                    VisualBasicSettings settings = VisualBasic.GetSettings(root);
                    NamespaceHelper.SetVisualBasicSettings(changedPropertyValue, settings);
                }
                else
                {
                    IList <AssemblyReference> referencedAssemblies;
                    IList <string>            namespaces = NamespaceHelper.GetTextExpressionNamespaces(root, out referencedAssemblies);
                    NamespaceHelper.SetTextExpressionNamespaces(rootActivity, namespaces, referencedAssemblies);
                }
            }
        }
Exemple #22
0
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            string str = value as string;

            if (str == null)
            {
                return(base.ConvertFrom(context, culture, value));
            }
            if (str.Equals("Assembly references and imported namespaces for internal implementation"))
            {
                VisualBasicSettings settings = this.CollectXmlNamespacesAndAssemblies(context);
                if (settings != null)
                {
                    settings.SuppressXamlSerialization = true;
                }
                return(settings);
            }
            if (!str.Equals(string.Empty) && !str.Equals("Assembly references and imported namespaces serialized as XML namespaces"))
            {
                throw FxTrace.Exception.AsError(new InvalidOperationException(System.Activities.SR.InvalidVisualBasicSettingsValue));
            }
            return(this.CollectXmlNamespacesAndAssemblies(context));
        }
        private void AddDynamicAssembly(Assembly asm)
        {
            AssemblyContextControlItem acci = (AssemblyContextControlItem)(_WorkflowDesigner.Context.Items.GetValue(typeof(AssemblyContextControlItem)));
            var root     = GetRootElement();
            var fullname = asm.FullName;

            if (null == root)
            {
                return;
            }
            VisualBasicSettings vbs = VisualBasic.GetSettings(root) ?? new VisualBasicSettings();

            var namespaces = (from type in asm.GetTypes() select type.Namespace).Distinct();

            foreach (var name in namespaces)
            {
                var import = new VisualBasicImportReference()
                {
                    Assembly = fullname, Import = name
                };
                vbs.ImportReferences.Add(import);
            }
            VisualBasic.SetSettings(root, vbs);
        }
Exemple #24
0
        public Activity RecompileReference(ActivityWithResult lValue, out Type returnType, out SourceExpressionException compileError, out VisualBasicSettings vbSettings)
        {
            ITextExpression textExpression = lValue as ITextExpression;

            if (textExpression == null || textExpression.Language != Language)
            {
                throw FxTrace.Exception.AsError(new ArgumentException());
            }
            string expressionText = textExpression.ExpressionText;
            LocationReferenceEnvironment environment = lValue.GetParentEnvironment();

            List <string> namespaces;
            List <string> referencedAssemblies;

            GetAllImportReferences(lValue, out namespaces, out referencedAssemblies);

            return(CreatePrecompiledReference(
                       null,
                       expressionText,
                       namespaces,
                       referencedAssemblies,
                       environment,
                       out returnType,
                       out compileError,
                       out vbSettings));
        }
Exemple #25
0
        public static VisualBasicSettings CollectXmlNamespacesAndAssemblies(ITypeDescriptorContext context)
        {
            // access XamlSchemaContext.ReferenceAssemblies
            // for the Compiled Xaml scenario
            IList <Assembly>           xsCtxReferenceAssemblies  = null;
            IXamlSchemaContextProvider xamlSchemaContextProvider = context.GetService(typeof(IXamlSchemaContextProvider)) as IXamlSchemaContextProvider;

            if (xamlSchemaContextProvider != null && xamlSchemaContextProvider.SchemaContext != null)
            {
                xsCtxReferenceAssemblies = xamlSchemaContextProvider.SchemaContext.ReferenceAssemblies;
                if (xsCtxReferenceAssemblies != null && xsCtxReferenceAssemblies.Count == 0)
                {
                    xsCtxReferenceAssemblies = null;
                }
            }

            VisualBasicSettings    settings          = null;
            IXamlNamespaceResolver namespaceResolver = (IXamlNamespaceResolver)context.GetService(typeof(IXamlNamespaceResolver));

            if (namespaceResolver == null)
            {
                return(null);
            }

            lock (AssemblyCache.XmlnsMappingsLockObject)
            {
                // Fetch xmlnsMappings for the prefixes returned by the namespaceResolver service

                foreach (NamespaceDeclaration prefix in namespaceResolver.GetNamespacePrefixes())
                {
                    ReadOnlyXmlnsMapping mapping;
                    WrapCachedMapping(prefix, out mapping);
                    if (!mapping.IsEmpty)
                    {
                        if (settings == null)
                        {
                            settings = new VisualBasicSettings();
                        }

                        if (!mapping.IsEmpty)
                        {
                            foreach (ReadOnlyVisualBasicImportReference importReference in mapping.ImportReferences)
                            {
                                if (xsCtxReferenceAssemblies != null)
                                {
                                    // this is "compiled Xaml"
                                    VisualBasicImportReference newImportReference;

                                    if (importReference.EarlyBoundAssembly != null)
                                    {
                                        if (xsCtxReferenceAssemblies.Contains(importReference.EarlyBoundAssembly))
                                        {
                                            newImportReference = importReference.Clone();
                                            newImportReference.EarlyBoundAssembly = importReference.EarlyBoundAssembly;
                                            settings.ImportReferences.Add(newImportReference);
                                        }
                                        continue;
                                    }

                                    for (int i = 0; i < xsCtxReferenceAssemblies.Count; i++)
                                    {
                                        AssemblyName xsCtxAssemblyName = VisualBasicHelper.GetFastAssemblyName(xsCtxReferenceAssemblies[i]);
                                        if (importReference.AssemblySatisfiesReference(xsCtxAssemblyName))
                                        {
                                            // bind this assembly early to the importReference
                                            // so later AssemblyName resolution can be skipped
                                            newImportReference = importReference.Clone();
                                            newImportReference.EarlyBoundAssembly = xsCtxReferenceAssemblies[i];
                                            settings.ImportReferences.Add(newImportReference);
                                            break;
                                        }
                                    }
                                }
                                else
                                {
                                    // this is "loose Xaml"
                                    VisualBasicImportReference newImportReference = importReference.Clone();
                                    if (importReference.EarlyBoundAssembly != null)
                                    {
                                        // VBImportReference.Clone() method deliberately doesn't copy
                                        // its EarlyBoundAssembly to the cloned instance.
                                        // we need to explicitly copy the original's EarlyBoundAssembly
                                        newImportReference.EarlyBoundAssembly = importReference.EarlyBoundAssembly;
                                    }
                                    settings.ImportReferences.Add(newImportReference);
                                }
                            }
                        }
                    }
                }
            }
            return(settings);
        }
 public static Activity CreatePrecompiledReference(Type targetType, string expressionText, IEnumerable <string> namespaces, IEnumerable <string> referencedAssemblies,
                                                   LocationReferenceEnvironment environment, out Type returnType, out SourceExpressionException compileError, out VisualBasicSettings vbSettings) =>
 Impl.CreatePrecompiledReference(targetType, expressionText, namespaces, referencedAssemblies, environment, out returnType, out compileError, out vbSettings);
 public static Activity RecompileReference(ActivityWithResult lValue, out Type returnType, out SourceExpressionException compileError, out VisualBasicSettings vbSettings) =>
 Impl.RecompileReference(lValue, out returnType, out compileError, out vbSettings);
Exemple #28
0
 public static void SetSettings(object target, VisualBasicSettings value)
 {
     AttachablePropertyServices.SetProperty(target, settingsPropertyID, value);
 }
Exemple #29
0
        internal static void ConvertToVBSettings(IList <string> importedNamespaces, IList <AssemblyReference> references, EditingContext context, out VisualBasicSettings settings)
        {
            Dictionary <string, List <string> > visualBasicImports = new Dictionary <string, List <string> >();

            foreach (string importedNamespace in importedNamespaces)
            {
                visualBasicImports.Add(importedNamespace, new List <string>());
            }

            Collection <Assembly>         assemblies            = new Collection <Assembly>();
            IMultiTargetingSupportService multiTargetingService = context.Services.GetService <IMultiTargetingSupportService>();

            foreach (AssemblyReference reference in references)
            {
                Assembly assembly;
                if (multiTargetingService == null)
                {
                    reference.LoadAssembly();
                    assembly = reference.Assembly;
                }
                else
                {
                    assembly = AssemblyContextControlItem.GetAssembly(reference.AssemblyName, multiTargetingService);
                }

                if (assembly != null)
                {
                    assemblies.Add(assembly);
                }
            }

            AssemblyContextControlItem assemblyContextItem = context.Items.GetValue <AssemblyContextControlItem>();
            AssemblyName localAssembly = null;

            if (assemblyContextItem != null)
            {
                localAssembly = assemblyContextItem.LocalAssemblyName;
            }

            if (localAssembly != null)
            {
                Assembly assembly = AssemblyContextControlItem.GetAssembly(localAssembly, multiTargetingService);
                if (assembly != null)
                {
                    assemblies.Add(assembly);
                }
            }

            foreach (Assembly assembly in assemblies)
            {
                foreach (Type type in assembly.GetTypes())
                {
                    string ns = type.Namespace;
                    if ((ns != null) && visualBasicImports.ContainsKey(ns))
                    {
                        string assemblyName = assembly.GetName().Name;
                        visualBasicImports[ns].Add(assemblyName);
                    }
                }
            }

            settings = new VisualBasicSettings();
            foreach (KeyValuePair <string, List <string> > entries in visualBasicImports)
            {
                string importedNamespace = entries.Key;
                foreach (string assemblyName in entries.Value)
                {
                    settings.ImportReferences.Add(new VisualBasicImportReference
                    {
                        Import   = importedNamespace,
                        Assembly = assemblyName
                    });
                }
            }
        }
Exemple #30
0
        public Activity CreatePrecompiledValue(Type targetType, string expressionText, IEnumerable <string> namespaces, IEnumerable <string> referencedAssemblies,
                                               LocationReferenceEnvironment environment, out Type returnType, out SourceExpressionException compileError, out VisualBasicSettings vbSettings)
        {
            LambdaExpression       lambda        = null;
            HashSet <string>       namespacesSet = new HashSet <string>();
            HashSet <AssemblyName> assembliesSet = new HashSet <AssemblyName>();

            compileError = null;
            returnType   = null;

            if (namespaces != null)
            {
                foreach (string ns in namespaces)
                {
                    if (ns != null)
                    {
                        namespacesSet.Add(ns);
                    }
                }
            }

            if (referencedAssemblies != null)
            {
                foreach (string assm in referencedAssemblies)
                {
                    if (assm != null)
                    {
                        assembliesSet.Add(new AssemblyName(assm));
                    }
                }
            }

            var compilerHelper = CreateJitCompilerHelper(expressionText, assembliesSet, namespacesSet);

            if (targetType == null)
            {
                try
                {
                    lambda = compilerHelper.CompileNonGeneric(environment);
                    if (lambda != null)
                    {
                        returnType = lambda.ReturnType;
                    }
                }
                catch (SourceExpressionException e)
                {
                    compileError = e;
                    returnType   = typeof(object);
                }
                targetType = returnType;
            }
            else
            {
                MethodInfo genericCompileMethod = compilerHelper.GetType().GetMethod("Compile", new Type[] { typeof(LocationReferenceEnvironment) });
                genericCompileMethod = genericCompileMethod.MakeGenericMethod(new Type[] { targetType });
                try
                {
                    lambda     = (LambdaExpression)genericCompileMethod.Invoke(compilerHelper, new object[] { environment });
                    returnType = targetType;
                }
                catch (TargetInvocationException e)
                {
                    SourceExpressionException se = e.InnerException as SourceExpressionException;
                    if (se != null)
                    {
                        compileError = se;
                        returnType   = typeof(object);
                    }
                    else
                    {
                        throw FxTrace.Exception.AsError(e.InnerException);
                    }
                }
            }

            vbSettings = new VisualBasicSettings();
            if (lambda != null)
            {
                HashSet <Type> typeReferences = new HashSet <Type>();
                FindTypeReferences(lambda.Body, typeReferences);
                foreach (Type type in typeReferences)
                {
                    Assembly tassembly = type.Assembly;
                    if (tassembly.IsDynamic)
                    {
                        continue;
                    }
                    string assemblyName = AssemblyReference.GetFastAssemblyName(tassembly).Name;
                    VisualBasicImportReference importReference = new VisualBasicImportReference {
                        Assembly = assemblyName, Import = type.Namespace
                    };
                    vbSettings.ImportReferences.Add(importReference);
                }
            }

            Type concreteHelperType             = ExpressionFactoryType.MakeGenericType(targetType);
            ExpressionFactory expressionFactory = (ExpressionFactory)Activator.CreateInstance(concreteHelperType);

            return(expressionFactory.CreateValue(expressionText));
        }
        public static VisualBasicSettings CollectXmlNamespacesAndAssemblies(ITypeDescriptorContext context)
        {
            IList <Assembly>           referenceAssemblies = null;
            IXamlSchemaContextProvider service             = context.GetService(typeof(IXamlSchemaContextProvider)) as IXamlSchemaContextProvider;

            if ((service != null) && (service.SchemaContext != null))
            {
                referenceAssemblies = service.SchemaContext.ReferenceAssemblies;
                if ((referenceAssemblies != null) && (referenceAssemblies.Count == 0))
                {
                    referenceAssemblies = null;
                }
            }
            VisualBasicSettings    settings = null;
            IXamlNamespaceResolver resolver = (IXamlNamespaceResolver)context.GetService(typeof(IXamlNamespaceResolver));

            if (resolver == null)
            {
                return(null);
            }
            lock (AssemblyCache.XmlnsMappings)
            {
                foreach (System.Xaml.NamespaceDeclaration declaration in resolver.GetNamespacePrefixes())
                {
                    XmlnsMapping mapping;
                    XNamespace   key = XNamespace.Get(declaration.Namespace);
                    if (!AssemblyCache.XmlnsMappings.TryGetValue(key, out mapping))
                    {
                        Match match = assemblyQualifiedNamespaceRegex.Match(declaration.Namespace);
                        if (match.Success)
                        {
                            mapping.ImportReferences = new System.Collections.Generic.HashSet <VisualBasicImportReference>();
                            VisualBasicImportReference item = new VisualBasicImportReference {
                                Assembly = match.Groups["assembly"].Value,
                                Import   = match.Groups["namespace"].Value,
                                Xmlns    = key
                            };
                            mapping.ImportReferences.Add(item);
                        }
                        else
                        {
                            mapping.ImportReferences = new System.Collections.Generic.HashSet <VisualBasicImportReference>();
                        }
                        AssemblyCache.XmlnsMappings[key] = mapping;
                    }
                    if (!mapping.IsEmpty)
                    {
                        if (settings == null)
                        {
                            settings = new VisualBasicSettings();
                        }
                        foreach (VisualBasicImportReference reference2 in mapping.ImportReferences)
                        {
                            if (referenceAssemblies != null)
                            {
                                VisualBasicImportReference reference3;
                                AssemblyName assemblyName = reference2.AssemblyName;
                                if (reference2.EarlyBoundAssembly != null)
                                {
                                    if (referenceAssemblies.Contains(reference2.EarlyBoundAssembly))
                                    {
                                        reference3 = reference2.Clone();
                                        reference3.EarlyBoundAssembly = reference2.EarlyBoundAssembly;
                                        settings.ImportReferences.Add(reference3);
                                    }
                                }
                                else
                                {
                                    for (int i = 0; i < referenceAssemblies.Count; i++)
                                    {
                                        if (AssemblySatisfiesReference(VisualBasicHelper.GetFastAssemblyName(referenceAssemblies[i]), assemblyName))
                                        {
                                            reference3 = reference2.Clone();
                                            reference3.EarlyBoundAssembly = referenceAssemblies[i];
                                            settings.ImportReferences.Add(reference3);
                                            break;
                                        }
                                    }
                                }
                            }
                            else
                            {
                                VisualBasicImportReference reference4 = reference2.Clone();
                                if (reference2.EarlyBoundAssembly != null)
                                {
                                    reference4.EarlyBoundAssembly = reference2.EarlyBoundAssembly;
                                }
                                settings.ImportReferences.Add(reference4);
                            }
                        }
                    }
                }
            }
            return(settings);
        }
        internal static void ConvertToVBSettings(IList<string> importedNamespaces, IList<AssemblyReference> references, EditingContext context, out VisualBasicSettings settings)
        {
            Dictionary<string, List<string>> visualBasicImports = new Dictionary<string, List<string>>();
            foreach (string importedNamespace in importedNamespaces)
            {
                visualBasicImports.Add(importedNamespace, new List<string>());
            }

            Collection<Assembly> assemblies = new Collection<Assembly>();
            IMultiTargetingSupportService multiTargetingService = context.Services.GetService<IMultiTargetingSupportService>();
            foreach (AssemblyReference reference in references)
            {
                Assembly assembly;
                if (multiTargetingService == null)
                {
                    reference.LoadAssembly();
                    assembly = reference.Assembly;
                }
                else
                {
                    assembly = AssemblyContextControlItem.GetAssembly(reference.AssemblyName, multiTargetingService);
                }

                if (assembly != null)
                {
                    assemblies.Add(assembly);
                }
            }

            AssemblyContextControlItem assemblyContextItem = context.Items.GetValue<AssemblyContextControlItem>();
            AssemblyName localAssembly = null;
            if (assemblyContextItem != null)
            {
                localAssembly = assemblyContextItem.LocalAssemblyName;
            }

            if (localAssembly != null)
            {
                Assembly assembly = AssemblyContextControlItem.GetAssembly(localAssembly, multiTargetingService);
                if (assembly != null)
                {
                    assemblies.Add(assembly);
                }
            }

            foreach (Assembly assembly in assemblies)
            {
                foreach (Type type in assembly.GetTypes())
                {
                    string ns = type.Namespace;
                    if ((ns != null) && visualBasicImports.ContainsKey(ns))
                    {
                        string assemblyName = assembly.GetName().Name;
                        visualBasicImports[ns].Add(assemblyName);
                    }
                }
            }

            settings = new VisualBasicSettings();
            foreach (KeyValuePair<string, List<string>> entries in visualBasicImports)
            {
                string importedNamespace = entries.Key;
                foreach (string assemblyName in entries.Value)
                {
                    settings.ImportReferences.Add(new VisualBasicImportReference
                    {
                        Import = importedNamespace,
                        Assembly = assemblyName
                    });
                }
            }
        }
Exemple #33
0
        /// <summary>
        /// Executes a rule with arguments and return all output arguments by a Dictionary object.
        /// </summary>
        /// <param name="rule">The rule to execute</param>
        /// <param name="arguments">Arguments for executing the rule</param>
        /// <returns>The execution result</returns>
        public IDictionary <string, object> InvokeRule(IRule rule, IDictionary <string, object> arguments)
        {
            DynamicActivity activity = rule.Activity;

            if (activity == null)
            {
                throw new ArgumentException("The rule does not have content (activity)."); // NOXLATE
            }

            RuleExecutingContext executingContext = new RuleExecutingContext(this, rule, arguments);
            VisualBasicSettings  vbs = executingContext.GetVisualBasicSettings();

            Microsoft.VisualBasic.Activities.VisualBasic.SetSettings(activity, vbs);


            _invokeDepth++;
            IDictionary <string, object> results = null;

            try
            {
                if (_invokeDepth > MaxInvokeDepth)
                {
                    throw new RuleException(rule.FullName, Properties.Resources.ExceedsMaxInvokeDepth);
                }

                OnInvokingRule(rule, arguments);

                WorkflowInvoker invoker = new WorkflowInvoker(activity);
                RuleLogger      logger  = null;
                if (this.LoggingEnabled)
                {
                    if (_invokeDepth == 1)
                    {
                        Logger.BeginLogging(rule);
                        _rootRuleLogger = logger;
                    }
                    else
                    {
                        Debug.Assert(rule is NamedRule);
                        _rootRuleLogger.OnInvokingNamedRule(rule as NamedRule);
                        logger = _rootRuleLogger;
                    }

                    invoker.Extensions.Add(logger);
                }

                // Set original input argument to execution context.
                invoker.Extensions.Add(executingContext);

                IDictionary <string, object> workflowArgs = executingContext.GetWorkflowInvokerArguments();
                results = invoker.Invoke(workflowArgs);

                if (null != logger && _invokeDepth == 1)
                {
                    this.LoggingCompleted(this, new LoggingCompletedEventArgs(logger.Log));
                }
                return(results);
            }
            catch (RuleException)
            {
                throw;
            }
            catch (InvalidWorkflowException wfex)
            {
                throw new RuleException(rule.FullName, string.Format(Properties.Resources.CommonRuleExceptionUserMessage, wfex.Message));
            }
            catch (Exception ex)
            {
                throw new RuleException(rule.FullName, ex);
            }
            finally
            {
                _invokeDepth--;

                OnInvokedRule(rule, arguments, results);
            }
        }
 public static Activity RecompileVisualBasicValue(ActivityWithResult visualBasicValue, out Type returnType, out SourceExpressionException compileError, out VisualBasicSettings vbSettings)
 {
     IVisualBasicExpression expression = visualBasicValue as IVisualBasicExpression;
     if (expression == null)
     {
         throw FxTrace.Exception.AsError(new ArgumentException());
     }
     string expressionText = expression.ExpressionText;
     LocationReferenceEnvironment parentEnvironment = visualBasicValue.GetParentEnvironment();
     HashSet<VisualBasicImportReference> allImportReferences = VisualBasicHelper.GetAllImportReferences((parentEnvironment != null) ? parentEnvironment.Root : null);
     HashSet<string> namespaces = new HashSet<string>();
     HashSet<string> referencedAssemblies = new HashSet<string>();
     foreach (VisualBasicImportReference reference in allImportReferences)
     {
         namespaces.Add(reference.Import);
         referencedAssemblies.Add(reference.Assembly);
     }
     return CreatePrecompiledVisualBasicValue(null, expressionText, namespaces, referencedAssemblies, parentEnvironment, out returnType, out compileError, out vbSettings);
 }
        public static Activity CreatePrecompiledVisualBasicReference(Type targetType, string expressionText, IEnumerable<string> namespaces, IEnumerable<string> referencedAssemblies,
            LocationReferenceEnvironment environment,
            out Type returnType,
            out SourceExpressionException compileError,
            out VisualBasicSettings vbSettings)
        {
            LambdaExpression lambda = null;
            HashSet<string> namespacesSet = new HashSet<string>();
            HashSet<AssemblyName> assembliesSet = new HashSet<AssemblyName>();
            compileError = null;
            returnType = null;

            if (namespaces != null)
            {
                foreach (string ns in namespaces)
                {
                    if (ns != null)
                    {
                        namespacesSet.Add(ns);
                    }                    
                }
            }

            if (referencedAssemblies != null)
            {
                foreach (string assm in referencedAssemblies)
                {
                    if (assm != null)
                    {
                        assembliesSet.Add(new AssemblyName(assm));
                    }                    
                }
            }
            
            VisualBasicHelper vbhelper = new VisualBasicHelper(expressionText, assembliesSet, namespacesSet);
            if (targetType == null)
            {
                try
                {
                    lambda = vbhelper.CompileNonGeneric(environment);
                    if (lambda != null)
                    {
                        // inspect the expressionTree to see if it is a valid location expression(L-value)
                        string extraErrorMessage;
                        if (!ExpressionUtilities.IsLocation(lambda, targetType, out extraErrorMessage))
                        {
                            string errorMessage = SR.InvalidLValueExpression;
                            if (extraErrorMessage != null)
                            {
                                errorMessage += ":" + extraErrorMessage;
                            }
                            throw FxTrace.Exception.AsError(
                                new SourceExpressionException(SR.CompilerErrorSpecificExpression(expressionText, errorMessage)));
                        }
                        returnType = lambda.ReturnType;
                    }
                }
                catch (SourceExpressionException e)
                {
                    compileError = e;
                    returnType = typeof(object);
                }
                targetType = returnType;
            }
            else
            {
                MethodInfo genericCompileMethod = typeof(VisualBasicHelper).GetMethod("Compile", new Type[] { typeof(LocationReferenceEnvironment) });
                genericCompileMethod = genericCompileMethod.MakeGenericMethod(new Type[] { targetType });
                try
                {
                    lambda = (LambdaExpression)genericCompileMethod.Invoke(vbhelper, new object[] { environment });
                    // inspect the expressionTree to see if it is a valid location expression(L-value)
                    string extraErrorMessage = null;
                    if (!ExpressionUtilities.IsLocation(lambda, targetType, out extraErrorMessage))
                    {
                        string errorMessage = SR.InvalidLValueExpression;
                        if (extraErrorMessage != null)
                        {
                            errorMessage += ":" + extraErrorMessage;
                        }
                        throw FxTrace.Exception.AsError(
                            new SourceExpressionException(SR.CompilerErrorSpecificExpression(expressionText, errorMessage)));
                    }
                    returnType = targetType;
                }
                catch (SourceExpressionException e)
                {
                    compileError = e;
                    returnType = typeof(object);
                }
                catch (TargetInvocationException e)
                {
                    SourceExpressionException se = e.InnerException as SourceExpressionException;
                    if (se != null)
                    {
                        compileError = se;
                        returnType = typeof(object);
                    }
                    else
                    {
                        throw FxTrace.Exception.AsError(e.InnerException);
                    }
                }
            }

            vbSettings = new VisualBasicSettings();
            if (lambda != null)
            {
                HashSet<Type> typeReferences = new HashSet<Type>();
                FindTypeReferences(lambda.Body, typeReferences);
                foreach (Type type in typeReferences)
                {
                    Assembly tassembly = type.Assembly;
                    if (tassembly.IsDynamic)
                    {
                        continue;
                    }
                    string assemblyName = VisualBasicHelper.GetFastAssemblyName(tassembly).Name;
                    VisualBasicImportReference importReference = new VisualBasicImportReference { Assembly = assemblyName, Import = type.Namespace };
                    vbSettings.ImportReferences.Add(importReference);
                }
            }

            Type concreteHelperType = VisualBasicExpressionFactoryType.MakeGenericType(targetType);
            VisualBasicExpressionFactory expressionFactory = (VisualBasicExpressionFactory)Activator.CreateInstance(concreteHelperType);

            return expressionFactory.CreateVisualBasicReference(expressionText);
        }       
        private static Activity CreateVBExpression(ExpressionValidationContext context, out string newExpressionText, out Type expReturnType, out SourceExpressionException compileErrorMessages, out VisualBasicSettings vbSettings)
        {
            expReturnType = null;
            newExpressionText = null;
            compileErrorMessages = null;
            vbSettings = null;

            //try easy way first - look if there is a type converter which supports conversion between expression type and string
            ActivityWithResult literal = null;
            try
            {
                if (!context.UseLocationExpression)
                {
                    literal = ExpressionHelper.TryCreateLiteral(context.ExpressionType, context.ExpressionText, context.ParserContext);
                }

                if (literal != null)
                {
                    //need to get new expression text - converter might have changed its format, and we want it to be up to date
                    IValueSerializableExpression serializableExpression = literal as IValueSerializableExpression;
                    Fx.Assert(serializableExpression != null, "the expression has to be a Literal<>, which should be IValueSerializableExpression");
                    if (serializableExpression.CanConvertToString(context.ParserContext))
                    {
                        bool shouldBeQuoted = typeof(string) == context.ExpressionType || typeof(Uri) == context.ExpressionType;

                        //whether string begins and ends with quotes '"'. also, if there are
                        //more quotes within than those begining and ending ones, do not bother with literal - assume this is an expression.
                        bool isQuotedString = shouldBeQuoted &&
                                context.ExpressionText.StartsWith("\"", StringComparison.CurrentCulture) &&
                                context.ExpressionText.EndsWith("\"", StringComparison.CurrentCulture) &&
                                context.ExpressionText.IndexOf("\"", 1, StringComparison.CurrentCulture) == context.ExpressionText.Length - 1;
                        var formatString = isQuotedString ? "\"{0}\"" : "{0}";
                        newExpressionText = string.Format(CultureInfo.InvariantCulture, formatString, serializableExpression.ConvertToString(context.ParserContext));
                    }
                }
            }
            //conversion failed - do nothing, let VB compiler take care of the expression
            catch
            {
            }

            Activity valueExpression = literal;

            if (null == valueExpression)
            {
                if (!context.UseLocationExpression)
                {
                    //Compile for validation.
                    valueExpression = VisualBasicDesignerHelper.CreatePrecompiledVisualBasicValue(context.ExpressionType, context.ExpressionText, context.ParserContext.Namespaces, context.ReferencedAssemblies, context.ParserContext, out expReturnType, out compileErrorMessages, out vbSettings);
                }
                else
                {
                    //Compile for validation.
                    valueExpression = VisualBasicDesignerHelper.CreatePrecompiledVisualBasicReference(context.ExpressionType, context.ExpressionText, context.ParserContext.Namespaces, context.ReferencedAssemblies, context.ParserContext, out expReturnType, out compileErrorMessages, out vbSettings);
                }

                ////It's possible the inferred type of expression is a dynamic type (e.g. delegate type), in this case it will cause serialization failure.
                ////To prevent this, we'll always convert the expression type to be object if the inferred type is in dynamic assembly and user doesn't specify any ExpressionType property
                if ((expReturnType.Assembly.IsDynamic) && (context.ExpressionType == null))
                {
                    ActivityWithResult originalExpression = valueExpression as ActivityWithResult;
                    ActivityWithResult morphedExpression;
                    if (ExpressionHelper.TryMorphExpression(originalExpression, ExpressionHelper.IsGenericLocationExpressionType(originalExpression), typeof(object), context.EditingContext, out morphedExpression))
                    {
                        valueExpression = morphedExpression;
                    }
                }
            }

            return valueExpression;
        }
 static ExpressionEvaluator()
 {
     VbSettings = new VisualBasicSettings();
     AddImports(typeof(TIn), VbSettings.ImportReferences);
     AddImports(typeof(TOut), VbSettings.ImportReferences);
 }
 public override void SetValue(object component, object value)
 {
     NamespaceList namespaceList = value as NamespaceList;
     if (namespaceList != null)
     {
         if (namespaceList is VisualBasicNamespaceList)
         {
             VisualBasicNamespaceList visualBasicNamespaces = namespaceList as VisualBasicNamespaceList;
             VisualBasicSettings settings = new VisualBasicSettings();
             settings.ImportReferences.UnionWith(visualBasicNamespaces.VisualBasicImports);
             NamespaceHelper.SetVisualBasicSettings(component, settings);
         }
         else 
         {
             Fx.Assert(namespaceList is TextExpressionNamespaceList, "The namespace list must be either of VisualBaiscSettings or TextExpression attached properties.");
             TextExpressionNamespaceList textExpressionNamespace = namespaceList as TextExpressionNamespaceList;
             NamespaceHelper.SetTextExpressionNamespaces(
                 component, 
                 textExpressionNamespace.TextExpressionNamespaces, 
                 textExpressionNamespace.TextExpressionReferences);
         }
     }
     else
     {
         this.ResetValue(component);
     }
 }
        private static void CompileInputs(DynamicActivity activity, RuleSet ruleSet)
        {
            var settings = new VisualBasicSettings();
            foreach (var input in ruleSet.Inputs)
            {
                var inProperty = new DynamicActivityProperty
                {
                    Name = input.Key,
                    Type = typeof(InArgument<>).MakeGenericType(input.Value)
                };
                activity.Properties.Add(inProperty);

                settings.ImportReferences.Add(new VisualBasicImportReference
                    {
                        Assembly = input.Value.Assembly.GetName().Name,
                        Import = input.Value.Namespace
                    });
            }
            VisualBasic.SetSettings(activity, settings);
        }
 public static Activity CreatePrecompiledVisualBasicReference(Type targetType, string expressionText, IEnumerable<string> namespaces, IEnumerable<string> referencedAssemblies, LocationReferenceEnvironment environment, out Type returnType, out SourceExpressionException compileError, out VisualBasicSettings vbSettings)
 {
     LambdaExpression expression = null;
     HashSet<string> namespaceImportsNames = new HashSet<string>();
     HashSet<AssemblyName> refAssemNames = new HashSet<AssemblyName>();
     compileError = null;
     returnType = null;
     if (namespaces != null)
     {
         foreach (string str in namespaces)
         {
             if (str != null)
             {
                 namespaceImportsNames.Add(str);
             }
         }
     }
     if (referencedAssemblies != null)
     {
         foreach (string str2 in referencedAssemblies)
         {
             if (str2 != null)
             {
                 refAssemNames.Add(new AssemblyName(str2));
             }
         }
     }
     VisualBasicHelper helper = new VisualBasicHelper(expressionText, refAssemNames, namespaceImportsNames);
     if (targetType == null)
     {
         try
         {
             expression = helper.CompileNonGeneric(environment);
             if (expression != null)
             {
                 string str3;
                 if (!ExpressionUtilities.IsLocation(expression, targetType, out str3))
                 {
                     string invalidLValueExpression = System.Activities.SR.InvalidLValueExpression;
                     if (str3 != null)
                     {
                         invalidLValueExpression = invalidLValueExpression + ":" + str3;
                     }
                     throw FxTrace.Exception.AsError(new SourceExpressionException(System.Activities.SR.CompilerErrorSpecificExpression(expressionText, invalidLValueExpression)));
                 }
                 returnType = expression.ReturnType;
             }
         }
         catch (SourceExpressionException exception)
         {
             compileError = exception;
             returnType = typeof(object);
         }
         targetType = returnType;
     }
     else
     {
         MethodInfo info = typeof(VisualBasicHelper).GetMethod("Compile", new Type[] { typeof(LocationReferenceEnvironment) }).MakeGenericMethod(new Type[] { targetType });
         try
         {
             expression = (LambdaExpression) info.Invoke(helper, new object[] { environment });
             string extraErrorMessage = null;
             if (!ExpressionUtilities.IsLocation(expression, targetType, out extraErrorMessage))
             {
                 string str6 = System.Activities.SR.InvalidLValueExpression;
                 if (extraErrorMessage != null)
                 {
                     str6 = str6 + ":" + extraErrorMessage;
                 }
                 throw FxTrace.Exception.AsError(new SourceExpressionException(System.Activities.SR.CompilerErrorSpecificExpression(expressionText, str6)));
             }
             returnType = targetType;
         }
         catch (SourceExpressionException exception2)
         {
             compileError = exception2;
             returnType = typeof(object);
         }
         catch (TargetInvocationException exception3)
         {
             SourceExpressionException innerException = exception3.InnerException as SourceExpressionException;
             if (innerException == null)
             {
                 throw FxTrace.Exception.AsError(exception3.InnerException);
             }
             compileError = innerException;
             returnType = typeof(object);
         }
     }
     vbSettings = new VisualBasicSettings();
     if (expression != null)
     {
         HashSet<Type> typeReferences = new HashSet<Type>();
         FindTypeReferences(expression.Body, typeReferences);
         foreach (Type type in typeReferences)
         {
             Assembly assembly = type.Assembly;
             if (!assembly.IsDynamic)
             {
                 string name = VisualBasicHelper.GetFastAssemblyName(assembly).Name;
                 VisualBasicImportReference item = new VisualBasicImportReference {
                     Assembly = name,
                     Import = type.Namespace
                 };
                 vbSettings.ImportReferences.Add(item);
             }
         }
     }
     VisualBasicExpressionFactory factory = (VisualBasicExpressionFactory) Activator.CreateInstance(VisualBasicExpressionFactoryType.MakeGenericType(new Type[] { targetType }));
     return factory.CreateVisualBasicReference(expressionText);
 }