예제 #1
0
        internal static void InternalCompileFromDomBatch(string[] files, string[] codeFiles, WorkflowCompilerParameters parameters, WorkflowCompilerResults results, string localAssemblyPath)
        {
            // Check all the library paths are valid.
            foreach (string libraryPath in parameters.LibraryPaths)
            {
                if (!XomlCompilerHelper.CheckPathName(libraryPath))
                {
                    WorkflowCompilerError libPathError =
                        new WorkflowCompilerError(string.Empty, 0, 0, ErrorNumbers.Error_LibraryPath.ToString(CultureInfo.InvariantCulture), string.Format(CultureInfo.CurrentCulture, SR.GetString(SR.LibraryPathIsInvalid), libraryPath));
                    libPathError.IsWarning = true;
                    results.Errors.Add(libPathError);
                }
            }

            IList <AuthorizedType> authorizedTypes = null;

            if (parameters.CheckTypes)
            {
                //If we dont find the list of authorized types then return.
                authorizedTypes = WorkflowCompilationContext.Current.GetAuthorizedTypes();
                if (authorizedTypes == null)
                {
                    ValidationError error = new ValidationError(SR.GetString(SR.Error_ConfigFileMissingOrInvalid), ErrorNumbers.Error_ConfigFileMissingOrInvalid);
                    results.Errors.Add(CreateXomlCompilerError(error, parameters));
                    return;
                }
            }

            ITypeProvider typeProvider = WorkflowCompilationContext.Current.ServiceProvider.GetService(typeof(ITypeProvider)) as ITypeProvider;
            ArrayList     activities   = new ArrayList();

            using (PDBReader pdbReader = new PDBReader(localAssemblyPath))
            {
                // Validate all the compiled activities in the assembly.
                foreach (Type type in typeProvider.LocalAssembly.GetTypes())
                {
                    if (!TypeProvider.IsAssignable(typeof(Activity), type) || type.IsAbstract)
                    {
                        continue;
                    }

                    // Fetch file name.
                    string fileName = string.Empty;
                    WorkflowMarkupSourceAttribute[] sourceAttrs = (WorkflowMarkupSourceAttribute[])type.GetCustomAttributes(typeof(WorkflowMarkupSourceAttribute), false);
                    if (sourceAttrs != null && sourceAttrs.Length > 0)
                    {
                        fileName = sourceAttrs[0].FileName;
                    }
                    else
                    {
                        ConstructorInfo ctorMethod = type.GetConstructor(Type.EmptyTypes);
                        if (ctorMethod != null)
                        {
                            try
                            {
                                uint line = 0, column = 0;
                                pdbReader.GetSourceLocationForOffset((uint)ctorMethod.MetadataToken, 0, out fileName, out line, out column);
                            }
                            catch
                            {
                                // We don't want errors if the user has written their own custom
                                // activity and simply inherited the constructor
                            }
                        }

                        // In case of VB, if the ctor is autogenerated the PDB will not have symbol
                        // information. Use InitializeComponent method as the fallback. Bug 19085.
                        if (String.IsNullOrEmpty(fileName))
                        {
                            MethodInfo initializeComponent = type.GetMethod("InitializeComponent", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance, null, Type.EmptyTypes, null);
                            if (initializeComponent != null)
                            {
                                try
                                {
                                    uint line = 0, column = 0;
                                    pdbReader.GetSourceLocationForOffset((uint)initializeComponent.MetadataToken, 0, out fileName, out line, out column);

                                    if (!String.IsNullOrEmpty(fileName))
                                    {
                                        if (fileName.EndsWith(".designer.cs", StringComparison.OrdinalIgnoreCase))
                                        {
                                            fileName = fileName.Substring(0, fileName.Length - ".designer.cs".Length) + ".cs";
                                        }
                                        else if (fileName.EndsWith(".designer.vb", StringComparison.OrdinalIgnoreCase))
                                        {
                                            fileName = fileName.Substring(0, fileName.Length - ".designer.vb".Length) + ".vb";
                                        }
                                    }
                                }
                                catch
                                {
                                }
                            }
                        }
                    }

                    // Create the activity.
                    Activity activity = null;
                    try
                    {
                        try
                        {
                            Activity.ActivityType = type;
                            activity = Activator.CreateInstance(type) as Activity;
                        }
                        finally
                        {
                            Activity.ActivityType = null;
                        }
                        activity.UserData[UserDataKeys.CustomActivity] = false;
                        if (activity is CompositeActivity)
                        {
                            CompositeActivity compositeActivity = activity as CompositeActivity;
                            if (compositeActivity.CanModifyActivities)
                            {
                                results.Errors.Add(CreateXomlCompilerError(new ValidationError(SR.GetString(SR.Error_Missing_CanModifyProperties_False, activity.GetType().FullName), ErrorNumbers.Error_CustomActivityCantCreate), parameters));
                            }
                        }
                        if (sourceAttrs.Length > 0)
                        {
                            DesignerSerializationManager manager = new DesignerSerializationManager(WorkflowCompilationContext.Current.ServiceProvider);
                            Activity instance2 = null;
                            using (manager.CreateSession())
                            {
                                WorkflowMarkupSerializationManager xomlSerializationManager = new WorkflowMarkupSerializationManager(manager);
                                xomlSerializationManager.LocalAssembly = parameters.LocalAssembly;
                                using (XmlReader reader = XmlReader.Create((sourceAttrs[0].FileName)))
                                    instance2 = new WorkflowMarkupSerializer().Deserialize(xomlSerializationManager, reader) as Activity;
                            }
                            if (instance2 is CompositeActivity)
                            {
                                ActivityMarkupSerializer.ReplaceChildActivities(activity as CompositeActivity, instance2 as CompositeActivity);
                            }
                        }
                    }
                    catch (TargetInvocationException tie)
                    {
                        // For TypeInitializationException, the message is available at the inner Exception
                        if (tie.InnerException is TypeInitializationException && tie.InnerException.InnerException != null)
                        {
                            results.Errors.Add(CreateXomlCompilerError(new ValidationError(SR.GetString(SR.Error_CustomActivityCantCreate, type.FullName, tie.InnerException.InnerException.ToString()), ErrorNumbers.Error_CustomActivityCantCreate), parameters));
                        }
                        else if (tie.InnerException.InnerException != null)
                        {
                            results.Errors.Add(CreateXomlCompilerError(new ValidationError(tie.InnerException.InnerException.ToString(), ErrorNumbers.Error_CustomActivityCantCreate), parameters));
                        }
                        else
                        {
                            results.Errors.Add(CreateXomlCompilerError(new ValidationError(SR.GetString(SR.Error_CustomActivityCantCreate, type.FullName, tie.InnerException.ToString()), ErrorNumbers.Error_CustomActivityCantCreate), parameters));
                        }
                        continue;
                    }
                    catch (Exception e)
                    {
                        results.Errors.Add(CreateXomlCompilerError(new ValidationError(SR.GetString(SR.Error_CustomActivityCantCreate, type.FullName, e.ToString()), ErrorNumbers.Error_CustomActivityCantCreate), parameters));
                        continue;
                    }

                    // Work around : another set of work arounds.
                    activity.SetValue(ActivityCodeDomSerializer.MarkupFileNameProperty, fileName);
                    activity.SetValue(WorkflowMarkupSerializer.XClassProperty, type.FullName);

                    // Run the validators.
                    ValidateActivity(activity, parameters, results);
                    activities.Add(activity);
                }
            }

            // Add all type load errors to compiler results.
            foreach (KeyValuePair <object, Exception> entry in typeProvider.TypeLoadErrors)
            {
                WorkflowCompilerError compilerError = new WorkflowCompilerError(string.Empty, 0, 0, ErrorNumbers.Error_TypeLoad.ToString(CultureInfo.InvariantCulture), entry.Value.Message);
                compilerError.IsWarning = true;
                results.Errors.Add(compilerError);
            }
            results.CompiledUnit = WorkflowCompilerInternal.GenerateCodeFromFileBatch(files, parameters, results);

            WorkflowCompilationContext context = WorkflowCompilationContext.Current;

            if (context == null)
            {
                throw new Exception(SR.GetString(SR.Error_MissingCompilationContext));
            }
            // Fix standard namespaces and root namespace.
            WorkflowMarkupSerializationHelpers.ReapplyRootNamespace(results.CompiledUnit.Namespaces, context.RootNamespace, CompilerHelpers.GetSupportedLanguage(context.Language));
            WorkflowMarkupSerializationHelpers.FixStandardNamespacesAndRootNamespace(results.CompiledUnit.Namespaces, context.RootNamespace, CompilerHelpers.GetSupportedLanguage(context.Language));
            if (!results.Errors.HasErrors)
            {
                // ask activities to generate code for themselves
                CodeGenerationManager codeGenerationManager = new CodeGenerationManager(WorkflowCompilationContext.Current.ServiceProvider);
                codeGenerationManager.Context.Push(results.CompiledUnit.Namespaces);
                foreach (Activity activity in activities)
                {
                    // Need to call code generators associated with the root activity.
                    if (activity.Parent == null)
                    {
                        foreach (System.Workflow.ComponentModel.Compiler.ActivityCodeGenerator codeGenerator in codeGenerationManager.GetCodeGenerators(activity.GetType()))
                        {
                            codeGenerator.GenerateCode(codeGenerationManager, activity);
                        }
                    }
                }

                // If only ccu needed then return.
                if (!parameters.GenerateCodeCompileUnitOnly || parameters.CheckTypes)
                {
                    // Convert all compile units to source files.
                    SupportedLanguages language        = CompilerHelpers.GetSupportedLanguage(parameters.LanguageToUse);
                    CodeDomProvider    codeDomProvider = CompilerHelpers.GetCodeDomProvider(language, parameters.CompilerVersion);
                    ArrayList          ccus            = new ArrayList((ICollection)parameters.UserCodeCompileUnits);
                    ccus.Add(results.CompiledUnit);

                    ArrayList sourceFilePaths = new ArrayList();
                    sourceFilePaths.AddRange(codeFiles);
                    sourceFilePaths.AddRange(XomlCompilerHelper.GenerateFiles(codeDomProvider, parameters, (CodeCompileUnit[])ccus.ToArray(typeof(CodeCompileUnit))));

                    // Finally give it to Code Compiler.
                    CompilerResults results2 = codeDomProvider.CompileAssemblyFromFile(parameters, (string[])sourceFilePaths.ToArray(typeof(string)));
                    results.AddCompilerErrorsFromCompilerResults(results2);
                    results.PathToAssembly            = results2.PathToAssembly;
                    results.NativeCompilerReturnValue = results2.NativeCompilerReturnValue;

                    if (!results.Errors.HasErrors && parameters.CheckTypes)
                    {
                        foreach (string referenceType in MetaDataReader.GetTypeRefNames(results2.CompiledAssembly.Location))
                        {
                            bool authorized = false;
                            foreach (AuthorizedType authorizedType in authorizedTypes)
                            {
                                if (authorizedType.RegularExpression.IsMatch(referenceType))
                                {
                                    authorized = (String.Compare(bool.TrueString, authorizedType.Authorized, StringComparison.OrdinalIgnoreCase) == 0);
                                    if (!authorized)
                                    {
                                        break;
                                    }
                                }
                            }
                            if (!authorized)
                            {
                                ValidationError error = new ValidationError(SR.GetString(SR.Error_TypeNotAuthorized, referenceType), ErrorNumbers.Error_TypeNotAuthorized);
                                results.Errors.Add(CreateXomlCompilerError(error, parameters));
                            }
                        }
                    }
                    //this line was throwing for the delay sign case. besides, copying PathToAssembly should do the same...
                    if (!results.Errors.HasErrors && !parameters.GenerateCodeCompileUnitOnly && parameters.GenerateInMemory &&
                        (string.IsNullOrEmpty(parameters.CompilerOptions) || !parameters.CompilerOptions.ToLower(CultureInfo.InvariantCulture).Contains("/delaysign")))
                    {
                        results.CompiledAssembly = results2.CompiledAssembly;
                    }
                }
            }
        }
        private ValidationErrorCollection ValidateBindProperty(ValidationManager manager, Activity activity, PropertyBind bind, BindValidationContext validationContext)
        {
            ValidationErrorCollection errors = new ValidationErrorCollection();
            string   name = bind.Name;
            Activity enclosingActivity = Helpers.GetEnclosingActivity(activity);
            Activity refActivity       = enclosingActivity;

            if ((name.IndexOf('.') != -1) && (refActivity != null))
            {
                refActivity = Helpers.GetDataSourceActivity(activity, bind.Name, out name);
            }
            if (refActivity == null)
            {
                ValidationError error = new ValidationError(SR.GetString("Error_NoEnclosingContext", new object[] { activity.Name }), 0x130)
                {
                    PropertyName = base.GetFullPropertyName(manager) + ".Name"
                };
                errors.Add(error);
                return(errors);
            }
            ValidationError item         = null;
            PropertyInfo    property     = null;
            Type            activityType = null;

            if (property == null)
            {
                activityType = BindValidatorHelper.GetActivityType(manager, refActivity);
                if (activityType != null)
                {
                    property = activityType.GetProperty(name, BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance);
                }
            }
            if (activityType == null)
            {
                item = new ValidationError(SR.GetString("Error_TypeNotResolvedInPropertyName", new object[] { "Name" }), 0x163)
                {
                    PropertyName = base.GetFullPropertyName(manager)
                };
            }
            else if (property == null)
            {
                item = new ValidationError(SR.GetString("Error_PropertyNotExists", new object[] { base.GetFullPropertyName(manager), name }), 0x164)
                {
                    PropertyName = base.GetFullPropertyName(manager)
                };
            }
            else if (!property.CanRead)
            {
                item = new ValidationError(SR.GetString("Error_PropertyReferenceNoGetter", new object[] { base.GetFullPropertyName(manager), name }), 360)
                {
                    PropertyName = base.GetFullPropertyName(manager)
                };
            }
            else if (property.GetGetMethod() == null)
            {
                item = new ValidationError(SR.GetString("Error_PropertyReferenceGetterNoAccess", new object[] { base.GetFullPropertyName(manager), name }), 0x60a)
                {
                    PropertyName = base.GetFullPropertyName(manager)
                };
            }
            else if (((refActivity != enclosingActivity) && !property.GetGetMethod().IsAssembly) && !property.GetGetMethod().IsPublic)
            {
                item = new ValidationError(SR.GetString("Error_PropertyNotAccessible", new object[] { base.GetFullPropertyName(manager), name }), 0x165)
                {
                    PropertyName = base.GetFullPropertyName(manager)
                };
            }
            else if (property.PropertyType == null)
            {
                item = new ValidationError(SR.GetString("Error_PropertyTypeNotResolved", new object[] { base.GetFullPropertyName(manager), name }), 0x166)
                {
                    PropertyName = base.GetFullPropertyName(manager)
                };
            }
            else
            {
                MemberInfo memberInfo = property;
                if (((bind.Path == null) || (bind.Path.Length == 0)) && ((validationContext.TargetType != null) && !ActivityBindValidator.DoesTargetTypeMatch(validationContext.TargetType, property.PropertyType, validationContext.Access)))
                {
                    item = new ValidationError(SR.GetString("Error_PropertyTypeMismatch", new object[] { base.GetFullPropertyName(manager), property.PropertyType.FullName, validationContext.TargetType.FullName }), 0x167)
                    {
                        PropertyName = base.GetFullPropertyName(manager)
                    };
                }
                else if (!string.IsNullOrEmpty(bind.Path))
                {
                    memberInfo = MemberBind.GetMemberInfo(property.PropertyType, bind.Path);
                    if (memberInfo == null)
                    {
                        item = new ValidationError(SR.GetString("Error_InvalidMemberPath", new object[] { name, bind.Path }), 300)
                        {
                            PropertyName = base.GetFullPropertyName(manager) + ".Path"
                        };
                    }
                    else
                    {
                        using ((WorkflowCompilationContext.Current == null) ? WorkflowCompilationContext.CreateScope(manager) : null)
                        {
                            if (WorkflowCompilationContext.Current.CheckTypes)
                            {
                                item = MemberBind.ValidateTypesInPath(property.PropertyType, bind.Path);
                                if (item != null)
                                {
                                    item.PropertyName = base.GetFullPropertyName(manager) + ".Path";
                                }
                            }
                        }
                        if (item == null)
                        {
                            Type memberType = (memberInfo is FieldInfo) ? (memberInfo as FieldInfo).FieldType : (memberInfo as PropertyInfo).PropertyType;
                            if (!ActivityBindValidator.DoesTargetTypeMatch(validationContext.TargetType, memberType, validationContext.Access))
                            {
                                item = new ValidationError(SR.GetString("Error_TargetTypeDataSourcePathMismatch", new object[] { validationContext.TargetType.FullName }), 0x141)
                                {
                                    PropertyName = base.GetFullPropertyName(manager) + ".Path"
                                };
                            }
                        }
                    }
                }
                if (item == null)
                {
                    if (memberInfo is PropertyInfo)
                    {
                        PropertyInfo info3 = memberInfo as PropertyInfo;
                        if (!info3.CanRead && ((validationContext.Access & AccessTypes.Read) != 0))
                        {
                            item = new ValidationError(SR.GetString("Error_PropertyNoGetter", new object[] { info3.Name, bind.Path }), 0x142)
                            {
                                PropertyName = base.GetFullPropertyName(manager) + ".Path"
                            };
                        }
                        else if (!info3.CanWrite && ((validationContext.Access & AccessTypes.Write) != 0))
                        {
                            item = new ValidationError(SR.GetString("Error_PropertyNoSetter", new object[] { info3.Name, bind.Path }), 0x143)
                            {
                                PropertyName = base.GetFullPropertyName(manager) + ".Path"
                            };
                        }
                    }
                    else if (memberInfo is FieldInfo)
                    {
                        FieldInfo info4 = memberInfo as FieldInfo;
                        if (((info4.Attributes & (FieldAttributes.Literal | FieldAttributes.InitOnly)) != FieldAttributes.PrivateScope) && ((validationContext.Access & AccessTypes.Write) != 0))
                        {
                            item = new ValidationError(SR.GetString("Error_ReadOnlyField", new object[] { info4.Name }), 0x145)
                            {
                                PropertyName = base.GetFullPropertyName(manager) + ".Path"
                            };
                        }
                    }
                }
            }
            if (item != null)
            {
                errors.Add(item);
            }
            return(errors);
        }
