Wednesday, January 31, 2007

AJAX Framework: YUI, DOJO or GWT

Google Web Toolkit - Build AJAX apps in the Java language
White code in java, and then use GWT to compile to html and javascript file.

The Yahoo! User Interface (YUI) Library is a set of utilities and controls, written in JavaScript, for building richly interactive web applications using techniques such as DOM scripting, DHTML and AJAX. The YUI Library also includes several core CSS resources.

Dojo - is an Open Source DHTML toolkit written in JavaScript. It builds on several contributed code bases (nWidgets, Burstlib, f(m)), which is why we refer to it sometimes as a "unified" toolkit. Dojo aims to solve some long-standing historical problems with DHTML which prevented mass adoption of dynamic web application development.
One book for Dojo.

MochiKit - A lightweight Javascript library.

MooTools is a compact, modular, Object-Oriented JavaScript framework designed for the intermediate to advanced JavaScript developer. It allows you to write powerful, flexible, and cross-browser code with its elegant, well documented, and coherent API.

Prototype is a JavaScript Framework that aims to ease development of dynamic web applications.
Developer Notes for prototype.js

Tuesday, January 23, 2007

Format DateTime in XSLT in .Net 2.0

In .Net 2.0, we can use XslCompiledTransform to perform a transformation on XML:
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(xmlstring);

XslCompiledTransform xslDoc = new XslCompiledTransform(true);
StringReader strReader = new StringReader(xslstring);
XmlTextReader txtReader = new XmlTextReader(strReader);
xslDoc.Load(txtReader);

StringWriter strWriter = new StringWriter();
xslDoc.Transform(xmlDoc, null, strWriter);
outputstring = strWriter.ToString();

It's easy and simple to call this functions. But it takes time to write a working style sheet. One difficult thing is do datetime formating.

format-number is include in XSLT 1.0 , but not format-date. Each company have their extension to do that. For microsoft, this is the way doing it:

〈?xml version="1.0" encoding="UTF-8"?>
〈xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ms="urn:schemas-microsoft-com:xslt" xmlns:dt="urn:schemas-microsoft-com:datatypes">
〈xsl:template match="/DocumentElement">
〈table border="1">
〈tr bgcolor="grey">
〈th>BaseCurrExch〈/th>
〈th>OrdDate〈/th>
〈/tr>
〈xsl:for-each select="Row">
〈tr bgcolor="white">
〈td>〈xsl:value-of select="format-number(BaseCurrExch,'#.00')"/>〈/td>
〈td>〈xsl:value-of select="ms:format-date(OrdDate, 'MM/dd/yyyy')"/>〈/td>
〈/tr>
〈/xsl:for-each>
〈/table>
〈/xsl:template>
〈/xsl:stylesheet>

For more information, check Microsoft XPath Extension Functions.

Wednesday, January 17, 2007

MyGeneration and O/R Mapping Practics

First time, you have to go to the setting page to set up connection string and Database target mapping. For SQL Server, I use "DBType" as DbTarget.

Some template in MyGeneration can generate data access code according the key and index define on data fields. This will save your time to create your own code manually. We use to have these fields:
PKID (int,4) Indentity
DateCreated(datetime, 8)
LastUpdate(datetime, 8)
rowguid(uniqueidentifier, 16): (newid())

Tuesday, January 16, 2007

Use SmtpClient to Send Email

In Asp.Net 2.0, we can use SmtpClient to send email.
MailAddress from = new MailAddress(emailfrom);
MailAddress to = new MailAddress(emailto);
MailMessage mm = new MailMessage(from, to);
mm.Subject = subject;
mm.Body = body;
mm.IsBodyHtml = true;
mm.Attachments.Add(New Attachment(AttachmentFile.PostedFile.InputStream, AttachmentFile.FileName))

SmtpClient sc = new SmtpClient();
sc.DeliveryMethod = SmtpDeliveryMethod.Network; // Network;PickupDirectoryFromIis; SpecifiedPickupDirectory
sc.Host = host;
sc.Port = Convert.ToInt32(port)
sc.Credentials = New NetworkCredential(username, password);
sc.Send(mm);

Here AttachmentFile is a FileUpload control inside the page:
<asp:FileUpload ID="AttachmentFile" runat="server" />

If we do not want to specify the Host information, we can config it inweb.config, and SmtpClient will use this setting to connect to SMTP server:
<configuration>
 <system.net>
  <mailSettings>
   <smtp>
    <network host="relayServerHostname" port="portNumber" userName="username" password="password" />
   </smtp>
  </mailSettings>
 </system.net>
 <system.web> ... </system.web>
</configuration>

SmtpClient throws SmtpException exception.

Friday, January 12, 2007

Use WebSupergoo ABCPdf.Net component

This component can easy render HTML code to PDF output:
For example, we want all content inside the Literal control "litReport" to output to PDF, first we render the Literal web control to a string writer, then use AddImageHtml method of ABCPdf to load the content.

using System.Text;
using System.IO;
using WebSupergoo.ABCpdf5;
......

StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
litReport.RenderControl(htw);

Doc theDoc = new Doc();
theDoc.Color.Color = System.Drawing.Color.White;
theDoc.Rect.Inset(20,20);
int theID = 0;
theDoc.FrameRect();
theID = theDoc.AddImageHtml(sw.ToString());
while (true)
{
theDoc.FrameRect(); // add a black border
if (!theDoc.Chainable(theID))
break;
theDoc.Page = theDoc.AddPage();
theID = theDoc.AddImageToChain(theID);
}

After this, we use GetData to get the raw data and use BinaryWrite to output to browser.

Response.ContentType = "application/pdf;";
Response.AppendHeader("content-disposition", "attachment; filename=\"file.pdf\"");
Response.BinaryWrite(theDoc.GetData());
Response.Flush();
Response.End();

Monday, January 01, 2007

How to setup SVN on windows

1. Download
Subversion Find server side component, svn-1.4.2-setup.exe is for windows setup.
Svn service Run svn server (svnserve.exe) as MS Windows service (Don't need since SVN v1.4)
TortoiseSVN Client side component

2. Install and setup SVN server
Run setup file. Then Create a repository and configure access:
Create a new directory like d:\subversion\repositories, open a command line window and go inside this folder, run

svnadmin create "
d:\subversion\repositories"

This will create repository stucture folder under d:\subversion\repositories, go to d:\subversion\repositories\conf, change file svnserve.conf, uncomment the following line:

[general]
password-db = passwd

change file passwd, uncomment the following line:

[users]

and add the username and password you want to use when connecting to your subversion server

3.Install svnservice, and run install.bat to install a service for SVN, then start service "Subversion Service"

Note:
From v1.4,
svnserve can be run as a native Windows service. Use windows command line tools sc.exe to install svn service.

sc create svnservice
binpath= "c:\Subversion\bin\svnserve.exe
--service -r D:\svnroot"
displayname= "SVNService"
depend= Tcpip
start= auto

where "svnservice" is any service name, and "D:\svnroot" is the repository, you can use --listen-port parameter as well.

Then you can use the following to start/stop svn service
net start
svnservice
net stop
svnservice

To delete svn service
sc delete
svnservice

If the path to svnserve.exe contains spaces or other characters that
must be escaped, then you must enclose the path to svnserve.exe with
double-quotes, which themselves must be quoted using a backslash:

sc create
svnservice
binpath= "\"c:\program files\subversion\bin\svnserve.exe\" ..."


4. In client side, install TortoiseSVN and reboot computer, then create one projects folder like d:\projects and right click this folder and click "Import" menu, use URL:

svn://ip/projects
The default port SVN used is 3690.