Пример #1
0
        public static void CreateItemPool(string spaceName, string outputDir, string templateFilePath)
        {
            Type[] itemTypes = AssemblyUtility.GetDerivedTypes(typeof(ActionItem));
            if (itemTypes == null || itemTypes.Length == 0)
            {
                Debug.LogError($"ActionItemPoolCreator::CreateItemPool->ActionItem is not found!");
                return;
            }

            Dictionary <Type, Type> dataToItemTypeDic = new Dictionary <Type, Type>();

            foreach (var itemType in itemTypes)
            {
                ActionItemBindDataAttribute attr = itemType.GetCustomAttribute <ActionItemBindDataAttribute>();
                if (attr == null)
                {
                    Debug.LogError($"ActionItemPoolCreator::CreateItemPool->Attribute is not found.itemType = {itemType.FullName}");
                    continue;
                }

                dataToItemTypeDic.Add(attr.DataType, itemType);
            }

            StringContextContainer context = new StringContextContainer();

            context.Add("spaceName", spaceName);
            context.Add("dataToItemTypeDic", dataToItemTypeDic);

            string templateContent = File.ReadAllText(templateFilePath);

            string outputFilePath = $"{outputDir}/ActionItemPoolRegister.cs";
            string outputContent  = TemplateEngine.Execute(context, templateContent, new string[0]);

            File.WriteAllText(outputFilePath, outputContent);
        }
Пример #2
0
        /// <summary>
        /// Send a mail message
        /// </summary>
        /// <param name="tempalteName">The template</param>
        /// <param name="model">The data</param>
        public virtual void SendMail(string tempalteName, object model)
        {
            var mail = TemplateEngine.Execute(tempalteName, model);

            Sender.Send(mail);

            if (File.Exists(mail.GeneratedAssemblyName))
            {
                File.Delete(mail.GeneratedAssemblyName);
            }
        }
Пример #3
0
        public virtual void SendWelcomeMail(string name, string password, string email)
        {
            var model = new {
                From     = FromAddress,
                To       = email,
                Name     = name,
                Password = password,
                LogOnUrl = "http://mycompany.com/logon"
            };

            var mail = TemplateEngine.Execute(SendWelcomeMailTemplateName, model);

            Sender.Send(mail);
        }
Пример #4
0
        public virtual void SendThresholdCalculationMail(string subjectTemplate, string criteria, int count, Type type, ThresholdSeverity severity, string to)
        {
            var model = new {
                Criteria = criteria,
                Count    = count,
                DataType = CaptionHelper.GetClassCaption(type.FullName),
                Severity = severity
            };
            var mail = TemplateEngine.Execute(_name, model);

            to.Split(';').Each(s => mail.To.Add(s));
            mail.From    = ConfigurationManager.AppSettings["ThresholdEmailJobFrom"];
            mail.Subject = subjectTemplate;
            Sender.Send(mail);
        }
Пример #5
0
        private void ExportMessageID(string outputDir, MessageGroup group, StringContext context)
        {
            context.Add(CONTEXT_MESSAGE_GROUP_KEY, group);

            string outputFilePath = $"{outputDir}/{group.Name}_ID{GetExtension()}";
            string outputContent  = TemplateEngine.Execute(context, exportData.idTemplateContent, new string[] {
                typeof(MessageGroup).Assembly.Location
            });

            if (!string.IsNullOrEmpty(outputContent))
            {
                File.WriteAllText(outputFilePath, outputContent);
            }

            context.Remove(CONTEXT_MESSAGE_GROUP_KEY);
        }
Пример #6
0
        private void ExportMessageParser(string outputDir, MessageGroup encodeGroup, MessageGroup decodeGroup, StringContext context)
        {
            context.Add(CONTEXT_ENCODE_MESSAGE_GROUP_KEY, encodeGroup);
            context.Add(CONTEXT_DECODE_MESSAGE_GROUP_KEY, decodeGroup);

            string outputFilePath = $"{outputDir}/{context.Get<string>(CONTEXT_PLATFORM_KEY)}MessageParser{GetExtension()}";
            string outputContent  = TemplateEngine.Execute(context, exportData.parserTemplateContent, new string[] {
                typeof(MessageConfig).Assembly.Location
            });

            if (!string.IsNullOrEmpty(outputContent))
            {
                File.WriteAllText(outputFilePath, outputContent);
            }

            context.Remove(CONTEXT_ENCODE_MESSAGE_GROUP_KEY);
            context.Remove(CONTEXT_DECODE_MESSAGE_GROUP_KEY);
        }