예제 #3
0
 protected ContextScope(IServiceProvider serviceProvider)
 {
     this.serviceProvider = serviceProvider;
     this.currentContext = WorkflowCompilationContext.Current;
     WorkflowCompilationContext.Current = new WorkflowCompilationContext(this);
 }
예제 #4
0
        public WorkflowCompilerResults Compile(WorkflowCompilerParameters parameters, string[] allFiles)
        {
            WorkflowCompilerResults results = new WorkflowCompilerResults(parameters.TempFiles);

            // Split the xoml files from cs/vb files.
            StringCollection xomlFiles     = new StringCollection();
            StringCollection userCodeFiles = new StringCollection();

            foreach (string file in allFiles)
            {
                if (file.EndsWith(".xoml", StringComparison.OrdinalIgnoreCase))
                {
                    xomlFiles.Add(file);
                }
                else
                {
                    userCodeFiles.Add(file);
                }
            }

            string[] files = new string[xomlFiles.Count];
            xomlFiles.CopyTo(files, 0);
            string[] codeFiles = new string[userCodeFiles.Count];
            userCodeFiles.CopyTo(codeFiles, 0);

            string             mscorlibPath     = typeof(object).Assembly.Location;
            ServiceContainer   serviceContainer = new ServiceContainer();
            MultiTargetingInfo mtInfo           = parameters.MultiTargetingInformation;

            if (mtInfo == null)
            {
                XomlCompilerHelper.FixReferencedAssemblies(parameters, results, parameters.LibraryPaths);
            }
            string mscorlibName = Path.GetFileName(mscorlibPath);

            // Add assembly resolver.
            ReferencedAssemblyResolver resolver = new ReferencedAssemblyResolver(parameters.ReferencedAssemblies, parameters.LocalAssembly);

            AppDomain.CurrentDomain.AssemblyResolve += resolver.ResolveEventHandler;

            // prepare service container
            TypeProvider typeProvider  = new TypeProvider(new ServiceContainer());
            int          mscorlibIndex = -1;

            if ((parameters.ReferencedAssemblies != null) && (parameters.ReferencedAssemblies.Count > 0))
            {
                for (int i = 0; i < parameters.ReferencedAssemblies.Count; i++)
                {
                    string assemblyPath = parameters.ReferencedAssemblies[i];
                    if ((mscorlibIndex == -1) && (string.Compare(mscorlibName, Path.GetFileName(assemblyPath), StringComparison.OrdinalIgnoreCase) == 0))
                    {
                        mscorlibIndex = i;
                        mscorlibPath  = assemblyPath;
                    }
                    typeProvider.AddAssemblyReference(assemblyPath);
                }
            }
            // a note about references to mscorlib:
            //  If we found mscorlib in the list of reference assemblies, we should remove it prior to sending it to the CodeDOM compiler.
            //  The CodeDOM compiler would add the right mscorlib [based on the version of the provider we use] and the duplication would
            //  cause a compilation error.
            //  If we didn't found a reference to mscorlib we need to add it to the type-provider, though, so we will support exposing
            //  those known types.
            if (mscorlibIndex != -1)
            {
                parameters.ReferencedAssemblies.RemoveAt(mscorlibIndex);
                if (string.IsNullOrEmpty(parameters.CoreAssemblyFileName))
                {
                    parameters.CoreAssemblyFileName = mscorlibPath;
                }
            }
            else
            {
                typeProvider.AddAssemblyReference(mscorlibPath);
            }

            serviceContainer.AddService(typeof(ITypeProvider), typeProvider);

            TempFileCollection intermediateTempFiles = null;
            string             localAssemblyPath     = string.Empty;
            string             createdDirectoryName  = null;

            try
            {
                using (WorkflowCompilationContext.CreateScope(serviceContainer, parameters))
                {
                    parameters.LocalAssembly = GenerateLocalAssembly(files, codeFiles, parameters, results, out intermediateTempFiles, out localAssemblyPath, out createdDirectoryName);
                    if (parameters.LocalAssembly != null)
                    {
                        // WinOE

                        resolver.SetLocalAssembly(parameters.LocalAssembly);

                        // Work around HERE!!!
                        // prepare type provider
                        typeProvider.SetLocalAssembly(parameters.LocalAssembly);
                        typeProvider.AddAssembly(parameters.LocalAssembly);

                        results.Errors.Clear();
                        XomlCompilerHelper.InternalCompileFromDomBatch(files, codeFiles, parameters, results, localAssemblyPath);
                    }
                }
            }
            catch (Exception e)
            {
                results.Errors.Add(new WorkflowCompilerError(String.Empty, -1, -1, ErrorNumbers.Error_UnknownCompilerException.ToString(CultureInfo.InvariantCulture), SR.GetString(SR.Error_CompilationFailed, e.Message)));
            }
            finally
            {
                // Delate the temp files.
                if (intermediateTempFiles != null && parameters.TempFiles.KeepFiles == false)
                {
                    foreach (string file in intermediateTempFiles)
                    {
                        try
                        {
                            System.IO.File.Delete(file);
                        }
                        catch
                        {
                        }
                    }

                    try
                    {
                        // GenerateLocalAssembly may have created a directory, so let's try to delete it
                        // We can't just delete Path.GetDirectoryName(localAssemblyPath) because it might be the Temp directory.
                        if (createdDirectoryName != null)
                        {
                            Directory.Delete(createdDirectoryName, true);
                        }
                    }
                    catch
                    {
                    }
                }
            }

            return(results);
        }
