Example #1
0
        public string Transform(ITextTemplate template, IDictionary <string, object> data)
        {
            var engine = _settings.GetEngine(template.Engine); //will throw if not found
            var result = engine.Transform(template.Template, template.Format, data);

            return(result);
        }
Example #2
0
        public void GetTemplate_WithCommentReceveid_ReturnsPropertTemplate()
        {
            //arrange
            var templateEngine = new EmbeddedTemplateEngine();

            //act
            ITextTemplate template = templateEngine.GetTemplate("CommentReceived");

            //assert
            Assert.IsTrue(template.ToString().StartsWith("{spamflag}"));
        }
Example #3
0
        public void EmailCommentToBlogAuthor(FeedbackItem comment)
        {
            if (String.IsNullOrEmpty(Blog.Email) ||
                comment.FeedbackType == FeedbackType.PingTrack ||
                Context.User.IsAdministrator())
            {
                return;
            }

            string fromEmail = comment.Email;

            if (String.IsNullOrEmpty(fromEmail))
            {
                fromEmail = null;
            }

            var commentForTemplate = new
            {
                blog    = Blog,
                comment = new
                {
                    author    = comment.Author,
                    title     = comment.Title,
                    source    = Url.FeedbackUrl(comment).ToFullyQualifiedUrl(Blog),
                    email     = fromEmail ?? "none given",
                    authorUrl = comment.SourceUrl,
                    ip        = comment.IpAddress,
                    // we're sending plain text email by default, but body includes <br />s for crlf
                    body =
                        (comment.Body ?? string.Empty).Replace("<br />", Environment.NewLine).Replace("&lt;br /&gt;",
                                                                                                      Environment.
                                                                                                      NewLine)
                },
                spamFlag = comment.FlaggedAsSpam ? "Spam Flagged " : ""
            };

            ITextTemplate template = TemplateEngine.GetTemplate("CommentReceived");
            string        message  = template.Format(commentForTemplate);
            string        subject  = String.Format(CultureInfo.InvariantCulture, Resources.Email_CommentVia, comment.Title,
                                                   Blog.Title);

            if (comment.FlaggedAsSpam)
            {
                subject = "[SPAM Flagged] " + subject;
            }
            string from = EmailProvider.UseCommentersEmailAsFromAddress
                              ? (fromEmail ?? EmailProvider.AdminEmail)
                              : EmailProvider.AdminEmail;

            EmailProvider.Send(Blog.Email, from, subject, message);
        }
Example #4
0
        private async Task GenerateForEachModel(string projectTemplateFile, CodeGenTemplateSettingsData data)
        {
            // Create template data if not exists
            string projectTemplateDataFile = projectTemplateFile.Replace(".tt", ".cs");

            if (!await _fileService.Exists(projectTemplateDataFile))
            {
                string filePath = projectTemplateDataFile.Replace('\\', '/');

                string name      = Path.GetFileNameWithoutExtension(filePath);
                string nameSpace = "CodeGen." + filePath.Replace("/", ".").Replace($".{name}.cs", "");
                nameSpace = nameSpace.Replace("default", "@default");
                ModelBasedTemplate template = new ModelBasedTemplate(name, nameSpace);
                string             fileText = template.TransformText();

                _logger.LogInformation("Create template data: " + filePath);
                await _fileService.Create(filePath, fileText);

                return;
            }

            foreach (CodeGenModel model in _configService.CodeGenConfig.Models.List)
            {
                // File path
                string filePath = Path.Combine(
                    "_Output",
                    Path.GetDirectoryName(projectTemplateFile),
                    string.Format(data.Output, model.Name, model.NamePlural, model.Name.ToLower(), model.NamePlural.ToLower())
                    );
                filePath = filePath.Replace('\\', '/').Replace("Templates/", "");

                // File text
                string templateTypeFormat = projectTemplateFile.Replace("/", ".").Replace(".tt", "");
                Type   templateType       = Type.GetType($"CodeGen.{templateTypeFormat}, CodeGen");
                if (templateType == null)
                {
                    throw new Exception($"Can't get type for T4 template: CodeGen.{templateTypeFormat}, CodeGen");
                }
                ITextTemplate template = Activator.CreateInstance(templateType, _configService.CodeGenConfig, model) as ITextTemplate;
                string        fileText = template.TransformText();

                _logger.LogInformation("Create file: " + filePath);
                await _fileService.Create(filePath, fileText);
            }
        }
Example #5
0
 public string Transform(ITextTemplate template, IDictionary<string, object> data)
 {
     var engine = _settings.GetEngine(template.Engine); //will throw if not found
       var result = engine.Transform(template.Template, template.Format, data);
       return result;
 }
Example #6
0
 public BodyPart(ITextTemplate textTemplate, IPhoneTypeToText phoneTypeToText)
 {
     _textTemplate    = textTemplate;
     _phoneTypeToText = phoneTypeToText;
 }