Пример #7
0
        static void Main(string[] args)
        {
            string templateContent =
                @"using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
<%
string spaceName = context.Get<string>(""spaceName"");
string className = context.Get<string>(""className"");
List<int> list = context.Get<List<int>>(""values"");
%>

<%+using System.Collections.Generic;%>
namespace <%=spaceName%>
{
    public class <%=className%>
    {
        public void Print()
        {
            int[] values = {<%foreach(var value in list){%><%=value%>,<%}%>};
            foreach(var value in values)
            {
                Console.WriteLine(value);
            }
        }
    }
}
";
            StringContext context = new StringContext();

            context.Add("spaceName", "Com.Test");
            context.Add("className", "TestClass");
            context.Add("values", new List <int>()
            {
                1, 2, 3, 4, 5, 6
            });

            string output = TemplateEngine.Execute(context, templateContent, null);

            File.WriteAllText("D:/t.cs", output);
        }
        public virtual void SendWelcomeMail(string name, string password, string email, IList <string> names)
        {
            var model = new
            {
                From     = FromAddress,
                To       = email,
                Name     = name,
                Password = password,
                LogOnUrl = "http://mycompany.com/logon",
                Address  = new
                {
                    Street   = "Bla Street",
                    Suburb   = "Bl Blaburb",
                    City     = "Metroplis",
                    PostCode = 90210
                },
                Names = names
            };

            var mail = TemplateEngine.Execute(SendWelcomeMailTemplateName, model);

            Sender.Send(mail);
        }
Пример #9
0
        public MailMessage Render(string templateName, object model)
        {
            MailMessage message;

            var executionResult = e.Execute <EmailTemplate>(templateName, model);

            executionResult.AssembleParts();

            message = new MailMessage();

            message.Subject = executionResult.Subject;

            // Sender info
            if (executionResult.From != null)
            {
                message.From = executionResult.From;
            }
            if (executionResult.Sender != null)
            {
                message.Sender = executionResult.Sender;
            }
            foreach (var addr in executionResult.ReplyToList)
            {
                message.ReplyToList.Add(addr);
            }


            // Recepients
            foreach (var addr in executionResult.To)
            {
                message.To.Add(addr);
            }
            foreach (var addr in executionResult.CC)
            {
                message.CC.Add(addr);
            }
            foreach (var addr in executionResult.Bcc)
            {
                message.Bcc.Add(addr);
            }

            // Options
            message.DeliveryNotificationOptions = executionResult.DeliveryNotificationOptions;
            message.Priority = executionResult.Priority;

            foreach (var hdr in executionResult.Headers)
            {
                message.Headers.Add(hdr.Key, hdr.Value);
            }
            //Public property HeadersEncoding Gets or sets the encoding used for the user-defined custom headers for this e-mail message.


            message.Subject = executionResult.Subject;
            //Public property SubjectEncoding Gets or sets the encoding used for the subject content for this e-mail message.

            foreach (var att in executionResult.Attachments)
            {
                message.Attachments.Add(att);
            }


            string TextBody  = executionResult.Text;            // @section Text { ... }
            string HtmlBody  = executionResult.Html;            // @section Html { ... }
            string PlainBody = executionResult.Body;            // content not in section(s).


            if (string.IsNullOrWhiteSpace(TextBody) && string.IsNullOrWhiteSpace(HtmlBody))
            {
                // no sections defined
                message.Body       = PlainBody;
                message.IsBodyHtml = false;
                return(message);
            }

            // no html part
            if (string.IsNullOrWhiteSpace(executionResult.Html))
            {
                message.Body       = TextBody;
                message.IsBodyHtml = false;
                return(message);
            }

            // clean up and move css inline to maximise compatibility with mail clients
            // stripping style block, class attributes and comments
            var preMailerResult = PreMailer.Net.PreMailer.MoveCssInline(HtmlBody, removeStyleElements: true, stripIdAndClassAttributes: true, removeComments: true);

            HtmlBody = preMailerResult.Html;


            // html, no text
            if (string.IsNullOrWhiteSpace(executionResult.Text))
            {
                // are there any embedded images?
                // no
                message.Body       = HtmlBody;
                message.IsBodyHtml = true;
                return(message);
            }

            // both text and html parts

            // create text alternate part

            // create html alternate part
            // add embeded (linked) resources


            var TextPart = AlternateView.CreateAlternateViewFromString(TextBody, new System.Net.Mime.ContentType("text/plain"));
            var HtmlPart = AlternateView.CreateAlternateViewFromString(HtmlBody, new System.Net.Mime.ContentType("text/html"));

            foreach (var i in executionResult.LinkedResources.Values)
            {
                HtmlPart.LinkedResources.Add(i);
            }

            message.AlternateViews.Add(TextPart);
            message.AlternateViews.Add(HtmlPart);

            //AlternateViews Gets the attachment collection used to store alternate forms of the message body.
            //Public property Body Gets or sets the message body.
            //Public property IsBodyHtml Gets or sets a value indicating whether the mail message body is in Html.

            //Public property BodyEncoding Gets or sets the encoding used to encode the message body.
            //Public property BodyTransferEncoding Gets or sets the transfer encoding used to encode the message body.



            return(message);
        }
Пример #10
0
        public void SendMail(BaseTemplateModel model)
        {
            Email mail = TemplateEngine.Execute(Enum.GetName(typeof(EmailTemplateType), model.TemplateName), model);

            Sender.Send(mail);
        }