protected virtual void Generate(CastleProxyGeneratorOptions options)
        {
            string outputAssemblyPath = options.OutputAssemblyPath;

            Assembly[] inputAssemblies = options.InputAssemblies;

            Configuration nhibernateConfiguration = CreateNHibernateConfiguration(inputAssemblies, options);

            if (nhibernateConfiguration.ClassMappings.Count == 0)
            {
                FailNoClassMappings(inputAssemblies);
            }

            GenerateProxiesResult proxyResult = GenerateProxies(nhibernateConfiguration, options.IntermediateProxyAssemblyPath);

            string staticProxyFactorySourceCode = GenerateStaticProxyFactorySourceCode(proxyResult.Proxies, inputAssemblies[0].GetName().Version);

            CompilerResults result = CompileStaticProxyFactory(nhibernateConfiguration, proxyResult.Assembly, staticProxyFactorySourceCode, options.IntermediateCastleStaticProxyFactoryAssemblyPath);

            if (result.Errors.HasErrors)
            {
                StringBuilder errors = new StringBuilder();
                foreach (CompilerError error in result.Errors)
                {
                    errors.AppendLine(error.ToString());
                }
                throw new ProxyGeneratorException(errors.ToString());
            }

            MergeStaticProxyFactoryWithProxies(result.CompiledAssembly, proxyResult.Assembly, inputAssemblies, outputAssemblyPath);
        }
        protected virtual void CleanUpIntermediateFiles(CastleProxyGeneratorOptions castleOptions)
        {
            if (File.Exists(castleOptions.IntermediateProxyAssemblyPath))
            {
                File.Delete(castleOptions.IntermediateProxyAssemblyPath);
            }

            string intermediateProxyAssemblyPdbPath = Path.ChangeExtension(castleOptions.IntermediateProxyAssemblyPath, "pdb");

            if (File.Exists(intermediateProxyAssemblyPdbPath))
            {
                File.Delete(intermediateProxyAssemblyPdbPath);
            }

            if (File.Exists(castleOptions.IntermediateCastleStaticProxyFactoryAssemblyPath))
            {
                File.Delete(castleOptions.IntermediateCastleStaticProxyFactoryAssemblyPath);
            }

            string intermediateCastleStaticProxyFactoryAssemblyPdbPath = Path.ChangeExtension(castleOptions.IntermediateCastleStaticProxyFactoryAssemblyPath, "pdb");

            if (File.Exists(intermediateCastleStaticProxyFactoryAssemblyPdbPath))
            {
                File.Delete(intermediateCastleStaticProxyFactoryAssemblyPdbPath);
            }
        }
        private static void Generate(object[] args)
        {
            CastleProxyGenerator        proxyGenerator   = (CastleProxyGenerator)args[0];
            CastleProxyGeneratorOptions generatorOptions = (CastleProxyGeneratorOptions)args[1];

            using (AssemblyResolver resolver = new AssemblyResolver(generatorOptions.InputAssemblyPaths))
            {
                generatorOptions.InputAssemblies = resolver.LoadFrom(generatorOptions.InputAssemblyPaths);
                proxyGenerator.Generate(generatorOptions);
            }
        }
        public Assembly Generate(ProxyGeneratorOptions options)
        {
            CastleProxyGeneratorOptions castleOptions = ValidateOptions(options);

            try
            {
                CrossAppDomainCaller.RunInOtherAppDomain(Generate, this, castleOptions);
            }
            finally
            {
                CleanUpIntermediateFiles(castleOptions);
            }

            return(Assembly.LoadFrom(options.OutputAssemblyPath));
        }
