UltimateTemplateEngine allows you to declare and initialize an array like:
Copy Code
{%arr = {1,2,3,"abc"}/}
{! arr is an array containing four items 1,2,3 and "abc" !}
{%foreach item in arr%}
$item$
javascript:void(0)
{$foreach%}
The output would be:
1
2
3
abc
The array created above is a fixed array and you cannot add more element to it.
To create a fixed array without initialization in your template code, you can call NewFixedArray function returning a reference to a newly created fixed array. See the following example for more details:
Copy Code
{%arr = NewFixedArray(typeof("char"), 5)/}
{! arr is a fixed array of five characters !}
If you wish to create a dynamic array for further manipulation, UltimateTemplateEngine provides another easy declaration for dynamic array, as shown below:
Copy Code
{%dynarr = {}/}
{%dynarr.Add("123");dynarr.Add("abc");/}
{! dynarr is a dynamic array containing two elements 123 and abc !}
With the array declared above you can add, remove elements to/from it.
You can also use indexer operator to assign a value to a specific element in the array. The indexer operator is applied for both fixed array and dynamic array:
Copy Code
{%dynarr = {};dynarr.Add(10)/}
{%arr = {1,2,3}/}
$dynarr[0]$ {! Print out the value at index 0 of the dynamic array !}
$arr[0]$ {! Print out the value at index 0 of the fixed array !}
{%dynarr[0] = 1/} {! Assignment !}
{%arr[0] = 11/} {! Assignment !}
Sunday, July 18, 2010
Caching in UltimateTemplateEngine
With ComponentSoft Template Engine, you can easily cache your loaded template data to speed up your application performance by using two events in TemplateEngine class, as shown below:
* Uses OnLoadTemplateFromCache for loading cached template data.
* Uses OnSaveTemplateToCache for saving template data to cache.
The Web Sample code-behind below shows how to load/save template data from/to Http Cache.
C# Copy Code
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using ComponentSoft;
public partial class _Default : System.Web.UI.Page
{
protected override void Render(HtmlTextWriter writer)
{
try
{
TemplateEngine dt = new TemplateEngine();
dt.OnLoadTemplateFromCache += new EventHandler(dt_OnLoadTemplateFromCache);
dt.OnSaveTemplateToCache += new EventHandler(dt_OnSaveTemplateToCache);
dt.LoadFromFile("MyTemplate.tpl");
dt.SetValue("CompanyName", "My Company Name");
dt.SetValue("EmailAddress", "myemail@somedomain.com");
dt.SetValue("FullName", "John Borders");
dt.Run(writer);
}
catch (Exception exc)
{
writer.Write("An error occurred: " + exc.Message);
}
}
void dt_OnSaveTemplateToCache(object sender, TemplateEngineCacheEventArgs e)
{
HttpContext.Current.Cache[e.CacheName] = e.CacheData;
}
void dt_OnLoadTemplateFromCache(object sender, TemplateEngineCacheEventArgs e)
{
e.CacheData = HttpContext.Current.Cache[e.CacheName];
}
}
VB.NET Copy Code
Imports System
Imports System.Data
Imports System.Configuration
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls
Imports ComponentSoft
Partial Public Class _Default
Inherits System.Web.UI.Page
Protected Overloads Overrides Sub Render(ByVal writer As HtmlTextWriter)
Try
Dim dt As New TemplateEngine()
AddHandler dt.OnLoadTemplateFromCache, AddressOf dt_OnLoadTemplateFromCache
AddHandler dt.OnSaveTemplateToCache, AddressOf dt_OnSaveTemplateToCache
dt.LoadFromFile("MyTemplate.tpl")
dt.SetValue("CompanyName", "My Company Name")
dt.SetValue("EmailAddress", "myemail@somedomain.com")
dt.SetValue("FullName", "John Borders")
dt.Run(writer)
Catch exc As Exception
writer.Write("An error occurred: " + exc.Message)
End Try
End Sub
Private Sub dt_OnSaveTemplateToCache(ByVal sender As Object, ByVal e As TemplateEngineCacheEventArgs)
HttpContext.Current.Cache(e.CacheName) = e.CacheData
End Sub
Private Sub dt_OnLoadTemplateFromCache(ByVal sender As Object, ByVal e As TemplateEngineCacheEventArgs)
e.CacheData = HttpContext.Current.Cache(e.CacheName)
End Sub
End Class
* Uses OnLoadTemplateFromCache for loading cached template data.
* Uses OnSaveTemplateToCache for saving template data to cache.
The Web Sample code-behind below shows how to load/save template data from/to Http Cache.
C# Copy Code
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using ComponentSoft;
public partial class _Default : System.Web.UI.Page
{
protected override void Render(HtmlTextWriter writer)
{
try
{
TemplateEngine dt = new TemplateEngine();
dt.OnLoadTemplateFromCache += new EventHandler
dt.OnSaveTemplateToCache += new EventHandler
dt.LoadFromFile("MyTemplate.tpl");
dt.SetValue("CompanyName", "My Company Name");
dt.SetValue("EmailAddress", "myemail@somedomain.com");
dt.SetValue("FullName", "John Borders");
dt.Run(writer);
}
catch (Exception exc)
{
writer.Write("An error occurred: " + exc.Message);
}
}
void dt_OnSaveTemplateToCache(object sender, TemplateEngineCacheEventArgs e)
{
HttpContext.Current.Cache[e.CacheName] = e.CacheData;
}
void dt_OnLoadTemplateFromCache(object sender, TemplateEngineCacheEventArgs e)
{
e.CacheData = HttpContext.Current.Cache[e.CacheName];
}
}
VB.NET Copy Code
Imports System
Imports System.Data
Imports System.Configuration
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls
Imports ComponentSoft
Partial Public Class _Default
Inherits System.Web.UI.Page
Protected Overloads Overrides Sub Render(ByVal writer As HtmlTextWriter)
Try
Dim dt As New TemplateEngine()
AddHandler dt.OnLoadTemplateFromCache, AddressOf dt_OnLoadTemplateFromCache
AddHandler dt.OnSaveTemplateToCache, AddressOf dt_OnSaveTemplateToCache
dt.LoadFromFile("MyTemplate.tpl")
dt.SetValue("CompanyName", "My Company Name")
dt.SetValue("EmailAddress", "myemail@somedomain.com")
dt.SetValue("FullName", "John Borders")
dt.Run(writer)
Catch exc As Exception
writer.Write("An error occurred: " + exc.Message)
End Try
End Sub
Private Sub dt_OnSaveTemplateToCache(ByVal sender As Object, ByVal e As TemplateEngineCacheEventArgs)
HttpContext.Current.Cache(e.CacheName) = e.CacheData
End Sub
Private Sub dt_OnLoadTemplateFromCache(ByVal sender As Object, ByVal e As TemplateEngineCacheEventArgs)
e.CacheData = HttpContext.Current.Cache(e.CacheName)
End Sub
End Class
Declaring variables
This topics shows how to declare and initialize variables in your template code:
Template.tpl Copy Code
{%double db = 10.4/}
$db$
{%double db2 = 10D/}
$db2$
{%db3 = 10.3/} {! db3 is a double !}
This declares a double and assign it to value of 10.4. The output will be
10.4
10
10.3
UltimateTemplateEngine supports the following value types: bool, char, byte, sbyte, double, float, int, long, short, uint, ulong, ushort, string, fixed array, dynamic array, dictionary and .NET object.
C# Copy Code
using System;
using System.Collections.Generic;
using System.Text;
using ComponentSoft;
namespace CSharp
{
public class Sample
{
[STAThread]
static void Main()
{
TemplateEngine dt = new TemplateEngine();
dt.LoadFromFile("Template.tpl");
string output = dt.Run();
Console.WriteLine(output);
}
}
}
VB.NET Copy Code
Imports ComponentSoft
Module Sample
Sub Main()
Dim dt As TemplateEngine = New TemplateEngine()
Dim output As String
dt.LoadFromFile("Template.tpl")
output = dt.Run()
Console.WriteLine(output)
End Sub
End Module
Template.tpl Copy Code
{%double db = 10.4/}
$db$
{%double db2 = 10D/}
$db2$
{%db3 = 10.3/} {! db3 is a double !}
This declares a double and assign it to value of 10.4. The output will be
10.4
10
10.3
UltimateTemplateEngine supports the following value types: bool, char, byte, sbyte, double, float, int, long, short, uint, ulong, ushort, string, fixed array, dynamic array, dictionary and .NET object.
C# Copy Code
using System;
using System.Collections.Generic;
using System.Text;
using ComponentSoft;
namespace CSharp
{
public class Sample
{
[STAThread]
static void Main()
{
TemplateEngine dt = new TemplateEngine();
dt.LoadFromFile("Template.tpl");
string output = dt.Run();
Console.WriteLine(output);
}
}
}
VB.NET Copy Code
Imports ComponentSoft
Module Sample
Sub Main()
Dim dt As TemplateEngine = New TemplateEngine()
Dim output As String
dt.LoadFromFile("Template.tpl")
output = dt.Run()
Console.WriteLine(output)
End Sub
End Module
Getting reference of template in code
If you wish to obtain a reference to a template object and render it, you have to use the FindTemplate method in the TemplateEngine class of the ComponentSoft TemplateEngine.
There are two kinds of templates you need to consider when finding them:
1. Template inside a templateclass: you need to add '$' character at the beginning of templateclass name and template name; e.g.: to find a template named 'mymethod' in 'myclass' templateclass you need to pass '$myclass.mymethod' to the FindTemplate, that will be: FindTemplate("$myclass.mymethod");
2. Normal template; a template are not inside any templateclasses: you need to pass the template name to the FindTemplate method.
To find a child template you use character '.'(dot) in between parent and child templates.
The following examples demonstrate how to use FindTemplate method to find a template:
Sample.tpc Copy Code
templateclass myclass
{
mytemplate(a,b,c,d)
{#
$a - b - d - c$
{%template child1%}
This is a child template in a class.
{$template%}
#}
}
Template.tpl Copy Code
Hi,
{%template child2%}
This is a child template.
{$template%}
C# Copy Code
using System;
using System.Collections.Generic;
using System.Text;
using ComponentSoft;
namespace CSharp
{
public class TemplateClass2Sample
{
[STAThread]
static void Main()
{
TemplateEngine dt = new TemplateEngine();
string output;
dt.LoadTemplateClassesFromFile("Sample.tpc");
dt.LoadFromFile("Template.tpl");
dt.SetValue("a", 100);
dt.SetValue("b", 2);
dt.SetValue("c", 1);
dt.SetValue("d", 8);
// Find template "mytemplate" inside "myclass" and render it.
Template tpl1 = dt.FindTemplate("global::myclass.mytemplate");
output = dt.Run(tpl1);
Console.WriteLine(output);
// Find child template "child1" of "mytemplate" inside "myclass" and render it.
Template tpl2 = dt.FindTemplate("global::myclass.mytemplate.child1");
output = dt.Run(tpl2);
Console.WriteLine(output);
// Find child template "child2" defined in Template.tpl and render it.
Template tpl3 = dt.FindTemplate("child2");
output = dt.Run(tpl3);
Console.WriteLine(output);
// Render the mainly loaded template.
output = dt.Run();
Console.WriteLine(output);
}
}
}
VB.NET Copy Code
Imports ComponentSoft
Module TemplateClass2Sample
Sub Main()
Dim dt As New TemplateEngine()
Dim output As String
dt.LoadTemplateClassesFromFile("Sample.tpc")
dt.LoadFromFile("Template.tpl")
dt.SetValue("a", 100)
dt.SetValue("b", 2)
dt.SetValue("c", 1)
dt.SetValue("d", 8)
' Find template "mytemplate" inside "myclass" and render it.
Dim tpl1 As Template = dt.FindTemplate("global::myclass.mytemplate")
output = dt.Run(tpl1)
Console.WriteLine(output)
' Find child template "child1" of "mytemplate" inside "myclass" and render it.
Dim tpl2 As Template = dt.FindTemplate("global::myclass.mytemplate.child1")
output = dt.Run(tpl2)
Console.WriteLine(output)
' Find child template "child2" defined in Template.tpl and render it.
Dim tpl3 As Template = dt.FindTemplate("child2")
output = dt.Run(tpl3)
Console.WriteLine(output)
' Render the mainly loaded template.
output = dt.Run()
Console.WriteLine(output)
End Sub
End Module
There are two kinds of templates you need to consider when finding them:
1. Template inside a templateclass: you need to add '$' character at the beginning of templateclass name and template name; e.g.: to find a template named 'mymethod' in 'myclass' templateclass you need to pass '$myclass.mymethod' to the FindTemplate, that will be: FindTemplate("$myclass.mymethod");
2. Normal template; a template are not inside any templateclasses: you need to pass the template name to the FindTemplate method.
To find a child template you use character '.'(dot) in between parent and child templates.
The following examples demonstrate how to use FindTemplate method to find a template:
Sample.tpc Copy Code
templateclass myclass
{
mytemplate(a,b,c,d)
{#
$a - b - d - c$
{%template child1%}
This is a child template in a class.
{$template%}
#}
}
Template.tpl Copy Code
Hi,
{%template child2%}
This is a child template.
{$template%}
C# Copy Code
using System;
using System.Collections.Generic;
using System.Text;
using ComponentSoft;
namespace CSharp
{
public class TemplateClass2Sample
{
[STAThread]
static void Main()
{
TemplateEngine dt = new TemplateEngine();
string output;
dt.LoadTemplateClassesFromFile("Sample.tpc");
dt.LoadFromFile("Template.tpl");
dt.SetValue("a", 100);
dt.SetValue("b", 2);
dt.SetValue("c", 1);
dt.SetValue("d", 8);
// Find template "mytemplate" inside "myclass" and render it.
Template tpl1 = dt.FindTemplate("global::myclass.mytemplate");
output = dt.Run(tpl1);
Console.WriteLine(output);
// Find child template "child1" of "mytemplate" inside "myclass" and render it.
Template tpl2 = dt.FindTemplate("global::myclass.mytemplate.child1");
output = dt.Run(tpl2);
Console.WriteLine(output);
// Find child template "child2" defined in Template.tpl and render it.
Template tpl3 = dt.FindTemplate("child2");
output = dt.Run(tpl3);
Console.WriteLine(output);
// Render the mainly loaded template.
output = dt.Run();
Console.WriteLine(output);
}
}
}
VB.NET Copy Code
Imports ComponentSoft
Module TemplateClass2Sample
Sub Main()
Dim dt As New TemplateEngine()
Dim output As String
dt.LoadTemplateClassesFromFile("Sample.tpc")
dt.LoadFromFile("Template.tpl")
dt.SetValue("a", 100)
dt.SetValue("b", 2)
dt.SetValue("c", 1)
dt.SetValue("d", 8)
' Find template "mytemplate" inside "myclass" and render it.
Dim tpl1 As Template = dt.FindTemplate("global::myclass.mytemplate")
output = dt.Run(tpl1)
Console.WriteLine(output)
' Find child template "child1" of "mytemplate" inside "myclass" and render it.
Dim tpl2 As Template = dt.FindTemplate("global::myclass.mytemplate.child1")
output = dt.Run(tpl2)
Console.WriteLine(output)
' Find child template "child2" defined in Template.tpl and render it.
Dim tpl3 As Template = dt.FindTemplate("child2")
output = dt.Run(tpl3)
Console.WriteLine(output)
' Render the mainly loaded template.
output = dt.Run()
Console.WriteLine(output)
End Sub
End Module
Including an external template file
In some specific cases, you need to include an external template file to the current context. It can be done by using usetemplate keyword and to render a previously loaded template you have to use rendertemplate keyword, as shown in the following example:
ExtTemplate.tpl Copy Code
{%string str = "Second template"/}
Second Template
Template.tpl Copy Code
{%usetemplate myext "ExtTemplate.tpl"/}
First Template
{%rendertemplate myext/}
The output will be:
First Template
Second Template
C# Copy Code
using System;
using System.Collections.Generic;
using System.Text;
using ComponentSoft;
namespace CSharp
{
public class Sample
{
[STAThread]
static void Main()
{
TemplateEngine dt = new TemplateEngine();
dt.LoadFromFile("Template.tpl");
string output = dt.Run();
Console.WriteLine(output);
}
}
}
VB.NET Copy Code
Imports ComponentSoft
Module Sample
Sub Main()
Dim dt As TemplateEngine = New TemplateEngine()
Dim output As String
dt.LoadFromFile("Template.tpl")
output = dt.Run()
Console.WriteLine(output)
End Sub
End Module
ExtTemplate.tpl Copy Code
{%string str = "Second template"/}
Second Template
Template.tpl Copy Code
{%usetemplate myext "ExtTemplate.tpl"/}
First Template
{%rendertemplate myext/}
The output will be:
First Template
Second Template
C# Copy Code
using System;
using System.Collections.Generic;
using System.Text;
using ComponentSoft;
namespace CSharp
{
public class Sample
{
[STAThread]
static void Main()
{
TemplateEngine dt = new TemplateEngine();
dt.LoadFromFile("Template.tpl");
string output = dt.Run();
Console.WriteLine(output);
}
}
}
VB.NET Copy Code
Imports ComponentSoft
Module Sample
Sub Main()
Dim dt As TemplateEngine = New TemplateEngine()
Dim output As String
dt.LoadFromFile("Template.tpl")
output = dt.Run()
Console.WriteLine(output)
End Sub
End Module
Introduction to TemplateClass
UltimateTemplateEngine v1.2 introduces the notions of templateclass that allows you to define lots of small templates in a single templateclass, and a template file may contains as many templateclasses as you want. A templateclass can also be defined as an abstract templateclass, so that derived templateclasses should implement abstract methods, as shown in the examples below:
Templateclass file and Template file:
Sample.tpc Copy Code
templateclass thebaseclass
{
themethod() {! Define a base template !}
{#
Oh, great
#}
}
templateclass theabstract
{
templatea(a,b,c); {! Abstract template requiring three parameters !}
templateb(a,b,c); {! Abstract template requiring three parameters !}
templatec(a,b,c)
{#
templatec$a$$b$$c$
#}
}
templateclass theclass : thebaseclass, theabstract {! theclass derives from thebaseclass and theabstract classes !}
{
templatea(a,b,c) {! Override the templatea template !}
{#
$a$$b$$c$
#}
templateb(a,b,c) {! Override the templateb template !}
{#
$a$$b$$c$
#}
mytemplateb(a,b,c) {! Define a new template requiring three parameters !}
{#
$a$$b$$c$
{%template MyEmbeddedTemplate first,second%} {! Defines an embedded template requiring two parameters: "first" and "second"!}
The Embedded Template
{$template%}
#}
}
Template.tpl Copy Code
{! Render template themethod in the "thebaseclass" templateclass !}
{%rendertemplate $theclass.themethod/}
{! Render overriding template templatea in the "theclass", values of 1,2,3 are passed to corresponding parameters !}
{%rendertemplate $theclass.templatea a=1 b=2 c=3/}
Loading template file and templateclass file in C# and VB.NET
C# Copy Code
using System;
using System.Collections.Generic;
using System.Text;
using ComponentSoft;
namespace CSharp
{
public class TemplateClassSample
{
[STAThread]
static void Main()
{
TemplateEngine dt = new TemplateEngine();
dt.LoadTemplateClassesFromFile("Sample.tpc");
dt.LoadFromFile("Template.tpl");
string output = dt.Run();
Console.WriteLine(output);
}
}
}
VB.NET Copy Code
Imports ComponentSoft
Module TemplateClassSample
Sub Main()
Dim dt As TemplateEngine = New TemplateEngine()
Dim output As String
dt.LoadTemplateClassesFromFile("Sample.tpc")
dt.LoadFromFile("Template.tpl")
output = dt.Run()
Console.WriteLine(output)
End Sub
End Module
Templateclass file and Template file:
Sample.tpc Copy Code
templateclass thebaseclass
{
themethod() {! Define a base template !}
{#
Oh, great
#}
}
templateclass theabstract
{
templatea(a,b,c); {! Abstract template requiring three parameters !}
templateb(a,b,c); {! Abstract template requiring three parameters !}
templatec(a,b,c)
{#
templatec$a$$b$$c$
#}
}
templateclass theclass : thebaseclass, theabstract {! theclass derives from thebaseclass and theabstract classes !}
{
templatea(a,b,c) {! Override the templatea template !}
{#
$a$$b$$c$
#}
templateb(a,b,c) {! Override the templateb template !}
{#
$a$$b$$c$
#}
mytemplateb(a,b,c) {! Define a new template requiring three parameters !}
{#
$a$$b$$c$
{%template MyEmbeddedTemplate first,second%} {! Defines an embedded template requiring two parameters: "first" and "second"!}
The Embedded Template
{$template%}
#}
}
Template.tpl Copy Code
{! Render template themethod in the "thebaseclass" templateclass !}
{%rendertemplate $theclass.themethod/}
{! Render overriding template templatea in the "theclass", values of 1,2,3 are passed to corresponding parameters !}
{%rendertemplate $theclass.templatea a=1 b=2 c=3/}
Loading template file and templateclass file in C# and VB.NET
C# Copy Code
using System;
using System.Collections.Generic;
using System.Text;
using ComponentSoft;
namespace CSharp
{
public class TemplateClassSample
{
[STAThread]
static void Main()
{
TemplateEngine dt = new TemplateEngine();
dt.LoadTemplateClassesFromFile("Sample.tpc");
dt.LoadFromFile("Template.tpl");
string output = dt.Run();
Console.WriteLine(output);
}
}
}
VB.NET Copy Code
Imports ComponentSoft
Module TemplateClassSample
Sub Main()
Dim dt As TemplateEngine = New TemplateEngine()
Dim output As String
dt.LoadTemplateClassesFromFile("Sample.tpc")
dt.LoadFromFile("Template.tpl")
output = dt.Run()
Console.WriteLine(output)
End Sub
End Module
ComponentSoft Template Engine Calling Restriction
UltimateTemplateEngine allows you to restrict the call to specific namespaces, methods and properties, you can allow and restrict the call to namespaces, methods and properties by using wildcard characters (*,?) or extract names as well.
The following example shows how to use RestrictedMethodList, AllowedMethodList, RestrictedPropertyList and AllowedPropertyList of TemplateEngine class.
C# Copy Code
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using ComponentSoft;
namespace MethodAndPropertyRestriction
{
public static class MyTestClass
{
public static string TestString
{
get { return "Static String"; }
}
public static string GetStaticString(string s)
{
return string.Format("GetStaticString returns {0}", s);
}
}
public static class ClassRestricted
{
public static string TestString
{
get { return "Test String in a restricted class"; }
}
}
public static class MethodAndProperty
{
public static string TestStringRestricted
{
get { return "Restricted String"; }
}
public static string GetStaticStringRestricted(string s)
{
return string.Format("GetStaticStringRestricted returns {0}", s);
}
public static string StaticStringAllowed
{
get
{
return "StaticStringAllowed";
}
}
}
static class Program
{
///
/// The main entry point for the application.
///
[STAThread]
static void Main()
{
try
{
UltimateTemplateEngine ctl = new UltimateTemplateEngine();
ctl.LoadFromString("$using(\"MethodAndPropertyRestriction,MethodAndPropertyRestriction\")$$MyTestClass.TestString$\r\n$MyTestClass.GetStaticString(\"Test\")$\r\n$ClassRestricted.TestString$\r\n$MethodAndProperty.TestStringRestricted$\r\n$MethodAndProperty.GetStaticStringRestricted("static string")$\r\n$MethodAndProperty.StaticStringAllowed$");
ctl.RestrictedMethodList.Add("*.ClassRestricted.*");
ctl.RestrictedPropertyList.Add("*.ClassRestricted.*");
ctl.RestrictedMethodList.Add("*.MethodAndProperty.GetStaticString*");
ctl.AllowedMethodList.Add("*.MethodAndProperty.GetStaticStringAllowed");
ctl.RestrictedPropertyList.Add("*.TestStringRestricted");
string s = ctl.Run();
MessageBox.Show(s);
}
catch (Exception exc)
{
MessageBox.Show(exc.Message);
}
}
}
}
The following example shows how to use RestrictedMethodList, AllowedMethodList, RestrictedPropertyList and AllowedPropertyList of TemplateEngine class.
C# Copy Code
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using ComponentSoft;
namespace MethodAndPropertyRestriction
{
public static class MyTestClass
{
public static string TestString
{
get { return "Static String"; }
}
public static string GetStaticString(string s)
{
return string.Format("GetStaticString returns {0}", s);
}
}
public static class ClassRestricted
{
public static string TestString
{
get { return "Test String in a restricted class"; }
}
}
public static class MethodAndProperty
{
public static string TestStringRestricted
{
get { return "Restricted String"; }
}
public static string GetStaticStringRestricted(string s)
{
return string.Format("GetStaticStringRestricted returns {0}", s);
}
public static string StaticStringAllowed
{
get
{
return "StaticStringAllowed";
}
}
}
static class Program
{
///
/// The main entry point for the application.
///
[STAThread]
static void Main()
{
try
{
UltimateTemplateEngine ctl = new UltimateTemplateEngine();
ctl.LoadFromString("$using(\"MethodAndPropertyRestriction,MethodAndPropertyRestriction\")$$MyTestClass.TestString$\r\n$MyTestClass.GetStaticString(\"Test\")$\r\n$ClassRestricted.TestString$\r\n$MethodAndProperty.TestStringRestricted$\r\n$MethodAndProperty.GetStaticStringRestricted("static string")$\r\n$MethodAndProperty.StaticStringAllowed$");
ctl.RestrictedMethodList.Add("*.ClassRestricted.*");
ctl.RestrictedPropertyList.Add("*.ClassRestricted.*");
ctl.RestrictedMethodList.Add("*.MethodAndProperty.GetStaticString*");
ctl.AllowedMethodList.Add("*.MethodAndProperty.GetStaticStringAllowed");
ctl.RestrictedPropertyList.Add("*.TestStringRestricted");
string s = ctl.Run();
MessageBox.Show(s);
}
catch (Exception exc)
{
MessageBox.Show(exc.Message);
}
}
}
}
Calling .NET Framework's methods and properties
This topic shows how to call .NET Framework's methods in your template code with ComponentSoft Template Engine. For static methods and properties, you don't have to create a new instance of a .NET object before calling them.
The easiest way to demonstrate what goes on is by example:
Template.tpl Copy Code
{%using("System.IO")/}
$art.ArticleId$ {! Prints out object's property !}
$Path.GetDirectoryName("C:\Temp\Temp.tmp")$ {! Calls the static method GetDirectoryName !}
$art.GetFullName()$ {! Calls method GetFullName() in Article class !}
The output will be:
100
C:\Temp
LEO DANG
C# Copy Code
using System;
using System.Collections.Generic;
using System.Text;
using ComponentSoft;
namespace CSharp
{
class ArticleAuthor
{
public string FullName
{
get
{
return "Leo Dang";
}
}
}
class Article
{
public int ArticleId
{
get
{
return 100;
}
}
public ArticleAuthor ArticleAuthor
{
get
{
return new ArticleAuthor();
}
}
public string GetFullName()
{
return this.ArticleAuthor.FullName.ToUpper();
}
}
public class PropertyAndMethodSample
{
[STAThread]
static void Main()
{
TemplateEngine dt = new TemplateEngine();
dt.LoadFromFile("Template.tpl");
Article art = new Article();
dt.SetValue("art", art);
string output = dt.Run();
Console.WriteLine(output);
}
}
}
VB.NET Copy Code
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports ComponentSoft
Module PropertyAndMethodSample
Class ArticleAuthor
Public ReadOnly Property FullName() As String
Get
Return "Leo Dang"
End Get
End Property
End Class
Class Article
Public ReadOnly Property ArticleId() As Integer
Get
Return 100
End Get
End Property
Public ReadOnly Property ArticleAuthor() As ArticleAuthor
Get
Return New ArticleAuthor()
End Get
End Property
Public Function GetFullName() As String
Return Me.ArticleAuthor.FullName.ToUpper()
End Function
End Class
Sub Main()
Dim dt As New TemplateEngine()
dt.LoadFromFile("Template.tpl")
Dim art As New Article()
dt.SetValue("art", art)
Dim output As String = dt.Run()
Console.WriteLine(output)
End Sub
End Module
The easiest way to demonstrate what goes on is by example:
Template.tpl Copy Code
{%using("System.IO")/}
$art.ArticleId$ {! Prints out object's property !}
$Path.GetDirectoryName("C:\Temp\Temp.tmp")$ {! Calls the static method GetDirectoryName !}
$art.GetFullName()$ {! Calls method GetFullName() in Article class !}
The output will be:
100
C:\Temp
LEO DANG
C# Copy Code
using System;
using System.Collections.Generic;
using System.Text;
using ComponentSoft;
namespace CSharp
{
class ArticleAuthor
{
public string FullName
{
get
{
return "Leo Dang";
}
}
}
class Article
{
public int ArticleId
{
get
{
return 100;
}
}
public ArticleAuthor ArticleAuthor
{
get
{
return new ArticleAuthor();
}
}
public string GetFullName()
{
return this.ArticleAuthor.FullName.ToUpper();
}
}
public class PropertyAndMethodSample
{
[STAThread]
static void Main()
{
TemplateEngine dt = new TemplateEngine();
dt.LoadFromFile("Template.tpl");
Article art = new Article();
dt.SetValue("art", art);
string output = dt.Run();
Console.WriteLine(output);
}
}
}
VB.NET Copy Code
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports ComponentSoft
Module PropertyAndMethodSample
Class ArticleAuthor
Public ReadOnly Property FullName() As String
Get
Return "Leo Dang"
End Get
End Property
End Class
Class Article
Public ReadOnly Property ArticleId() As Integer
Get
Return 100
End Get
End Property
Public ReadOnly Property ArticleAuthor() As ArticleAuthor
Get
Return New ArticleAuthor()
End Get
End Property
Public Function GetFullName() As String
Return Me.ArticleAuthor.FullName.ToUpper()
End Function
End Class
Sub Main()
Dim dt As New TemplateEngine()
dt.LoadFromFile("Template.tpl")
Dim art As New Article()
dt.SetValue("art", art)
Dim output As String = dt.Run()
Console.WriteLine(output)
End Sub
End Module
Writting a custom function
You can add a custom function to the TemplateEngine class by passing an alias name and function address to SetFunction method. It can led you to replace the Built-in functions by your own functions.
The example below shows how to write two custom functions:
* Pow returns a specified number raised to the specified power.
* Concat returns a concatenated of two specified strings.
C# Copy Code
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using ComponentSoft;
namespace Function
{
static class Program
{
[STAThread]
static void Main(string[] args)
{
FunctionSample();
}
static object Power(TemplateEngine dt, object[] args)
{
// Function has two parameters
if (!TemplateEngine.VerifyParameters(dt, "Pow", args, 2))
return string.Empty;
try
{
double x = Convert.ToDouble(args[0]);
double y = Convert.ToDouble(args[1]);
return Math.Pow(x, y);
}
catch (Exception exc)
{
dt.WriteError("Invalid parameter, error: " + exc.Message);
return string.Empty;
}
}
///
/// Although UltimateTemplateEngine already provided a powerful + operator for string object, we purposely create a function to concatenate two strings for demonstration only.
///
static object Concat(TemplateEngine dt, object[] args)
{
// Function has two parameters in string type.
if (!TemplateEngine.VerifyParameters(dt, "Concat", args, 2, typeof(string), typeof(string)))
return string.Empty;
string s1 = args[0] as string;
string s2 = args[1] as string;
return s1 + s2;
}
public static void FunctionSample()
{
try
{
UltimateTemplateEngine dn = new UltimateTemplateEngine();
dn.LoadFromString("Custom Pow Function demo: $x$ ^ $y$ = $Pow(x,y)$\r\nCustom String Concatenation: \"$str1$\" + \"$str2$\" = \"$Concat(str1, str2)$\"");
dn.SetFunction("Pow", new TplRuntimeFunction(Power));
dn.SetFunction("Concat", new TplRuntimeFunction(Concat));
dn.SetValue("x", 15.0f);
dn.SetValue("y", 2.3f);
dn.SetValue("str1", "Hello ");
dn.SetValue("str2", "World");
MessageBox.Show(dn.Run());
}
catch (Exception exc)
{
MessageBox.Show("An exception occurred: " + exc.Message);
}
}
}
}
VB.NET Copy Code
Imports System
Imports System.Collections.Generic
Imports System.Windows.Forms
Imports Microsoft.VisualBasic
Imports ComponentSoft
Module [Function]
Sub Main(ByVal args As String())
FunctionSample()
End Sub
Private Function Power(ByVal dt As UltimateTemplateEngine, ByVal args As Object()) As Object
' Function has two parameters
If Not UltimateTemplateEngine.VerifyParameters(dt, "Pow", args, 2) Then
Return String.Empty
End If
Try
Dim x As Double = Convert.ToDouble(args(0))
Dim y As Double = Convert.ToDouble(args(1))
Return Math.Pow(x, y)
Catch exc As Exception
dt.WriteError("Invalid parameter, error: " + exc.Message)
Return String.Empty
End Try
End Function
'''
''' Although UltimateTemplateEngine already provided a powerful + operator for string object, we purposely create a function to concat two strings for demonstration only.
'''
Private Function Concat(ByVal dt As UltimateTemplateEngine, ByVal args As Object()) As Object
' Function has two parameters in string type.
If Not UltimateTemplateEngine.VerifyParameters(dt, "Concat", args, 2, GetType(String), GetType(String)) Then
Return String.Empty
End If
Dim s1 As String = TryCast(args(0), String)
Dim s2 As String = TryCast(args(1), String)
Return s1 + s2
End Function
Public Sub FunctionSample()
Try
Dim dn As New TemplateEngine()
dn.LoadFromString("Custom Pow Function demo: $x$ ^ $y$ = $Pow(x,y)$" & Chr(13) & "" & Chr(10) & "Custom String Concatenation: ""$str1$"" + ""$str2$"" = ""$Concat(str1, str2)$""")
dn.SetFunction("Pow", New TplRuntimeFunction(AddressOf Power))
dn.SetFunction("Concat", New TplRuntimeFunction(AddressOf Concat))
dn.SetValue("x", 15.0F)
dn.SetValue("y", 2.3F)
dn.SetValue("str1", "Hello ")
dn.SetValue("str2", "World")
MessageBox.Show(dn.Run())
Catch exc As Exception
MessageBox.Show("An exception occurred: " + exc.Message)
End Try
End Sub
End Module
The example below shows how to write two custom functions:
* Pow returns a specified number raised to the specified power.
* Concat returns a concatenated of two specified strings.
C# Copy Code
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using ComponentSoft;
namespace Function
{
static class Program
{
[STAThread]
static void Main(string[] args)
{
FunctionSample();
}
static object Power(TemplateEngine dt, object[] args)
{
// Function has two parameters
if (!TemplateEngine.VerifyParameters(dt, "Pow", args, 2))
return string.Empty;
try
{
double x = Convert.ToDouble(args[0]);
double y = Convert.ToDouble(args[1]);
return Math.Pow(x, y);
}
catch (Exception exc)
{
dt.WriteError("Invalid parameter, error: " + exc.Message);
return string.Empty;
}
}
///
/// Although UltimateTemplateEngine already provided a powerful + operator for string object, we purposely create a function to concatenate two strings for demonstration only.
///
static object Concat(TemplateEngine dt, object[] args)
{
// Function has two parameters in string type.
if (!TemplateEngine.VerifyParameters(dt, "Concat", args, 2, typeof(string), typeof(string)))
return string.Empty;
string s1 = args[0] as string;
string s2 = args[1] as string;
return s1 + s2;
}
public static void FunctionSample()
{
try
{
UltimateTemplateEngine dn = new UltimateTemplateEngine();
dn.LoadFromString("Custom Pow Function demo: $x$ ^ $y$ = $Pow(x,y)$\r\nCustom String Concatenation: \"$str1$\" + \"$str2$\" = \"$Concat(str1, str2)$\"");
dn.SetFunction("Pow", new TplRuntimeFunction(Power));
dn.SetFunction("Concat", new TplRuntimeFunction(Concat));
dn.SetValue("x", 15.0f);
dn.SetValue("y", 2.3f);
dn.SetValue("str1", "Hello ");
dn.SetValue("str2", "World");
MessageBox.Show(dn.Run());
}
catch (Exception exc)
{
MessageBox.Show("An exception occurred: " + exc.Message);
}
}
}
}
VB.NET Copy Code
Imports System
Imports System.Collections.Generic
Imports System.Windows.Forms
Imports Microsoft.VisualBasic
Imports ComponentSoft
Module [Function]
Sub Main(ByVal args As String())
FunctionSample()
End Sub
Private Function Power(ByVal dt As UltimateTemplateEngine, ByVal args As Object()) As Object
' Function has two parameters
If Not UltimateTemplateEngine.VerifyParameters(dt, "Pow", args, 2) Then
Return String.Empty
End If
Try
Dim x As Double = Convert.ToDouble(args(0))
Dim y As Double = Convert.ToDouble(args(1))
Return Math.Pow(x, y)
Catch exc As Exception
dt.WriteError("Invalid parameter, error: " + exc.Message)
Return String.Empty
End Try
End Function
'''
''' Although UltimateTemplateEngine already provided a powerful + operator for string object, we purposely create a function to concat two strings for demonstration only.
'''
Private Function Concat(ByVal dt As UltimateTemplateEngine, ByVal args As Object()) As Object
' Function has two parameters in string type.
If Not UltimateTemplateEngine.VerifyParameters(dt, "Concat", args, 2, GetType(String), GetType(String)) Then
Return String.Empty
End If
Dim s1 As String = TryCast(args(0), String)
Dim s2 As String = TryCast(args(1), String)
Return s1 + s2
End Function
Public Sub FunctionSample()
Try
Dim dn As New TemplateEngine()
dn.LoadFromString("Custom Pow Function demo: $x$ ^ $y$ = $Pow(x,y)$" & Chr(13) & "" & Chr(10) & "Custom String Concatenation: ""$str1$"" + ""$str2$"" = ""$Concat(str1, str2)$""")
dn.SetFunction("Pow", New TplRuntimeFunction(AddressOf Power))
dn.SetFunction("Concat", New TplRuntimeFunction(AddressOf Concat))
dn.SetValue("x", 15.0F)
dn.SetValue("y", 2.3F)
dn.SetValue("str1", "Hello ")
dn.SetValue("str2", "World")
MessageBox.Show(dn.Run())
Catch exc As Exception
MessageBox.Show("An exception occurred: " + exc.Message)
End Try
End Sub
End Module
Template Engine Object Property
UltimateTemplateEngine offers a number of flexible ways to access object's properties and class's static properties. You can deeply access properties as easily as you do in .NET Framework.
The following example shows you how to a access public property, static property of Book class and deeply access a property in the Author class:
Template.tpl Copy Code
$Book.StaticId$
ID: $bk.BookId$ - Author: $bk.Author.Name$
Length of the author's Name: $bk.Author.Name.Length$
The output will be:
AABB
ID: 100 - Author: John Borders
12
C# Copy Code
using System;
using System.Collections.Generic;
using System.Text;
using ComponentSoft;
namespace CSharp
{
class Author
{
public string Name
{
get
{
return "John Borders";
}
}
}
class Book
{
public static string StaticId
{
get
{
return "AABB";
}
}
public int BookId
{
get
{
return 100;
}
}
public Author Author
{
get
{
return new Author();
}
}
}
public class PropertySample1
{
[STAThread]
static void Main()
{
TemplateEngine dt = new TemplateEngine();
dt.LoadFromFile("Template.tpl");
Book book = new Book();
dt.SetValue("bk", book);
dt.UsingNamespace("CSharp,Demo");
string output = dt.Run();
Console.WriteLine(output);
}
}
}
VB.NET Copy Code
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports ComponentSoft
Module PropertySample1
Class Author
Public ReadOnly Property Name() As String
Get
Return "John Borders"
End Get
End Property
End Class
Class Book
Public Shared ReadOnly Property StaticId() As String
Get
Return "AABB"
End Get
End Property
Public ReadOnly Property BookId() As Integer
Get
Return 100
End Get
End Property
Public ReadOnly Property Author() As Author
Get
Return New Author()
End Get
End Property
End Class
Sub Main()
Dim dt As New TemplateEngine()
dt.LoadFromFile("Template.tpl")
Dim book As New Book()
dt.SetValue("bk", book)
Dim output As String = dt.Run()
Console.WriteLine(output)
End Sub
End Module
The following example shows you how to a access public property, static property of Book class and deeply access a property in the Author class:
Template.tpl Copy Code
$Book.StaticId$
ID: $bk.BookId$ - Author: $bk.Author.Name$
Length of the author's Name: $bk.Author.Name.Length$
The output will be:
AABB
ID: 100 - Author: John Borders
12
C# Copy Code
using System;
using System.Collections.Generic;
using System.Text;
using ComponentSoft;
namespace CSharp
{
class Author
{
public string Name
{
get
{
return "John Borders";
}
}
}
class Book
{
public static string StaticId
{
get
{
return "AABB";
}
}
public int BookId
{
get
{
return 100;
}
}
public Author Author
{
get
{
return new Author();
}
}
}
public class PropertySample1
{
[STAThread]
static void Main()
{
TemplateEngine dt = new TemplateEngine();
dt.LoadFromFile("Template.tpl");
Book book = new Book();
dt.SetValue("bk", book);
dt.UsingNamespace("CSharp,Demo");
string output = dt.Run();
Console.WriteLine(output);
}
}
}
VB.NET Copy Code
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports ComponentSoft
Module PropertySample1
Class Author
Public ReadOnly Property Name() As String
Get
Return "John Borders"
End Get
End Property
End Class
Class Book
Public Shared ReadOnly Property StaticId() As String
Get
Return "AABB"
End Get
End Property
Public ReadOnly Property BookId() As Integer
Get
Return 100
End Get
End Property
Public ReadOnly Property Author() As Author
Get
Return New Author()
End Get
End Property
End Class
Sub Main()
Dim dt As New TemplateEngine()
dt.LoadFromFile("Template.tpl")
Dim book As New Book()
dt.SetValue("bk", book)
Dim output As String = dt.Run()
Console.WriteLine(output)
End Sub
End Module
Changing delimiters in Template Engine
By default, tags are delimited by {%, /}, {$ and %}; expressions are delimited by '$': $ ... $; comments are delimited by {! and !}; This is good for the most common case of HTML generation. Sometimes, you may want to change the delimiters to avoid conflict with other formats like SQL statement generation. You can change the delimiters by setting BeginChar, EndChar, CommentChar and BeginEndExpressionChar in TemplateEngineSettings class.
The following example shows you how to change these delimiters in ComponentSoft Template Engine:
Template.tpl Copy Code
<%float f = 10.2f/> <# Initializes variable f #>
$f$ <# Prints out the variable f #>
The output will be:
10.2
C# Copy Code
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using ComponentSoft;
namespace CSharp
{
public class ChangeDelimiterCharacters
{
[STAThread]
static void Main()
{
TemplateEngine dt = new TemplateEngine();
dt.Settings.BeginChar = '<';
dt.Settings.EndChar = '>';
dt.Settings.CommentChar = '#';
dt.Settings.BeginEndExpressionChar = '$';
dt.LoadFromFile("Template.tpl");
string output = dt.Run();
Console.WriteLine(output);
}
}
}
VB.NET Copy Code
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports System.Collections
Imports ComponentSoft
Module ChangeDelimiterCharacters
Sub Main()
Dim dt As New TemplateEngine()
dt.Settings.BeginChar = "<"
dt.Settings.EndChar = ">"
dt.Settings.CommentChar = "#"
dt.Settings.BeginEndExpressionChar = "@"
dt.LoadFromFile("Template.tpl")
Dim output As String = dt.Run()
Console.WriteLine(output)
End Sub
End Module
The following example shows you how to change these delimiters in ComponentSoft Template Engine:
Template.tpl Copy Code
<%float f = 10.2f/> <# Initializes variable f #>
$f$ <# Prints out the variable f #>
The output will be:
10.2
C# Copy Code
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using ComponentSoft;
namespace CSharp
{
public class ChangeDelimiterCharacters
{
[STAThread]
static void Main()
{
TemplateEngine dt = new TemplateEngine();
dt.Settings.BeginChar = '<';
dt.Settings.EndChar = '>';
dt.Settings.CommentChar = '#';
dt.Settings.BeginEndExpressionChar = '$';
dt.LoadFromFile("Template.tpl");
string output = dt.Run();
Console.WriteLine(output);
}
}
}
VB.NET Copy Code
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports System.Collections
Imports ComponentSoft
Module ChangeDelimiterCharacters
Sub Main()
Dim dt As New TemplateEngine()
dt.Settings.BeginChar = "<"
dt.Settings.EndChar = ">"
dt.Settings.CommentChar = "#"
dt.Settings.BeginEndExpressionChar = "@"
dt.LoadFromFile("Template.tpl")
Dim output As String = dt.Run()
Console.WriteLine(output)
End Sub
End Module
ComponentSoft Template Engine Feature Overview
This topic outlines some important general features of ComponentSoft UltimateTemplateEngine v2.0
Key Features
* Supports Unicode.
* Can be use to generate any kind of text: HTML, XML, RTF, Email, Source Code, etc.
* Lightweight and easy to ship with your product (just only one DLL file).
* Template syntax is similar to C# and very easy to understand.
* Powerful template language with all usual directives: include, selection statements(if-else), Iteration Statements(do, for, foreach, while, break, continue).
* Initializing and changing variables in template code.
* Expressions can be as complex as you want.
* Powerful built-in functions (string, type conversion, collection rendering).
* Highly extensible with custom function.
* Smart and high-performance data type conversion.
* Gets template source directory, it's very useful for including external files such as Css or Javascript files in your web page.
* Gets and invokes any static, non-static public properties and methods in .NET Framework.
* Allows or restricts the calls to specific .NET methods and properties.
* Powerful array and dictionary rendering methods.
* Able to change tag, expression and template comment delimiters to avoid conflict with other formats.
* Direct output to your own TextWriter.
* Able to cache parsed template data to speed up performance.
* Template and TemplateClass can be loaded from many sources: file, stream, plain-text.
* Utilizes the power of .NET Framework.
* Template and TemplateClass reusability (you can define one template that will be used for many further purposes).
* Unified .NET exception.
Support
* Royalty free run-time.
* 1 year minor and major product updates.
* Full Windows Vista support.
* Support Visual Studio 2005, Visual Studio 2008, Delphi 8, C# Builder and other compliant development environments.
* Support Drag/Drop integration within Visual Studio.
* ComponentSoft UltimateTemplateEngine can run under both .NET Framework 2.x and 3.x.
* UltimateTemplateEngine can be used from ASP.NET web pages, Windows Form and Web Services.
.NET Technology
* 100% managed code written in C# (Complete source code included in the Gold License with Source Code).
* CLS compliant (Common Language Specification).
* Passed almost Microsoft FxCop's rules.
* Object-oriented design created specifically for .NET Framework version 2.x and above.
* Does not use unsafe blocks for minimal permission requirements.
* Seamless integration with the .NET base class libraries.
* Documentation fully integrated into Visual Studio .NET.
* C# and VB.NET samples included in the setup package show how to work with UltimateTemplateEngine.
Key Features
* Supports Unicode.
* Can be use to generate any kind of text: HTML, XML, RTF, Email, Source Code, etc.
* Lightweight and easy to ship with your product (just only one DLL file).
* Template syntax is similar to C# and very easy to understand.
* Powerful template language with all usual directives: include, selection statements(if-else), Iteration Statements(do, for, foreach, while, break, continue).
* Initializing and changing variables in template code.
* Expressions can be as complex as you want.
* Powerful built-in functions (string, type conversion, collection rendering).
* Highly extensible with custom function.
* Smart and high-performance data type conversion.
* Gets template source directory, it's very useful for including external files such as Css or Javascript files in your web page.
* Gets and invokes any static, non-static public properties and methods in .NET Framework.
* Allows or restricts the calls to specific .NET methods and properties.
* Powerful array and dictionary rendering methods.
* Able to change tag, expression and template comment delimiters to avoid conflict with other formats.
* Direct output to your own TextWriter.
* Able to cache parsed template data to speed up performance.
* Template and TemplateClass can be loaded from many sources: file, stream, plain-text.
* Utilizes the power of .NET Framework.
* Template and TemplateClass reusability (you can define one template that will be used for many further purposes).
* Unified .NET exception.
Support
* Royalty free run-time.
* 1 year minor and major product updates.
* Full Windows Vista support.
* Support Visual Studio 2005, Visual Studio 2008, Delphi 8, C# Builder and other compliant development environments.
* Support Drag/Drop integration within Visual Studio.
* ComponentSoft UltimateTemplateEngine can run under both .NET Framework 2.x and 3.x.
* UltimateTemplateEngine can be used from ASP.NET web pages, Windows Form and Web Services.
.NET Technology
* 100% managed code written in C# (Complete source code included in the Gold License with Source Code).
* CLS compliant (Common Language Specification).
* Passed almost Microsoft FxCop's rules.
* Object-oriented design created specifically for .NET Framework version 2.x and above.
* Does not use unsafe blocks for minimal permission requirements.
* Seamless integration with the .NET base class libraries.
* Documentation fully integrated into Visual Studio .NET.
* C# and VB.NET samples included in the setup package show how to work with UltimateTemplateEngine.
Ultimate Mail Merge for C#, VB.NET and ASP.NET
ComponentSoft Ultimate Mail Merge component is a part of the Ultimate Mail Expert Package. It helps you to send personalized e-mail messages utilizing the power of .NET Framework with the Ultimate Template Engine and Ultimate Mail components.
Easily personalize e-mail messages with the Ultimate Template Engine
UltimateTemplateEngine is a .NET Template Engine for generating formatted text output from source template and input variables. Examples of such output includes Web Pages, Emails, Source Code, etc. By using ComponentSoft TemplateEngine you can strictly enforce a clean separation of design and development (MVC) on your ASP.NET web application. It has the following unique features:
* Can be used to generate any kind of text: HTML, XML, RTF, Email, Source Code, etc.
* Lightweight and easy to ship with your product (just only one DLL file).
* Template and TemplateClass can be loaded from many sources: file, stream, plain-text.
* Template and TemplateClass reusability (you can define one template that will be used for many further purposes).
* Utilizes the power of .NET Framework.
* Template syntax is similar to C# and very easy to understand.
* Powerful template language with all usual directives: include, selection statements(if-else), Iteration Statements(do, for, foreach, while, break, continue).
* Initialize and change variables in template code.
* Support complex expressions.
* Powerful built-in functions (string, type conversion, collection rendering).
* Highly extensible with custom function.
* Smart and high-performance data type conversion.
* Get template source directory, it's very useful for including external files such as Css or Javascript files in your web page.
* Get and invoke any static, non-static public properties and methods in .NET Framework.
* Allow or restrict the calls to specific .NET methods and properties.
* Powerful array and dictionary rendering methods.
* Able to change tag, expression and template comment delimiters to avoid confliction with other formats.
* Direct output to your own TextWriter.
* Able to cache parsed template data to speed up output text generation.
* Supports Unicode.
* Unified .NET exception.
Downloading and managing email messages and mailboxes easily
The Ultimate Mail component offers a comprehensive interface for IMAP, providing the developer with everything that he needs to incorporate mail management tasks in an application as listed below:
* Connect to standard IMAP server or secure IMAP server over TLS/SSL. It supports both Implicit and Explicit security modes
* List email messages
* Download entire or partial messages to a disk file or stream
* Upload messages stored in a file or memory stream
* Copy messages
* Delete messages
* Purge messages
* Move messages between folders/mailboxes
* Mark/unmark message flags
* Listing mailboxes/folders
* Create mailboxes/folders
* Rename mailboxes/folders
* Delete mailboxes/folders
* Subscribe and unsubscribe mailboxes/folders
* Obtain mailbox information
* Search messages with advanced options
* Authenticate securely with CRAM-MD5, DIGEST-MD5, NTLM, and Kerberos methods
Top
Receiving and managing email messages easily with POP3 classes
The POP3 client class simplifies the tasks needed to manage your email messages on a POP3 server. It offers the following features:
* Connect to standard POP3 server or secure POP3 server over TLS/SSL. It supports both Implicit and Explicit security modes
* List email messages
* Download entire or partial messages to a disk file or stream
* Delete messages
* Purge messages
* Obtain mailbox information
* Authenticate securely with APOP, CRAM-MD5, DIGEST-MD5, NTLM, and Kerberos methods
Top
Sending email messages easily with SMTP classes
In addition to supporting IMAP and POP3 protocols. The Ultimate Mail component also offers a comprehensive interface for SMTP, providing the developer with everything that he needs to incorporate email sending tasks in an application as listed below:
* Connect to standard SMTP server or secure SMTP server over TLS/SSL. It supports both Implicit and Explicit security modes
* Send bulk messages
* Send to relay SMTP server
* Quick send with static methods
* Submit to IIS SMTP queue
* Support PIPELINING
* Delivery Status Notification (DSN)
* Obtain mailbox information
* ESMTP authentication with LOGIN, PLAIN, CRAM-MD5, DIGEST-MD5, NTLM, and Kerberos methods
Top
Supports MIME and S/MIME
When designing the IMAP component, we mainly forcus on ease-of-use, performance, reliability, and flexibility. As a benefit, you do not need to have deep knowledge of how the IMAP protocol is implemented and how to read, encrypt, decrypt, sign and validate a message. IMAP component does all the hard works for you. The following is a list of some key MIME and S/MIME features:
* Load and save message from/into MailMessage object
* Supports multiple recipients with To, CC, and BCC headers
* Attach multiple files
* Encrypt, decrypt, sign, and validate email messages easily
* Extract attachments from MS-TNEF (winmail.dat) files
* Import HTML file or web page into e-mail
* Forward message as attachment
* Base64 and Quoted-Printable
* Fullly support creating and displaying HTML messages with embedded resources such as Image, source, etc. in your applications
Top
Security and Reliability
The Ultimate Mail component provides industry standard security using the Secure Sockets Layer (SSL) and Transport Layer Security (TLS) protocols. Our components support strong, commercial grade encryption, and we do not rely on any third-party toolkits which have licensing restrictions or are encumbered by patents. By setting a single property or option, the component automatically handles all of the complex certificate management, protocol negotiation and encryption for you. Even advanced options, such as using client certificates, are handled easily with just a few lines of code.
Top
Supports HTTP Connect, SOCKS4, SOCKS4A & SOCKS5 Proxy Servers
Ultimate Mail provides full support for Proxy Servers such as HTTP CONNECT, SOCKS4, SOCKS4A, and SOCKS5. By simply setting a few properties, you are able to download, upload, send, and manage email messages and mailboxes from POP3, IMAP, and SMTP servers through the desired proxy server, providing your application with the greatest flexibility and highest level of security available.
Top
Support for IPv6, the next generation Internet protocol
IPv6 (Internet Protocol version 6), the next-generation protocol designed by the IETF (Internet Engineering Task Force), will gradually replace the current version of the Internet Protocol, IPv4.
With Ultimate Mail Component, users have an integrated service assurance solution that will provide them with Mail, and Proxy capabilities in mixed IPv4 and IPv6 environments. This helps organizations with the adoption of and the transition to IPv6 by making the management of such networks seamless.
Top
.NET Technology
By using 100% managed code written in C#, the Ultimate Mail component takes advantage of the numerous built-in features of the .NET Framework to enhance performance, moreover, the component is CLS compliant, and it does not use any unsafe blocks for minimal permission requirements.
Top
Supports many .NET Platforms
Ultimate Mail Component for .NET supports the following platforms:
* Windows Forms
* Web Forms
* Web Services
In addition, it is also possible to use the component in PowerShell - Microsoft’s new command console and scripting language.
Ultimate Mail is fully compatible with Visual Studio 2005 and Visual Studio 2008, as well as upcomming release of Visual Studio 2010. As a benefit, you are always up-to-date with Microsoft's Technologies when using our products.
Top
Supports event-driven (Asynchronous) and blocking (Synchronous) Design
Most applications written with the Mail component will be synchronous. Synchronous method gives you the ease-of-use, but it can only returns the control back to the caller after it has finished, meaning that it blocks the execution of the caller for a period of time. Using synchronous method is recommended when you only need to execute one Mail operation at a time.
You might decide that your design requires an asynchronous operation when it is needed to manage email messages simultaneously. Asynchronous methods provide a great deal of power. Asynchronous method is executed on a thread separate from the calling thread. Such operation is useful when an Mail operation is time consuming and other codes need to execute without waiting for the initial operation to complete. In addition, the user interface will be most responsive when asynchronous methods are used.
Top
Flexibility
The Mail component has been designed with a great degree of flexibility and can be used with a wide variety of programming languages and different types of development environments. Available as a managed .NET class, it is fully supported by languages such as Visual Basic, Visual C#, J#, Managed C++, Borland C# Builder, and Delphi.
Top
Fully Documented
As important as functionality, features and stability are, comprehensive documentation is equally as important to the application developer. This is why the ComponentSoft Mail for .NET product includes a Developer's Guide and a complete Technical Reference which documents every property, method and event supported by the component. A printable version of the documentation is included with the product, as well as context-sensitive online help which can be accessed directly from within the development environment.
Top
Lots of complete Mail client samples in VB.NET, C#, and ASP.NET
In addition to the fully documented Developer's Guide and a complete Technical Reference, Ultimate Mail component also includes a number of samples with full source code which help you to become familiar with the features of the component and provide code which you can re-use in your own applications. The setup package contains three complete Mail client applications: Mail Console Client, Mail WinForms Client, and Mail WebForms Client.
Top
Royalty-free
ComponentSoft understands today's software development requirements which often require support for multiple operating systems and different programming languages. As with all ComponentSoft components, the product is licensed to a single developer, and applications built using the Mail component can be redistributed to as many end-users as needed without additional royalties or runtime licensing fees. Developers are also permitted to install the product on different development systems as long as they are the only one using it and there is no chance that it can be used by more than one developer at the same time.
Easily personalize e-mail messages with the Ultimate Template Engine
UltimateTemplateEngine is a .NET Template Engine for generating formatted text output from source template and input variables. Examples of such output includes Web Pages, Emails, Source Code, etc. By using ComponentSoft TemplateEngine you can strictly enforce a clean separation of design and development (MVC) on your ASP.NET web application. It has the following unique features:
* Can be used to generate any kind of text: HTML, XML, RTF, Email, Source Code, etc.
* Lightweight and easy to ship with your product (just only one DLL file).
* Template and TemplateClass can be loaded from many sources: file, stream, plain-text.
* Template and TemplateClass reusability (you can define one template that will be used for many further purposes).
* Utilizes the power of .NET Framework.
* Template syntax is similar to C# and very easy to understand.
* Powerful template language with all usual directives: include, selection statements(if-else), Iteration Statements(do, for, foreach, while, break, continue).
* Initialize and change variables in template code.
* Support complex expressions.
* Powerful built-in functions (string, type conversion, collection rendering).
* Highly extensible with custom function.
* Smart and high-performance data type conversion.
* Get template source directory, it's very useful for including external files such as Css or Javascript files in your web page.
* Get and invoke any static, non-static public properties and methods in .NET Framework.
* Allow or restrict the calls to specific .NET methods and properties.
* Powerful array and dictionary rendering methods.
* Able to change tag, expression and template comment delimiters to avoid confliction with other formats.
* Direct output to your own TextWriter.
* Able to cache parsed template data to speed up output text generation.
* Supports Unicode.
* Unified .NET exception.
Downloading and managing email messages and mailboxes easily
The Ultimate Mail component offers a comprehensive interface for IMAP, providing the developer with everything that he needs to incorporate mail management tasks in an application as listed below:
* Connect to standard IMAP server or secure IMAP server over TLS/SSL. It supports both Implicit and Explicit security modes
* List email messages
* Download entire or partial messages to a disk file or stream
* Upload messages stored in a file or memory stream
* Copy messages
* Delete messages
* Purge messages
* Move messages between folders/mailboxes
* Mark/unmark message flags
* Listing mailboxes/folders
* Create mailboxes/folders
* Rename mailboxes/folders
* Delete mailboxes/folders
* Subscribe and unsubscribe mailboxes/folders
* Obtain mailbox information
* Search messages with advanced options
* Authenticate securely with CRAM-MD5, DIGEST-MD5, NTLM, and Kerberos methods
Top
Receiving and managing email messages easily with POP3 classes
The POP3 client class simplifies the tasks needed to manage your email messages on a POP3 server. It offers the following features:
* Connect to standard POP3 server or secure POP3 server over TLS/SSL. It supports both Implicit and Explicit security modes
* List email messages
* Download entire or partial messages to a disk file or stream
* Delete messages
* Purge messages
* Obtain mailbox information
* Authenticate securely with APOP, CRAM-MD5, DIGEST-MD5, NTLM, and Kerberos methods
Top
Sending email messages easily with SMTP classes
In addition to supporting IMAP and POP3 protocols. The Ultimate Mail component also offers a comprehensive interface for SMTP, providing the developer with everything that he needs to incorporate email sending tasks in an application as listed below:
* Connect to standard SMTP server or secure SMTP server over TLS/SSL. It supports both Implicit and Explicit security modes
* Send bulk messages
* Send to relay SMTP server
* Quick send with static methods
* Submit to IIS SMTP queue
* Support PIPELINING
* Delivery Status Notification (DSN)
* Obtain mailbox information
* ESMTP authentication with LOGIN, PLAIN, CRAM-MD5, DIGEST-MD5, NTLM, and Kerberos methods
Top
Supports MIME and S/MIME
When designing the IMAP component, we mainly forcus on ease-of-use, performance, reliability, and flexibility. As a benefit, you do not need to have deep knowledge of how the IMAP protocol is implemented and how to read, encrypt, decrypt, sign and validate a message. IMAP component does all the hard works for you. The following is a list of some key MIME and S/MIME features:
* Load and save message from/into MailMessage object
* Supports multiple recipients with To, CC, and BCC headers
* Attach multiple files
* Encrypt, decrypt, sign, and validate email messages easily
* Extract attachments from MS-TNEF (winmail.dat) files
* Import HTML file or web page into e-mail
* Forward message as attachment
* Base64 and Quoted-Printable
* Fullly support creating and displaying HTML messages with embedded resources such as Image, source, etc. in your applications
Top
Security and Reliability
The Ultimate Mail component provides industry standard security using the Secure Sockets Layer (SSL) and Transport Layer Security (TLS) protocols. Our components support strong, commercial grade encryption, and we do not rely on any third-party toolkits which have licensing restrictions or are encumbered by patents. By setting a single property or option, the component automatically handles all of the complex certificate management, protocol negotiation and encryption for you. Even advanced options, such as using client certificates, are handled easily with just a few lines of code.
Top
Supports HTTP Connect, SOCKS4, SOCKS4A & SOCKS5 Proxy Servers
Ultimate Mail provides full support for Proxy Servers such as HTTP CONNECT, SOCKS4, SOCKS4A, and SOCKS5. By simply setting a few properties, you are able to download, upload, send, and manage email messages and mailboxes from POP3, IMAP, and SMTP servers through the desired proxy server, providing your application with the greatest flexibility and highest level of security available.
Top
Support for IPv6, the next generation Internet protocol
IPv6 (Internet Protocol version 6), the next-generation protocol designed by the IETF (Internet Engineering Task Force), will gradually replace the current version of the Internet Protocol, IPv4.
With Ultimate Mail Component, users have an integrated service assurance solution that will provide them with Mail, and Proxy capabilities in mixed IPv4 and IPv6 environments. This helps organizations with the adoption of and the transition to IPv6 by making the management of such networks seamless.
Top
.NET Technology
By using 100% managed code written in C#, the Ultimate Mail component takes advantage of the numerous built-in features of the .NET Framework to enhance performance, moreover, the component is CLS compliant, and it does not use any unsafe blocks for minimal permission requirements.
Top
Supports many .NET Platforms
Ultimate Mail Component for .NET supports the following platforms:
* Windows Forms
* Web Forms
* Web Services
In addition, it is also possible to use the component in PowerShell - Microsoft’s new command console and scripting language.
Ultimate Mail is fully compatible with Visual Studio 2005 and Visual Studio 2008, as well as upcomming release of Visual Studio 2010. As a benefit, you are always up-to-date with Microsoft's Technologies when using our products.
Top
Supports event-driven (Asynchronous) and blocking (Synchronous) Design
Most applications written with the Mail component will be synchronous. Synchronous method gives you the ease-of-use, but it can only returns the control back to the caller after it has finished, meaning that it blocks the execution of the caller for a period of time. Using synchronous method is recommended when you only need to execute one Mail operation at a time.
You might decide that your design requires an asynchronous operation when it is needed to manage email messages simultaneously. Asynchronous methods provide a great deal of power. Asynchronous method is executed on a thread separate from the calling thread. Such operation is useful when an Mail operation is time consuming and other codes need to execute without waiting for the initial operation to complete. In addition, the user interface will be most responsive when asynchronous methods are used.
Top
Flexibility
The Mail component has been designed with a great degree of flexibility and can be used with a wide variety of programming languages and different types of development environments. Available as a managed .NET class, it is fully supported by languages such as Visual Basic, Visual C#, J#, Managed C++, Borland C# Builder, and Delphi.
Top
Fully Documented
As important as functionality, features and stability are, comprehensive documentation is equally as important to the application developer. This is why the ComponentSoft Mail for .NET product includes a Developer's Guide and a complete Technical Reference which documents every property, method and event supported by the component. A printable version of the documentation is included with the product, as well as context-sensitive online help which can be accessed directly from within the development environment.
Top
Lots of complete Mail client samples in VB.NET, C#, and ASP.NET
In addition to the fully documented Developer's Guide and a complete Technical Reference, Ultimate Mail component also includes a number of samples with full source code which help you to become familiar with the features of the component and provide code which you can re-use in your own applications. The setup package contains three complete Mail client applications: Mail Console Client, Mail WinForms Client, and Mail WebForms Client.
Top
Royalty-free
ComponentSoft understands today's software development requirements which often require support for multiple operating systems and different programming languages. As with all ComponentSoft components, the product is licensed to a single developer, and applications built using the Mail component can be redistributed to as many end-users as needed without additional royalties or runtime licensing fees. Developers are also permitted to install the product on different development systems as long as they are the only one using it and there is no chance that it can be used by more than one developer at the same time.
Subscribe to:
Posts (Atom)