コード例 #1
0
        private byte[] InternalCompile(AppDomain compilationTempAppDomain, bool refusePermissions)
        {
            if (this.m_builder.HasExpressions)
            {
                CompilerParameters compilerParameters = new CompilerParameters();
                compilerParameters.OutputAssembly          = System.IO.Path.Combine(Path.GetTempPath(), this.m_expressionHostAssemblyHolder.ExprHostAssemblyName, "ExpressionHost.dll");
                compilerParameters.TempFiles               = new TempFileCollection(Path.GetDirectoryName(compilerParameters.OutputAssembly));
                compilerParameters.GenerateExecutable      = false;
                compilerParameters.GenerateInMemory        = false;
                compilerParameters.IncludeDebugInformation = false;
                compilerParameters.ReferencedAssemblies.Add(typeof(AspNetCore.Reporting.InternalLocalReport).Assembly.Location);
                compilerParameters.ReferencedAssemblies.Add(AppDomain.CurrentDomain.GetAssemblies().Where(t => t.FullName.Contains("netstandard,")).FirstOrDefault().Location);
                //compilerParameters.ReferencedAssemblies.Add("System.dll");
                //compilerParameters.ReferencedAssemblies.Add("mscorlib.dll");
                //compilerParameters.ReferencedAssemblies.Add(Path.Combine(compilationTempAppDomain.BaseDirectory, "Microsoft.SqlServer.Types.dll"));
                //compilerParameters.ReferencedAssemblies.Add(Path.Combine(compilationTempAppDomain.BaseDirectory, "Microsoft.ReportViewer.Common.dll"));
                //compilerParameters.ReferencedAssemblies.Add(Path.Combine(compilationTempAppDomain.BaseDirectory, "Microsoft.ReportViewer.ProcessingObjectModel.dll"));
                //compilerParameters.ReferencedAssemblies.Add(typeof(SqlGeography).Assembly.Location);
                //CompilerParameters compilerParameters2 = compilerParameters;
                compilerParameters.CompilerOptions += this.m_langParser.GetCompilerArguments();
                if (this.m_expressionHostAssemblyHolder.CodeModules != null)
                {
                    this.ResolveAssemblylocations(this.m_expressionHostAssemblyHolder.CodeModules, compilerParameters, this.m_errorContext, compilationTempAppDomain);
                }
                CompilerResults compilerResults = null;
                try
                {
                    ProcessingIntermediateFormatVersion version = new ProcessingIntermediateFormatVersion(AspNetCore.ReportingServices.ReportIntermediateFormat.Persistence.IntermediateFormatVersion.Current);
                    CodeCompileUnit exprHost = this.m_builder.GetExprHost(version, refusePermissions);
                    this.m_expressionHostAssemblyHolder.CompiledCodeGeneratedWithRefusedPermissions = refusePermissions;
                    CodeDomProvider codeCompiler = this.m_langParser.GetCodeCompiler();
                    compilerResults = codeCompiler.CompileAssemblyFromDom(compilerParameters, exprHost);

                    if (compilerResults == null)
                    {
                        throw new Exception("CompileAssemblyFromDom fail.");
                    }
                    if (Global.Tracer.TraceVerbose)
                    {
                        try
                        {
                            using (MemoryStream memoryStream = new MemoryStream())
                            {
                                IndentedTextWriter indentedTextWriter = new IndentedTextWriter(new StreamWriter(memoryStream), "    ");
                                codeCompiler.GenerateCodeFromCompileUnit(exprHost, indentedTextWriter, new CodeGeneratorOptions());
                                indentedTextWriter.Flush();
                                memoryStream.Position = 0L;
                                StreamReader streamReader = new StreamReader(memoryStream);
                                Global.Tracer.Trace(streamReader.ReadToEnd().MarkAsPrivate());
                            }
                        }
                        catch
                        {
                        }
                    }
                    if (compilerResults.NativeCompilerReturnValue == 0 && compilerResults.Errors.Count <= 0)
                    {
                        using (FileStream fileStream = File.OpenRead(compilerResults.PathToAssembly))
                        {
                            byte[] array = new byte[fileStream.Length];
                            int    num   = fileStream.Read(array, 0, (int)fileStream.Length);
                            Global.Tracer.Assert(num == fileStream.Length, "(read == fs.Length)");
                            return(array);
                        }
                    }
                    this.ParseErrors(compilerResults);
                    return(new byte[0]);
                }
                finally
                {
                    Directory.Delete(compilerParameters.TempFiles.TempDir, true);
                }
            }
            return(new byte[0]);
        }
