Inheritance: IGenerationHost, IDisposable
Beispiel #1
0
 public virtual int ExecuteTemplate()
 {
     #if USE_APP_DOMAIN
     // Execute the (initial) template by GenerationHost in separate AppDomain:
     AppDomain appDomain = null;
     GenerationHost genHost = null;
     try
     {
         AppDomainSetup info = new AppDomainSetup();
         info.ApplicationBase = new FileInfo(Assembly.GetEntryAssembly().Location).Directory.FullName;
         info.ShadowCopyFiles = "true";
         appDomain = AppDomain.CreateDomain("CodeGenSpace", AppDomain.CurrentDomain.Evidence, info);
         genHost = (GenerationHost)appDomain.CreateInstance(typeof(GenerationHost).Assembly.FullName, typeof(GenerationHost).FullName).Unwrap();
         genHost.Initialize(this.Settings);
         return this.ExecuteTemplate(genHost);
     }
     finally
     {
         if (genHost != null) genHost.Dispose();
         if (appDomain != null) AppDomain.Unload(appDomain);
     }
     #else
     // execute the generationhost locally
     using (ResourceBasedGenerationHost genHost = new ResourceBasedGenerationHost())
     {
         genHost.Initialize(this.Settings);
         return this.ExecuteTemplate(genHost);
     }
     #endif
 }
Beispiel #2
0
        public virtual int ExecuteTemplate(ResourceBasedGenerationHost genHost, string templateFilename, string outputFilename, object[] templateParameters)
        {
            if (genHost == null)
            {
                throw new ArgumentNullException("genHost");
            }

            using (log4net.NDC.Push(templateFilename))
            {
                try
                {
                    if (Log.IsDebugEnabled)
                    {
                        Log.DebugFormat("Executing template");
                    }
                    genHost.Initialize(this.Settings);
                    genHost.CallTemplateToFile(templateFilename, outputFilename, templateParameters);
                    return(0);
                }
                catch (CompilationFailedException ex)
                {
                    Log.Error("Template compilation failed", ex);
                    foreach (CompilerError err in ex.Errors)
                    {
                        Log.WarnFormat("{0} {1}: {2}\r\n  \"{3}\", line #{4}",
                                       err.IsWarning ? "Warning" : "Error",
                                       err.ErrorNumber,
                                       err.ErrorText,
                                       err.FileName,
                                       err.Line);
                    }
                    throw;
                }
            }
        }
Beispiel #3
0
        public virtual int ExecuteTemplate()
        {
#if USE_APP_DOMAIN
            // Execute the (initial) template by GenerationHost in separate AppDomain:
            AppDomain      appDomain = null;
            GenerationHost genHost   = null;
            try
            {
                AppDomainSetup info = new AppDomainSetup();
                info.ApplicationBase = new FileInfo(Assembly.GetEntryAssembly().Location).Directory.FullName;
                info.ShadowCopyFiles = "true";
                appDomain            = AppDomain.CreateDomain("CodeGenSpace", AppDomain.CurrentDomain.Evidence, info);
                genHost = (GenerationHost)appDomain.CreateInstance(typeof(GenerationHost).Assembly.FullName, typeof(GenerationHost).FullName).Unwrap();
                genHost.Initialize(this.Settings);
                return(this.ExecuteTemplate(genHost));
            }
            finally
            {
                if (genHost != null)
                {
                    genHost.Dispose();
                }
                if (appDomain != null)
                {
                    AppDomain.Unload(appDomain);
                }
            }
#else
            // execute the generationhost locally
            using (ResourceBasedGenerationHost genHost = new ResourceBasedGenerationHost())
            {
                genHost.Initialize(this.Settings);
                return(this.ExecuteTemplate(genHost));
            }
#endif
        }
Beispiel #4
0
        public virtual int ExecuteTemplate(ResourceBasedGenerationHost genHost, string templateFilename, string outputFilename, object[] templateParameters)
        {
            if (genHost == null) { throw new ArgumentNullException("genHost"); }

            using (log4net.NDC.Push(templateFilename))
            {
                try
                {
                    if (Log.IsDebugEnabled)
                    {
                        Log.DebugFormat("Executing template");
                    }
                    genHost.Initialize(this.Settings);
                    genHost.CallTemplateToFile(templateFilename, outputFilename, templateParameters);
                    return 0;
                }
                catch (CompilationFailedException ex)
                {
                    Log.Error("Template compilation failed", ex);
                    foreach (CompilerError err in ex.Errors)
                    {
                        Log.WarnFormat("{0} {1}: {2}\r\n  \"{3}\", line #{4}",
                            err.IsWarning ? "Warning" : "Error",
                            err.ErrorNumber,
                            err.ErrorText,
                            err.FileName,
                            err.Line);
                    }
                    throw;
                }
            }
        }
Beispiel #5
0
 public virtual int ExecuteTemplate(ResourceBasedGenerationHost genHost)
 {
     return this.ExecuteTemplate(genHost, this.Settings["template"], this.Settings["output"], this.TemplateParameters);
 }
Beispiel #6
0
 public virtual int ExecuteTemplate(ResourceBasedGenerationHost genHost)
 {
     return(this.ExecuteTemplate(genHost, this.Settings["template"], this.Settings["output"], this.TemplateParameters));
 }