Beispiel #1
0
        // if the 1st parameter "supportedVersionXamlxfilePath" is null, we fall back to the primary generated type
        internal static ICompiledExpressionRoot GetExpressionRoot(string supportedVersionXamlxfilePath, WorkflowService service, string virtualPath)
        {
            Assembly compiledAssembly = BuildManager.GetCompiledAssembly(virtualPath);

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

            Type generatedType;

            if (supportedVersionXamlxfilePath != null)
            {
                string fullTypeNameToSearch = GeneratedNamespace + "." + WorkflowServiceHostFactory.GetSupportedVersionGeneratedTypeName(supportedVersionXamlxfilePath) + ExpressionRootFactorySuffix;
                generatedType = compiledAssembly.GetType(fullTypeNameToSearch);
            }
            else
            {
                generatedType = BuildManager.GetCompiledType(virtualPath);
            }

            Type workflowServiceType = typeof(WorkflowService);

            if (generatedType != workflowServiceType && workflowServiceType.IsAssignableFrom(generatedType))
            {
                MethodInfo createExpressionRootMethod = generatedType.GetMethod(CreateExpressionRootMethodName, BindingFlags.Public | BindingFlags.Static);
                if (createExpressionRootMethod != null)
                {
                    return((ICompiledExpressionRoot)createExpressionRootMethod.Invoke(null, new object[] { service.Body }));
                }
            }

            return(null);
        }
Beispiel #2
0
        void GenerateSource(bool isSupportedVersion, string filePath, AssemblyBuilder assemblyBuilder, WorkflowService workflowService, out string codeFileName, out bool generatedSource, out string activityName)
        {
            // Get unique file and type name for the workflowservice
            codeFileName = assemblyBuilder.GetTempFilePhysicalPath(assemblyBuilder.CodeDomProvider.FileExtension);

            if (isSupportedVersion)
            {
                activityName = WorkflowServiceHostFactory.GetSupportedVersionGeneratedTypeName(filePath);
            }
            else
            {
                activityName = workflowService.Name.LocalName + "_" + Guid.NewGuid().ToString().Replace("-", "_");
            }

            TextExpressionCompilerSettings settings = new TextExpressionCompilerSettings
            {
                Activity               = workflowService.Body,
                ActivityName           = activityName,
                ActivityNamespace      = GeneratedNamespace,
                Language               = CodeDomProvider.GetLanguageFromExtension(assemblyBuilder.CodeDomProvider.FileExtension),
                GenerateAsPartialClass = false,
                AlwaysGenerateSource   = false,
                ForImplementation      = false
            };

            TextExpressionCompiler compiler = new TextExpressionCompiler(settings);

            generatedSource = false;
            using (StreamWriter fileStream = new StreamWriter(codeFileName))
            {
                try
                {
                    generatedSource = compiler.GenerateSource(fileStream);
                }
                catch (Exception ex)
                {
                    if (Fx.IsFatal(ex))
                    {
                        throw;
                    }

                    throw FxTrace.Exception.AsError(new HttpCompileException(SR.XamlBuildProviderExtensionException(ex.Message)));
                }
            }
        }