コード例 #1
0
        protected TextFile ProcessTemplate(ITemplateInfo templateInfo, OdcmObject odcmObject, string fileName)
        {
            logger.Trace($"Generating file {fileName}");
            var host = TemplateProcessor.Host(templateInfo, this.TemplatesDirectory, odcmObject, this.CurrentModel);

            Func <ITextTemplatingEngineHost, string> preProcessedTemplate;

            if (!this.preProcessedTemplates.TryGetValue(templateInfo.FullPath, out preProcessedTemplate))
            {
                preProcessedTemplate = this.PreProcessTemplate(templateInfo);
                this.preProcessedTemplates.Add(templateInfo.FullPath, preProcessedTemplate);
            }

            var output = preProcessedTemplate(host);

            if (!string.IsNullOrEmpty(host.TemplateName))
            {
                fileName = host.TemplateName;
            }

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

            var path = this.PathWriter.WritePath(templateInfo, fileName);

            logger.Debug("Wrote template to path {0}", path);

            host.TemplateHostStats.RecordProcessed(templateInfo, odcmObject != null ? odcmObject.Name : string.Empty, path);
            return(new TextFile(path, output));
        }
コード例 #2
0
        protected TextFile ProcessTemplate(ITemplateInfo templateInfo, OdcmObject odcmObject, string fileName)
        {
            logger.Trace($"Generating file {fileName}");
            var host = TemplateProcessor.Host(templateInfo, this.TemplatesDirectory, odcmObject, this.CurrentModel);

            Func <ITextTemplatingEngineHost, string> preProcessedTemplate;

            if (!this.preProcessedTemplates.TryGetValue(templateInfo.FullPath, out preProcessedTemplate))
            {
                preProcessedTemplate = this.PreProcessTemplate(templateInfo);
                this.preProcessedTemplates.Add(templateInfo.FullPath, preProcessedTemplate);
            }

            var output = preProcessedTemplate(host);

            if (!string.IsNullOrEmpty(host.TemplateName))
            {
                fileName = host.TemplateName;
            }

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

            string @namespace = ConfigurationService.Settings.PrimaryNamespaceName;

            switch (odcmObject)
            {
            case OdcmType t:
                @namespace = t.Namespace.GetNamespaceName();
                break;

            case OdcmProperty p:
                if (templateInfo.TemplateLanguage.Equals("java", StringComparison.OrdinalIgnoreCase))
                {
                    @namespace = p.Type.Namespace.Name;
                    if (@namespace == "Edm")
                    {
                        @namespace = "Microsoft.Graph";
                    }
                }
                else
                {
                    @namespace = p?.Class.Namespace.GetNamespaceName();
                }
                break;

            default:
                break;
            }

            var path = this.PathWriter.WritePath(templateInfo, @namespace, fileName);

            logger.Debug("Wrote template to path {0}", path);

            host.TemplateHostStats.RecordProcessed(templateInfo, odcmObject != null ? odcmObject.Name : string.Empty, path);
            return(new TextFile(path, output));
        }