예제 #1
0
        protected virtual IEnumerable <TextFile> ProcessEntityTypes(TemplateFileInfo templateInfo)
        {
            var entityTypes = CurrentModel.GetEntityTypes();

            foreach (OdcmObject entityType in entityTypes)
            {
                yield return(ProcessTemplate(templateInfo, entityType));
            }
        }
예제 #2
0
        protected virtual IEnumerable <TextFile> ProcessComplexTypes(TemplateFileInfo templateInfo)
        {
            var complexTypes = CurrentModel.GetComplexTypes();

            foreach (OdcmObject complexType in complexTypes)
            {
                yield return(ProcessTemplate(templateInfo, complexType));
            }
        }
예제 #3
0
        protected static CustomT4Host Host(TemplateFileInfo templateInfo, String templatesDirectory, OdcmObject odcmObject, OdcmModel odcmModel)
        {
            if (_host == null)
            {
                _host = new CustomT4Host(templateInfo, templatesDirectory, odcmObject, odcmModel);
            }
            else
            {
                _host.Reset(templateInfo, templatesDirectory, odcmObject, odcmModel);
            }

            return(_host);
        }
예제 #4
0
        public IEnumerable <TextFile> Process(TemplateFileInfo templateInfo)
        {
            FileType fileType;
            Func <TemplateFileInfo, IEnumerable <TextFile> > subProcessor;

            Boolean valid = Enum.TryParse(templateInfo.TemplateBaseName, true, out fileType);

            if (valid)
            {
                SubProcessors.TryGetValue(fileType, out subProcessor);
            }
            else
            {
                SubProcessors.TryGetValue(FileType.Other, out subProcessor);
            }
            return(subProcessor(templateInfo));
        }
예제 #5
0
        protected TextFile ProcessTemplate(TemplateFileInfo templateInfo, OdcmObject odcmObject)
        {
            var host = TemplateProcessor.Host(templateInfo, this.TemplatesDirectory, odcmObject, this.CurrentModel);

            var templateContent = File.ReadAllText(host.TemplateFile);

            var output = this.T4Engine.ProcessTemplate(templateContent, host);

            if (host.Errors != null && host.Errors.HasErrors)
            {
                var errors = this.LogErrors(host, templateInfo);
                throw new InvalidOperationException(errors);
            }

            String fileName = (odcmObject != null) ? odcmObject.Name.ToUpperFirstChar() : templateInfo.TemplateBaseName.ToUpperFirstChar();
            var    path     = this.PathWriter.WritePath(templateInfo, fileName);

            return(new TextFile(path, output));
        }
예제 #6
0
        public string LogErrors(CustomT4Host host, TemplateFileInfo templateInfo)
        {
            var sb = new StringBuilder();

            if (host.Errors == null || host.Errors.Count <= 0)
            {
                return(sb.ToString());
            }

            foreach (CompilerError error in host.Errors)
            {
                sb.AppendLine("TemplateProcessor ERROR").
                AppendFormat(@"Name:     {0}{1}", templateInfo.TemplateName, Environment.NewLine).
                AppendFormat(@"Line:     {0}{1}", error.Line, Environment.NewLine).
                AppendFormat(@"Details:  {0}{1}", error.ErrorText, Environment.NewLine).
                AppendLine().
                AppendLine();
            }
            return(sb.ToString());
        }
예제 #7
0
 protected IEnumerable <TextFile> ProcessTemplate(TemplateFileInfo templateInfo)
 {
     yield return(this.ProcessTemplate(templateInfo, null));
 }
예제 #8
0
        protected virtual IEnumerable <TextFile> ProcessEntityContainerType(TemplateFileInfo templateInfo)
        {
            var container = this.CurrentModel.EntityContainer;

            yield return(ProcessTemplate(templateInfo, container));
        }