protected static TypeProvider CreateTypeProvider(Activity rootActivity)
        {
            TypeProvider typeProvider = new TypeProvider(null);

            Type companionType = rootActivity.GetType();
            typeProvider.SetLocalAssembly(companionType.Assembly);
            typeProvider.AddAssembly(companionType.Assembly);

            foreach (AssemblyName assemblyName in companionType.Assembly.GetReferencedAssemblies())
            {
                Assembly referencedAssembly = null;
                try
                {
                    referencedAssembly = Assembly.Load(assemblyName);
                    if (referencedAssembly != null)
                    {
                        typeProvider.AddAssembly(referencedAssembly);
                    }
                }
                catch (Exception e)
                {
                    if (Fx.IsFatal(e))
                    {
                        throw;
                    }
                }

                if (referencedAssembly == null && assemblyName.CodeBase != null)
                {
                    typeProvider.AddAssemblyReference(assemblyName.CodeBase);
                }
            }

            return typeProvider;
        }
Пример #2
0
        public RuleSetDialog(Activity activity, RuleSet ruleSet)
        {
            if (activity == null)
                throw (new ArgumentNullException("activity"));

            InitializeDialog(ruleSet);

            ITypeProvider typeProvider;
            this.serviceProvider = activity.Site;
            if (this.serviceProvider != null)
            {
                typeProvider = (ITypeProvider)this.serviceProvider.GetService(typeof(ITypeProvider));
                if (typeProvider == null)
                {
                    string message = string.Format(CultureInfo.CurrentCulture, Messages.MissingService, typeof(ITypeProvider).FullName);
                    throw new InvalidOperationException(message);
                }

                WorkflowDesignerLoader loader = this.serviceProvider.GetService(typeof(WorkflowDesignerLoader)) as WorkflowDesignerLoader;
                if (loader != null)
                    loader.Flush();

            }
            else
            {
                // no service provider, so make a TypeProvider that has all loaded Assemblies
                TypeProvider newProvider = new TypeProvider(null);
                foreach (Assembly a in AppDomain.CurrentDomain.GetAssemblies())
                    newProvider.AddAssembly(a);
                typeProvider = newProvider;
            }

            RuleValidation validation = new RuleValidation(activity, typeProvider, false);
            this.ruleParser = new Parser(validation);
        }
Пример #3
0
        /// <summary>
        /// Display the specified workflow type.
        /// </summary>
        /// <param name="root">Type of the workflow.</param>
        public void DisplayType(Type root)
        {
            if (!typeof(Activity).IsAssignableFrom(root))
            {
                throw new ArgumentException("WorkflowViewPanel only supports displaying Activity objects.", "root");
            }

            this.surface = new DesignSurface();
            
            this.host = this.surface.GetService(typeof(IDesignerHost)) as IDesignerHost;

            TypeProvider provider = new TypeProvider(this.surface);
            provider.AddAssembly(typeof(string).Assembly);
            IServiceContainer container = this.surface.GetService(typeof(IServiceContainer)) as IServiceContainer;
            container.AddService(typeof(ITypeProvider), provider);

            if (this.host == null)
            {
                throw new ApplicationException("Cannot work with a null host.");
            }

            Queue<Activity> toProcess = new Queue<Activity>();

            try
            {
                toProcess.Enqueue((Activity)root.InvokeMember(string.Empty, System.Reflection.BindingFlags.CreateInstance, null, null, null, CultureInfo.InvariantCulture));
            }
            catch (Exception exc)
            {
                MessageBox.Show("Could not load workflow type: " + exc.ToString());
                this.surface = null;
                this.host = null;
                return;
            }

            // Do a non-recursive walk of the activity
            // tree to display all activities.
            while (toProcess.Count > 0)
            {
                Activity activity = toProcess.Dequeue();
                host.Container.Add(activity, activity.QualifiedName);

                if (activity is CompositeActivity)
                {
                    foreach (Activity child in ((CompositeActivity)activity).Activities)
                    {
                        toProcess.Enqueue(child);
                    }
                }
            }

            this.surface.BeginLoad(new WorkflowLoader());

            workflowView = new MouseDisabledWorkflowView(host as IServiceProvider);
            workflowView.Dock = DockStyle.Fill;

            this.Controls.Add(workflowView);
        }