예제 #5
0
        internal static CodeCompileUnit GenerateCodeFromFileBatch(string[] files, WorkflowCompilerParameters parameters, WorkflowCompilerResults results)
        {
            WorkflowCompilationContext context = WorkflowCompilationContext.Current;

            if (context == null)
            {
                throw new Exception(SR.GetString(SR.Error_MissingCompilationContext));
            }

            CodeCompileUnit codeCompileUnit = new CodeCompileUnit();

            foreach (string fileName in files)
            {
                Activity rootActivity = null;
                try
                {
                    DesignerSerializationManager manager = new DesignerSerializationManager(context.ServiceProvider);
                    using (manager.CreateSession())
                    {
                        WorkflowMarkupSerializationManager xomlSerializationManager = new WorkflowMarkupSerializationManager(manager);
                        xomlSerializationManager.WorkflowMarkupStack.Push(parameters);
                        xomlSerializationManager.LocalAssembly = parameters.LocalAssembly;
                        using (XmlReader reader = XmlReader.Create(fileName))
                            rootActivity = WorkflowMarkupSerializationHelpers.LoadXomlDocument(xomlSerializationManager, reader, fileName);

                        if (parameters.LocalAssembly != null)
                        {
                            foreach (object error in manager.Errors)
                            {
                                if (error is WorkflowMarkupSerializationException)
                                {
                                    results.Errors.Add(new WorkflowCompilerError(fileName, (WorkflowMarkupSerializationException)error));
                                }
                                else
                                {
                                    results.Errors.Add(new WorkflowCompilerError(fileName, -1, -1, ErrorNumbers.Error_SerializationError.ToString(CultureInfo.InvariantCulture), error.ToString()));
                                }
                            }
                        }
                    }
                }
                catch (WorkflowMarkupSerializationException xomlSerializationException)
                {
                    results.Errors.Add(new WorkflowCompilerError(fileName, xomlSerializationException));
                    continue;
                }
                catch (Exception e)
                {
                    results.Errors.Add(new WorkflowCompilerError(fileName, -1, -1, ErrorNumbers.Error_SerializationError.ToString(CultureInfo.InvariantCulture), SR.GetString(SR.Error_CompilationFailed, e.Message)));
                    continue;
                }

                if (rootActivity == null)
                {
                    results.Errors.Add(new WorkflowCompilerError(fileName, 1, 1, ErrorNumbers.Error_SerializationError.ToString(CultureInfo.InvariantCulture), SR.GetString(SR.Error_RootActivityTypeInvalid)));
                    continue;
                }

                bool createNewClass = (!string.IsNullOrEmpty(rootActivity.GetValue(WorkflowMarkupSerializer.XClassProperty) as string));
                if (!createNewClass)
                {
                    results.Errors.Add(new WorkflowCompilerError(fileName, 1, 1, ErrorNumbers.Error_SerializationError.ToString(CultureInfo.InvariantCulture), SR.GetString(SR.Error_CannotCompile_No_XClass)));
                    continue;
                }

                //NOTE: CompileWithNoCode is meaningless now. It means no x:Code in a XOML file. It exists until the FP migration is done
                //Ideally FP should just use XOML files w/o X:Class and run them w/o ever compiling them
                if ((parameters.CompileWithNoCode) && XomlCompilerHelper.HasCodeWithin(rootActivity))
                {
                    ValidationError error = new ValidationError(SR.GetString(SR.Error_CodeWithinNotAllowed), ErrorNumbers.Error_CodeWithinNotAllowed);
                    error.UserData[typeof(Activity)] = rootActivity;
                    results.Errors.Add(XomlCompilerHelper.CreateXomlCompilerError(error, parameters));
                }

                ValidationErrorCollection errors = new ValidationErrorCollection();

                errors = ValidateIdentifiers(context.ServiceProvider, rootActivity);
                foreach (ValidationError error in errors)
                {
                    results.Errors.Add(XomlCompilerHelper.CreateXomlCompilerError(error, parameters));
                }

                if (results.Errors.HasErrors)
                {
                    continue;
                }

                codeCompileUnit.Namespaces.AddRange(WorkflowMarkupSerializationHelpers.GenerateCodeFromXomlDocument(rootActivity, fileName, context.RootNamespace, CompilerHelpers.GetSupportedLanguage(context.Language), context.ServiceProvider));
            }

            WorkflowMarkupSerializationHelpers.FixStandardNamespacesAndRootNamespace(codeCompileUnit.Namespaces, context.RootNamespace, CompilerHelpers.GetSupportedLanguage(context.Language));
            return(codeCompileUnit);
        }
