public virtual void Initialize(ITextTemplatingEngineHost host)
 {
     if (host == null)
     {
         throw new ArgumentException();
     }
 }
 public override void Initialize(ITextTemplatingEngineHost host)
 {
     if (host == null)
     {
         throw new ArgumentNullException("host");
     }
     base.Initialize(host);
     this.templatingHost = host;
 }
Exemple #3
0
        public string ProcessTemplate(string content, ITextTemplatingEngineHost host)
        {
            AppDomain             appdomain = host.ProvideTemplatingAppDomain(content);
            ITextTemplatingEngine engine;

            if (appdomain != null)
            {
                engine = (ITextTemplatingEngine)
                         appdomain.CreateInstanceAndUnwrap(typeof(TemplatingEngine).Assembly.FullName,
                                                           typeof(TemplatingEngine).FullName);
            }
            else
            {
                engine = new TemplatingEngine();
            }

            return(engine.ProcessTemplate(content, host));
        }
 public string PreprocessTemplate(string content, ITextTemplatingEngineHost host, string className,
                                  string classNamespace, out string language, out string[] references)
 {
     return(engine.PreprocessTemplate(content, host, className, classNamespace, out language, out references));
 }
 public string ProcessTemplate(string content, ITextTemplatingEngineHost host)
 {
     return(engine.ProcessTemplate(content, host));
 }
Exemple #6
0
 public override void Initialize(ITextTemplatingEngineHost host)
 {
     base.Initialize(host);
     this.host = host;
 }
        private TextTransformation CreateTextTransformation(string fullClassName, ITextTemplatingEngineHost host, Assembly assembly, ITextTemplatingSession userSession)
        {
            object obj2 = null;

            try
            {
                obj2 = assembly.CreateInstance(fullClassName);
                if (obj2 == null)
                {
                    this.LogError(Resources.ExceptionInstantiatingTransformationObject, false);
                    return(null);
                }
                Type transformationType = obj2.GetType();
                if (host != null)
                {
                    try
                    {
                        transformationType.GetProperty("Host").SetValue(obj2, host, null);
                    }
                    catch (Exception exception)
                    {
                        if (Engine.IsCriticalException(exception))
                        {
                            throw;
                        }
                        this.LogError(string.Format(CultureInfo.CurrentCulture, Resources.ExceptionSettingHost, new object[] { transformationType.FullName }), false);
                    }
                }
                try
                {
                    PropertyInfo mostDerivedProperty = GetMostDerivedProperty(transformationType, "Session");
                    if (mostDerivedProperty != null)
                    {
                        mostDerivedProperty.SetValue(obj2, userSession, null);
                    }
                }
                catch (Exception exception2)
                {
                    if (Engine.IsCriticalException(exception2))
                    {
                        throw;
                    }
                    this.LogError(string.Format(CultureInfo.CurrentCulture, Resources.ExceptionSettingSession, new object[] { transformationType.FullName }), false);
                }
                return((TextTransformation)obj2);
            }
            catch (Exception exception3)
            {
                if (Engine.IsCriticalException(exception3))
                {
                    IDisposable disposable = obj2 as IDisposable;
                    if (disposable != null)
                    {
                        disposable.Dispose();
                    }
                    throw;
                }
                this.LogError(Resources.ExceptionInstantiatingTransformationObject + string.Format(CultureInfo.CurrentCulture, Resources.Exception, new object[] { exception3.ToString() }), false);
            }
            return(null);
        }
        public void RunTransformation(TemplateProcessingSession session, string source, ITextTemplatingEngineHost host, out string result)
        {
            ToStringHelper.FormatProvider = session.FormatProvider;
            CodeDomProvider codeDomProvider = session.CodeDomProvider;
            string          errorOutput     = Resources.ErrorOutput;
            bool            validBaseClass  = string.IsNullOrEmpty(session.BaseClassName);
            Assembly        assembly        = null;

            try
            {
                if (this.ValidateBaseClass(session.BaseClassName, session.ImportDirectives, validBaseClass))
                {
                    session.AssemblyDirectives.Add(base.GetType().Assembly.Location);
                    session.AssemblyDirectives.Add(typeof(ITextTemplatingEngineHost).Assembly.Location);
                    assembly = this.LocateAssembly(session.CacheAssemblies, session.ClassFullName, source, session.TemplateFile, session.Debug, codeDomProvider, session.AssemblyDirectives, session.CompilerOptions);
                }
                if (assembly != null)
                {
                    using (TextTransformation transformation = this.CreateTextTransformation(session.ClassFullName, host, assembly, session.UserTransformationSession))
                    {
                        if (transformation != null)
                        {
                            try
                            {
                                transformation.Initialize();
                            }
                            catch (Exception exception)
                            {
                                if (Engine.IsCriticalException(exception))
                                {
                                    throw;
                                }
                                this.LogError(Resources.ErrorInitializingTransformationObject + string.Format(CultureInfo.CurrentCulture, Resources.Exception, new object[] { exception.ToString() }), false);
                            }
                            if (!transformation.Errors.HasErrors && !this.Errors.HasErrors)
                            {
                                try
                                {
                                    errorOutput = transformation.TransformText();
                                }
                                catch (Exception exception2)
                                {
                                    if (Engine.IsCriticalException(exception2))
                                    {
                                        throw;
                                    }
                                    if (exception2.Data["TextTemplatingProgress"] != null)
                                    {
                                        errorOutput = exception2.Data["TextTemplatingProgress"].ToString();
                                    }
                                    ArgumentNullException exception3 = exception2 as ArgumentNullException;
                                    if ((exception3 != null) && (StringComparer.OrdinalIgnoreCase.Compare(exception3.ParamName, "objectToConvert") == 0))
                                    {
                                        this.LogError(Resources.ExpressionBlockNull + Environment.NewLine + exception3.StackTrace, false);
                                    }
                                    else
                                    {
                                        this.LogError(Resources.TransformationErrorPrepend + exception2.ToString(), false);
                                    }
                                }
                            }
                            foreach (CompilerError error in transformation.Errors)
                            {
                                error.ErrorText = Resources.TransformationErrorPrepend + error.ErrorText;
                            }
                            this.Errors.AddRange(transformation.Errors);
                        }
                    }
                }
            }
            catch (Exception exception4)
            {
                if (Engine.IsCriticalException(exception4))
                {
                    throw;
                }
                this.LogError(Resources.ExceptionWhileRunningCode + string.Format(CultureInfo.CurrentCulture, Resources.Exception, new object[] { exception4.ToString() }), false);
            }
            result = errorOutput;
        }
 public virtual void Initialize(ITextTemplatingEngineHost host)
 {
 }
Exemple #10
0
 public override void Initialize(ITextTemplatingEngineHost host)
 {
     base.Initialize(host);
     this.host = host;
     throw new NotImplementedException();
 }
Exemple #11
0
 public static void Initialize(Microsoft.VisualStudio.TextTemplating.ITextTemplatingEngineHost BaseHost)
 {
     SharpInclude.Host            = BaseHost;
     Environment.CurrentDirectory = Path.GetDirectoryName(Host.TemplateFile);
 }