Пример #4
0
        public static void DesignRule(System.Workflow.ComponentModel.Activity activity, bool UseProvider)
        {
            RuleSet ruleSet = null;
            //MessageBox.Show(activity.UserData[0].ToString());
            //MessageBox.Show(activity.GetType().ToString());
            string ruleName = activity.UserData[0].ToString();

            //load ruleset
            try
            {
                ruleSet = RuleSetManagerFactory.CreateRuleSetManager(RuleDesigner.RemotingUrl).getRuleSetDesign("", "", ruleName);
            }
            catch (Exception e)
            {
                MessageBox.Show("Error deserializing file: " + ruleName + e.Message);
            }

            if (ruleSet == null)
            {
                MessageBox.Show("RuleSet is null");
                ruleSet = new RuleSet(ruleName);
            }

            RuleSetDialog ruleSetDialog = null;
            if (UseProvider)
            {
                TypeProvider provider = new TypeProvider(null);
                AssemblyName[] ass = activity.GetType().Assembly.GetReferencedAssemblies();
                provider.AddAssembly(activity.GetType().Assembly);
                FillWithAssemblies(provider, ass);
                ruleSetDialog = new RuleSetDialog(activity.GetType(), provider, ruleSet);
            }
            else
            {
                ruleSetDialog = new RuleSetDialog(activity, ruleSet);
            }

            var result = ruleSetDialog.ShowDialog();

            // Only update the .rules file if the OK is pressed 
            if (result == DialogResult.OK)
            {
                ruleSet = ruleSetDialog.RuleSet;
                try
                {
                    Console.WriteLine(ruleName);
                    RuleSetManagerFactory.CreateRuleSetManager(RuleDesigner.RemotingUrl).saveRuleSetDesign("", "", ruleName, ruleSet);
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.ToString());
                }
            }
        }
Пример #5
0
 private static void FillWithAssemblies(TypeProvider provider, AssemblyName[] assbls)
 {
     if (provider != null && assbls != null && assbls.Length > 0)
     {
         foreach (AssemblyName assbl in assbls)
         {
             Assembly asb = Assembly.Load(assbl);
             if (asb != null)
                 provider.AddAssembly(asb);
         }
     }
 }
 public RuleConditionDialog(Activity activity, CodeExpression expression)
 {
     ITypeProvider provider;
     this.ruleExpressionCondition = new RuleExpressionCondition();
     if (activity == null)
     {
         throw new ArgumentNullException("activity");
     }
     this.InitializeComponent();
     this.serviceProvider = activity.Site;
     if (this.serviceProvider != null)
     {
         IUIService service = this.serviceProvider.GetService(typeof(IUIService)) as IUIService;
         if (service != null)
         {
             this.Font = (Font) service.Styles["DialogFont"];
         }
         provider = (ITypeProvider) this.serviceProvider.GetService(typeof(ITypeProvider));
         if (provider == null)
         {
             throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Messages.MissingService, new object[] { typeof(ITypeProvider).FullName }));
         }
         WorkflowDesignerLoader loader = this.serviceProvider.GetService(typeof(WorkflowDesignerLoader)) as WorkflowDesignerLoader;
         if (loader != null)
         {
             loader.Flush();
         }
     }
     else
     {
         TypeProvider provider2 = new TypeProvider(null);
         foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
         {
             provider2.AddAssembly(assembly);
         }
         provider = provider2;
     }
     RuleValidation validation = new RuleValidation(activity, provider, false);
     this.ruleParser = new Parser(validation);
     this.InitializeDialog(expression);
 }
        public RuleConditionDialog(Activity activity, CodeExpression expression)
        {
            if (activity == null)
                throw (new ArgumentNullException("activity"));

            InitializeComponent();

            ITypeProvider typeProvider;
            serviceProvider = activity.Site;
            if (serviceProvider != null)
            {
                IUIService uisvc = serviceProvider.GetService(typeof(IUIService)) as IUIService;
                if (uisvc != null)
                    this.Font = (Font)uisvc.Styles["DialogFont"];
                typeProvider = (ITypeProvider)serviceProvider.GetService(typeof(ITypeProvider));
                if (typeProvider == null)
                {
                    string message = string.Format(CultureInfo.CurrentCulture, Messages.MissingService, typeof(ITypeProvider).FullName);
                    throw new InvalidOperationException(message);
                }

                WorkflowDesignerLoader loader = serviceProvider.GetService(typeof(WorkflowDesignerLoader)) as WorkflowDesignerLoader;
                if (loader != null)
                    loader.Flush();
            }
            else
            {
                // no service provider, so make a TypeProvider that has all loaded Assemblies
                TypeProvider newProvider = new TypeProvider(null);
                foreach (Assembly a in AppDomain.CurrentDomain.GetAssemblies())
                    newProvider.AddAssembly(a);
                typeProvider = newProvider;
            }

            RuleValidation validation = new RuleValidation(activity, typeProvider, false);
            this.ruleParser = new Parser(validation);

            InitializeDialog(expression);
        }