예제 #6
0
 protected ContextScope(IServiceProvider serviceProvider)
 {
     this.serviceProvider = serviceProvider;
     this.currentContext  = WorkflowCompilationContext.Current;
     WorkflowCompilationContext.Current = new WorkflowCompilationContext(this);
 }
예제 #7
0
        public WorkflowCompilerResults Compile(WorkflowCompilerParameters parameters, string[] allFiles)
        {
            WorkflowCompilerResults results  = new WorkflowCompilerResults(parameters.TempFiles);
            StringCollection        strings  = new StringCollection();
            StringCollection        strings2 = new StringCollection();

            foreach (string str in allFiles)
            {
                if (str.EndsWith(".xoml", StringComparison.OrdinalIgnoreCase))
                {
                    strings.Add(str);
                }
                else
                {
                    strings2.Add(str);
                }
            }
            string[] array = new string[strings.Count];
            strings.CopyTo(array, 0);
            string[] strArray2 = new string[strings2.Count];
            strings2.CopyTo(strArray2, 0);
            string           location        = typeof(object).Assembly.Location;
            ServiceContainer serviceProvider = new ServiceContainer();

            if (parameters.MultiTargetingInformation == null)
            {
                XomlCompilerHelper.FixReferencedAssemblies(parameters, results, parameters.LibraryPaths);
            }
            string fileName = Path.GetFileName(location);
            ReferencedAssemblyResolver resolver = new ReferencedAssemblyResolver(parameters.ReferencedAssemblies, parameters.LocalAssembly);

            AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(resolver.ResolveEventHandler);
            TypeProvider serviceInstance = new TypeProvider(new ServiceContainer());
            int          index           = -1;

            if ((parameters.ReferencedAssemblies != null) && (parameters.ReferencedAssemblies.Count > 0))
            {
                for (int i = 0; i < parameters.ReferencedAssemblies.Count; i++)
                {
                    string path = parameters.ReferencedAssemblies[i];
                    if ((index == -1) && (string.Compare(fileName, Path.GetFileName(path), StringComparison.OrdinalIgnoreCase) == 0))
                    {
                        index    = i;
                        location = path;
                    }
                    serviceInstance.AddAssemblyReference(path);
                }
            }
            if (index != -1)
            {
                parameters.ReferencedAssemblies.RemoveAt(index);
            }
            else
            {
                serviceInstance.AddAssemblyReference(location);
            }
            serviceProvider.AddService(typeof(ITypeProvider), serviceInstance);
            TempFileCollection files             = null;
            string             localAssemblyPath = string.Empty;

            try
            {
                using (WorkflowCompilationContext.CreateScope(serviceProvider, parameters))
                {
                    parameters.LocalAssembly = this.GenerateLocalAssembly(array, strArray2, parameters, results, out files, out localAssemblyPath);
                    if (parameters.LocalAssembly != null)
                    {
                        resolver.SetLocalAssembly(parameters.LocalAssembly);
                        serviceInstance.SetLocalAssembly(parameters.LocalAssembly);
                        serviceInstance.AddAssembly(parameters.LocalAssembly);
                        results.Errors.Clear();
                        XomlCompilerHelper.InternalCompileFromDomBatch(array, strArray2, parameters, results, localAssemblyPath);
                    }
                }
                return(results);
            }
            catch (Exception exception)
            {
                int num4 = 0x15c;
                results.Errors.Add(new WorkflowCompilerError(string.Empty, -1, -1, num4.ToString(CultureInfo.InvariantCulture), SR.GetString("Error_CompilationFailed", new object[] { exception.Message })));
            }
            finally
            {
                if ((files != null) && !parameters.TempFiles.KeepFiles)
                {
                    string directoryName = string.Empty;
                    if (File.Exists(localAssemblyPath))
                    {
                        directoryName = Path.GetDirectoryName(localAssemblyPath);
                    }
                    foreach (string str7 in files)
                    {
                        try
                        {
                            File.Delete(str7);
                        }
                        catch
                        {
                        }
                    }
                    try
                    {
                        if (!string.IsNullOrEmpty(directoryName))
                        {
                            Directory.Delete(directoryName);
                        }
                    }
                    catch
                    {
                    }
                }
            }
            return(results);
        }
