Пример #1
0
        string GetFileName(ClassMapping clazz)
        {
            var T4   = new Microsoft.VisualStudio.TextTemplating.Engine();
            var host = new CustomHost()
            {
                TemplateFile = "config"
                ,
                Logger = log
            };

            CallContext.LogicalSetData("clazz", clazz);
            string fileName = T4.ProcessTemplate(GetTemplateForOutputName()
                                                 , host
                                                 ).Trim();

            if (host.HasError)
            {
                throw new Exception(); // errors are logged by the engine
            }
            return(fileName);
        }
Пример #2
0
        public override void Render(string savedToPackage, string savedToClass, ClassMapping classMapping, IDictionary class2classmap, StreamWriter writer)
        {
            Microsoft.VisualStudio.TextTemplating.Engine T4;
            CallContext.LogicalSetData("clazz", classMapping);
            CallContext.LogicalSetData("savedToClass", savedToClass);
            CallContext.LogicalSetData("class2classmap", class2classmap);
            T4 = new Microsoft.VisualStudio.TextTemplating.Engine();
            string res = T4.ProcessTemplate(CustomHost.GetTemplateCode(template)
                                            , new CustomHost()
            {
                TemplateFile = template
                , Logger     = log
            }
                                            );

            log.Debug("Generated File:\n" + res);
            writer.Write(res);
            writer.Flush();
            if (writer.BaseStream is FileStream)
            {
                log.Info("Flushed file:" + (writer.BaseStream as FileStream).Name);
            }
        }
Пример #3
0
 string GetFileName(ClassMapping clazz)
 {
     var T4 = new Microsoft.VisualStudio.TextTemplating.Engine();
     var host = new CustomHost()
     {
         TemplateFile = "config"
         ,
         Logger = log
     };
     CallContext.LogicalSetData("clazz", clazz);
     string fileName = T4.ProcessTemplate(GetTemplateForOutputName()
                                 , host
                                 ).Trim();
     if (host.HasError)
         throw new Exception(); // errors are logged by the engine
     return fileName;
 }