Пример #8
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 Bug 17591: we must set the local assembly here,
                        // otherwise, the resolver won't be able to resolve custom types correctly.
                        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;
        }
 internal static TypeProvider CreateTypeProvider(Activity rootActivity)
 {
     TypeProvider provider = new TypeProvider(null);
     Type type = rootActivity.GetType();
     provider.SetLocalAssembly(type.Assembly);
     provider.AddAssembly(type.Assembly);
     foreach (AssemblyName name in type.Assembly.GetReferencedAssemblies())
     {
         Assembly assembly = null;
         try
         {
             assembly = Assembly.Load(name);
             if (assembly != null)
             {
                 provider.AddAssembly(assembly);
             }
         }
         catch
         {
         }
         if ((assembly == null) && (name.CodeBase != null))
         {
             provider.AddAssemblyReference(name.CodeBase);
         }
     }
     return provider;
 }
Пример #10
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);
        }
        internal static TypeProvider CreateTypeProvider(Activity rootActivity)
        {
            TypeProvider typeProvider = new TypeProvider(null);

            Type companionType = rootActivity.GetType();
            typeProvider.SetLocalAssembly(companionType.Assembly);
            typeProvider.AddAssembly(companionType.Assembly);

            foreach (AssemblyName assemblyName in companionType.Assembly.GetReferencedAssemblies())
            {
                Assembly referencedAssembly = null;
                try
                {
                    referencedAssembly = Assembly.Load(assemblyName);
                    if (referencedAssembly != null)
                        typeProvider.AddAssembly(referencedAssembly);
                }
                catch
                {
                }

                if (referencedAssembly == null && assemblyName.CodeBase != null)
                    typeProvider.AddAssemblyReference(assemblyName.CodeBase);
            }
            return typeProvider;
        }
Пример #12
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);
        }
 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;
 }
 public RuleSetDialog(Activity activity, System.Workflow.Activities.Rules.RuleSet ruleSet)
 {
     ITypeProvider service;
     this.sortOrder = new bool[4];
     if (activity == null)
     {
         throw new ArgumentNullException("activity");
     }
     this.InitializeDialog(ruleSet);
     this.serviceProvider = activity.Site;
     if (this.serviceProvider != null)
     {
         service = (ITypeProvider) this.serviceProvider.GetService(typeof(ITypeProvider));
         if (service == null)
         {
             throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Messages.MissingService, new object[] { typeof(ITypeProvider).FullName }));
         }
         WorkflowDesignerLoader loader = this.serviceProvider.GetService(typeof(WorkflowDesignerLoader)) as WorkflowDesignerLoader;
         if (loader != null)
         {
             loader.Flush();
         }
     }
     else
     {
         TypeProvider provider2 = new TypeProvider(null);
         foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
         {
             provider2.AddAssembly(assembly);
         }
         service = provider2;
     }
     RuleValidation validation = new RuleValidation(activity, service, false);
     this.ruleParser = new Parser(validation);
 }