예제 #8
0
        internal static CodeCompileUnit GenerateCodeFromFileBatch(string[] files, WorkflowCompilerParameters parameters, WorkflowCompilerResults results)
        {
            WorkflowCompilationContext current = WorkflowCompilationContext.Current;

            if (current == null)
            {
                throw new Exception(SR.GetString("Error_MissingCompilationContext"));
            }
            CodeCompileUnit unit = new CodeCompileUnit();

            foreach (string str in files)
            {
                Activity rootActivity = null;
                try
                {
                    DesignerSerializationManager manager = new DesignerSerializationManager(current.ServiceProvider);
                    using (manager.CreateSession())
                    {
                        WorkflowMarkupSerializationManager xomlSerializationManager = new WorkflowMarkupSerializationManager(manager);
                        xomlSerializationManager.WorkflowMarkupStack.Push(parameters);
                        xomlSerializationManager.LocalAssembly = parameters.LocalAssembly;
                        using (XmlReader reader = XmlReader.Create(str))
                        {
                            rootActivity = WorkflowMarkupSerializationHelpers.LoadXomlDocument(xomlSerializationManager, reader, str);
                        }
                        if (parameters.LocalAssembly != null)
                        {
                            foreach (object obj2 in manager.Errors)
                            {
                                if (obj2 is WorkflowMarkupSerializationException)
                                {
                                    results.Errors.Add(new WorkflowCompilerError(str, (WorkflowMarkupSerializationException)obj2));
                                }
                                else
                                {
                                    int num2 = 0x15b;
                                    results.Errors.Add(new WorkflowCompilerError(str, -1, -1, num2.ToString(CultureInfo.InvariantCulture), obj2.ToString()));
                                }
                            }
                        }
                    }
                }
                catch (WorkflowMarkupSerializationException exception)
                {
                    results.Errors.Add(new WorkflowCompilerError(str, exception));
                    continue;
                }
                catch (Exception exception2)
                {
                    int num3 = 0x15b;
                    results.Errors.Add(new WorkflowCompilerError(str, -1, -1, num3.ToString(CultureInfo.InvariantCulture), SR.GetString("Error_CompilationFailed", new object[] { exception2.Message })));
                    continue;
                }
                if (rootActivity == null)
                {
                    int num4 = 0x15b;
                    results.Errors.Add(new WorkflowCompilerError(str, 1, 1, num4.ToString(CultureInfo.InvariantCulture), SR.GetString("Error_RootActivityTypeInvalid")));
                }
                else if (string.IsNullOrEmpty(rootActivity.GetValue(WorkflowMarkupSerializer.XClassProperty) as string))
                {
                    int num5 = 0x15b;
                    results.Errors.Add(new WorkflowCompilerError(str, 1, 1, num5.ToString(CultureInfo.InvariantCulture), SR.GetString("Error_CannotCompile_No_XClass")));
                }
                else
                {
                    if (parameters.CompileWithNoCode && XomlCompilerHelper.HasCodeWithin(rootActivity))
                    {
                        ValidationError error = new ValidationError(SR.GetString("Error_CodeWithinNotAllowed"), 0x16a);
                        error.UserData[typeof(Activity)] = rootActivity;
                        results.Errors.Add(XomlCompilerHelper.CreateXomlCompilerError(error, parameters));
                    }
                    ValidationErrorCollection errors = new ValidationErrorCollection();
                    foreach (ValidationError error2 in ValidateIdentifiers(current.ServiceProvider, rootActivity))
                    {
                        results.Errors.Add(XomlCompilerHelper.CreateXomlCompilerError(error2, parameters));
                    }
                    if (!results.Errors.HasErrors)
                    {
                        unit.Namespaces.AddRange(WorkflowMarkupSerializationHelpers.GenerateCodeFromXomlDocument(rootActivity, str, current.RootNamespace, CompilerHelpers.GetSupportedLanguage(current.Language), current.ServiceProvider));
                    }
                }
            }
            WorkflowMarkupSerializationHelpers.FixStandardNamespacesAndRootNamespace(unit.Namespaces, current.RootNamespace, CompilerHelpers.GetSupportedLanguage(current.Language));
            return(unit);
        }
        private ValidationErrorCollection ValidateField(ValidationManager manager, Activity activity, FieldBind bind, BindValidationContext validationContext)
        {
            ValidationErrorCollection errors = new ValidationErrorCollection();
            string   name = bind.Name;
            Activity enclosingActivity = Helpers.GetEnclosingActivity(activity);

            if ((name.IndexOf('.') != -1) && (enclosingActivity != null))
            {
                enclosingActivity = Helpers.GetDataSourceActivity(activity, bind.Name, out name);
            }
            if (enclosingActivity == null)
            {
                ValidationError error = new ValidationError(SR.GetString("Error_NoEnclosingContext", new object[] { activity.Name }), 0x130)
                {
                    PropertyName = base.GetFullPropertyName(manager) + ".Name"
                };
                errors.Add(error);
                return(errors);
            }
            ValidationError item            = null;
            Type            dataSourceClass = Helpers.GetDataSourceClass(enclosingActivity, manager);

            if (dataSourceClass == null)
            {
                item = new ValidationError(SR.GetString("Error_TypeNotResolvedInFieldName", new object[] { "Name" }), 0x11f)
                {
                    PropertyName = base.GetFullPropertyName(manager)
                };
            }
            else
            {
                FieldInfo field = dataSourceClass.GetField(name, BindingFlags.FlattenHierarchy | BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance);
                if (field == null)
                {
                    item = new ValidationError(SR.GetString("Error_FieldNotExists", new object[] { base.GetFullPropertyName(manager), name }), 0x120)
                    {
                        PropertyName = base.GetFullPropertyName(manager)
                    };
                }
                else if (field.FieldType == null)
                {
                    item = new ValidationError(SR.GetString("Error_FieldTypeNotResolved", new object[] { base.GetFullPropertyName(manager), name }), 290)
                    {
                        PropertyName = base.GetFullPropertyName(manager)
                    };
                }
                else
                {
                    MemberInfo memberInfo = field;
                    if (((bind.Path == null) || (bind.Path.Length == 0)) && ((validationContext.TargetType != null) && !ActivityBindValidator.DoesTargetTypeMatch(validationContext.TargetType, field.FieldType, validationContext.Access)))
                    {
                        item = new ValidationError(SR.GetString("Error_FieldTypeMismatch", new object[] { base.GetFullPropertyName(manager), field.FieldType.FullName, validationContext.TargetType.FullName }), 0x13f)
                        {
                            PropertyName = base.GetFullPropertyName(manager)
                        };
                    }
                    else if (!string.IsNullOrEmpty(bind.Path))
                    {
                        memberInfo = MemberBind.GetMemberInfo(field.FieldType, bind.Path);
                        if (memberInfo == null)
                        {
                            item = new ValidationError(SR.GetString("Error_InvalidMemberPath", new object[] { name, bind.Path }), 300)
                            {
                                PropertyName = base.GetFullPropertyName(manager) + ".Path"
                            };
                        }
                        else
                        {
                            using ((WorkflowCompilationContext.Current == null) ? WorkflowCompilationContext.CreateScope(manager) : null)
                            {
                                if (WorkflowCompilationContext.Current.CheckTypes)
                                {
                                    item = MemberBind.ValidateTypesInPath(field.FieldType, bind.Path);
                                    if (item != null)
                                    {
                                        item.PropertyName = base.GetFullPropertyName(manager) + ".Path";
                                    }
                                }
                            }
                            if (item == null)
                            {
                                Type memberType = (memberInfo is FieldInfo) ? (memberInfo as FieldInfo).FieldType : (memberInfo as PropertyInfo).PropertyType;
                                if (!ActivityBindValidator.DoesTargetTypeMatch(validationContext.TargetType, memberType, validationContext.Access))
                                {
                                    item = new ValidationError(SR.GetString("Error_TargetTypeDataSourcePathMismatch", new object[] { validationContext.TargetType.FullName }), 0x141)
                                    {
                                        PropertyName = base.GetFullPropertyName(manager) + ".Path"
                                    };
                                }
                            }
                        }
                    }
                    if (item == null)
                    {
                        if (memberInfo is PropertyInfo)
                        {
                            PropertyInfo info3 = memberInfo as PropertyInfo;
                            if (!info3.CanRead && ((validationContext.Access & AccessTypes.Read) != 0))
                            {
                                item = new ValidationError(SR.GetString("Error_PropertyNoGetter", new object[] { info3.Name, bind.Path }), 0x142)
                                {
                                    PropertyName = base.GetFullPropertyName(manager) + ".Path"
                                };
                            }
                            else if (!info3.CanWrite && ((validationContext.Access & AccessTypes.Write) != 0))
                            {
                                item = new ValidationError(SR.GetString("Error_PropertyNoSetter", new object[] { info3.Name, bind.Path }), 0x143)
                                {
                                    PropertyName = base.GetFullPropertyName(manager) + ".Path"
                                };
                            }
                        }
                        else if (memberInfo is FieldInfo)
                        {
                            FieldInfo info4 = memberInfo as FieldInfo;
                            if (((info4.Attributes & (FieldAttributes.Literal | FieldAttributes.InitOnly)) != FieldAttributes.PrivateScope) && ((validationContext.Access & AccessTypes.Write) != 0))
                            {
                                item = new ValidationError(SR.GetString("Error_ReadOnlyField", new object[] { info4.Name }), 0x145)
                                {
                                    PropertyName = base.GetFullPropertyName(manager) + ".Path"
                                };
                            }
                        }
                    }
                }
            }
            if (item != null)
            {
                errors.Add(item);
            }
            return(errors);
        }
        internal static void InternalCompileFromDomBatch(string[] files, string[] codeFiles, WorkflowCompilerParameters parameters, WorkflowCompilerResults results, string localAssemblyPath)
        {
            foreach (string str in parameters.LibraryPaths)
            {
                if (!CheckPathName(str))
                {
                    int num5 = 0x160;
                    WorkflowCompilerError error = new WorkflowCompilerError(string.Empty, 0, 0, num5.ToString(CultureInfo.InvariantCulture), string.Format(CultureInfo.CurrentCulture, SR.GetString("LibraryPathIsInvalid"), new object[] { str }))
                    {
                        IsWarning = true
                    };
                    results.Errors.Add(error);
                }
            }
            IList <AuthorizedType> authorizedTypes = null;

            if (parameters.CheckTypes)
            {
                authorizedTypes = WorkflowCompilationContext.Current.GetAuthorizedTypes();
                if (authorizedTypes == null)
                {
                    ValidationError error2 = new ValidationError(SR.GetString("Error_ConfigFileMissingOrInvalid"), 0x178);
                    results.Errors.Add(CreateXomlCompilerError(error2, parameters));
                    return;
                }
            }
            ITypeProvider service = WorkflowCompilationContext.Current.ServiceProvider.GetService(typeof(ITypeProvider)) as ITypeProvider;
            ArrayList     list2   = new ArrayList();

            using (PDBReader reader = new PDBReader(localAssemblyPath))
            {
                foreach (Type type in service.LocalAssembly.GetTypes())
                {
                    if (TypeProvider.IsAssignable(typeof(Activity), type) && !type.IsAbstract)
                    {
                        string fileLocation = string.Empty;
                        WorkflowMarkupSourceAttribute[] customAttributes = (WorkflowMarkupSourceAttribute[])type.GetCustomAttributes(typeof(WorkflowMarkupSourceAttribute), false);
                        if ((customAttributes != null) && (customAttributes.Length > 0))
                        {
                            fileLocation = customAttributes[0].FileName;
                        }
                        else
                        {
                            ConstructorInfo constructor = type.GetConstructor(Type.EmptyTypes);
                            if (constructor != null)
                            {
                                try
                                {
                                    uint line   = 0;
                                    uint column = 0;
                                    reader.GetSourceLocationForOffset((uint)constructor.MetadataToken, 0, out fileLocation, out line, out column);
                                }
                                catch
                                {
                                }
                            }
                            if (string.IsNullOrEmpty(fileLocation))
                            {
                                MethodInfo info2 = type.GetMethod("InitializeComponent", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance, null, Type.EmptyTypes, null);
                                if (info2 != null)
                                {
                                    try
                                    {
                                        uint num3 = 0;
                                        uint num4 = 0;
                                        reader.GetSourceLocationForOffset((uint)info2.MetadataToken, 0, out fileLocation, out num3, out num4);
                                        if (!string.IsNullOrEmpty(fileLocation))
                                        {
                                            if (fileLocation.EndsWith(".designer.cs", StringComparison.OrdinalIgnoreCase))
                                            {
                                                fileLocation = fileLocation.Substring(0, fileLocation.Length - ".designer.cs".Length) + ".cs";
                                            }
                                            else if (fileLocation.EndsWith(".designer.vb", StringComparison.OrdinalIgnoreCase))
                                            {
                                                fileLocation = fileLocation.Substring(0, fileLocation.Length - ".designer.vb".Length) + ".vb";
                                            }
                                        }
                                    }
                                    catch
                                    {
                                    }
                                }
                            }
                        }
                        Activity activity = null;
                        try
                        {
                            try
                            {
                                Activity.ActivityType = type;
                                activity = Activator.CreateInstance(type) as Activity;
                            }
                            finally
                            {
                                Activity.ActivityType = null;
                            }
                            activity.UserData[UserDataKeys.CustomActivity] = false;
                            if (activity is CompositeActivity)
                            {
                                CompositeActivity activity2 = activity as CompositeActivity;
                                if (activity2.CanModifyActivities)
                                {
                                    results.Errors.Add(CreateXomlCompilerError(new ValidationError(SR.GetString("Error_Missing_CanModifyProperties_False", new object[] { activity.GetType().FullName }), 0x117), parameters));
                                }
                            }
                            if (customAttributes.Length > 0)
                            {
                                DesignerSerializationManager manager = new DesignerSerializationManager(WorkflowCompilationContext.Current.ServiceProvider);
                                Activity activity3 = null;
                                using (manager.CreateSession())
                                {
                                    WorkflowMarkupSerializationManager serializationManager = new WorkflowMarkupSerializationManager(manager)
                                    {
                                        LocalAssembly = parameters.LocalAssembly
                                    };
                                    using (XmlReader reader2 = XmlReader.Create(customAttributes[0].FileName))
                                    {
                                        activity3 = new WorkflowMarkupSerializer().Deserialize(serializationManager, reader2) as Activity;
                                    }
                                }
                                if (activity3 is CompositeActivity)
                                {
                                    ActivityMarkupSerializer.ReplaceChildActivities(activity as CompositeActivity, activity3 as CompositeActivity);
                                }
                            }
                        }
                        catch (TargetInvocationException exception)
                        {
                            if ((exception.InnerException is TypeInitializationException) && (exception.InnerException.InnerException != null))
                            {
                                results.Errors.Add(CreateXomlCompilerError(new ValidationError(SR.GetString("Error_CustomActivityCantCreate", new object[] { type.FullName, exception.InnerException.InnerException.ToString() }), 0x117), parameters));
                            }
                            else if (exception.InnerException.InnerException != null)
                            {
                                results.Errors.Add(CreateXomlCompilerError(new ValidationError(exception.InnerException.InnerException.ToString(), 0x117), parameters));
                            }
                            else
                            {
                                results.Errors.Add(CreateXomlCompilerError(new ValidationError(SR.GetString("Error_CustomActivityCantCreate", new object[] { type.FullName, exception.InnerException.ToString() }), 0x117), parameters));
                            }
                            continue;
                        }
                        catch (Exception exception2)
                        {
                            results.Errors.Add(CreateXomlCompilerError(new ValidationError(SR.GetString("Error_CustomActivityCantCreate", new object[] { type.FullName, exception2.ToString() }), 0x117), parameters));
                            continue;
                        }
                        activity.SetValue(ActivityCodeDomSerializer.MarkupFileNameProperty, fileLocation);
                        activity.SetValue(WorkflowMarkupSerializer.XClassProperty, type.FullName);
                        ValidateActivity(activity, parameters, results);
                        list2.Add(activity);
                    }
                }
            }
            foreach (KeyValuePair <object, Exception> pair in service.TypeLoadErrors)
            {
                int num7 = 0x161;
                WorkflowCompilerError error3 = new WorkflowCompilerError(string.Empty, 0, 0, num7.ToString(CultureInfo.InvariantCulture), pair.Value.Message)
                {
                    IsWarning = true
                };
                results.Errors.Add(error3);
            }
            results.CompiledUnit = WorkflowCompilerInternal.GenerateCodeFromFileBatch(files, parameters, results);
            WorkflowCompilationContext current = WorkflowCompilationContext.Current;

            if (current == null)
            {
                throw new Exception(SR.GetString("Error_MissingCompilationContext"));
            }
            WorkflowMarkupSerializationHelpers.ReapplyRootNamespace(results.CompiledUnit.Namespaces, current.RootNamespace, CompilerHelpers.GetSupportedLanguage(current.Language));
            WorkflowMarkupSerializationHelpers.FixStandardNamespacesAndRootNamespace(results.CompiledUnit.Namespaces, current.RootNamespace, CompilerHelpers.GetSupportedLanguage(current.Language));
            if (!results.Errors.HasErrors)
            {
                CodeGenerationManager manager3 = new CodeGenerationManager(WorkflowCompilationContext.Current.ServiceProvider);
                manager3.Context.Push(results.CompiledUnit.Namespaces);
                foreach (Activity activity4 in list2)
                {
                    if (activity4.Parent == null)
                    {
                        foreach (ActivityCodeGenerator generator in manager3.GetCodeGenerators(activity4.GetType()))
                        {
                            generator.GenerateCode(manager3, activity4);
                        }
                    }
                }
                if (!parameters.GenerateCodeCompileUnitOnly || parameters.CheckTypes)
                {
                    CodeDomProvider codeDomProvider = CompilerHelpers.GetCodeDomProvider(CompilerHelpers.GetSupportedLanguage(parameters.LanguageToUse), parameters.CompilerVersion);
                    ArrayList       list3           = new ArrayList((ICollection)parameters.UserCodeCompileUnits);
                    list3.Add(results.CompiledUnit);
                    ArrayList list4 = new ArrayList();
                    list4.AddRange(codeFiles);
                    list4.AddRange(GenerateFiles(codeDomProvider, parameters, (CodeCompileUnit[])list3.ToArray(typeof(CodeCompileUnit))));
                    CompilerResults results2 = codeDomProvider.CompileAssemblyFromFile(parameters, (string[])list4.ToArray(typeof(string)));
                    results.AddCompilerErrorsFromCompilerResults(results2);
                    results.PathToAssembly            = results2.PathToAssembly;
                    results.NativeCompilerReturnValue = results2.NativeCompilerReturnValue;
                    if (!results.Errors.HasErrors && parameters.CheckTypes)
                    {
                        foreach (string str3 in MetaDataReader.GetTypeRefNames(results2.CompiledAssembly.Location))
                        {
                            bool flag = false;
                            foreach (AuthorizedType type2 in authorizedTypes)
                            {
                                if (type2.RegularExpression.IsMatch(str3))
                                {
                                    flag = string.Compare(bool.TrueString, type2.Authorized, StringComparison.OrdinalIgnoreCase) == 0;
                                    if (!flag)
                                    {
                                        break;
                                    }
                                }
                            }
                            if (!flag)
                            {
                                ValidationError error4 = new ValidationError(SR.GetString("Error_TypeNotAuthorized", new object[] { str3 }), 0x16b);
                                results.Errors.Add(CreateXomlCompilerError(error4, parameters));
                            }
                        }
                    }
                    if (((!results.Errors.HasErrors && !parameters.GenerateCodeCompileUnitOnly) && parameters.GenerateInMemory) && (string.IsNullOrEmpty(parameters.CompilerOptions) || !parameters.CompilerOptions.ToLower(CultureInfo.InvariantCulture).Contains("/delaysign")))
                    {
                        results.CompiledAssembly = results2.CompiledAssembly;
                    }
                }
            }
        }