IEnumerable <TextFile> ProcessTemplates()
        {
            // There is no need to process "shared" tempaltes, they are only meant to be imported from other templates.
            var templates = this.TemplateInfoProvider.Templates().Where(templateInfo => templateInfo.TemplateType != Template.Shared);

            logger.Debug($"Processing {templates.Count()} templates.");

            // Initialize processor.
            var pathWriterClassName = String.Format(this.PathWriterClassNameFormatString, ConfigurationService.Settings.TargetLanguage);

            logger.Debug($"Using writer {pathWriterClassName}.");

            var type = Type.GetType(pathWriterClassName);

            if (type == null)
            {
                throw new InvalidOperationException("Unable to find path writer " + pathWriterClassName);
            }

            IPathWriter pathWriterInstance = (IPathWriter)Activator.CreateInstance(type);

            this.Processor = new TemplateProcessor(pathWriterInstance, this.CurrentModel, this.TemplatesDirectory);

            foreach (ITemplateInfo template in templates)
            {
                foreach (TextFile outputFile in this.Processor.Process(template))
                {
                    logger.Debug("Created file {0}", outputFile.RelativePath);
                    yield return(outputFile);
                }
            }
        }
Example #2
0
 public TemplateProcessor(IPathWriter pathWriter, OdcmModel odcmModel, String templatesDirectory)
 {
     this.T4Engine           = new Microsoft.VisualStudio.TextTemplating.Engine();
     this.CurrentModel       = odcmModel;
     this.PathWriter         = pathWriter;
     this.PathWriter.Model   = odcmModel;
     this.TemplatesDirectory = templatesDirectory;
 }
 public TemplateProcessor(IPathWriter pathWriter, OdcmModel odcmModel, string templatesDirectory)
 {
     this.T4Engine              = new Microsoft.VisualStudio.TextTemplating.Engine();
     this.CurrentModel          = odcmModel;
     this.PathWriter            = pathWriter;
     this.PathWriter.Model      = odcmModel;
     this.TemplatesDirectory    = templatesDirectory;
     this.preProcessedTemplates = new Dictionary <string, Func <ITextTemplatingEngineHost, string> >();
 }
Example #4
0
 public ObjectiveCTemplateProcessor(IPathWriter pathWriter, OdcmModel model, string baseFilePath)
     : base(pathWriter, model, baseFilePath)
 {
     StrategyName = "ObjectiveC";
     Templates.Add("Models", ProcessSimpleFile);
     Templates.Add("Protocols", ProcessSimpleFile);
     Templates.Add("ODataEntities", ProcessSimpleFile);
     Templates.Add("EntityCollectionFetcher", EntityTypes);
     Templates.Add("EntryPoint", ProcessEntryPoint);
 }
Example #5
0
        public BaseTemplateProcessor(IPathWriter pathWriter, OdcmModel model, string baseFilePath)
        {
            Engine       = new Engine();
            Model        = model;
            PathWriter   = pathWriter;
            BaseFilePath = baseFilePath;

            Templates = new Dictionary <string, Func <Template, IEnumerable <TextFile> > >(StringComparer.InvariantCultureIgnoreCase)
            {
                //Model
                { EntityType, EntityTypes },
                { ComplexType, ComplexTypes },
                { EnumType, EnumTypes },
                { ODataBaseEntity, BaseEntity },
                //OData
                { EntityCollectionOperation, EntityTypes },
                { EntityFetcher, EntityTypes },
                { EntityOperations, EntityTypes },
                //EntityContainer
                { EntryPoint, CreateEntryPoint },
            };
        }
Example #6
0
        IEnumerable <TextFile> ProcessTemplates()
        {
            IEnumerable <TemplateFileInfo> allTemplates = Utilities.ReadTemplateFiles(this.TemplatesDirectory).ToList();

            IEnumerable <TemplateFileInfo> runnableTemplates =
                allTemplates.Where(templateInfo => templateInfo.TemplateType != TemplateType.Base);

            // Initialize processor.
            String pathWriterClassName = String.Format(PathWriterClassNameFormatString,
                                                       ConfigurationService.Settings.TargetLanguage);
            var         type = Type.GetType(pathWriterClassName);
            IPathWriter pathWriterInstance = (IPathWriter)Activator.CreateInstance(type);

            this.Processor = new TemplateProcessor(pathWriterInstance, this.CurrentModel, this.TemplatesDirectory);

            foreach (TemplateFileInfo runnableTemplate in runnableTemplates)
            {
                foreach (TextFile outputFile in this.Processor.Process(runnableTemplate))
                {
                    yield return(outputFile);
                }
            }
        }
Example #7
0
 public JavaTemplateProcessor(IPathWriter pathWriter, OdcmModel model, string baseFilePath) : base(pathWriter, model, baseFilePath)
 {
     StrategyName = "Java";
 }