Ejemplo n.º 1
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;
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
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);
        }
 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;
 }