Пример #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);
        }
Пример #2
0
        public void GenerateCode(AssemblyBuilder assemblyBuilder, Stream xamlStream, BuildProvider buildProvider)
        {
            object serviceObject = WorkflowServiceHostFactory.LoadXaml(xamlStream);

            WorkflowService workflowService = serviceObject as WorkflowService;

            if (workflowService != null && workflowService.Body != null)
            {
                string activityName;
                if (this.TryGenerateSource(assemblyBuilder, buildProvider, workflowService, false, null, out activityName))
                {
                    this.generatedPrimaryTypeName = GeneratedNamespace + "." + activityName + ExpressionRootFactorySuffix;
                }

                // find all supported versions xamlx files, load and compile them
                IList <Tuple <string, Stream> > streams = null;

                string xamlVirtualFile = GetXamlVirtualPath(buildProvider);
                string xamlFileName    = Path.GetFileNameWithoutExtension(VirtualPathUtility.GetFileName(xamlVirtualFile));
                WorkflowServiceHostFactory.GetSupportedVersionStreams(xamlFileName, out streams);
                if (streams != null)
                {
                    try
                    {
                        foreach (Tuple <string, Stream> stream in streams)
                        {
                            try
                            {
                                WorkflowService service = WorkflowServiceHostFactory.CreatetWorkflowService(stream.Item2, workflowService.Name);
                                if (service != null && service.Body != null)
                                {
                                    this.TryGenerateSource(assemblyBuilder, buildProvider, service, true, stream.Item1, out activityName);
                                }
                            }
                            catch (Exception e)
                            {
                                Exception newException;
                                if (Fx.IsFatal(e) || !WorkflowServiceHostFactory.TryWrapSupportedVersionException(stream.Item1, e, out newException))
                                {
                                    throw;
                                }

                                throw FxTrace.Exception.AsError(newException);
                            }
                        }
                    }
                    finally
                    {
                        foreach (Tuple <string, Stream> stream in streams)
                        {
                            stream.Item2.Dispose();
                        }
                    }
                }
            }
        }
Пример #3
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)));
                }
            }
        }