public void GetAndCreateTest() { GeneratorSettings generatorSettings = new GeneratorSettings(); UniqueNamer uniqueNamer = new UniqueNamer(); TemplateContent templateContent = new TemplateContent(generatorSettings, uniqueNamer); AbpDbContentTemplate abpDbContentTemplate = new AbpDbContentTemplate(templateContent); MySQLSchemaProvider mySqlSchemaProvider = new MySQLSchemaProvider(); const string mysqlConn = "Server=127.0.0.1;Database=esms;Uid=root;Pwd=123qwe!@#;"; SchemaSelector schemaSelector = new SchemaSelector(mySqlSchemaProvider, mysqlConn); foreach (TableSchema tableSchema in schemaSelector.Tables) { foreach (DataObjectBase columnSchema in tableSchema.Columns) { Console.WriteLine(columnSchema.FullName); } } //EntityContext<AbpEntity, AbpEntityProperty> entityContext = abpDbContentTemplate.GetAndCreate(schemaSelector); //Entity<AbpEntityProperty> entity = entityContext.Entities.First(t => t.ClassName == "SysUser"); //foreach (Relationship relationship in entity.Relationships.Where(t=>t.ThisEntity.Contains("SysUser")&&t.ThisPropertyName=="LastRole")) //{ // Console.WriteLine(relationship.JoinTable); //} }
public async Task Render_Template_Returns_Correct_Content() { // Setup string apiKey = ConfigurationManager.AppSettings["APIKey"]; string templateName = ConfigurationManager.AppSettings["TemplateExample"]; // Exercise var api = new MandrillApi(apiKey); var templateContent = new TemplateContent { Content = "Test", Name = "model1" }; RenderedTemplate result = await api.Render(new RenderTemplateRequest(templateName) { TemplateContent = new List <TemplateContent> { templateContent } }); string expected = "<span>Test</span>"; // Verify Assert.AreEqual(expected, result.Html); }
void ISupportInitialize.EndInit() { if (this.propertyName != null) { if (this.TargetName == null) { this.Property = DependencyPropertyConverter.Resolve(this.serviceProvider, this.propertyName); } else { // TargetName is specified so we need to look in the containing template for the named element IAmbientProvider ambient = (IAmbientProvider)this.serviceProvider.GetService(typeof(IAmbientProvider)); IXamlSchemaContextProvider schema = (IXamlSchemaContextProvider)this.serviceProvider.GetService(typeof(IXamlSchemaContextProvider)); // Look up the FrameworkTemplate.Template property in the xaml schema. XamlType frameworkTemplateType = schema.SchemaContext.GetXamlType(typeof(FrameworkTemplate)); XamlMember templateProperty = frameworkTemplateType.GetMember("Template"); // Get the value of the first ambient FrameworkTemplate.Template property. TemplateContent templateContent = (TemplateContent)ambient.GetFirstAmbientValue(new[] { frameworkTemplateType }, templateProperty).Value; // Look in the template for the type of TargetName. Type targetType = templateContent.GetTypeForName(this.TargetName); // Finally, find the dependency property on the type. this.Property = DependencyObject.GetPropertyFromName(targetType, this.propertyName); } } }
protected void btn_Save_Click(object sender, EventArgs e) { DataEntities ent = new DataEntities(); int id = WS.RequestInt("id"); TemplateContent tl; try { tl = (from l in ent.TemplateContent where l.ID == id select l).First(); } catch { tl = new TemplateContent(); } tl.TempName = txt_TempName.Text;; tl.TimeFormat = txt_TimeFormat.Text; tl.Content = txt_Content.Text.Replace("'", "''"); tl.SysModel = ddl_SysModel.SelectedValue.ToInt32(); if (tl.ID <= 0) { tl.GroupID = 1; tl.SysModel = 1; ent.AddToTemplateContent(tl); } ent.SaveChanges(); ent.Dispose(); Js.AlertAndGoback("保存成功!"); }
private void AssertTemplate(TemplateContent content, byte[] buffer) { AssertContent(content, TemplateNamePattern, TemplateFilePattern, buffer.Length); var ms = content.Buffer.ToMemoryStream(); Assert.Equal(buffer, ms.ToArray()); }
// Token: 0x060050FC RID: 20732 RVA: 0x0016B894 File Offset: 0x00169A94 internal override void ProcessTemplateBeforeSeal() { FrameworkElementFactory visualTree; if (base.HasContent) { TemplateContent template = base.Template; XamlType xamlType = template.SchemaContext.GetXamlType(typeof(Panel)); if (template.RootType == null || !template.RootType.CanAssignTo(xamlType)) { throw new InvalidOperationException(SR.Get("ItemsPanelNotAPanel", new object[] { template.RootType })); } } else if ((visualTree = base.VisualTree) != null) { if (!typeof(Panel).IsAssignableFrom(visualTree.Type)) { throw new InvalidOperationException(SR.Get("ItemsPanelNotAPanel", new object[] { visualTree.Type })); } visualTree.SetValue(Panel.IsItemsHostProperty, true); } }
public MainWindowViewModel(IConnpassClient connpassClient, IFilePickerService filePickerService, IClipBoardService clipBoardService, IArticleTemplateEngine articleTemplateEngine) { _connpassClient = connpassClient; _filePickerService = filePickerService; _clipBoardService = clipBoardService; _articleTemplateEngine = articleTemplateEngine; ConnpassUrl.Subscribe(s => _connpassClient.ConnpassURL.Value = s); ArticleData = _connpassClient.Article; ArticleContent = TemplateContent.Merge(TranslateCommand) //.Where(s => ArticleData != null && !string.IsNullOrWhiteSpace(TemplateContent.Value) && string.IsNullOrWhiteSpace(ConnpassUrl.Value)) .Select(s => _articleTemplateEngine.ReplaceArticleData(TemplateContent.Value, ArticleData.Value)) .ToReactiveProperty(); CopyArticleContentCommand.Subscribe(() => _clipBoardService.CopyToClipBoard(ArticleContent.Value)); TemplateContent = _filePickerService.FileContent; OpenTemplateFileFromLocal.Subscribe(() => _filePickerService.ShowFilePicker()); SwitchTagView.Subscribe(() => IsOpenTagView.SwitchValue()); CopyTag.Subscribe(() => _clipBoardService.CopyToClipBoard($"{{{SelectedTag.Value}}}")); AddTag.Subscribe(() => TemplateContent.Value += $"{{{SelectedTag.Value}}}"); }
public void DataTemplate_Can_Be_Empty() { using (UnitTestApplication.Start(TestServices.StyledWindow)) { var xaml = @" <s:SampleTemplatedObjectContainer xmlns='https://github.com/avaloniaui' xmlns:sys='clr-namespace:System;assembly=netstandard' xmlns:s='clr-namespace:Avalonia.Markup.Xaml.UnitTests.Xaml' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'> <s:SampleTemplatedObjectContainer.Template> <s:SampleTemplatedObjectTemplate> <s:SampleTemplatedObject x:Name='root'> <s:SampleTemplatedObject x:Name='child1' Foo='foo' /> <s:SampleTemplatedObject x:Name='child2' Foo='bar' /> </s:SampleTemplatedObject> </s:SampleTemplatedObjectTemplate> </s:SampleTemplatedObjectContainer.Template> </s:SampleTemplatedObjectContainer>"; var container = (SampleTemplatedObjectContainer)AvaloniaRuntimeXamlLoader.Load(xaml, typeof(GenericTemplateTests).Assembly); var res = TemplateContent.Load <SampleTemplatedObject>(container.Template.Content); Assert.Equal(res.Result, res.NameScope.Find("root")); Assert.Equal(res.Result.Content[0], res.NameScope.Find("child1")); Assert.Equal(res.Result.Content[1], res.NameScope.Find("child2")); Assert.Equal("foo", res.Result.Content[0].Foo); Assert.Equal("bar", res.Result.Content[1].Foo); } }
/// <summary> /// 打印标签 /// </summary> /// <param name="cartonInfo"></param> private void PrintLabel(WaitRePrintCarton cartonInfo) { string strProcedureName = $"{className}.{MethodBase.GetCurrentMethod().Name}"; int errCode = 0; string errText = ""; #region 根据 T117LeafID 获取标签打印模板 TemplateContent template = new TemplateContent(); IRAPMDMClient.Instance.ufn_GetInfo_TemplateFMTStr( IRAPUser.Instance.CommunityID, cartonInfo.T117LeafID, IRAPUser.Instance.SysLogID, ref template, out errCode, out errText); WriteLog.Instance.Write( $"({errCode}){errText}", strProcedureName); if (errCode != 0 || template.TemplateFMTStr.Trim() == "") { XtraMessageBox.Show( $"无法获取到 [T117LeafID={cartonInfo.T117LeafID}] 的模板", "", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else { PrintCartonLabel(cartonInfo, template.TemplateFMTStr); } #endregion }
private void ContentControl_MouseRightButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e) { if (TemplateContent.IsMouseOver == true) { int imageCount = SelectedTemplate.Template_ImageCount; for (int i = 0; i < imageCount; i++) { if (((FrameworkElement)TemplateContent.FindName("Image" + i)).IsMouseOver) { if (typeof(Image) == TemplateContent.FindName("Image" + i).GetType()) { Image iTarget = (Image)TemplateContent.FindName("Image" + i); if (!string.IsNullOrEmpty(iTarget.Uid)) { if (MessageBox.Show("確定移除樣板圖片?", "提示", MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes) { string DefaultImage = tableTemplates_Images.RemoveAndReturnUidTemplatesImages(int.Parse(iTarget.Uid)); iTarget.Dispatcher.Invoke(() => { iTarget.Source = new BitmapImage(new Uri(@"pack://application:,,,/iDental;" + DefaultImage, UriKind.Absolute)); }); } } else { MessageBox.Show("此區域尚未放置圖片", "提示", MessageBoxButton.OK, MessageBoxImage.Information); } } } } } }
private void FillTemplateContent(TemplateContent templateContent, string dir) { // subjects should not be html, but we will first try loading html file if (m_fileSystem.ExistFile(Path.Combine(dir, FILE_SUBJECT + EXT_HTML))) { templateContent.Subject = m_fileSystem.GetContents(Path.Combine(dir, FILE_SUBJECT + EXT_HTML)); } else { templateContent.Subject = m_fileSystem.GetContents(Path.Combine(dir, FILE_SUBJECT + EXT_TEXT)); } if (m_fileSystem.ExistFile(Path.Combine(dir, FILE_SUMMARYSUBJECT + EXT_HTML))) { templateContent.SummarySubject = GetContentsExpandIncludes(Path.Combine(dir, FILE_SUMMARYSUBJECT + EXT_HTML)); } else { templateContent.SummarySubject = GetContentsExpandIncludes(Path.Combine(dir, FILE_SUMMARYSUBJECT + EXT_TEXT)); } templateContent.Body = GetContentsExpandIncludes(Path.Combine(dir, FILE_BODY + EXT_HTML)); templateContent.SummaryBody = GetContentsExpandIncludes(Path.Combine(dir, FILE_SUMMARYBODY + EXT_HTML)); templateContent.SummaryHeader = GetContentsExpandIncludes(Path.Combine(dir, FILE_SUMMARYHEADER + EXT_HTML)); templateContent.SummaryFooter = GetContentsExpandIncludes(Path.Combine(dir, FILE_SUMMARYFOOTER + EXT_HTML)); templateContent.TextBody = GetContentsExpandIncludes(Path.Combine(dir, FILE_BODY + EXT_TEXT)); templateContent.SummaryTextBody = GetContentsExpandIncludes(Path.Combine(dir, FILE_SUMMARYBODY + EXT_TEXT)); templateContent.SummaryTextHeader = GetContentsExpandIncludes(Path.Combine(dir, FILE_SUMMARYHEADER + EXT_TEXT)); templateContent.SummaryTextFooter = GetContentsExpandIncludes(Path.Combine(dir, FILE_SUMMARYFOOTER + EXT_TEXT)); }
//------------------------------------------------------------------- // // Internal Methods // //------------------------------------------------------------------- // // ProcessTemplateBeforeSeal // // This is used in the case of templates defined with FEFs. For templates // in Baml (the typical case), see the OnApply override. // // 1. Verify that // a. root element is a Panel // 2. Set IsItemsHost = true // internal override void ProcessTemplateBeforeSeal() { FrameworkElementFactory root; if (HasContent) { // This is a Baml-style template // Validate the root type (it must be a Panel) TemplateContent templateHolder = Template as TemplateContent; System.Xaml.XamlType panelType = templateHolder.SchemaContext.GetXamlType(typeof(Panel)); if (templateHolder.RootType == null || !templateHolder.RootType.CanAssignTo(panelType)) { throw new InvalidOperationException(SR.Get(SRID.ItemsPanelNotAPanel, templateHolder.RootType)); } } else if ((root = this.VisualTree) != null) { // This is a FEF-style template if (!typeof(Panel).IsAssignableFrom(root.Type)) { throw new InvalidOperationException(SR.Get(SRID.ItemsPanelNotAPanel, root.Type)); } root.SetValue(Panel.IsItemsHostProperty, true); } }
private TemplateDetails TransformFull(TemplateContent contentItem, IEnumerable <TemplateField> fields) { var template = new TemplateDetails(); Transform(contentItem, template); template.Buffer = contentItem.Buffer; template.Fields = fields; return(template); }
public void Ctor_WithInterface_CreatesInstance() { string templateText = "Hello {{FullName}} from {{Address.StreetNumber}} {{Address.StreetName}}! on {{JoinDate}}"; ITemplate template = BuildTemplate(1, templateText); var content = new TemplateContent(template); Assert.NotNull(content); }
private TemplateContent CreateContent(ProjectRewriteCacheEntry projectInfos) { var content = new TemplateContent(); var project = new Project(); project.ReplaceParameters = true; project.File = Path.GetFileName(projectInfos.ProjectFilePath); project.TargetFileName = projectInfos.ProjectTemplateReference; AddFiles(project, projectInfos); content.Children = new NestableContent[] { project }; return(content); }
public MainWindow() { InitializeComponent(); ControlTemplate cttc1 = tc1.Template; IEnumerable ch = LogicalTreeHelper.GetChildren(tc1); foreach (var item in ch) { string s = item.GetType().FullName; Debug.WriteLine(s); } TemplateContent tc = cttc1.Template; object r = cttc1.Resources; }
protected void LoadInfo() { ddl_SysModel.DataSource = TemplateAction.AllSysModel; ddl_SysModel.DataTextField = "ModelName"; ddl_SysModel.DataValueField = "ID"; ddl_SysModel.DataBind(); int id = WS.RequestInt("id"); TemplateContent tl = TemplateContentView.GetModelByID(id.ToS()); txt_TempName.Text = tl.TempName; txt_TimeFormat.Text = tl.TimeFormat; txt_Content.Text = tl.Content; ddl_SysModel.SelectedValue = tl.SysModel.ToS(); }
// Module defining this command // Optional custom code for this activity /// <summary> /// Returns a configured instance of System.Management.Automation.PowerShell, pre-populated with the command to run. /// </summary> /// <param name="context">The NativeActivityContext for the currently running activity.</param> /// <returns>A populated instance of System.Management.Automation.PowerShell</returns> /// <remarks>The infrastructure takes responsibility for closing and disposing the PowerShell instance returned.</remarks> protected override ActivityImplementationContext GetPowerShell(NativeActivityContext context) { System.Management.Automation.PowerShell invoker = global::System.Management.Automation.PowerShell.Create(); System.Management.Automation.PowerShell targetCommand = invoker.AddCommand(PSCommandName); // Initialize the arguments if (Delimiter.Expression != null) { targetCommand.AddParameter("Delimiter", Delimiter.Get(context)); } if (PropertyNames.Expression != null) { targetCommand.AddParameter("PropertyNames", PropertyNames.Get(context)); } if (TemplateFile.Expression != null) { targetCommand.AddParameter("TemplateFile", TemplateFile.Get(context)); } if (TemplateContent.Expression != null) { targetCommand.AddParameter("TemplateContent", TemplateContent.Get(context)); } if (IncludeExtent.Expression != null) { targetCommand.AddParameter("IncludeExtent", IncludeExtent.Get(context)); } if (UpdateTemplate.Expression != null) { targetCommand.AddParameter("UpdateTemplate", UpdateTemplate.Get(context)); } if (InputObject.Expression != null) { targetCommand.AddParameter("InputObject", InputObject.Get(context)); } return(new ActivityImplementationContext() { PowerShellInstance = invoker }); }
private string LoadTemplateFromDB(int t117LeafID) { string rlt = ""; string strProcedureName = string.Format( "{0}.{1}", className, MethodBase.GetCurrentMethod().Name); WriteLog.Instance.WriteBeginSplitter(strProcedureName); try { int errCode = 0; string errText = ""; TemplateContent data = new TemplateContent(); IRAPMDMClient.Instance.ufn_GetInfo_TemplateFMTStr( IRAPUser.Instance.CommunityID, t117LeafID, IRAPUser.Instance.SysLogID, ref data, out errCode, out errText); WriteLog.Instance.WriteBeginSplitter(strProcedureName); if (errCode == 0) { rlt = data.TemplateFMTStr; } else { IRAPMessageBox.Instance.Show(errText, "获取标签模板", MessageBoxIcon.Error); } } catch (Exception error) { WriteLog.Instance.Write(error.Message, strProcedureName); WriteLog.Instance.Write(error.StackTrace, strProcedureName); IRAPMessageBox.Instance.Show(error.Message, "获取标签模板", MessageBoxIcon.Error); } finally { WriteLog.Instance.WriteEndSplitter(strProcedureName); } return(rlt); }
public async Task <IActionResult> SendKeysViaEmail(string listId) { var existingKeys = await new AccessKey().RetrieveAllAsync(); var mailChimp = new MailChimpManager("3f4978dbd632a4471650eeeebe681ce3-us12"); var mandrill = new MandrillApi("DQCr_ZMk5Ga5slGv9uWGPQ"); List mailChimpList; try { mailChimpList = await mailChimp.Lists.GetAsync(listId); } catch (MailChimpException) { return(ErrorView($"MailChimp list with ID {listId} doesn't exist.")); } var resultsList = new List <string> { $"Scanned MailChimp list {mailChimpList.Name} and sent an access key for each member:" }; var listMembers = await mailChimp.Members.GetAllAsync(listId); foreach (var listMember in listMembers) { var accessKey = await new AccessKey().AddAsync(existingKeys, listMember.EmailAddress); existingKeys.Add(accessKey); var emailMessage = new EmailMessage() { To = new List <EmailAddress> { new EmailAddress(listMember.EmailAddress) } }; var accessKeyContent = new TemplateContent() { Name = "acces-key", Content = accessKey.Id }; var sendRequest = new SendMessageTemplateRequest(emailMessage, "Access Key", new List <TemplateContent> { accessKeyContent }); var sendResults = await mandrill.SendMessageTemplate(sendRequest); var result = sendResults.First(); resultsList.Add($" - Sent key {accessKey.Id} to {result.Email} with status {result.Status}. " + (result.Status != EmailResultStatus.Sent ? $"Reject reason: {result.RejectReason}" : string.Empty)); } return(View("SendAccessKeysResult", resultsList)); }
public TemplateResult GenerateResult(object data, TemplateContent content) { var template = RT.Template .WithBaseType <RT.TemplateBase>() .AddNamespace("DAF.Core") .AddNamespace("DAF.Web") .Compile(content.Body); string body = template.Render(data); return(new TemplateResult() { Name = content.Name, Body = body, OutFilePath = null }); }
public void Render_UsingNonGeneric_ReplacesValues() { string templateText = "Hello {{FullName}} from {{Address.StreetNumber}} {{Address.StreetName}}! on {{JoinDate}}"; ITemplate template = BuildTemplate(1, templateText); var templateContent = new TemplateContent(template); var message = new WelcomeMessage() { FullName = "Devon", Address = new Address { StreetName = "Main" } }; var text = templateContent.Render(message); Assert.Contains("Devon", text); }
// Setters and triggers may have a sourceName which we need to resolve // This only works in templates and it works by looking up the mapping between // name and type in the template. We use ambient lookup to find the Template property // and then query it for the type. private static Type GetTypeFromName(XamlSchemaContext schemaContext, IAmbientProvider ambientProvider, string target) { XamlType frameworkTemplateXType = schemaContext.GetXamlType(typeof(FrameworkTemplate)); XamlMember templateProperty = frameworkTemplateXType.GetMember("Template"); AmbientPropertyValue ambientValue = ambientProvider.GetFirstAmbientValue(new XamlType[] { frameworkTemplateXType }, templateProperty); TemplateContent templateHolder = ambientValue.Value as System.Windows.TemplateContent; if (templateHolder != null) { return(templateHolder.GetTypeForName(target).UnderlyingType); } return(null); }
/// <summary> /// DataTable转换为list /// </summary> /// <param name="dt"></param> /// <returns></returns> protected static List <TemplateContent> DataTableToList(DataTable dt) { List <TemplateContent> Ms = new List <TemplateContent>(); for (int i = 0; i < dt.Rows.Count; i++) { TemplateContent M = new TemplateContent(); M.ID = dt.Rows[i]["ID"].ToInt32(); M.GroupID = dt.Rows[i]["GroupID"].ToInt32(); M.SysModel = dt.Rows[i]["SysModel"].ToInt32(); M.TempName = dt.Rows[i]["TempName"].ToString(); M.TimeFormat = dt.Rows[i]["TimeFormat"].ToString(); M.Content = dt.Rows[i]["Content"].ToString(); Ms.Add(M); } return(Ms); }
/// <summary> /// 将修改过的实体修改到数据库 /// </summary> /// <param name="M">赋值后的实体</param> /// <returns></returns> public static int Update(TemplateContent M) { IDbHelper Sql = GetHelper(); StringBuilder sb = new StringBuilder(); sb.Append("update [TemplateContent] set "); sb.Append("[GroupID]=" + M.GroupID.ToS()); sb.Append(","); sb.Append("[SysModel]=" + M.SysModel.ToS()); sb.Append(","); sb.Append("[TempName]=N'" + M.TempName + "'"); sb.Append(","); sb.Append("[TimeFormat]=N'" + M.TimeFormat + "'"); sb.Append(","); sb.Append("[Content]=N'" + M.Content + "'"); sb.Append(" where ID='" + M.ID + "'"); sb.Append(""); if (DataBase.CmsDbType == DataBase.DbType.SqlServer) { sb.Append(";select @@ROWCOUNT"); } if (DataBase.CmsDbType == DataBase.DbType.SQLite) { sb.Append(";select 0"); } if (DataBase.CmsDbType == DataBase.DbType.MySql) { sb.Append(";SELECT ROW_COUNT()"); } if (DataBase.CmsDbType == DataBase.DbType.Access) { sb.Append(";select 0"); } if (DataBase.CmsDbType == DataBase.DbType.Oracle) { sb.Append(";select SQL%ROWCOUNT"); } return(Sql.ExecuteScalar(CommandType.Text, sb.ToString()).ToInt32()); }
// Token: 0x0600210D RID: 8461 RVA: 0x00098390 File Offset: 0x00096590 private static Type GetTypeFromName(XamlSchemaContext schemaContext, IAmbientProvider ambientProvider, string target) { XamlType xamlType = schemaContext.GetXamlType(typeof(FrameworkTemplate)); XamlMember member = xamlType.GetMember("Template"); AmbientPropertyValue firstAmbientValue = ambientProvider.GetFirstAmbientValue(new XamlType[] { xamlType }, new XamlMember[] { member }); TemplateContent templateContent = firstAmbientValue.Value as TemplateContent; if (templateContent != null) { return(templateContent.GetTypeForName(target).UnderlyingType); } return(null); }
private TemplateContent BuildRootTemplateContent(ProjectRewriteCache cache) { /** * root.vstemplate links like * <ProjectTemplateLink ProjectName="$safeprojectname$.Interface" CopyParameters="true"> * Interface\InterfaceTemplate.vstemplate * </ProjectTemplateLink> */ var content = new TemplateContent(); var contentBuilder = new SolutionTemplateContentBuilder(cache, Context); content.Children = new NestableContent[] { contentBuilder.BuildProjectCollection() }; return(content); }
public Task <TemplateContent> CreateTemplate(string templateName, Stream contents) { if (string.IsNullOrEmpty(templateName)) { throw new ArgumentNullException(nameof(templateName)); } if (contents == null || contents.Length == 0) { throw new ArgumentNullException(nameof(contents)); } var templateVersionName = $"{templateName}_{DateTime.Now.Ticks}"; var templateFilename = $"{templateVersionName}.docx"; var templatePath = Path.Combine(TemplatesFolder, templateFilename); WriteContents(templatePath, contents); TemplateContent result = ContentItemFactory.BuildTemplate(templatePath, contents); return(Task.FromResult(result)); }
public void Render_Template_Returns_Correct_Content() { // Setup var apiKey = ConfigurationManager.AppSettings["APIKey"]; var templateName = ConfigurationManager.AppSettings["TemplateExample"]; // Exercise var api = new MandrillApi(apiKey); var templateContent = new TemplateContent { content = "Test", name = "model1" }; var result = api.Render(templateName, new List<TemplateContent>{templateContent}, null); string expected = "<!DOCTYPE html>\n<span>Test</span>"; // Verify Assert.AreEqual(expected, result.html); }
/// <summary> /// 将数据插入表 /// </summary> /// <param name="M">赋值后的实体</param> /// <returns></returns> public static void Insert(TemplateContent M) { IDbHelper Sql = GetHelper(); StringBuilder sb = new StringBuilder(); sb.Append("insert into [TemplateContent]([GroupID],[SysModel],[TempName],[TimeFormat],[Content]) values("); sb.Append(M.GroupID.ToS()); sb.Append(","); sb.Append(M.SysModel.ToS()); sb.Append(","); sb.Append("N'" + M.TempName + "'"); sb.Append(","); sb.Append("N'" + M.TimeFormat + "'"); sb.Append(","); sb.Append("N'" + M.Content + "'"); sb.Append(")"); if (DataBase.CmsDbType == DataBase.DbType.SqlServer) { sb.Append(";select @@Identity"); } if (DataBase.CmsDbType == DataBase.DbType.SQLite) { sb.Append(";select last_insert_rowid()"); } if (DataBase.CmsDbType == DataBase.DbType.MySql) { sb.Append(";select LAST_INSERT_ID()"); } if (DataBase.CmsDbType == DataBase.DbType.Access) { sb.Append(";select max(ID) from TemplateContent"); } if (DataBase.CmsDbType == DataBase.DbType.Oracle) { sb.Append(";select LAST_INSERT_ID()"); } M.ID = Sql.ExecuteScalar(CommandType.Text, sb.ToString()).ToInt32(); }
private void FillTemplateContent(TemplateContent templateContent, CultureInfo ci, string key) { // subjects should not be html, but we will first try loading the html key and then fallback to the text key templateContent.Subject = GetContentsExpandIncludes(string.Format(KEY_SUBJECT, key, KEY_TYPE_HTML), ci) ?? GetContentsExpandIncludes(string.Format(KEY_SUBJECT, key, KEY_TYPE_TEXT), ci); templateContent.SummarySubject = GetContentsExpandIncludes(string.Format(KEY_SUMMARYSUBJECT, key, KEY_TYPE_HTML), ci) ?? GetContentsExpandIncludes(string.Format(KEY_SUMMARYSUBJECT, key, KEY_TYPE_TEXT), ci); templateContent.Body = GetContentsExpandIncludes(string.Format(KEY_BODY, key, KEY_TYPE_HTML), ci); templateContent.SummaryBody = GetContentsExpandIncludes(string.Format(KEY_SUMMARYBODY, key, KEY_TYPE_HTML), ci); templateContent.SummaryHeader = GetContentsExpandIncludes(string.Format(KEY_SUMMARYHEADER, key, KEY_TYPE_HTML), ci); templateContent.SummaryFooter = GetContentsExpandIncludes(string.Format(KEY_SUMMARYFOOTER, key, KEY_TYPE_HTML), ci); templateContent.TextBody = GetContentsExpandIncludes(string.Format(KEY_BODY, key, KEY_TYPE_TEXT), ci); templateContent.SummaryTextBody = GetContentsExpandIncludes(string.Format(KEY_SUMMARYBODY, key, KEY_TYPE_TEXT), ci); templateContent.SummaryTextHeader = GetContentsExpandIncludes(string.Format(KEY_SUMMARYHEADER, key, KEY_TYPE_TEXT), ci); templateContent.SummaryTextFooter = GetContentsExpandIncludes(string.Format(KEY_SUMMARYFOOTER, key, KEY_TYPE_TEXT), ci); }
public void Render_UsingNonGeneric_ReplacesValues() { string templateText = "Hello {{FullName}} from {{Address.StreetNumber}} {{Address.StreetName}}! on {{JoinDate}}"; ITemplate template = BuildTemplate(1, templateText); var templateContent = new TemplateContent(template); var message = new WelcomeMessage(){ FullName = "Devon", Address = new Address{ StreetName = "Main"} }; var text = templateContent.Render(message); Assert.Contains("Devon", text); }
public void AddToTemplateContent(TemplateContent templateContent) { base.AddObject("TemplateContent", templateContent); }
public static TemplateContent CreateTemplateContent(int id) { TemplateContent templateContent = new TemplateContent(); templateContent.ID = id; return templateContent; }