Beispiel #5
0
        protected virtual void CleanUpIntermediateFiles(CastleProxyGeneratorOptions castleOptions)
        {
            if (File.Exists(castleOptions.IntermediateProxyAssemblyPath))
            {
                File.Delete(castleOptions.IntermediateProxyAssemblyPath);
            }

            string intermediateProxyAssemblyPdbPath = Path.ChangeExtension(castleOptions.IntermediateProxyAssemblyPath, "pdb");
            if (File.Exists(intermediateProxyAssemblyPdbPath))
            {
                File.Delete(intermediateProxyAssemblyPdbPath);
            }

            if (File.Exists(castleOptions.IntermediateCastleStaticProxyFactoryAssemblyPath))
            {
                File.Delete(castleOptions.IntermediateCastleStaticProxyFactoryAssemblyPath);
            }

            string intermediateCastleStaticProxyFactoryAssemblyPdbPath = Path.ChangeExtension(castleOptions.IntermediateCastleStaticProxyFactoryAssemblyPath, "pdb");
            if (File.Exists(intermediateCastleStaticProxyFactoryAssemblyPdbPath))
            {
                File.Delete(intermediateCastleStaticProxyFactoryAssemblyPdbPath);
            }
        }
        public CastleProxyGeneratorOptions ValidateOptions(ProxyGeneratorOptions options)
        {
            CastleProxyGeneratorOptions castleOptions = options as CastleProxyGeneratorOptions;

            if (castleOptions == null)
            {
                throw new ProxyGeneratorException("options must be of type {0}", typeof(CastleProxyGeneratorOptions).Name);
            }

            if (string.IsNullOrEmpty(castleOptions.OutputAssemblyPath))
            {
                throw new ProxyGeneratorException("options.OutputAssemblyPath is Required");
            }

            if (!Path.IsPathRooted(castleOptions.OutputAssemblyPath))
            {
                castleOptions.OutputAssemblyPath = Path.GetFullPath(castleOptions.OutputAssemblyPath);
            }

            if (castleOptions.InputAssemblyPaths == null || castleOptions.InputAssemblyPaths.Length == 0)
            {
                throw new ProxyGeneratorException("At least one input assembly is required");
            }

            if (string.IsNullOrEmpty(castleOptions.IntermediateProxyAssemblyPath))
            {
                castleOptions.IntermediateProxyAssemblyPath = ModuleScope.DEFAULT_FILE_NAME;
            }

            if (string.IsNullOrEmpty(castleOptions.IntermediateCastleStaticProxyFactoryAssemblyPath))
            {
                castleOptions.IntermediateCastleStaticProxyFactoryAssemblyPath = typeof(CastleStaticProxyFactory).Name + ".dll";
            }

            return(castleOptions);
        }
Beispiel #7
0
        protected virtual void Generate( CastleProxyGeneratorOptions options )
        {
            string outputAssemblyPath = options.OutputAssemblyPath;

            Assembly[] inputAssemblies = options.InputAssemblies;

            Configuration nhibernateConfiguration = CreateNHibernateConfiguration(inputAssemblies, options );
            if (nhibernateConfiguration.ClassMappings.Count == 0) FailNoClassMappings(inputAssemblies);

            GenerateProxiesResult proxyResult = GenerateProxies(nhibernateConfiguration, options.IntermediateProxyAssemblyPath);

            string staticProxyFactorySourceCode = GenerateStaticProxyFactorySourceCode(proxyResult.Proxies, inputAssemblies[0].GetName().Version);

            CompilerResults result = CompileStaticProxyFactory(nhibernateConfiguration, proxyResult.Assembly, staticProxyFactorySourceCode, options.IntermediateCastleStaticProxyFactoryAssemblyPath);

            if (result.Errors.HasErrors)
            {
                StringBuilder errors = new StringBuilder();
                foreach (CompilerError error in result.Errors)
                {
                    errors.AppendLine(error.ToString());
                }
                throw new ProxyGeneratorException(errors.ToString());
            }

            MergeStaticProxyFactoryWithProxies(result.CompiledAssembly, proxyResult.Assembly, inputAssemblies, outputAssemblyPath);
        }