コード例 #2
0
        private byte[] InternalCompile(AppDomain compilationTempAppDomain, bool refusePermissions)
        {
            if (m_builder.HasExpressions)
            {
                CompilerParameters compilerParameters = new CompilerParameters();
                compilerParameters.OutputAssembly          = string.Format(CultureInfo.InvariantCulture, "{0}{1}.dll", Path.GetTempPath(), m_expressionHostAssemblyHolder.ExprHostAssemblyName);
                compilerParameters.GenerateExecutable      = false;
                compilerParameters.GenerateInMemory        = false;
                compilerParameters.IncludeDebugInformation = false;
                compilerParameters.ReferencedAssemblies.Add("System.dll");

                string pathForRV = typeof(ReportObjectModelProxy).Assembly.Location;
                if (String.IsNullOrEmpty(pathForRV))
                {
                    pathForRV = System.Reflection.Assembly.GetExecutingAssembly().Location;
                }
                if (String.IsNullOrEmpty(pathForRV))
                {
                    pathForRV = Process.GetCurrentProcess().MainModule.FileName;
                }
                compilerParameters.ReferencedAssemblies.Add(pathForRV);

                compilerParameters.CompilerOptions += m_langParser.GetCompilerArguments();
                if (m_expressionHostAssemblyHolder.CodeModules != null)
                {
                    ResolveAssemblylocations(m_expressionHostAssemblyHolder.CodeModules, compilerParameters, m_errorContext, compilationTempAppDomain);
                }
                CompilerResults compilerResults = null;
                try
                {
                    ProcessingIntermediateFormatVersion version = new ProcessingIntermediateFormatVersion(Microsoft.ReportingServices.ReportIntermediateFormat.Persistence.IntermediateFormatVersion.Current);
                    CodeCompileUnit exprHost = m_builder.GetExprHost(version, refusePermissions);
                    m_expressionHostAssemblyHolder.CompiledCodeGeneratedWithRefusedPermissions = refusePermissions;
                    CodeDomProvider codeCompiler = m_langParser.GetCodeCompiler();
                    compilerResults = codeCompiler.CompileAssemblyFromDom(compilerParameters, exprHost);
                    if (Global.Tracer.TraceVerbose)
                    {
                        try
                        {
                            using (MemoryStream memoryStream = new MemoryStream())
                            {
                                IndentedTextWriter indentedTextWriter = new IndentedTextWriter(new StreamWriter(memoryStream), "    ");
                                codeCompiler.GenerateCodeFromCompileUnit(exprHost, indentedTextWriter, new CodeGeneratorOptions());
                                indentedTextWriter.Flush();
                                memoryStream.Position = 0L;
                                StreamReader streamReader = new StreamReader(memoryStream);
                                Global.Tracer.Trace(streamReader.ReadToEnd().MarkAsPrivate());
                            }
                        }
                        catch
                        {
                        }
                    }
                    if (compilerResults.NativeCompilerReturnValue != 0 || compilerResults.Errors.Count > 0)
                    {
                        ParseErrors(compilerResults);
                        return(new byte[0]);
                    }
                    using (FileStream fileStream = File.OpenRead(compilerResults.PathToAssembly))
                    {
                        byte[] array = new byte[fileStream.Length];
                        int    num   = fileStream.Read(array, 0, (int)fileStream.Length);
                        Global.Tracer.Assert(num == fileStream.Length, "(read == fs.Length)");
                        return(array);
                    }
                }
                finally
                {
                    if (compilerResults != null && compilerResults.PathToAssembly != null)
                    {
                        File.Delete(compilerResults.PathToAssembly);
                    }
                }
            }
            return(new byte[0]);
        }