Nothing Special   »   [go: up one dir, main page]

DNDJ - 2006 - 05

Download as pdf or txt
Download as pdf or txt
You are on page 1of 52

BEST KEPT SECRETS IN .NET p.

44
Presented by

THE WORLD’S LEADING .NET RESOURCE

2006 Volume 4 Issue5

F# on a Virtual Super Computer Heard on


Understanding grid computing Hanselminutes
Interview with Web developer and
Building a Simple Content technologist Scott Hanselman
Management System — SEE PAGES 32-33 AND 46-47 FOR DETAILS —
Learn how to enable your editors to visually edit HTML
content online
Presorted
Standard
US Postage
PAID
St. Croix Press

W W W . D O T N E T D E V E L O P E R S J O U R N A L . C O M
SUPERCHARGE
YOUR APPS WITH
THE POWER OF

LOCATION
INTELLIGENCE Enable Location Intelligent web services
Single environment for deployment
to desktop or web
Full integration with VisualStudio .NET

Create applications for:


• Web-based store/asset location finders • Visualizing where your customers are
• Analyzing where revenue comes from – and where it doesn’t • Managing assets such as cell towers, vehicles and ATMs

Try it and see for yourself. Visit www.mapinfo.com/sdk


Learn more about the MapInfo Location Platform for .NET,
access whitepapers and download free SDKs.

Contact us at sales@mapinfo.com
DBA: “I suspect it’s your application server
code that’s causing the problem.”
App Dev: “It must be a database problem.”

Eliminate the finger pointing with WebLOAD Analyzer™.


101000101101000101101001010101010001011010010101011010001011010001110100101010101

Want to accelerate resolution


of Web performance problems?
You can with WebLOAD Analyzer—the only load testing tool
with root cause analysis for .NET and Microsoft Web applications.
WebLOAD Analyzer employs unique “black box” software to
capture actual problems at multiple synchronized levels, enabling
users to drill down to the individual component. By pinpointing
the root cause of all kinds of application problems, WebLOAD
Analyzer reduces problem resolution time by 60%—significantly
improving application performance and eliminating finger pointing
once and for all.

Get a FREE “No more finger pointing” T-shirt. >> > > Learn more at www.radview.com/analyze

10100010110100010110100101010101000101101

0101010110100010110100011101001010101011

© RadView Software, Limited.All rights reserved. The Smart Choice in Web Application Testing
M a y 2 0 0 6 Volume 4 Issue 5

Inside DNDJ EDITORIAL

Web 2.0 ‘Goes Mainstream’


18 By Jeremy Geelan ..................................................................... 7

F# on a BOOK REVIEW

Virtual Super Computer Amazon.com Top 10 .NET Books


Provided by Amazon.com........................................................ 8
UNDERSTANDING GRID COMPUTING
BY CHAD ALBRECHT
INTERVIEW

Heard on Hanselminutes
12
26
Hosted by Carl Franklin ............................................................

TOOLS

Flash ASP.NET
Adding Validation 40
By Ryan Moore ..........................................................................

Capabilities to a BoundField
USING ASP.NET BOOK REVIEW
BY OSCAR PELI Best Kept Secrets in .NET
By Steven Mandel ..................................................................... 44

34 BOOK REVIEW

Practical Mono
Building a Simple Content By Dennis Hayes ....................................................................... 48
Management System
LEARN HOW TO ENABLE YOUR EDITORS TO MONO
VISUALLY EDIT HTML CONTENT ONLINE
BY CRISTIAN IVASCU
Mono Beta for 1.2 Released...
By Dennis Hayes ....................................................................... 50

4 May 2006 • dotnetdevelopersjournal.com


��������������������������������������

������������������������������������

�������������������������������������
�������������������������������������������

������������������������������������������������������������������
��������������������������������������������
������������������������������������������������������������������

���������������������������������� ������������������������������
����������������������������������������������������������������������
������������������������������������������������������������������������
�������������������������������������������

��������������������������������������
4 ��������������������������������������������������������
����������������������������������������
4 ����������������������������������������������������������������
�����������������������������������������������������
���������������������������
4 ����������������������������������������������������������
�������������������������������������������������������� ��������������������������������������������
���������������������
4 ������������������������������������������������

����������������������������������������������������������������
������������������������������������ ��������������
���������������������
�������������

�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������
�����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������
Editorial

EDITORIAL BOARD
dotnetboard@sys-con.com
Editor-in-Chief
Derek Ferguson derekf@speakeasy.net
Web 2.0 ‘Goes Mainstream’
w
Group Publisher hen newsstands through- the Web.” This is a much more power-
Jeremy Geelan jeremy@sys-con.com out America on Monday, ful rallying cry and I, for one, should
Mobility Editor
BY JEREMY GEELAN
Jon Box jbox@psgi.net March 27, started display- have much preferred to see it used as
Security Editor ing the April 3 issue of Newsweek’s front-cover headline, but Jeremy Geelan is group publisher of
Patrick Hynds phynds@criticalsites.com
Open Source Editor Newsweek with its cover story such is the way of the world. Maybe the SYS-CON Media and is responsible
Dennis Hayes dennisdotnet@yahoo.com about “Web 2.0” – “Putting the ‘We’ in editors at MSNBC “get it” better than for the development of new titles
Product Review Editor
Doug Holland doug.holland@precisionobjects.com Web” – it seems to me that we have those at Newsweek. and technology portals for the
VB Editor reached one of Malcolm Gladwell’s I can’t wait for BusinessWeek to ad- firm. He regularly represents
Keith Franklin keithf@magenic.com
Smart Client Editor
now-famous Tipping Points. dress the same story: they’ll get the title SYS-CON at conferences and trade
Tim Huckaby timh@interknowlogy.com In the Newsweek piece, written by spot-on, just watch!! shows, speaking to technology
BizTalk Editor
Brian Loesgen brian.loesgen@neudesic.com
the magazine’s senior editor Steven Newsweek’s two authors triangu- audiences both in North America

ADVISORY BOARD Levy and its Silicon Valley correspon- lated on James Surowiecki, whom they and overseas.
dotnetadvisors@sys-con.com dent Brad Stone, the authors report quote, so his “Wisdom of Crowds” no-
Derek Ferguson derekf@magenic.com
Jeremy Geelan jeremy@sys-con.com how, “less than a decade ago, when we tion is included in the article. (“It’s clear 4jeremy@sys-con.com
Thom Robbins trobbins@microsoft.com were first getting used to the idea of an that the Web is structurally congenial
John Gomez John.Gomez@eclipsys.com
Scott Hanselman scott@hanselman.com Internet, people described the act of to the wisdom of crowds,” he’s quoted
Dean Guida deang@infragistics.com going online as venturing into some as saying.) But my instincts tell me
John Sharp johns@contentmaster.com
Jacob Cynamon jacobcy@microsoft.com foreign realm that, for all that
Chris Mayo cmayo@microsoft.com called cyber- Steven Levy and
Gary Cornell gary@thecornells.com
Joe Stagner joestag@microsoft.com space.” But Brad Stone are to
Peter DeBetta peter@debetta.com that metaphor, be thanked and
Executive Editor
Nancy Valentine nancy@sys-con.com the authors congratulated for
Online Editor suggest, no producing the
Roger Strukhoff roger@sys-con.com
Assistant Online Editor longer applies: article, they don’t
Nicholas DeJesus nick@sys-con.com “MySpace, necessarily – yet,
SUBSCRIPTIONS Flickr, and anyway – fully
For subscriptions and requests for bulk orders,
please send your letters to Subscription Department all the other comprehend the
Subscription Hotline: subscribe@sys-con.com newcomers technologies of
Cover Price: $6.99/issue
Domestic: $69.99/yr. (12 issues) aren’t places to “social comput-
Canada/Mexico: $99.99/yr. Overseas: $129.99/yr. go, but things ing” like RSS. And
(u.s. banks or money orders). Back issues: $12/ea.,
plus shipping and handling. to do, ways to they certainly
EDITORIAL OFFICES express ourselves means to connect don’t have a clue what AJAX actually
SYS-CON Media 135 Chestnut Ridge Rd., with others and extend our own is. (It is hastily referenced in a single
Montvale, NJ 07645
Telephone: 201 802-3000 Fax: 201 782-9638 horizons.” sentence buried right in the middle of
.NET Developer’s Journal (issn#1541-2849) is
published monthly (12 times a year) for $69.99 by
“Cyberspace was somewhere else,” the piece.)
SYS-CON Publications, Inc.,135 Chestnut Ridge Road, they write. Whereas “The Web is where Again, all credit to Newsweek,
Montvale, NJ 07645.
Postmaster: Send address changes to: we live.” [My emphasis.] though, for the resonant final para-
.NET Developer’s Journal, What’s the tipping point, you ask. graph:
SYS-CON Publications, Inc.,
135 Chestnut Ridge Road Well, for me – and for plenty of others,
Montvale, NJ 07645 it seems – what’s special/unusual is Less than a decade ago, when we were
Copyright © 2006 by SYS-CON Publications, Inc.
All rights reserved. No part of this publication may be reproduced or that Newsweek, a mainstream publica- first getting used to the idea of an In-
transmitted in any form or by any means, electronic or mechanical,
including photocopy or any information storage and retrieval system, tion, deems “Web 2.0” worthy not just ternet, people described the act of going
without written permission. For promotional reprints, contact Reprint
Coordinator Dorothy Gil, dorothy@sys-con.com. of an in-depth article but also of an online as venturing into some foreign
Worldwide Newsstand Distribution
Curtis Circulation Company, New Milford, NJ
in-depth article that it puts on its cover. realm called cyberspace. But that meta-
Newsstand Distribution Consultant: It means that the notion of a “live Web” phor no longer applies. MySpace, Flickr
Gregory Associates / W.R.D.S.
732 607-9941 - BJGAssociates@cs.com is getting prime time, along with the and all the other newcomers aren’t
For list rental information:
Kevin Collopy: 845 731-2684, terminology of Web 2.0 like “tagging,” places to go, but things to do, ways to
kevin.collopy@edithroman.com;
Frank Cipolla: 845 731-3832, “mash-ups,” “collective intelligence,” express yourself, means to connect with
frank.cipolla@epostdirect.com
All brand and product names used on these pages are trade names, and “social media.” others and extend your own horizons.
service marks, or trademarks of their respective companies. SYS-CON
Publications, Inc., is not affiliated with the companies or products Web 2.0, make no mistake about it, is Cyberspace was somewhere else. The
covered in .NET Developer’s Journal. .NET and .NET-based marks are
trademarks or registered trademarks of Microsoft Corporation in the United going mainstream. Web is where we live.
States and other countries.
SYS-CON Publications, Inc., reserves the right to revise,
For those who think that one weak-
republish and authorize its readers to use the articles ness of the Newsweek piece is its title, With these five sentences, given their
submitted for publication.
MSNBC has come to the rescue by appearance in one of the world’s most
repurposing it under the – in my view, widely read news magazines, “Web 2.0”
far sharper– title “The New Wisdom of has truly arrived in Main Street.

dotnetdevelopersjournal.com • May 2006


7
Book Review

Amazon.com Top 10 .NET Books President and CEO

10 4
Murach’s MCAD/MCSD Fuat Kircaali fuat@sys-con.com
Beginning Visual Training Guide President, SYS-CON Events
Basic .NET (70-320): Grisha Davida grisha@sys-con.com
Group Publisher
(Murach: Training Developing XML
Jeremy Geelan jeremy@sys-con.com
& Reference) Web Services
and Server ADVERTISING
by Anne Prince Components with Visual C# Senior Vice President, Sales and Marketing
.NET and the .NET Framework Carmen Gonzalez carmen@sys-con.com
by Amit Kalani Vice President, Sales and Marketing

9 Programming Miles Silverman miles@sys-con.com


Advertising Director

3
ASP.NET MCAD/MCSD
Robyn Forma robyn@sys-con.com
Training Guide
Advertising Sales Manager
(70-315): Megan Mussa megan@sys-con.com
Developing and Associate Sales Managers
Implementing Kerry Mealia kerry@sys-con.com
Web Lauren Orsi lauren@sys-con.com

by Jesse Liberty Applications with Visual C#


PRODUCTION
and Visual Studio.NET
Lead Designer
by Amit Kalani Tami Lima tami@sys-con.com

8
Developing Art Director

2
Web MCAD/MCSD Alex Botero alex@sys-con.com

Applications Self-Paced Associate Art Directors


Louis F. Cuffari louis@sys-con.com
with ASP.NET Training Kit: Andrea Boden andrea@sys-con.com
and C# Microsoft Video Editor
.NET Core Ryan Palmieri ryan@sys-con.com
by Hank Meyne Requirements,
Exams 70-305, 70-315, 70- WEB SERVICES
306, 70-316, 70-310, 70-320, Information Systems Consultant
Robert Diamond robert@sys-con.com

7
Developing and 70-300
Web Designers
Application Microsoft Corporation Stephen Kilmurray stephen@sys-con.com
Frameworks in Wayne Uffleman wayne@sys-con.com
.NET
ACCOUNTING
Financial Analyst
Joan LaRose joan@sys-con.com
by Xin Chen
Accounts Payable
Betty White betty@sys-con.com
Accounts Receivable
PROVIDED BY

6 Enterprise Gail Naples gailn@sys-con.com

Solution
Patterns Using SYS-CON EVENTS
Microsoft .Net: President, Sys-con Events

1
Grisha Davida grisha@sys-con.com
Version 2.0 Programming Microsoft
National Sales Manager
: Patterns & Visual Basic .NET Version Jim Hanchrow jimh@sys-con.com
Practices 2003 (Book & CD-ROM)
Microsoft Corporation SUBSCRIPTIONS
by Francesco Balena 201 802-3012
888 303-5282

5
subscribe@sys-con.com
MCAD/MCSD
Self-Paced
CUSTOMER RELATIONS
Training Kit: Circulation Service Coordinators
Developing Edna Earle Russell edna@sys-con.com
Web JDJ Store Manager
Applications Brunilda Staropoli bruni@sys-con.com
with Microsoft Visual Basic
.NET and Microsoft Visual C#
.NET, Second Edition
Microsoft Corporation

8 May 2006 • dotnetdevelopersjournal.com


Interview

Heard on Hanselminutes
Interview with Web developer and technologist Scott Hanselman

h
anselminutes is a weekly ule, or you do it on a check-in. For aged by the ThoughtWorks guys. And
30-minute podcast with us at Corillian we do a combination. this is an automated build solution
Web developer and tech- Every single time someone checks in, and a server for .NET written in .NET.
nologist Scott Hanselman a server on the other end starts watch- The final 1.0 release came out last
hosted by Carl Franklin. The following ing, and says, “All right I am going to November, although we have been
is a transcript from show number 4 on kick off a build. Someone just checked using it since version 0.7.
Continuous Integration. You can listen something in, I want to kick off a
online at www.hanselminutes.com. build, but I’ll wait 10 minutes just in CF: Very cool.
case there are other things coming.” SH: CruiseControl runs as a Window
Carl Franklin: All right so let’s get into Because when you do a check-in you service. You can also run it from the
Continuous Integration. Why don’t might have a couple of things batched command line. It will watch your
you start by telling us what it is? up. So it’s not going to kick off a build source control and check to see if
Scott Hanselman: So Continuous every single check-in. But once a anything is updated. It works with
Integration is a concept that came batch of things has been checked in virtually any source control – CVS,
from a paper that Martin Fowler wrote and nothing has happened for, say, 10 SourceSafe, Perforce, SourceGear,
along with a guy named Matthew minutes, it says, “All right. Something PVCS, StarTeam; any source control
Foemmel from ThoughtWorks. dramatic has happened. I am going to that’s out there that’s worth its salt will
Martin Fowler is the chief scientist run the build. I want to test the build. work just great. When it detects that a
at ThoughtWorks. And he uses the I’ll build and install and I’ll send the change has occurred then it will kick
term Continuous Integration within report to the entire team.” off the build. Typically these builds are
the larger extreme programming or kicked off using something like NAnt,
XP series of practices. Continuous CF: How long typically does that pro- the .NET port of ANT, which basically
Integration is something that’s been cess take for you guys? make files with angle brackets.
around for a long time but people SH: For us using a big project we have
really never put a name on it. It’s the got one that takes as much as an hour CF: Yeah.
automation of a daily build, the for- but for a smaller project it can take SH: You can get that at nant.source-
malization of that process, keeping a between 10 and 20 minutes. forge.net and NAnt is similar to
single place where all the source code MSbuild and there are already
lives, so that everyone can always go CF: And is it easy to interrupt? Let’s people on the Net who are using
to the exact same place to get the cur- say you actually did want to add CruiseControl with MSbuild. So at
rent source for the current (and any something else and you knew that it its simplest you can certainly kick
previous) version. It’s automating the was going to break. off a batch file. But for the most part
build but it’s also automating the test- SH: Yeah, that’s a good point. If you CruiseControl and NAnt go hand-
ing so that you can run the test on the check something in and you knew in-hand. The idea is that you should
entire suite at any time. An executable that it would break the build, if you always be able to check your source
HOSTED BY
would pop out of the end. didn’t check it in within that first 10- out, go out to the command line and
CARL FRANKLIN
So the ideal Continuous minute window you are out of luck, type ‘build’ or ‘go’ or whatever, and get
Integration environment, in my opin- you’ll get a broken build. But the build a build, it needs to be that simple.
ion and in many people’s opinion, would be fixed on your immediate So when you’re building these
would be: A developer sits down. He next check-in. So we have literally NAnt files you typically build targets
checks out his code, goes out to the dozens of builds a day. within them. So you will say build
command line – he types, “build,” and all, build test, build install, so that
he gets a complete build that is totally CF: Interesting. people can hit these different targets:
tested on the spot. If he says some- SH: So there are a number of tools that build debug, build release, these are all
thing like “build install” it will actu- you can get, the most well-known is targets within the NAnt file, this XML-
ally pop out an MSI installer and he’s one called CruiseControl at cruisec- based file. These tasks in the NAnt file
completely set up. He can do this in a ontrol.sourceforge.net. There are also can be written by you or picked up
repeatable fashion on any machine. some competitors: Draco at draconet. from other places. So, there’s a task for
He can make changes to the code, sourceforge.net and Hippo, which is getting source from source control.
check it in, and a build server dedi- another old one that hasn’t changed There might be a task for calling a
cated to this task would automatically very recently (hipponet.sourceforge. Web Service or looking in the registry.
run the build upon his check-in. net). But CruiseControl is largely Each of these tasks is associated with
Now, there are some arguments: thought of as being the one that is the a specific XML element in that NAnt
that you do these things on a sched- most mature. It’s the one that is man- file.

12 May 2006 • dotnetdevelopersjournal.com


Interview
CF: That’s great. How long have you CF: Right. CF: And, by the way, code auditor is
guys been using this? SH: Or make sure that when you are at shrinkster.com/bmd.
SH: We have been doing this for doing COM Integration, you have COM SH: Cool! So if I can add NUnit doing
probably three-and-a-half or four visible equals true or false. I mean automated testing, and I can do
years. This is one of the first things there’s a litany of rules that the guys FxCop, what are some other things
that I wanted to make happen when that made the Microsoft Base Class that I can do? Well, NUnit of course
I got to Corillian. We also have a Library, the .NET BCL followed, and is a testing framework and there are
number of XP pundits. We had you get these rules as well. And then also things like MBUnit.
Wayne Allen, who is an XP expert. you can write these rules yourself.
We had a guy named Jim Little and So after you build, and after you CF: Now the automated builds aren’t
now Jim Shore who worked here at test, FxCop can be run at the com- going to test automatically unless
Corillian, and now works elsewhere mand line and generate a report that you have test cases, isn’t that right,
focusing entirely on XP. So we really tells you all these different things so you have to use some sort of test-
had a nice confluence where all about your source code. With FxCop generation tool to begin with?
these people who are into this style it’s all done via Reflection. And we’ve SH: Well, not necessarily a test-gen-
of development came together really added rules, pluggable DLLs you can eration tool but some kind of testing
quickly. And then Patrick Caldwell write yourself to check for specific methodology. It would be silly to
bought a thing called an Ambient things that you want to cover within have things build and not know if
Orb. This is basically a big crystal your particular project: rules about they are healthy.
ball that would glow green or red how properties should be named, how
depending on the health of the fields should be done, how inheritance CF: Sure.
build. should work. It’s totally up to you. SH: So one of the things that hap-
What’s great about this is that pens is: when you have to build a
CF: Oh gosh! the XML report that comes out of dozen times a day you start to crave
SH: Other people online have put NAnt, the XML report that comes out this feedback. Is this a healthy prod-
together Budweiser neon signs that of Nunit, and the XML report that uct that we’ve made? We know it
flash if the build is broken. The idea comes out of FxCop are all brought keeps building, we can look and see,
being that collective code ownership together automatically by CCNet, oh, look, for example, the Voyager
happens when you have an auto- the CruiseControl.NET (it’s colloqui- SDK project that I worked on has a
mated build. ally called CCNet), in what’s called a 75% success rating on builds. That
Publisher. So you go into a file called means it builds successfully three
CF: Yeah. ccnet.config and you can set up mul- out of four times except if a test
SH: If you schedule a build you don’t tiple publishers saying “Well, I’ve got fails. Let’s say it compiles but the
know how things are doing. You don’t some XML coming from here and test fails. We count that as a failed
know if you’re healthy. But if you can some XML coming from here and I build. That’s a fundamental part of
look up and see a stoplight that says want to use these Style Sheets, these Continuous Integration because
red, green, yellow…you know that XXL Style Sheets, a lot of which come building is easy. Building a testable
things are good. with CruiseControl to build up a giant integrated application and popping
report at the end.” So I’m going to take an installer out at the end is more
CF: So where does FxCop fit into the that XML that comes out of each of difficult.
puzzle? these different tools and turn it into
SH: So this is the thing that’s so amaz- a really rich dynamic report that gets CF: Right.
ing about Continuous Integration and sent out to the entire team and they SH: We can also set it up so that cer-
it’s the simplest, it’s simply using NAnt get told how things are doing. tain FxCop rules that we feel strongly
and NUnit to build and test your stuff. about will break the build.
But what are other things you could CF: And that’s what you need at the
do to really improve the quality of end of the day. Have you seen Adam CF: How often, Scott, has the process
your software? Cogan’s Code Auditor that we talked turned out a “good build” and then it
about on .NET Rocks last week? turns out you find bugs anyway?
CF: Yeah. SH: Absolutely! There are lots of great SH: Probably half the time. I mean
SH: FxCop is a rules engine you can tools like Adam’s auditor. FxCop is you still need good QA people.
get at shrinkster.com/bmb. This similar. Adam’s app works on code.
is a tool that Microsoft released. FxCop works on Reflection. These CF: That’s the point I wanted to
It has rules like properties should are the kinds of things that you might make. That all this testing framework
have camel casing or make sure that want to build in. It would be a really and stuff doesn’t take the place of
public interfaces have words that are great thing if Adam created XML as somebody actually sitting down and
spelt correctly. I mean all the kinds of an output of his Code Auditor, I don’t testing it manually.
things that really go unsaid that you know if he does, that could then be SH: Exactly, and that QA person
say should happen: don’t put mis- read in and included in a report and more and more at Corillian is push-
spelled words in public properties or CCNet would automatically be able to ing that test data back into the
anything for that matter. handle that. product.

14 May 2006 • dotnetdevelopersjournal.com


XML’s Endless Possibilities,

None of the Risk.

Forum XWall™ Web Services Firewall - Reinventing Security

Security should never be an inhibitor to new opportunity: Forum XWall™ Web Services
Firewall has been enabling Fortune 1000 companies to move forward with XML Web
services confidently. Forum XWall regulates the flow of XML data, prevents unwanted
intrusions and controls access to critical Web services.

Visit us at www.forumsys.com to learn more about how you can take your next leap
forward without increasing the risks to your business.

fo r u m syst e m s ™ – t h e l e a d e r i n we b s e rv i c e s s ec u r i t y ™
Interview
CF: Cool! CF: So you mentioned building install- basis. And then you can flag things
SH: Ideally, we would actually build ers as part of CI. What are some tools in the build and, say, wow, anything
the entire thing, do a functional NUnit to automate that process? that has a complexity of 10, indicat-
test, then we would actually do a SH: So at the simplest level, of course, ing that there are 10 or more ways
silent install of the product as part of Visual Studio supports building through this method, which is argu-
the build, and then do an end-to-end installers from the development envi- ably a number that is greater than the
integration test. And while NUnit does ronment itself. For a lot of our stuff number of paths that a human can
easy functional testing, there are tools we just actually shell out and launch comfortably store in his head, right?
like NUnitASP and NunitForms, you the deployment project that comes
can get those at nunitforms.source- with Visual Studio from the com- CF: Right.
forge.net and nunitasp.sourceforge. mand line. But for the times that that SH: I can barely hold my phone nuber
net. These are extensions to NUnit that doesn’t work you can use a number of and my wife’s phone number. I can’t
let you test WinForms – actually like different toolsets. You can use com- hold 10 different paths through some
push buttons and poke around on a mand-line versions of InstallShield, code. That would be the time then to
WinForm – or test ASP.NET Forms. for example. kick it out – we need to have a code
At Corillian we have been using a tool But since the Continuous review. Now whether you choose to
called WATIR, Web Application Testing Integration world and the break the build or not it’s really up
in Ruby, and I have a little article on it CruiseControl world are so focused to you. But these are some [of the]
up on my blog at shrinkster.com/bm8. on getting a lot of great work done kinds of feedback you can get that you
If you go up on my blog and search with Open Source tools, the tools couldn’t before.
for Watir, you’ll find not only stuff that you will often find are things like Another one is the tool called
I’ve done with Watir but stuff that one Windows Installer XML or WIX, that Simian, which is a similarity-based
of our guys at Corillian by the name of is at sourceforge.net/project/wix tool. It’s actually kind of funny. It looks
Travis Illig has done to extend Watir. or the Nullsoft Scriptable Install for copy[ing and] pasting in your
We have another guy named Dustin System, NSIS, that used to be called source code base. It’s at shrinkster.
Woodhouse who’s extending Watir the PiMP. This is the tool that the com/bma. Simian is actually written
and NUnit such that this Ruby-based guys that made Winamp used to in Java but it will work on .NET code
scripting language will actually create install Winamp. This is a very elegant and it will find places where, say, you
NUnit tests and NUnit results. install system at nsis.sourceforge. and I are working on the same project
net. So you can call these different and I found a For loop that I really
CF: Now a lot of people might not installer makers at the end of your liked. I copied and pasted it but edited
know what Ruby is. NantScript and if you wanted to take a little bit. And it will go and say, you
SH: So, Ruby is a scripting language it to the next level then you would do know this is suspiciously similar, I
that a lot of people find very beautiful a remote deploy, or remote install of think this is a candidate for refactor-
in its style. Feels kind of like Python; your application, and then start doing ing. We did this on dasBlog and I think
it feels kind of like Scheme, it feels integration testing. we found something like 14% or 15%
kind of like C++. It’s just one of those Some of the other things that you of it was just complete duplication.
languages that feels nice in your can stick at the end of your build
mouth. There’s actually a fellow who once you have the ability to do all CF: Mark Miller told me once that
did a presentation where he had no these things that framework are doing Developer Express’s refactor looks at
bullet points. He only had Ruby code things like development metrics like Cyclomatic Complexity and that’s one
because he felt that the beauty of the what’s called Cyclomtic Complexity. of the main characteristics they use
code spoke enough. It’s that kind of Cyclomatic Complexity is a measure to determine whether refactoring is
code. A gentleman named John Lam at of how many different paths through a necessary.
iunknown.com believes very strongly particular function there are. Let’s say SH: Totally. Mark Miller being an
in the beauty of Ruby. And every once that if there’s a function called Foo that expert on refactoring generally with
in a while he’ll have epiphany while he takes a Boolean. It has one input and all the refactors that he put into
is writing Ruby and then he’ll post it it can be false or true. There are two Refactor and into CodeRush. Having
on his blog: “Oh! I took these six lines ways through that particular method the nice chart and graph that you get
of code and turned into that two lines so then its complexity might be con- as a toolbox in the CodeRush product
of code in Ruby and I’m just enamored sidered two. is pretty powerful stuff. That’s a very
with Ruby today.” There are some papers that are visceral way of finding out which
Then Watir is an IE, an Internet written about Cyclomatic Complexity function in your application kind of
Explorer wrapper for Ruby so that you and there are great tools like sucks the most.
can write these kinds of tests. And DevMetrics from a company called
then I wrote a little cheapy application Anticipating Minds at shrinkster. Listen to the entire interview online
called Watir Maker that would basical- com/bm9. They have a command- at www.hanselminutes.com. The
ly record your experience while you’re line tool that will go through your Hanselminutes Podcast is produced
inside of IE and it would basically entire source code base and tell you weekly by Pwop Productions, a pod-
write out the beginnings of a Watir test. the complexity of your particular casting services company at www.
People are looking to extend that. project on a method-by-method pwop.com.

16 May 2006 • dotnetdevelopersjournal.com


������������������
���������������������
����������������������
����������������������������������������������������������������������������������������������������������
�����������������������������������������

����������������
���������������������������������������������������������������������������������������������������������������
������������������������������������������������

��������������������������
����������������������������������������������������������������������������������������

�������������������������������
���������������������������������������������������������������������������������������������������������������������������������
��������������������������������������������������������������������������������������������������������������������������������������
������������������������������������������������������������������������
Super Computer

F# on a Virtual Super Computer Understanding grid computing

w ith all the hype on the


Web about grid com-
puting and scaling out
applications, I decided it
used to analyze various complex
problems, then harnessing it to a
virtual supercomputer seemed like a
logical thing. Slated to learn two new
executer. Both can run as a desktop
application or a service. The man-
ager takes care of getting the desired
process (job) up and running on the
was time to get my hands dirty. technologies, I was hoping I hadn’t grid and ensuring its completion.
What’s grid computing you ask? bit off more than I could chew. The executor, on the other hand, is
According to Wikipedia, “Grid the workhorse of the framework; it
computing is an emerging model The Grid runs on the nodes of the grid and
that provides the ability to perform The first thing I wanted to do was does the bulk of the work.
higher throughput computing by find out what was being done with I started by installing the manager
taking advantage of many networked grids in the .NET environment. I and executor on my development
computers to model a virtual com- was quickly led to the Alchemi open box along with firing up some of the
puter architecture that is able to source project at the University of samples that came with Alchemi: the
distribute process execution across a Melbourne. Alchemi was conceived Pi calculator, prime number genera-
parallel infrastructure.” and designed in July 2002 by Akshay tor, and fractal generator. All the sam-
If you’re more confused by that Luther while in the penultimate ples ran perfectly, but only on one
definition, don’t worry. It’s really just year of his software engineering machine. Wanting to watch what was
a way of using computing power degree. Now hosted on SourceForge, happening on the grid, I dug through
from a bunch of computers con- it looked like a great staring point. the documentation and found the
nected to a network. After downloading and examining Alchemi SDK (Alchemi-1.0.0-sdk.zip),
This, in essence, creates a virtual the source (Alchemi-1.0.0-src.zip) which includes a console application.
supercomputer. I was impressed with how straight- This application lets you hook into
At this point, I was searching for forward it was. Alchemi uses two the manager to monitor the grid jobs
a project to work on that could help key modules, the manager and the and their performance.
me understand and use a grid. After
BY CHAD ALBRECHT attending optionsScalper’s presenta-
tion on “F# under an Application
of Quantitative Finance,” I had
my answer. F# (say F Sharp) is a
.NET meta-programming language
developed by the Programming
Principles and Tools Group at
Microsoft Research in Cambridge,
the same group that brought us .NET
Generics.
Like OCaml, F# is excellent at
writing tools for symbolic program-
ming. Examples of this type of pro-
gramming include static analysis,
compilers, and other sophisticated
analyses over structured data terms.
Remember using Maple or Matlab?
How about Mathematica? That’s
what writing F# is like. If F# is to be f1 Figure 1: Alchemi grid (Source: Alchemi: User Guide)

18 May 2006 • dotnetdevelopersjournal.com


I chose the Pi Calculator example After examining the Alchemi sample 2. Create a class that’s derived from AUTHOR BIO:
to compare performance metrics. First source, it was apparent that I had two GThread that uses our algorithm. This is Chad Albrecht is a consultant
I wanted to see how quickly the job roads I could go down: launch the F# as done in the PiCalcGridThread class. with 15 years of experience
would run with just the one executor its own job using the classes provided by 3. Put the threads on the grid using developing connected
on my system. According to the console Alchemi or use C# to write a bootstrapper the Alchemi API. This is done in the applications. His domain
application I had 3.407GHz available to to load my F# functions. I chose to start PiCalculatorMain class. knowledge includes business
execute the job, which makes sense on a with the bootstrapper method because I analysis, communication
P4 3.4Ghz system. The result is shown in thought it would be the simplest way to In Listing 2, I show what the Plouffe- systems, embedded design,
Figure 3. get something working. My approach was Bellard calculation class looks like database architecture and
The next step was to install the to use the Pi calculator sample provided so we can move on to step two. The mobile computing. Chad
executor on a handful of boxes and see by Alchemi and rewrite the Plouffe- PiCalcGridThread derives from GThread currently serves as president
how much faster the samples ran. For Bellard Pi calculation example in F#. and is as in Listing 3. of EnerLinx.com, Inc. (http://
starters, I installed the executor on four In Listing 3 you can see that the www.enerlinx.com), and has
other machines and watched the avail- Fabrice Bellard and Pi constructor takes the start digit number clients in the Milwaukee and
able power rise to 11.823GHz…not bad! It’s important to note that the algo- and the number of digits as arguments. Chicago markets (http://www.
With all five executors ready to run the Pi rithm I used is an implementation of These arguments are the means by chadalbrecht.com).
Calculator job in parallel, I fired it up and Fabrice Bellard’s 1997 Pi calculation algo- which we break the job of calculat-
stood back. The time to complete the rithm. Based on the Taylor series, Bellard ing Pi into smaller pieces. Putting the 4calbrecht@enerlinx.com
job fell from 27 seconds to 14 seconds. found Equation 1. PiCalcGridThread class on the grid is
Impressed with the overall performance From Equation 1, Bellard used the
and ease of use, I decided to try getting work of Simon Plouffe and improved the
some F# code running on the grid. algorithm to produce one whose running
time is O(n^2). This work is published in
The Parallel Problem his article “Computation of the n’th digit e1 Equation 1: Fabrice Bellard’s Pi Calculation Equation
One of the problems, or at least con- of pi in any base in O(n^2).” We’ll use
cerns, with grid computing is the change the algorithm from section 3 of Bellard’s
in thinking required to develop applica- paper, Equation 2, as the algorithm for
tions. Typically developers write code determining n’th digit of π in base B.
using a single thread, only using multi- Since Bellard’s equations are based
threading when performance is an issue. on the work of Plouffe, I’ll refer to them
For an application to run on a grid, as Plouffe-Bellard for the remainder of
everything has to be written as a thread. this article.
Additionally, these threads have to be The Plouffe-Bellard Pi calculation
able to handle pieces of an overall task. example that’s provided with Alchemi is
For example, say we wanted to create a in Listing 2.
simple job that counted from 1 to 100 To get my application running on the
with a one-second delay between each Alchemi grid, I needed to:
increment. On one machine, using one 1. Build a class that implements a parallel
task this would take 100 seconds. If we processing algorithm. This is done in
broke the job into 10 threads and had the Plouffe-Bellard calculation class. e2 Equation 2: Fabrice Bellard’s Revised Pi Calculation Algorithm
each thread count from n to n+10, it in O(n^2)
would take 10 seconds to complete.
The difficulty is defining the problem
in such a way that it can be broken into
these parallel tasks.
Historically, problems that can be
broken down nicely have been confined
to the realm of mathematics and engi-
neering. More recently companies like
IBM, HP, Oracle, and Sun are making
strides to make grid computing a viable
solution in the business environment.
While still not mainstream, aware-
ness, research, and tools like Alchemi can
help bring grid computing to the busi-
ness enterprise environment.
In Alchemi, parallel tasks are defined
in the GThread abstract base class. As
shown in Listing 1, the developer can, for
the most part, design the thread as if it
were to run locally. f2 Figure 2: Alchemi console application with one executor

dotnetdevelopersjournal.com • May 2006


19
Super Computer
From Listing 6, we see that we
begin by declaring the implementa-
tion of module pb followed by open-
ing System. Opening in F# is equiva-
lent to the using statement in C#. Next
we define a function CalculatePiDigits
using the let syntax. CalculatePiDigits
will explicitly take an integer, n, as an
input argument and implicitly return
a string. This is a key and unique fea-
ture of F#, the ability to mix explicit
and implicit typing.
To call the F# code contained in
the pb module, I modified the Start
method of the PiCalcGridThread class
f3 Figure 3: Pi Calculator run with one executor and included the Microsoft.FSharp
namespace statement in Listing 7.
After compiling the solution and
running it, everything appeared to
work but it showed Pi as 3 with no
numbers after the decimal. A little
digging into the Alchemi user guide
and the log file revealed that my F#
based plouffe_bellard.dll wasn’t being
sent to the executor. To overcome that
I had to add the lines in Listing 8 to
the startup code.
Adding file dependencies to the
GApplication manifest let Alchemi
distribute these files with the tasks.
As a result the F# code can run on
remote machines. Alternatively you
f4 Figure 4: F# PiCalculator Test Run can specify the standalone compiler
option to compile these into a single
done in the PiCalculatorMain class Next I wanted to get a bit of F# DLL. If you use this option the depen-
and looks like Listing 4. code written that would run on the dency code looks like Listing 9. After
In Listing 4, App is an instance grid. This was the hardest part of the this was done, the job ran. Figure 4
of the Alchemi GApplication class. project since thinking in F# is a bit like shows the result of the first test run.
Since the example code provided speaking in another language. Until I could now move on to rewriting
with Alchemi does a nice job of get- you’re immersed in it and understand the C# Plouffe-Bellard calculation class
ting the task up on the grid, we’ll the culture, a lot of things don’t make in F#. As a result of a lot of reading and
use it without modification. sense. instant messaging with optionsScalp-
The pb.fsi file defines the inter- er, the first working F# Plouffe-Bellard
Starting with F# face to your F# code. This is the module is in Listing 10.
From this point I wanted to do the mechanism that F# uses to interface To compare the differences
Plouffe-Bellard calculation using an F# to other chunks of code. It’s the rela- between C# and F# take a look at
library. It took me a while to get F# to tively simple file in Listing 5. Listing 2 and Listing 10. As you can
play nicely in the Alchemi PiCalculator Listing 5 defines a module see the use of F# mutables helps in
solution, but after I figured it out it called pb and creates a prototype this endeavor immensely! Mutables
boiled down to only a few steps. for the CalculatePiDigits func- in F# are modifiable, by reference, val-
1. Download and install the F# tion. To a C# developer this looks ues that are implicitly dereferenced.
compiler. really strange! It’s essentially saying Mutables use the local mutation
2. Add a new F# project to the CalculatePiDigits takes an integer assignment operator: id � exp r. As
PiCalculator example solution. as an input and returns a string. you become a more experienced F#
3. Set the F# project output to DLL The strangeness will continue as we developer, you’ll find yourself using
(pb.dll). look at the meat of the calculation mutables less. However, mutables are
4. Add the files pb.fsi and pb.fs to the class. But before I got into full- indispensable when doing direct C#
F# project. fledged F# development, I wanted to F# conversion as you’ll see.
5. Include pb.dll, mllib.dll and fslib. to make sure it would run on the
dll references in the PiCalculator grid. I added the code in Listing 6 Going All In
project. to pb.fs as a test. With the basic Plouffe-Bellard

20 May 2006 • dotnetdevelopersjournal.com


� � � �� �� �� � � � �� ���� � � �� �� �� � �� � ���� �� �� � �� � �� �� �� ���� �� ������ �� � �� � �� �� �� ��� ��� ���� �� �
� �� �
� � � � �� �� � � � � � � � � � � � � � � � �� � � � � � �� � � � � � � � � � � � � � �
� �� �� �� �� �
��� � � �� �� ���� �� �
� �� �� ��� � ���� �� �� ��� � �� �� �� ���� �� �� ���� �� ��� � �� �� �� ��� � �� ���� �� �

���������������������������������������
��������������������������������������������
��������������������������������������������

�������������������������������������������������������
������������������������������������������������������������
��������� � ����������������������������������������������������������������������������������������������������������������������
���������������������������������������������������������������������������������������������������������������������� ������ �
���������� ������������ �����������������������������������������������������������������������������������������������������
���������������������������������������������������������������������������������������������������������������������������������
������������������������������������� ����������������������������������������������������������������������������������������
�������������������������������������������� ����������������������������������������������������������������������������������

��������������������������������
������������������������������������������������������������������������������������������������������������������������ ���������������������������������������������������������������������� ���������������������������������������������������� ������������������������������������������������������������������������������

� � � � � � � � � � � � � � � � � � � �
� � � � � � � � � � � � � � � � � � � �
Super Computer
Without any optimization the
F# implementation took 453 ms. C#
finished up in 62 ms. Turning opti-
mization on caused the C# results to
drop to 46 ms. And, most shocking
of all, the F# was dead even at 46 ms!
t1 Table 1: Performance Results Apparently, the F# compiler does an
excellent job optimizing the code.
algorithm working well in F#, it was on types that are derived from a more Continuing on, I ran the entire C#
time to get rid of the C# all together. I general type. and F# grid applications against one
began by converting the C# GThread An example would be type car is another. Without any optimization
over to F# by adding the definition to derived from type vehicle then car the C# code took 3.9 seconds to cal-
the pb.fsi file and the implementation needs to be up cast to a vehicle and culate 100 digits of pi while F# only
to pb.fs as shown in Listing 11 and 12. vehicle needs to be down cast to a car. took 2.8 seconds. Optimizing this
You’ll see the similarities between application showed that F# would fin-
Listing 4 and Listing 12. The differ- More Advanced F# ish in 1.5 seconds while C# would not
ences include: F# was originally written by Dr. complete any faster than 2.6 seconds.
• Inheritance technique Don Syme of Microsoft Research. Dr. A look at the IL showed the reason
• Constructor implementation Syme still maintains F# and plays an for the difference. From the begin-
• Use of base class active part of the F# community. After ning of Listing 10 you can see the
• Method overloading technique discussing this article and its code use of the inline keyword, not avail-
with him, he suggested some chang- able in C#, this lets F# squeeze out a
While certainly not an all-inclusive es. The changes highlight some of the little more performance. If you’re not
list of differences, they are some of the advantages of using F#. In particular familiar with the concept of inline
items I ran into. Inheritance is done he suggested: functions, let me explain. Each time a
using the inherit keyword just below • Use for-loops instead of while loops function is called arguments need to
the class definition. • Try to remove mutables be pushed onto the stack or stored in
Constructors are implemented • Try to stick with F# convention and registers. When the function is done
using the new keyword and can be use lower case variable names results need to be pushed onto the
defined as using the keyword to for most letbound variables and stack, all this takes time. The cost of
access the base class. The use of the arguments these calls can be avoided by mov-
base class is required to implement • Make your classes smaller and more ing the function into the body of the
method overloading using the over- reusable. Classes rarely need to cap- calling code. The C# compiler doesn’t
ride keyword. ture variables explicitly support the inlining, instead, it relies
Finally, I implemented the main on the JIT to do this. Here’s a sim-
code in F# in Listing 13.(Listings 13-14 Dr. Syme was nice enough to pro- plified list of heuristics that the JIT
and additional source code can be vide a rewrite of some of my code seg- uses to decide if a method should be
downloaded from the online version ments. In Listing 14 you can see some inlined:
of this article at http://dotnet.sys-con. of the major areas where thinking in • Methods that are greater than 32
com.) F# can produce more elegant code. bytes of IL won’t be inlined.
In this code segment, some of the The hardest thing for me to adapt • Virtual functions aren’t inlined.
issues I ran into with F# are: to has been the use of let-bound • Methods that have complex flow
• Hooking into events functions. While it reminds me of the control won’t be in-lined. Complex
• Exception handling use of macros in other languages, flow control is any flow control other
• Type up and down casting I’m still not used to seeing them than if/then/else; in this case, switch
inline with the rest of the code. You or while.
The method for hooking events can see an example of this in Listing • Methods that contain exception-
in F# reminds me of COM connec- 14. The declaration of check in the handling blocks aren’t inlined,
tion points. Instead of the addition is_prime function took me a while to though methods that throw excep-
assignment operator used in C#, we understand. tions are still candidates for inlining.
use the Add method of the IEvent • If any of the method’s formal argu-
interface. To the Add method we pass Performance Comparison ments are structs, the method won’t
fun evArgs -> expr, where expr is an One of the most interesting parts be inlined.
appropriate implementation of a call- of this process was examining the
back. Exception handling takes on the performance differences between C# F# can still take advantage of
try/with and try/finally forms in F#. and F#. My initial assumption was the JIT optimization but also allows
Try/with is similar to try-catch blocks that the F# code had to be slower. the developer to control the use of
in C# while try/finally is similar to the This, in fact, is not the case. In a start- method inlining. As a result, an F#
try-finally. Up casting occurs when a ing benchmark, I wanted to examine developer can more explicitly control
type is converted to a more general the differences in performance of the the performance characteristics of an
type whereas down casting can occur Plouffe-Bellard calculation. application.

22 May 2006 • dotnetdevelopersjournal.com


Conclusion your list of tools available to attack future • Microsoft Research-F# Web site, http://
The intent of this article was to provide problems. research.microsoft.com/fsharp/fsharp.
you with a glimpse into some exciting aspx
new technologies. I’ve presented some Resources • Dr. Don Syme’s Blog, http://blogs.msdn.
strategies for converting C# to F#, imple- • Fabrice Bellard, “Computation of the com/dsyme/
mentation of algorithms in F# and cor- n’th digit of pi in any base in O(n^2),” • Alchemi Web site, http://www.alchemi.
responding performance results. While January 1997. net/
discussing this article with a number of • Simon Plouffe, “On the computation of • optionsScalper’s Web site, http://
colleagues, it’s obvious that there are a lot the n’th decimal digit of various tran- cs.jjbresearch.org/
of applications for the coupling of these scendental numbers,” November 1996. • Fabrice Bellard’s Web site, http://
technologies. Further work might include • Akshay Luther, Krishna Nadiminti, fabrice.bellard.free.fr/
the integration of grid computing into the Rajkumar Buyya, “Alchemi: A .NET- • Simon Plouffe’s Web site, http://www.
F# language as well as the F# interactive based Enterprise Grid System and lacim.uqam.ca/~plouffe/
console. Hopefully this article will inspire Framework - User Guide for Alchemi • OCaml Web site, http://caml.inria.
you to include F# and grid computing in 1.0,” July 2005. fr/

Listing 1 Deriving from the GThread Class return n;


[Serializable] }
class CustomGridThread : GThread { public String CalculatePiDigits(int n) {
public override void Start() { } int av, vmax, num, den, s, t;
} int N = (int) ((n + 20) * Math.Log(10) / Math.
Log(2));
double sum = 0;
Listing 2 Plouffe-Bellard Calculation Class in C# for (int a = 3; a <= (2 * N); a = next_prime(a)) {
public class Plouffe_Bellard vmax = (int) (Math.Log(2 * N) / Math.Log(a));
{ av = 1;
public Plouffe_Bellard() {} for (int i = 0; i < vmax; i++) {
private static int mul_mod(int a, int b, int m) { av = av * a;
return (int) (((long) a * (long) b) % m); }
} s = 0; num = 1; den = 1;
private static int inv_mod(int x, int y) { int v = 0;
int q,u,v,a,c,t; int kq = 1;
u=x; v=y; c=1; a=0; int kq2 = 1;
do { for (int k = 1; k <= N; k++) {
q=v/u; t=c; c=a-q*c; t = k;
a=t; t=u; u=v-q*u; v=t; if (kq >= a) {
} while (u!=0); do {
a=a%y; t = t / a;
if (a<0) { v--;
a=y+a; } while ((t % a) == 0);
} kq = 0;
return a; }
} kq++;
private static int pow_mod(int a, int b, int m) { num = mul_mod(num, t, av);
int r, aa; t = 2 * k - 1;
r=1; aa=a; if (kq2 >= a) {
while (true) { if (kq2 == a) {
if ((b & 1) != 0) do {
r = mul_mod(r, aa, m); t = t / a;
b = b >> 1; v++;
if (b == 0) break; } while ((t % a) == 0);
aa = mul_mod(aa, aa, m); }
} kq2 -= a;
return r; }
} den = mul_mod(den, t, av);
private static bool is_prime(int n) { kq2 += 2;
if ((n % 2) == 0) if (v > 0) {
return false; t = inv_mod(den, av);
int r = (int) Math.Sqrt(n); t = mul_mod(t, num, av);
for (int i = 3; i <= r; i += 2) { t = mul_mod(t, k, av);
if ((n % i) == 0) for (int i = v; i < vmax; i++){
return false; t = mul_mod(t, a, av);
} }
return true; s += t;
} if (s >= av) s -= av;
private static int next_prime(int n) { }
do { }
n++; t = pow_mod(10, n - 1, av);
} while (!is_prime(n)); s = mul_mod(s, t, av);

dotnetdevelopersjournal.com • May 2006


23
Super Computer
sum = (sum + (double) s / (double) Listing 6 pb.fs Test Code
av) % 1.0; module pb
} open System
int Result = (int) (sum * 1e9); let CalculatePiDigits (n:int) =
String StringResult = String.Format(“{0: string.Format(“{0}11111111”, n.ToString())
D9}”, Result);
return StringResult;
Listing 7 Pi Calculation Thread Using F# Module
}
public override void Start(){
}
StringBuilder temp = new StringBuilder();
for (int i = 0;
Listing 3 GThread Implementation Using the C# i <= Math.Ceiling((double)_
Calculation Class NumDigits / 9); i++) {
temp.Append(pb.CalculatePiDigits(_
public class PiCalcGridThread : GThread StartDigitNum +
(i
{
* 9)));
private int _StartDigitNum; }
private int _NumDigits; _Result = temp.ToString().Substring(0, _
private string _Result; NumDigits);
}
public int StartDigitNum
{ get { return _StartDigitNum ; } }
public int NumDigits Listing 8 Adding F# File Dependencies
{ get { return _NumDigits; } } Module PbMod = typeof(pb).Module;
App.Manifest.Add(new EmbeddedFileDependency(
public string Result
PbMod.Name, PbMod.FullyQualifiedName));
{ get { return _Result; } } Module FsMod = typeof(Microsoft.FSharp.Math.
public PiCalcGridThread(int startDigitNum, Matrix).Module;
int numDigits) { App.Manifest.Add(new EmbeddedFileDependency(
_StartDigitNum = startDigitNum; _ FsMod.Name, FsMod.FullyQualifiedName));
Module MlMod = typeof(Microsoft.FSharp.MLLib.
NumDigits = numDigits; Arg).Module;
} App.Manifest.Add(new EmbeddedFileDependency(
public override void Start() { MlMod.Name, MlMod.FullyQualifiedName));
StringBuilder temp = new
StringBuilder();
Listing 9 Adding F# File Dependencies with the
Plouffe_Bellard pb = new Plouffe_ standalone option
Bellard(); Module PbMod = typeof(pb).Module;
for (int i = 0; App.Manifest.Add(new EmbeddedFileDependency(
PbMod.Name, PbMod.FullyQualifiedName));
i <= Math.Ceiling((double)_
NumDigits / 9); i++) {
temp.Append(pb.CalculatePiDigits(_ Listing 10 Plouffe-Bellard Module in F#
StartDigitNum+(i * 9))); module pb
} open System
let inline is_prime(n) =
_Result = temp.ToString().Substring(0,
let mutable ret = true in
_NumDigits); if (n%2) = 0 then ret <- false
} else begin
} let r = Int32.of_float(sqrt(Float.of_int(n)))
in
let mutable i = 3 in
Listing 4 PiCalcGridThread Instantiation while i <= r && ret do
for (int i = 0; i < NumThreads; i++){ if (n % i) = 0 then ret <- false;
int StartDigitNum = 1 + (i*DigitsPerThread); i <- i + 2
done;
int DigitsForThisThread = Math. end;
Min(DigitsPerThread, ret
NumberOfDigits - i * DigitsPerThread); let inline next_prime (a) =
PiCalcGridThread thread = new let mutable n = a in
PiCalcGridThread( n <- n + 1;
StartDigitNum, while not(is_prime(n)) do
DigitsForThisThread n <- n + 1;
); done;
App.Threads.Add(thread); n
} let inline inv_mod( x, y ) =
let mutable q = 0 in
let mutable u = 0 in
Listing 5 pb.fsi let mutable v = 0 in
module pb let mutable a = 0 in
val CalculatePiDigits: int -> string let mutable c = 1 in

24 May 2006 • dotnetdevelopersjournal.com


let mutable t = 0 in den <- mul_mod(den, t, av);
u <- x; v <- y; q <- v/u; kq2 <- kq2 + 2;
t <- c; c <- a-q*c; a <- t; if (v > 0) then begin
t <- u; u <- v-q*u; v <- t; t <- inv_mod(den, av);
while not(u=0) do t <- mul_mod(t, num, av);
q <- v/u; t <- c; c <- a-q*c; t <- mul_mod(t, k, av);
a <- t; t <- u; u <- v-q*u; v <- t; i <- v;
done; while i < vmax do
a <- a%y; t <- mul_mod(t, a, av);
if (a<0) then a<-y+a; i <- i + 1;
a done;
let inline mul_mod( a, b, c ) = (a*b) % c s <- s + t;
let inline pow_mod( (a), (inb), (m)) = if (s >= av) then s <- (s - av);
let mutable r = 1 in end;
let mutable aa = 0 in k <- k + 1;
let mutable run = true in done;
let mutable b = 0 in t <- pow_mod(10, n - 1, av);
b <- inb; s <- mul_mod(s, t, av);
aa <- a; sum <- (sum + Float.of_int(s) / Float.of_int(av)) %
while run do 1.0;
if not((b &&& 1) = 0) then r <- mul_mod(r, aa, m); a <- next_prime(a)
b <- b >>> 1; done;
if (b = 0) then run <- false let Result = Int32.of_float(sum * 1e9) in
else aa <- mul_mod(aa, aa, m) string.Format(“{0:D9}”, Result)
done;
r
let CalculatePiDigits (n:int) = Listing 11 pb.fsi with GThread declaration
let mutable av = 0 in module pb
let mutable vmax = 0 in open Alchemi.Core.Owner;;
let mutable sum = 0.0 in val CalculatePiDigits: int -> string
let N = Int32.of_float( type FsPiCalcGThread =
Float.of_int(n+20) * (log(10.0) / log(2.0))) in class
let mutable a = 3 in inherit GThread
let mutable i = 0 in val _StartDigitNum : int;
let mutable s = 0 in val _NumDigits : int;
let mutable t = 0 in val mutable Result : string;
let mutable num = 0 in new : int * int->FsPiCalcGThread
let mutable den = 0 in end
while a <= 2*N do
vmax <- Int32.of_float( log(Float.of_int(2*N)) /
log(Float.of_int(a)) ); Listing 12 F# GThread implementation
av <- 1; i <- 0; [<Serializable>]
while i < vmax do type FsPiCalcGThread =
av <- av * a; i <- i + 1 class
done; inherit GThread
s <- 0; num <- 1; den <- 1; val _StartDigitNum : int;
let mutable v = 0 in val _NumDigits : int;
let mutable k = 1 in val mutable Result : string;
let mutable kq = 1 in new(startDigitNum, numDigits) as x = {
let mutable kq2 = 1 in _StartDigitNum=startDigitNum;
while k <= N do _NumDigits=numDigits;
t <- k; Result=String.Empty; }
if (kq >= a) then begin override x.Start() =
t <- t / a; v <- v - 1; begin
while ((t % a) = 0) do let mutable i = 0 in
t <- t / a; v <- v - 1; let mutable str = String.Empty in
done;
kq <- 0 let temp = new StringBuilder() in
end; while i <= Int32.of_float(Math.Ceiling(
kq <- kq + 1; Float.of_int(x._NumDigits) / 9.0)) do
num <- mul_mod(num, t, av);
t <- 2 * k - 1; str <- CalculatePiDigits(
if (kq2 >= a) then begin x._StartDigitNum + (i * 9));
if (kq2 = a) then begin temp.Append(str);
t <- t / a; v <- v + 1; i <- i + 1;
while ((t % a) = 0) do done;
t <- t / a; v <- v + 1; str <- temp.ToString();
done; x.Result <- str.Substring(0,x._NumDigits);
end;
kq2 <- kq2 - a; end;
end; end

dotnetdevelopersjournal.com • May 2006


25
ASP.NET

Adding Validation Capabilities


to a BoundField Using ASP.NET

t
he new family of bound In the case of an error you have to • RequiredErrorMessage: The string
controls lets developers submit data to the user so he or she can value that represents the error mes-
build data-driven appli- correct the mistake and do this until all sage displayed to the user when he
cations almost without the fields are filled correctly. or she leave a required field blank.
writing a line of code at page level, but You could avoid all the roundtrips • RegularExpressionValidationStri
there’s more work to do to build really to the server if you could check for ng: The string value that represents
robust, fully featured controls. data correctness on the client side (of the regular expression to be satisfied
With the new version of .NET course, to check the correctness server- by the data inserted in the bound
Framework, developers can extend side is a best practice that I warmly field.
base controls to build “powered” ones advice). • RegularExpressionValidationErro
that satisfy particular needs that base Using validator controls is a way rMessage: The string value that rep-
controls can’t. to do client-side validation; a detailed resents the error message displayed
In this article you’ll see how to description of the validator controls to the user when he or she inserts
extend the BoundField control add- are outside the scope of this article so if an invalid expression.
ing validation capabilities using ASP. you want a detailed description, point
NET validation controls. These con- your browser to http://msdn.microsoft. Listing 2 shows some of these
trols provide two ways of validation: com/library/default.asp?url=/library/ properties (note that the property
server-side and client-side. The nice en-us/cpgenref/html/cpconaspnetsyn- value is stored in the ViewState to pre-
thing about these validation controls is taxforvalidationcontrols.asp. serve it from postbacks).
that they will do client-side validation The goal now is to extend a The properties just created let you
when they detect that the browser can BoundControl so that, in edit or insert define the behavior of the control and
(unless client-side validation has been mode, user input can be validated what kind of validation controls have
disabled), thus reducing roundtrips. against a validation control. to be injected when the control is ren-
BY OSCAR PELI And it will do server-side where nec- dered.
essary. This client-side/server-side The PoweredBoundFiled Class Add a RequiredFieldValidator con-
detection and validation are done First of all create a class that inher- trol if the required property is set to
without extra work by the developer. its from the BoundField class (see true; add a RegularExpressionValidator
Listing 1). This lets you start with a control if the RegularExpressionValidat
BoundField Control class that behaves exactly like a generic ionString property isn’t empty.
The BoundField control is used BoundField control. The RegularExpressionValidati
by data-bound controls (such as You have to add properties onErrorMessage property and the
GridView and DetailsView) to display and override methods to imple- RequiredErrorMessage property let
the value of a field as text. ment the validation feature. The the developer customize the error
In edit/insert mode the control PoweredBoundField control will sup- message to present to the user in case
displays a textbox where the user can port the required validation and regular of erroneous inputs (note that these
change the value of the underlying field. expression validation capabilities, so properties have a default value for dis-
With a base BoundField you can’t vali- the first step is to create some proper- playing a generic message).
date the user input in any way so you ties to carry some information about
have to check the server side to see that, this. PoweredBoundField Overrides
for example, all the mandatory fields Add the following public properties: The validation feature of the
are filled and all the rules for special • Required: The Boolean value that PoweredBoundField control is provid-
fields (like e-mail fields) are satisfied. indicates if the field is mandatory. ed by validation controls; you have to

26 May 2006 • dotnetdevelopersjournal.com


bind these controls to the TextBox displayed www.microsoft.com/downloads/details. <asp:ValidationSummary AUTHOR BIO:
in edit or insert mode. aspx?familyid=220549b5-0b07-4448-8848- ID=”ValidationSummary1” Runat=”server” />Oscar Peli is a .NET
You already know that you have to dcc397514b41&displaylang=en and the Solution Architect and
execute this task in the InitializeCell method AdventureWorks sample database at http:// In the GridView declaration the cool Pda/Smartphone chief in
(see Listing 3). www.microsoft.com/downloads/details. portion is the Columns fragment; note Ancona (Italy) Town Council.
First, call the base method since you aspx?familyid=9697AAAA-AD4B-416E- that you can mix native BoundField con- Assistant at Macarata
have to add some stuff and not override the 87A4-A8B154F92787&displaylang=en). trols with PoweredBoundField controls. University where I develop
standard behaviour. Remember to add a SQL Server login so From the Purchasing.Vendor table of the web based applications to
that the connection string you find in the AdventureWorks sample database you’ll support research projects..
base.InitializeCell(cell, cellType, row- web.config file works correctly, otherwise manage three fields (this is enough for
State, rowIndex); change the connection string with a suit- the sample): 4 opeli@unimc.it
able login account. • A read-only VendorID (ID)
MyBase.InitializeCell(cell, cellType, Let’s look at the aspx code (see Listing 5). • A required Account Number that has
rowState, rowIndex) First register the control at page level to be composed of at least one upper
with a Register directive: case letter followed by four digits
Then if the current row is a data row • A required Name
(neither a header nor a footer) and if the <%@ Register Assembly=”Powered01Cs”
current row is in edit or insert mode, find Namespace=”Powered01Cs” To test the control run the Default.
the TextBox bound to the DataField. TagPrefix=”Powered01Cs” %> aspx (or DefaultVb.aspx) page, then click
one edit link of the GridView to edit the
TextBox tb = (TextBox)cell.Controls[0]; <%@ Register Assembly=”Powered01Vb” fields values then change the contents
Namespace=”Powered01Vb” of the fields so that some of the former
Dim tb As TextBox = CType(cell. TagPrefix=”Powered01Vb” %> rules are violated, and finally click the
Controls(0), TextBox) update link to see how it happens.
This creates an association between As you can see from Figure 1, the
Then set the TextBox id that you will use a tag prefix and the control that provides error messages are displayed depending
to link the possible validation controls. a concise way to refer to it in the aspx on what field contains the erroneous
page. Then note that you have to put a values; and, of course, the page doesn’t
tb.ID = DataField; ValidationSummary control on top of post back until you don’t insert right
the form because even if you’ve built the values.
tb.ID = DataField control with all the features to present nice Please note that to develop this fully
error messages to the user, you still have to featured page you didn’t have to write a
Finally add a RequiredFieldValidator collect all the error messages at page level. single line of code at page level.
control to the current cell if the Required
property is true and/or add a RegularExpres
sionValidator control if the RegularExpressi
onValidationString property isn’t blank.
These controls are associated with the
TextBox bound to the DataField via the
ControlToValidate property.
Two functions are created to encapsu-
late the validation control creation process.
There create a new instance of the valida-
tion control then set some control values
(Listing 4 shows one of these functions).

PoweredBoundField at Work
Now you can see the new Powered-
BoundField in action; first compile the
above class in a class library dll then use it
inside an aspx page. (You can download the
whole Visual Studio 2005 solution from the
online version of this article at http://dotnet.
sys-con.com.)
You’ll use the PoweredBoundField
control just created inside a GridView
control that will bind to a table in the
AdventureWorks sample database that
ships with SQL Server 2005 (to run this
example you can download Microsoft
SQL Server 2005 Express Edition at http:// f1 Figure 1: PowerBoundField at work

dotnetdevelopersjournal.com • May 2006


27
ASP.NET
Conclusion With the new version of the .NET capabilities using ASP.NET validation
The new family of bound controls Framework developers can extend base controls.
lets developers build data-driven appli- controls to build “powered” ones that In this way you could validate user
cations almost without writing a line satisfy particular needs that base con- input during the edit of a GridView row.
of code at page level, but there’s some trols can’t. As a result you’ve built a data access
other work to do to build really robust In this article you saw how to extend page with validation capabilities without
fully featured controls. a base-bound control adding validation writing a line of code at page level.

Listing 1 PoweredBoundField class declaration Public Property Required() As Boolean


using System; Get
using System.ComponentModel; Dim o As Object = ViewState(“EnableRequired”)
using System.Web.UI.WebControls; If (IsNothing(o)) Then
namespace Powered01Cs Return False
{ Else
public class PoweredBoundField : BoundField Return CBool(o)
{ End If
End Get
} Set(ByVal value As Boolean)
} ViewState(“EnableRequired”) = value
End Set
End Property
Imports System.Web.UI.WebControls
Public Property RequiredErrorMessage() As String
Public Class PoweredBoundField Get
Inherits BoundField Dim o As Object = ViewState(“RequiredErrorMessage”)
If (IsNothing(o)) Then
End Class Return “Required Field!!!”
Else
Return CStr(o)
End If
Listing 2 Some PoweredBoundField properties End Get
/// <summary> Set(ByVal value As String)
/// Enable/Disable Required Validation. ViewState(“RequiredErrorMessage”) = value
/// </summary> End Set
[ End Property
Description(“Required Validation”),
Category(“Behavior”), Listing 3 The InitializeCell method where we add the vali-
DefaultValue(“false”), dator controls to the TextBox bound to the DataField
] public override void InitializeCell(
public bool Required DataControlFieldCell cell,
{ DataControlCellType cellType,
get DataControlRowState rowState, int rowIndex)
{ {
object o = ViewState[“EnableRequired”]; base.InitializeCell(cell, cellType, rowState, rowIndex);
return (o != null ? (bool)o : false); if (cellType == DataControlCellType.DataCell)
} {
set // If the row is in edit mode try to add Validators
{ if ((rowState & DataControlRowState.Edit) != 0 ||
ViewState[“EnableRequired”] = value; (rowState & DataControlRowState.Insert) != 0)
} {
} try
{
/// <summary> // find the TextBox bound to the DataField
/// Required Validation Error Message. TextBox tb = (TextBox)cell.Controls[0];
/// </summary> tb.ID = DataField;
[ if (Required)
Description(“Required Validation Error Message”), {
Category(“Behavior”), // add a RequiredFieldValidator and link it
DefaultValue(“”), // to the TextBox bound to the DataField
] cell.Controls.Add(GetRequiredValidator(tb.ID,
public string RequiredErrorMessage RequiredErrorMessage));
{ }
get if (RegularExpressionValidationString != “”)
{ {
object o = ViewState[“RequiredErrorMessage”]; // add a RegularExpressionValidator and link it
return (o != null ? o.ToString() : “Required Field!!!”); // to the TextBox bound to the DataField
} cell.Controls.Add(GetRegularExpressionValidator(
set tb.ID, RegularExpressionValidationString,
{ RegularExpressionValidationErrorMessage));
ViewState[“RequiredErrorMessage”] = value; }
} }
} catch { }

28 May 2006 • dotnetdevelopersjournal.com


ASP.NET

} Return rev
} End Function
}

Listing 5 The Default.aspx page used to test


Public Overrides Sub InitializeCell( PoweredBoundField controls
ByVal cell As DataControlFieldCell, _ <%@ Page Language=”C#” AutoEventWireup=”true”
ByVal cellType As DataControlCellType, _ CodeFile=”Default.aspx.cs” Inherits=”_Default” %>
ByVal rowState As DataControlRowState, _ <%@ Register Assembly=”Powered01Cs”
ByVal rowIndex As Integer) Namespace=”Powered01Cs”
MyBase.InitializeCell(cell, cellType, rowState, rowIndex) TagPrefix=”Powered01Cs” %>
If cellType = DataControlCellType.DataCell Then
ʻ If the row is in edit mode try to add Validators <html xmlns=”http://www.w3.org/1999/xhtml” >
If (rowState And DataControlRowState.Edit) <> 0 _ <head runat=”server”>
OrElse (rowState And _ <title>Adding Validation Capabilities
DataControlRowState.Insert) <> 0 Then to BoundControls</title>
Try <link rel=”stylesheet” href=”Powered.css” />
ʻ find the TextBox bound to the DataField </head>
Dim tb As TextBox = CType(cell.Controls(0), TextBox) <body>
tb.ID = DataField <form id=”form1” runat=”server”>
If Required Then <h1>Adding Validation Capabilities to BoundControls</h1>
ʻ add a RequiredFieldValidator and link it <fieldset><legend>System Messages</legend>
ʻ to the TextBox bound to the DataField <span id=”Message” runat=”server” style=”FONT-SIZE: 8pt;
cell.Controls.Add(GetRequiredValidator(tb.ID, _ FONT-FAMILY: Verdana, Arial”>&nbsp;</span>
RequiredErrorMessage)) <asp:ValidationSummary ID=”ValidationSummary1”
End If Runat=”server” />
If RegularExpressionValidationString <> “” Then </fieldset>
ʻ add a RegularExpressionValidator and link it <p></p>
ʻ to the TextBox bound to the DataField <table>
<tr><td width=”50%”>
cell.Controls.Add(GetRegularExpressionValidator( _
<asp:GridView ID=”GridView1” runat=”server”
tb.ID, _
DataSourceID=”SqlDataSource1”
RegularExpressionValidationString, _
AutoGenerateColumns=”false”
RegularExpressionValidationErrorMessage))
AutoGenerateEditButton=”true” DataKeyNames=”VendorId”
End If
SelectedRowStyle-CssClass=”GRDSelectedItem”
Catch ex As Exception
AlternatingRowStyle-CssClass=”GRDAlternatingItem”
End Try
RowStyle-CssClass=”GRDItem”
End If
HeaderStyle-CssClass=”GRDHeader”
End If
BorderColor=”black” BorderWidth=”1”
End Sub
GridLines=”Both” AllowPaging=”true” PageSize=”20”
EnableSortingAndPagingCallbacks=”true”>
Listing 4 Private functions that build up validator controls <Columns>
private RegularExpressionValidator <asp:BoundField DataField=”VendorId” HeaderText=”Id”
GetRegularExpressionValidator( ReadOnly=”true” />
string inControlToValidate, <Powered01Cs:PoweredBoundField
string inRegExprValidationString, RegularExpressionValidationString=”^[A-Z]{1,10}\d{4}$”
string inRegExprValidationErrorMessage) Required=”true”
{ RequiredErrorMessage=”Must Insert an Account Number”
RegularExpressionValidator rev = DataField=”AccountNumber”
new RegularExpressionValidator(); HeaderText=”Account Number” />
rev.ControlToValidate = inControlToValidate; <Powered01Cs:PoweredBoundField Required=”true”
rev.ID = String.Concat(“RegularExpressionValidatorOf”, RequiredErrorMessage=”You Must Insert a Name”
inControlToValidate); DataField=”Name” HeaderText=”Name” />
rev.Display = ValidatorDisplay.Dynamic; </Columns>
rev.ValidationExpression = inRegExprValidationString; </asp:GridView>
rev.ErrorMessage = inRegExprValidationErrorMessage; <asp:SqlDataSource ID=”SqlDataSource1” runat=”server”
rev.Text = “&nbsp;(!)”; SelectCommand=”SELECT VendorId, AccountNumber, Name
return rev; FROM Purchasing.Vendor”
} SelectCommandType=”Text”
UpdateCommand=”UPDATE Purchasing.Vendor SET
AccountNumber=@AccountNumber, Name=@Name WHERE
Private Function GetRegularExpressionValidator( _ VendorId=@VendorId” UpdateCommandType=”Text”
ByVal inControlToValidate As String, _ ConnectionString=
ByVal inRegExprValidationString As String, _ “<%$ ConnectionStrings:DBConnectionString %>”
ByVal inRegExprValidationErrorMessage As String) _ OldValuesParameterFormatString=”{0}” >
As RegularExpressionValidator </asp:SqlDataSource>
Dim rev As New RegularExpressionValidator() </td>
rev.ControlToValidate = inControlToValidate <td valign=”top” align=”center” width=”50%”>
rev.ID = “RegularExpressionValidatorOf” & _ <img src=”Powered01.gif” /></td>
CStr(inControlToValidate) </tr>
rev.Display = ValidatorDisplay.Dynamic </table>
rev.ValidationExpression = inRegExprValidationString </form>
rev.ErrorMessage = inRegExprValidationErrorMessage </body>
rev.Text = “&nbsp;(!)” </html>

30 May 2006 • dotnetdevelopersjournal.com


���������������������
����������������������������
�����������������������
��������������
�������������������������� ������������

��������������������������� ��������������
������������

�������������
����������

����
���������������

�������

�������������������������������������������������������
��������������
�����������������������������������������������������
���������������������������������������������������������� �������������������
������������������������������������� �����������������������������
�������������������������������������������������������������� �������
���������������������������������������
�����������������������������������������������
������������������������������� ������������������������������
�������������������������������������������������������������� �������
���������������������������������������
�����������������������������������������������������������������

� � � �� ��������������������������������������������������������������� �����������������������������
�������������������������������������������������������������� �������

�� ��������� ����
����������������������������������������������������������������������� ���������������������������������������
����������������������������������������������������������������

����� �������� ��������������������������������������������������������������������� ����������������������������������
����������������������������������������������������������������������
����
����
��������� ������������������������������������������������������������������������ ������������������������������������������������������������������

� � ���������� ��
��
�������������������������������������������������� �������������������������������������
������������������������������������������
��� �����
�����
�������������
��������������������������������� ����������������
������������������ ������������������������������

������������

COPYRIGHT ©2006 SYS-CON MEDIA ALL RIGHTS RESERVED


�������
������������� �����������
���� ���� ������������� ���
��������� ���� ���� ��������� ������������
����� ����������� ���� ����
���������������������������
������������� ����������� ���������������������������������
���� ���� ������������� ��� ��������������������������������������� �����������������������������������������
��������� ���� ���� ��������� ���������������������������������������������������������������������������������������������������
�������������������������������������������� ���������������������������������������
��������������������������������������������������������������������������������������������������
����� ����������� ���� ���� ���������������������������������������������������������������������������������������������������
��������������������������������������������������������������������������������������������������
�����������������������������������������������������������������������������������������������������
����������������������������������������������������������������������������������������������������

������������� ����������� ������������������������������������������������������������������������������������������������������


���������������������������������������������������������������������������������������������������� ������������������������������������������������������������������������������������������������
���������������������������������������������������������������������������������������������������
������������������������������������������������������������������������������������������������ ������������������������������������������������������������������������������������������������
���� ���� ������������� ��� �������������������������������������������������������������������������������������������������
������������������������������������������������������������������������������������������������
����������������������������������������

��������� ���� ���� ��������� �������������������������������������������������������������������������������������������������������


���������������������������������������������������������������������������������������������������
������������������������������������������������������������������
����� ����������� ���� ���� �����������������������������
�����������������������������������
������������� ����������� ��������������������������������������������������
���� ���� ������������� ��� ��������������������������������� ������������������������������������������������������������������������������������������������������
������������������������������������������������������������������������������������������������������
������������������������������������� ����������������������������������������������������������������������������������������������������
�����������������������������������������������������������������������������������������������������
����������������������������������������������������� ��������������������������������������������������������������������������������������������������������
��������������������������������������������������������������������������������������������������� ����������������������������������������������������������������������������������������������������������
������������������������������������������������������������������������������������������������� ��������������������������������������������������������������������������������������������������������
��������������������������������������������������������������������������������������������������� �������������������������������������������������������������������������������������������������������
������������������������������������������������������������������������������������������������������� �����������������������������������������������������������������������������������������������������
������������������������������������������������������������������������������������������������������� ��������������������������������������
�����������������������������������������������������������������������������������������������������
�������������������������������������������������������������������������

�������������������������������
���������������
������������������������������������ ������������������������
����������������������������������������� �������������������������������������������������������������������������������������������������������
�������������������������������������������������������������������������������������������������������
�������������������������������� �������������������������������������������������������������������������������������������������������������
���������������������������������������������������������������������������������������������� ������������������������������������������������������������������������������������������������
������������������������������������������������������������������������������������������������������ ������������������������������������������������������������������������������������������������������
�������������������������������������������������������������������������������������������������� ������������������������������������������������������������������������������������������������
������������������������������������������������������������������������������������������������������
�������������������������������������������������������������������������������������������������������
����������������������������������������������������������������������������������������������������
������������������������������������������������������������������
��������������������������������
��������������������������������������������������������������
����������������������������������������������������������
�������������������������������������������������������������������������������������������������
���������������������������������������� �������������������������������������������������������������������������������������������������������
������������������������������������������������������������������������������������������������������
���������������������������������� ������������������������������������������������������������������������������������������������������������
�������������������������� ��������������������������������������������������������������������������������������������������������
����������������������������������������������������������������������������
�����������������������������������������������������������������������������������������������
����������������������������������������������������������������������������������������������
�� �� �� ������������������������������������������������������������������������������������������������
���������������������������������������������������������������������������������������������������
��������������������������������������������������������������������������������������������������� ��������������������������������
���������������������������������������������������������������������������������������������������
���������������������������������������������������������������������������������������������� ��������������������������������������������������������������
�������������������������������������������������������������������������������������
����������������������������������������������������������
������������������������������������������������������������������������������������������������������
�� �� �� ��������������������������������������������������������������������������������������������������������
���������������������������������������������������������������������������������������������������������
�����������������������������������������������������������������������������������������������������������
������������������������������������������������������������������������������������������������������������
�������������������������������������������������������������������
�����������������������������������
����������������������������������
�� �� �� ���������������������������������������������������������������������������������������������
�������������������������������������������������������������������������������������������������� ����������������������������������
�������������������������������������������������������������������������������������������
�������������������������������������������� ������������������������������������������������������
����������������������������������������������������������
����������������������������������������������������������������������������������������������������������
�������������������������������������������������������������������������������������������������������
�������������������������������������������������������������������������������������������������������
���������������������������������������������������������������������������������������������������������
����������������������������� ��������������������������������
������������������������������������������������������������������������������������������������������
����������������������������������������������������������������������������������������������������
����������������������������������������������������������������� ���������������������������� ������������������������

��� ����������������������������� �����������������������������������������������������������������������������������������������������������


� ��������������������������������������������������������������������� �������������������������������������������������������������������������������������������������
�����������������������������������������������������������������������������������������������������
��� ������������������� ������������������������������������������������������������������������������������������������������ �������������
� ��������������������������������������������������� ��������������������������������������������������������������������������������������������������
���������������������������������������������������������������������������������������������������� ����������������
��� ���������������������������������������������������
� ��������������������������������������������������������������������
��������������������������������������������������������������������������������������������������������� ���������������������������������������������
���������������������������������������������������������������������������������������������������������
�������������������������������������������������������������� ���������������������������������������������������������������������������������������������
��� �������� �����������������������������������������������������������������������������������������������������
� ���������������������������������������������������������������������������������������������� ��������������������������������������������������������������������������������������������������
��� ������������������ ��������������������������������������������������������������������������������������������������
� ������������������������������������������������������������������������������������������� ����������������������������������������������������������������������������������������������������
� ���������������������������������������������� ���������������������������������������

��� �������
��������������������������������
� �������������������������������������������������������������������������������������������� ����������������������������������������
� �������������������������������������
�������������������������������� ������������������������
��� ������������� ��������������������������������������������������������������������������������������������������
� ���������������������������������������������������������������������������������������������� ���������������������������������������������������������������������������������������������
���������������������������������������������������������������������������������������������������
���������������������������������������������
��� �����������������������������
� �������������������������������������������������������������������������������������������������� �����������������������������������������������������������������������������������������������������
� �������������������� ������������������������������������������������������������������������������������������������������ ��������������������������������������������������
���������������������������������������������������������������������������������������������������������
��� ������������������������������ ����������������������������������������������������������������������������������������������������� NOTE: SPEAKER LINE-UP SUBJECT TO CHANGE WITHOUT NOTICE
� �������������������������������������������������������������������������������� ���������������������������������������������������������������������������������������������� VISIT WWW.AJAXSEMINAR.COM FOR THE MOST COMPLETE UP-TO-DATE INFORMATION
CMS

Building a Simple Content Management System


Learn how to enable your editors to visually edit HTML content online

i
n this article you’ll learn HTML-Editor/KTML-for-.NET/Try- Access database and copy it into
how to create a basic con- Download/). the site root. You’ll also have to
tent management system 3. A database system, either Microsoft refresh the Solution Explorer
that stores articles in a Access or Microsoft SQL Server. view to access it from within the
database using Microsoft’s Visual 4. A basic knowledge of databases and platform.
Web Developer Express Edition (or the .NET platform.
Microsoft Visual Studio) and KTML 4 Your application setup is almost
Lite edition. The first step in building this complete. All you need to check
At the end of this article users of application is to set up your working now is that you have all the compo-
the Content Management System environment. nents handy.
will be able to:
• See the list of articles that exist in Setting Up the Environment Add the KTML 4 Lite Control to
the site database with the title and It only takes three easy steps to the Toolbox
short description. get you up and going. Let’s do it You’ll only use three controls
• Display the full article. now: to build your pages: the DataList,
• Edit or add articles using the free 1. Start the IDE you’re using. On the DetailsView, and the KTML 4
online HTML editor KTML Lite Welcome page that’s shown select Visual Studio control. The first two
that is easy to learn and use just the option to create a new ASP. are present by default in your plat-
like Microsoft Word. NET Web site. Select the path to form, right under the Data tab in
store the files and give it a proper the Toolbox. The latter is a custom
Using KTML Lite the text boxes or name, say, SimpleCMS. Note: control that you must manually
text areas used to edit content can be If you’ve disabled the Welcome add to the Toolbox:
replaced with an online HTML edi- page, you can create the new 1. Download the KTML 4 Lite for
tor that lets you format text, style it application from File > New Web the ASP.NET zip archive. Unpack
using CSS, upload and insert images Site. it to a folder of choice.
BY CRISTIAN IVASCU
and media, upload and manage files. 2. The new Web site starts off with 2. Inside the main package there
You need 20 minutes to complete a single page – default.aspx. On are two more archives – one for
this tutorial. this page you’ll display the list ASP.NET 1.1 and the other for
of articles. For the editing page version 2.0 of ASP.NET. Use the
Getting Started right-click the project title in the one that’s appropriate to your
Before starting on this project, Solution Explorer and select the specific ASP.NET version.
there are some prerequisites to take Add new Item option. Name the 3. Unpack the zip with KTML to a
care of. You need: new page edit.aspx. folder on your hard drive (e.g.,
1. Microsoft Visual Web Developer 2005 3. Next create a database with the c:\InterAKT\Ktml). The archive
Express Edition (see http://msdn. same structure as in Figure 1 or contains two folders – bin and
microsoft.com/vstudio/express/ download the sample Microsoft includes – and two files – one
vwd/) or Microsoft Visual Studio
2005 (see http://msdn.microsoft.
com/vstudio/default.aspx). Since the
steps are the same for both platforms
there will be no distinction in what
follows.
2. KTML 4 Lite for ASP.NET Visual
Studio Control (see www.inter-
aktonline.com/Products/Online- f1 Figure 1: The articles table structure

34 May 2006 • dotnetdevelopersjournal.com


containing a sample KTML control and in the ID text field enter 5. To complete and save the change, AUTHOR BIO:
applied and a sample web.config SimpleCMS. Then click OK to select the End template editing Cristian Ivascu is a technical
file. You won’t use any of these files proceed to step 2. option from the Tasks pane. writer with InterAKT Online.
in the tutorial. 6. In the second step you have to 6. For the last look change select He is a strong supporter of
4. Back in the IDE right-click an pick out the database to use. Click the AutoFormat option in the open-source software and a fan
empty spot on the toolbox and Browse and select the simpleCMS. Tasks pane. From the interface of Japanese culture and rock
select the Add Tab option. For the mdb file in the site root. The IDE that loads, select the Simple skin music.
name you can use InterAKT, the will convert the path to one rela- in the left list. Then click OK to
developer of the KTML control. tive to the application: ~/simpleC- apply it. 4 civascu@interaktonline.com
5. Right-click the newly added MS.mdb.
tab and select the Choose Items 7. In the last step select the database
option. A dialog box will load table and table columns to display
displaying already installed com- in the list. Only check the title_art
ponents and a Browse button and description_art columns.
to select new components to Then click Next and Finish.
install.
6. Click Browse and navigate to the Now the article list has been cre-
folder where you unpacked KTML. ated. And although it does its job
From within the bin subfolder as it should it looks…awful. So let’s
select the InterAKT.KTML4LITE.dll make it look a little better:
file and click Open. 1. Click the Smart Tag icon to display
7. Back in the Choose Toolbox items the Tasks pane if needed.
interface click OK. 2. From the list of tasks click the Edit
templates option. Now you can edit
Now the KTML control is dis- the content inside the list items. f2 Figure 2: KTML control
played in the Toolbox and it should The only concern isn’t to remove the added to the Toolbox
look like in Figure 2. dynamic labels – they’re bound to
With this last step the working the data fields to display.
environment is completely config- 3. First replace the title_art item with
ured and all bits and pieces are gath- Article title. Type it in then select
ered in the same spot. Now let’s start it and click the Bold button on the
gluing them together. toolbar.
4. Next replace description_art: with
Create the Article List Page Article description. Then select it
The first page of the CMS displays and apply the Bold formatting. To
a list of current articles. The list separate it better from the actual
doesn’t go into detail – only the arti- description hit SHIFT+ENTER to
cle title and a short description are add a line break. f3 Figure 3: Completed list of articles
displayed. To build the list you’ll use
the DataList control:
1. Open the Default.aspx page by
double-clicking it in the Solution
Explorer.
2. Make sure it’s set to display the
Design mode. If it shows some
code, just click the Design but-
ton at the bottom of the screen to
switch modes.
3. In the Toolbox expand the
Data tab and drag and drop the
DataList item onto the page. The
DataList Tasks pop-up should be
automatically displayed. If not,
click the Smart Tag to open it (the
> icon on top of the control).
4. From the Tasks pane in the Choose
Data Source dropdown menu
select the New Data Source option.
This will open the Data Source
Configuration wizard.
5. In the wizard’s first step click
on the Access Database icon f4 Figure 4: Set properties for each data bound field

dotnetdevelopersjournal.com • May 2006


35
CMS
b. Enable Inserting – this option
generates code that allows
adding a new article.
c. Enable Editing – this option
generates code that allows
editing an article.
d. Enable Deleting – this option
f5 Figure 5: Default editing for the DetailsView page generates code that allows
deleting an article.
With the article list in place we 8. As you check each option, no-
can move on and create the article tice that new links are displayed
details page. on the control: Edit, Delete,
New.
Create the Article Details Page 9. By default the control displays
After reviewing the list of articles, all columns retrieved from the
the site editor can move on to the table. To change this, select
details page and edit one or more of the Edit Fields option from the
the entries. The detail page displays Tasks pane. The user interface
a full article at a time and links to that loads has three areas:
add another article, edit or delete the a. Available fields – located in
current entry, and links to navigate the upper-left section displays
through the articles. When clicking all fields that can be added to
the edit link, the editor will be dis- the control.
played. To build this page, follow the b. Selected fields – in the lower
next steps: left displays the fields that are
1. Open the edit.aspx page. currently associated with the
2. From the Data tab of the Toolbox control.
drag and drop the DetailsView item c. BoundField properties – on
on page. the right allows setting the
f6 Figure 6: Change template options for the article description 3. The first steps for configuring the properties for any selected
control are the same as for the field.
With this last step the article list DataList: create a new data source 10. Since we already have all the
page has been created and styled. If and select the simpleCMS.mdb fields in the control, and
you want to test it out, simply save database. we want some of them
the page (File > Save), right-click 4. In the third step of the wizard you removed, we use only the
on it in the Solution Explorer, and must select all the columns for second and third area.
select View in Browser. You should retrieval. To do this just check the 11. Select the id_art field from
get a result similar to the one shown option marked with *. the Selected fields area and
in Figure 3. 5. Next click on the Advanced but- press the Delete button – the
To allow the site’s content editors ton. Since this data source must one with a large red X-shaped
to move from the article list to the allow updating content, check the icon.
article editing page without having to Generate Insert, Update and Delete 12. Next select each of the remain-
remember or bookmark the URL let’s statements option. Then click OK. ing data fields – text_art, de-
make a last addition to this page – a 6. Press Next and Finish to create the scription_art and content_art
link: data source. and for each one change the
1. Put the cursor on the last element 7. The DetailsView page item is updat- Header Text property in the
on the page and type Edit article. ed with the actual columns and a set BoundField properties area.
2. Select the text you’ve just entered of checkboxes are displayed in the Use Article title, Article de-
and click the Hyperlink button in Tasks pane. Check all four of them: scription, and Article content.
the toolbar. a. Enable paging – this option 13. Also, for each of the three fields,
3. In the URL text box enter edit.aspx generates links to navigate after changing the Header Text,
and hit Enter to create the link. through the records. click the Convert this field

“UsingKTML Lite the text boxes or text areas used to


edit content can be replaced with an online HTML editor
that lets you format text, style it using CSS, upload and
insert images and media, upload and manage files”

36 May 2006 • dotnetdevelopersjournal.com


u c to r!y
ibnstcrroipd offer
tion
su

A TRULY INDEPENDENT Here’s what you’ll find in


VOICE IN THE WORLD OF .NET every issue of .netdj:
.NET Developer’s Journal is the leading

independent monthly publication targeted at .NET Security Watch


Mobile .NET
developers, particularly advanced developers. It brings
.NET Trends
.NET developers everything they need to know in order
Tech Tips
to create great software.
Standards Watch
Published
Business Alerts
monthly, .NET
.NET News
Developer’s
Book and Software
Journal covers Announcements

everything of interest to .NET Developer’s Journal is for .NET


developers of all levels, especially those “in
developers working with the trenches” creating .NET code on a daily
basis:
Microsoft .NET technolo- • For beginners:
Each issue contains step-by-step tutorials.
gies – all from a • For intermediate developers:
There are more advanced articles.
completely independ-
• For advanced .NET developers:
In-depth technical articles and columns
ent and nonbiased per-
written by acknowledged .NET experts.
spective. Articles are care-

SUBSCRIBE ONLINE!
Regardless of their experience level, .NET
fully selected for their prime Developer’s Journal assumes that everyone
reading it shares a common desire to under-
technical content – technical www.sys-con.com/dotnet/ stand as much about .NET – and the busi-
ness forces shaping it – as possible. Our aim
details aren’t watered down with or Call is to help bring our reader-developers closer

lots of needless opinion and com-

mentary. Apart from the technical content, expert ana-


1 888 303-5282 and closer to that goal with each and every
new issue!

lysts and software industry commentators keep devel-

opers and their managers abreast of the business

forces influencing .NET’s rapid development. SAVE16% ANNUAL


COVER PRICE:

OFF $83.88
Wholly independent of both Microsoft Corporation

and the other main players now shaping the course of


YOU PAY

69
.NET and Web services, .NET Developer’s Journal

represents a constant, neutral, expert voice on the $ 99


THE ANNUAL COVER PRICE
state of .NET today – the good, the bad, and the
YOU SAVE
ugly…no exceptions. Get 12 issues of .NETDJ
for only $6999! $13.89
OFF THE ANNUAL
COVER PRICE
OFFER SUBJECT TO CHANGE WITHOUT NOTICE
CMS
But the problem is that the 2. Select the Field[1] – Article
default controls used to edit the description item from the
fields aren’t suited to the large Display dropdown menu in
amount of text an article requires. the Tasks pane. By selecting the
In the next section you’ll learn how top item, and not its children,
to replace the default fields with all properties can be edited at
KTML, the visual HTML editor the same time on the page, as
mentioned above. shown in Figure 6.
3. To change the field used for edit-
Replace the Default Editing ing, click on the text box inside
Controls the EditItemTemplate area.Then
Now to integrate various con- in the Properties panel change
trols that allow editing content the TextMode option to MultiLine.
in the DetailsView control. The Repeat the same steps for the
changes we are about to make con- InsertItemTemplate text box.
sist of: 4. Next select the Field[2] – Article
• Replacing the description text content item in the Display drop
field with a text area for both down menu. You’ll turn the text
edit and insert. fields into visual HTML editors
• Replacing the content text field with the help of KTML 4 Lite.
f7 Figure 7: Edit rich content live on the server with the KTML 4 Lite online 5. Put the cursor on the text field
HTML editor for both edit and inside the EditItemTemplate
into a TemplateField link beneath insert. section. From the InterAKT tab
the properties area. This allows of the Toolbox that you’ve cre-
defining the exact behavior for The first step towards making ated at the beginning of the
each element – from display to these changes possible has been article drag and drop the KTML 4
delete. already made in the previous section, Lite control next to the text field.
14. When done setting up all fields, when each dynamic field was turned In a second or so the control will
click OK to apply the changes. into a TemplateField. In the standard be rendered on your page.
15. When adding the control by data-bound controls provided by the 6. Now you have to bind the con-
default, it’s set to a minimum Microsoft IDE, each field’s properties trol to the text field it must
width that doesn’t work too (including the control used to edit its replace. Click the KTML 4 con-
well with larger texts. So grab the value) can be altered only if the field trol to select it and then from
right horizontal resize handler is set as a template. If this is true, the Properties panel in the
with the mouse and make it a then editing the field is reduced to ControlToBindTo dropdown
little larger. About half of the using the Edit template command menu select TextBox3 (the name
page is fine. from the Tasks pane for the control. of the text box it replaces).
16. Last, just as for the list, let’s pick So to edit the DetailsView control 7. Repeat steps 5 and for the
an appearance to use from the field we have to take these steps: text field in the InsertItem-
predefined set. Select the Auto 1. Select the Edit Templates option Template area.
Format option from the Tasks from the Tasks pane. From the 8. Now, in the Tasks pane for the
pane and select the Simple color Display dropdown menu you can DetailsView control click the
scheme from the gallery. select which of the field’s states (or End template editing option to
17. Then click OK to apply the even all at the same time) that you save the changes.
option and File > Save to save want to edit. Note: By states we 9. KTML 4 is an AJAX-enabled editor
the entire page changes. mean the way the field is displayed and it also uses some server-side
for a specific action. For example, code for file operations and
At this point the details view is for the Insert state or InsertItem other modules. So it depends on
up and running. It also allows basic Template, the field is displayed some files to work properly.
operations like browsing through as a text box, while for the default Browse to the folder where you
the records, adding, editing, and state (or simply Itemtemplate) it’s unpacked KTML at the beginning
deleting, as shown in Figure 5. a data-bound label. of this article. Inside is a folder


You’ll no longer have to rely on the Webmaster just
to update a piece of content and the site editors don’t
have to take HTML courses; if they know how to use a
word processor, they’ll have no trouble with KTML”

38 May 2006 • dotnetdevelopersjournal.com


named includes that you must tent for the site users using features like: for-.NET/Live-Demos/, where you can
copy to the root of the CMS project. • Text formatting to apply different for- use the editor and discover what it can
10. You also need to tell the page that matting options like bold, italic, sub- do.
HTML content in variables is allowed script, and superscript or align the text • The Unveiling KTML article at www.
– since this is what the KTML editor you just have to push a button. interaktonline.com/Products/
will submit to the server: valid • Style content visually using CSS. Simply Online-HTML-Editor/KTML-for-
XHTML code. To do this, switch to specify the CSS file to use in KTML and .NET/Documentation/Articles/
Source view inside the IDE. Locate editors can apply styles using a drop- Unveiling+KTML+4.html?id_art=28
the first line of the file and add the down menu. Entries in the menu are shows off the features and several uses of
following directive before the clos- already styled so you know what the the editor.
ing %> tag: ValidateRequest=”false”. result will look like before applying it. • The user manual is available online in
• Create ordered and unordered lists eas- Flash format at www.interaktonline.
Now you can save the page and load ily or organize your data into tables. com/Documentation/KTML/index.html.
it in a browser to test it. Click the edit link • Upload and manage site files, media, • If you want to push the limits of KTML
for one of the articles to test out KTML. or documents, insert images into the and extend what it can do for you, don’t
It seems much easier to add rich content page, or create links to files for down- miss the API at www.interaktonline.com/
than through the text box as you can see in load are all done using the integrated Documentation/KTMLLITE-API/index.
Figure 7. Remote File Explorer. html.
Now you no longer have to rely on the • Create forms. If you have to create a • KTML 4 Lite also has a big brother, the
Webmaster just to update a piece of con- quick submit form you can do it with- full version that adds more Property
tent and the site editors don’t have to take out resorting to the Webmaster. Panels for almost all the elements you
HTML courses. If they know how to use a can insert from the editor, spellcheck-
word processor, they will have no trouble Where to Go from Here ing, XHTML compliance, and even an
with KTML. You can find out more about KTML integrated image editor. You can find out
from these articles: what are the differences between the two
What to Do with KTML • The KTML live demo page, acces- versions at www.interaktonline.com/
Using KTML instead of a text area will sible here at www.interaktonline.com/ Products/Online-HTML-Editor/KTML-
make it easier to create and edit rich con- Products/Online-HTML-Editor/KTML- for-.NET/VersionComparison/.

Advertiser Index
ADVERTISER URL PHONE PG

.NET Developer’s Journal www.sys-con.com/dotnet 888-303-5282 37


AJAX Seminar www.ajaxseminar.com 201-802-3022 32,33
CFDynamics www.cfdynamics.com 866-233-9626 17
ESRI www.esri.com/develop 888-288-1277 6
Forum Systems www.forumsys.com 866-333-0210 15
GraphOn www.graphon.com/itsg 800-GRAPHON 21
Hosting.com www.hosting.com 800-446-7627 9
IBM ibm.com/takebackcontrol/flexible 10,11
IT Solutions Guide www.itsolutions.sys-con.com 888-303-5282 39
iTVcon.com Conference & Expo itvcon.com 201-802-3023 45
Java Developer’s Journal www.jdj.sys-con.com 888-303-5282 43
JavaOne Conference 2006 java.sun.com/javaone/sf 31
KaPow Technologies www.kapow.com 800-805-0823 Cover III
MapInfo www.mapinfo.com/sdk 800-327-8627 Cover II
Parasoft www.parasoft.com/jdjmagazine 888-305-0041 Cover IV
RadView Software www.radview.com/analyze 888-RADVIEW 3
SOA/EOS Conference www.soaeosconference.sys-con.com 201-802-3022 46,47
Synaptris www.intelliview.com/netj 866-99IVIEW 13
SYS-CON Website www.sys-con.com 888-303-5282 49
Telerik www.telerik.com/AJAX 5
Visual Paradigm www.visual-paradigm.com 408-426-8212 29
General Conditions: The Publisher reserves the right to refuse any advertising not meeting the standards that are set to protect the high edito-
rial quality of .Net Developer’s Journal. All advertising is subject to approval by the Publisher. The Publisher assumes no liability for any costs
or damages incurred if for any reason the Publisher fails to publish an advertisement. In no event shall the Publisher be liable for any costs or
damages in excess of the cost of the advertisement as a result of a mistake in the advertisement or for any other reason. The Advertiser is fully
responsible for all financial liability and terms of the contract executed by the agents or agencies who are acting on behalf of the Advertiser.
Conditions set in this document (except the rates) are subject to change by the Publisher without notice. No conditions other than those set forth
in this “General Conditions Document” shall be binding upon the Publisher. Advertisers (and their agencies) are fully responsible for the content
of their advertisements printed in .Net Developer’s Journal. Advertisements are to be printed at the discretion of the Publisher. This discretion
includes the positioning of the advertisement, except for “preferred positions” described in the rate table. Cancellations and changes to adver-
tisements must be made in writing before the closing date. “Publisher” in this “General Conditions Document” refers to SYS-CON Publications,
Inc. This index is provided as an additional service to our readers. The publisher does not assume any liability for errors or omissions.

dotnetdevelopersjournal.com • May 2006


39
Tools

Flash ASP.NET Dynamic interactive medium for Web applications

a s the World Wide Web’s


landscape has evolved from
the days of multimedia-void
static HMTL pages, the need
form-independent, and therefore isn’t
restricted to execute on a Microsoft-
based operating system.
The Open Source, platform-inde-
make it a good match for Flash devel-
opers. It’s because some of ASP.NET’s
underlying features match up perfectly
with the needs of Flash development
for a dynamic interactive medium for pendent distribution of the .NET that make it a perfect server-side com-
Web applications has become appar- Framework is called Mono and is avail- rade. And not only does ASP.NET pro-
ent. Adobe Flash, as many developers able at www.gomono.com. Among vide all of the machinery necessary for
know, is the most widely distributed, other things, the Mono Framework lets Flash development, but it makes that
capable technology for achieving this ASP.NET applications be deployed on machinery easy to operate, taking care
new Internet medium. But Flash devel- non-Microsoft base Web servers, such of much of the underlying grunt work
opers can’t achieve the features expect- as Linux or Sun. that other languages don’t.
ed from modern Web applications Languages like ASP.NET are typical- One of the foundations of the .NET
with Flash alone – for Flash’s resources ly referred to as “server-side” languages Framework and ASP.NET is called the
to be put to proper use, Flash must because, unlike Flash applications, Framework Class Library (referred
team up with a server-side technol- which are displayed and execute in to as FCL). The FCL is a collection of
ogy capable of functionality such as the Flash Player on a user’s computer, reusable, commonly used objects.
database access and file manipulation. server-side languages perform their These objects let developers build on
Microsoft’s newest Web technology, magic on a Web server. Typically, serv- complex code that has already been
ASP.NET, is a perfect counterpart for er-side languages like ASP.NET are used created, eliminating the need to “rein-
Flash, putting powerful capabilities at vent the wheel” in your application.
the fingertips of Flash developers, cre- The Framework Class Library is very
ated using a programming language similar to the pre-built classes and
that is both friendly and familiar to components provided in Flash such
ActionScript developers. as MovieClip, Button, and variable
types such as String and Number. The
ASP.NET libraries in FCL include tremendously
ASP.NET, like other Web platforms powerful collections, such as ADO.NET
such as PHP, JSP, and ColdFusion, is a set to generate HTML documents that are – the .NET Framework’s data access
of Web development technologies that sent to a browser for display. Server- libraries – and ASP.NET – the libraries
can be used to create Web applications side languages are used, for example, to that give .NET the ability to create and
and Web Services. ASP.NET is the next generate all of the content you see on distribute Web applications. Access
generation of Microsoft’s Active Server large-scale sites like www.amazon.com to the FCL gives developers a major
BY RYAN MOORE Pages, a technology that was widely or www.cnn.com. When used in con- jumpstart in application development,
used to create Web applications in the junction with Flash, however, ASP.NET allowing focus to reside on the higher-
90s and early 2000s. ASP.NET represents is used instead to access and process level design of the application and
not only the newest in Microsoft’s Web information, package that information steer clear of unnecessary dirty work.
technology arsenal, but also one of the in a well-defined manner, and transmit For Flash developers specifically this
most advanced Web development plat- that information to a Flash interface, means that you can spend more time
forms currently available. which displays it for a user. Its ability on the Flash side of the application and
ASP.NET by itself is actually just to function in this role lets developers less on server-side functionality.
a small part of a larger development access the powerful functionality of One of the classes included in FCL
framework created by Microsoft, ASP.NET without relying on HTML as that makes integrating with Flash a
known collectively as the .NET a user interface. Instead, a rich inter- breeze is Web Services. Using ASP.NET,
Framework. The .NET Framework is a active medium such as Flash can be the creation of Web Services is a very
software development platform that is employed, dramatically increasing the painless process, since much of the
used to build and deploy applications capabilities of Web-based applications. underlying work is already contained in
for a variety of uses, ranging from Web- FCL. Web Services make it possible for
based applications to Web Services to Why Use ASP.NET for Flash developers to execute complex func-
desktop-based applications. Although Development? tions with an ASP.NET application and
created by Microsoft, the .NET Just because ASP.NET is one of the return complex results to a Flash appli-
Framework is an Open Source stan- newest and most powerful server-side cation without having to create compli-
dard, designed to be completely plat- platforms available doesn’t necessarily cated data-formatting procedures.

40 May 2006 • dotnetdevelopersjournal.com


Another reason that Flash developers • Image manipulation on a client system, another on a Web AUTHOR BIO:
will find ASP.NET a good match is the – Using ASP.NET, image files that server. Because of this separation, it’s very Ryan Moore is the lead software
programming language commonly used exist on a Web server can be run important to understand the methods architect and a principal of
to create ASP.NET applications, C#. C# through any number of manipula- available to communicate between the Balance Studios Inc. (www.
(pronounced see sharp), is the newest tions, including resizing, cropping, two systems – without the proper com- balancestudios.com) as well as
language in the C family of languages. C# and conversion. This can be a very munication channel, the two systems are epicsoft, Inc. (www.epicsoft.
is a best-of-breed language combining useful feature when used in combi- useless to each other. As the Flash Player net) of Green Bay, WI. Ryan is
the most popular features of C++, Java, nation with Flash 8’s advanced has evolved, so have many methods a C# programmer and Certified
and Visual Basic – which share the same image processing techniques and available to do this communicating. Macromedia Flash Developer.
foundations as ActionScript’s foundation, user-uploaded image files. More of Ryan’s articles can be
JavaScript. Because C# and ActionScript • Security FlashVars found at his personal weblog,
have emerged from very similar mod- – ASP.NET is capable of many secu- FlashVars are a method of communi- www.rymoore.com.
els, their syntax is very similar, making rity-based functions that aren’t cating between ASP.NET and Flash that
for an easy transition between the two available when using just Flash. uses tags embedded in HTML to exchange 4web@balancestudios.com
languages. Like ActionScript 2.0, C# is FCL has advanced encryption and data. FlashVars only allow for one-way
also a fully object-oriented language, decryption algorithms built-in, communication – from the server to the
which makes development very intui- making it easy for developers to do Flash Movie. Because of this, FlashVars
tive for an ActionScript programmer. I complex security techniques. aren’t an alternative for applications that
should mention that, although C# is the require data to be sent from a client-side
preferred language for creating ASP.NET Creating ASP.NET Applications application to a Web server, such as an e-
applications, it’s by no means the only Another one of the strengths of ASP. mail form. FlashVars, however, are a very
one. Because of the flexibility of the .NET NET for Flash developers is the preferred fast and efficient form of communication
Framework, ASP.NET applications can be development environment used to create and are often overlooked in circumstances
written in any ASP.NET compatible lan- ASP.NET applications – Visual Studio.NET. where small amounts of data have to be
guage, such as VB.NET and JScript (Java Visual Studio.NET 2005 is one of the most sent to a Flash Movie (see Figure 1).
for .NET). This flexibility also makes the advanced development environments in FlashVars are unique among the
transition process easier for a developer existence today. The features built into exchange methods in that the data they
who might already be familiar with Visual Studio.NET not only help make contain is sent along with the .swf file
one of these compatible programming ASP.NET development more effortless, when requested by a client browser
languages. but also help developers new to .NET instead of in a separate load after a Flash
programming learn these languages more movie is loaded. This kind of exchange
What Types of Functionality Can easily. is less obtrusive to the user than other
ASP.NET Be Used For? In the past, Visual Studio.NET was not methods and is a good solution in certain
Although there are an infinite num- an affordable tool for many developers, circumstances.
ber of things that you can use ASP.NET with its various editions starting at around
to do, there are some powerful features $1,000. However, with its 2005 product
that are commonly incorporated into line, Microsoft has released a version of
Flash applications: Visual Studio.NET called the “Express
• Access stored data from a database Editions” that is available free of charge
– Using ASP.NET, it’s possible to until November 6, 2006. Specifically
retrieve data from nearly any kind for Flash developers, the Visual Web
of database, including Microsoft Developer Edition is a perfect tool for
SQL, MySQL, Access, and Oracle, to beginning ASP.NET development, and is f1 Figure 1: FlashVars
display in a Flash-based interface. available for download at http://msdn.
• Insert and update database data microsoft.com/vstudio/express/vwd/.
– ASP.NET can be used to update
or insert data coming from a Flash Methods Used for Flash-ASP.NET
interface into a database. Acting as Interaction
the intermediary, ASP.NET can When creating applications that
handle any database connectivity make use of Flash and ASP.NET, a major
issues and respond accordingly. obstacle can be the fact that they are two
• File uploads very separate systems – one executing f2 Figure 2: LoadVars
– File uploading is an essential
feature of many Web-based appli-
cations. With Flash 8, Adobe
released the ability to upload files
from a user’s file system directly to
a Web server, monitoring the prog-
ress along the way. Using ASP.NET,
it’s possible for Flash to “hand off”
the file to the Web server for proper
placement. f3 Figure 3: XML Object

dotnetdevelopersjournal.com • May 2006


41
Tools
LoadVars Flash Remoting is the most pow-
The LoadVars object is much more erful and versatile of the options for
versatile than FlashVars in terms of communicating between a Flash
the direction and amount of data movie and a .NET Web server. Using
that can be exchanged. The LoadVars Flash Remoting, it’s possible to access
object is capable of either sending data directly from an ASP.NET Web
data to the server for processing, load- application in a secure, quick, and
ing data from the server, or sending efficient way. Flash Remoting uses a
data to the server and waiting for a binary message format for transfer-
response back from the server in one ring messages between the Flash
operation. The LoadVars object uses client and server-side ASP.NET code
name-value pairs to exchange data called ActionScript Messaging Format,
between the client and the server. The or AMF. AMF, like any of the other
LoadVars object is best used in a sce- methods, travels between the client
nario that requires two-way commu- f4 Figure 4: Web Services and server over HTTP, so you don’t
nication between the Flash Movie and have to worry about security mecha-
server-side logic, but doesn’t require suitable than the LoadVars object for nisms (such as firewalls) interfering
large amounts of data to be passed. handling larger amounts of data (see with your communication. Although
The LoadVars object requires that the Figure 3). modeled on the same protocol as
.NET developer handle the formatting Web Services, AMF is much more
of the exchanged data – potentially a Web Services lightweight than the other communi-
real pain, depending on the amount Introduced with Flash MX 2004 cation options, and therefore travels
you intend to pass (see Figure 2). Processional Edition, Web Services are much more quickly than calls using
the newest method for communicat- the Web Service connector. AMF is
XML Object ing between Flash and ASP.NET. Web also securable using SSL, so it’s a
The Flash XML Object is another Services use SOAP (Simple Object great option for security-sensitive
option for communicating between Access Protocol), an XML-based applications. Using Adobe’s version
a Web server and Flash client. The format, to transfer data between the of Flash Remoting does come with a
XML object is very similar to the client and server. Web Services are price tag, however. Flash Remoting for
LoadVars object in functionality in an industry standard for exposing ASP.NET is a standalone server-side
that it can both send data to the Web proprietary “services” for others to component not included with Flash
server and get data from it. The dif- use in their applications. An example MX 2004, which costs $999 per Web
ference between the XML object and of a web Service is the search method server. Thankfully, there’s an Open
the LoadVars object is the format in offered by Google. By using this meth- Source alternative to the Adobe Flash
which the data being sent and received od through Web Services, it’s possible Remoting for .NET package called
is formatted. Whereas the LoadVars for you to make a Flash application Fluorine. Fluorine is an Open Source
object expects a name-value pair as a that uses the Google search engine. Flash (www.osflash.org) project and is
response, the XML object sends and As mentioned earlier, Web Service available for download at http://fluo-
receives a well-formatted structured creation is very easy with ASP.NET, rine.thesilentgroup.com/.
XML document. Structured XML data making it an excellent choice for Flash
makes the XML object much more applications. Flash & ASP.NET Resources
www.flashasp.net

The information I’ve covered in


this article is just a brief overview
of the world of Flash development
with ASP.NET. I have recently writ-
ten a book published by Friends of
Ed called Foundation ASP.NET for
Flash, which thoroughly covers all
of the Flash-ASP.NET communica-
tion methods mentioned above, as
well as a step-by-step introduction to
ASP.NET development with C# and
Visual Studio.NET. I encourage you
to pick up a copy and add yourself to
the growing community of Flash-ASP.
NET developers. You’ll also find a
growing source of Flash and ASP.NET
resources, as well as a support forum
on the Foundation ASP.NET for Flash
f5 Figure 5: Flash Remoting homepage at www.flashasp.net.

42 May 2006 • dotnetdevelopersjournal.com


The World’s Leading Java Resource
Is Just a >Click< Away!
JDJ is the world’s premier independent, vendor-neutral print resource
for the ever-expanding international community of Internet
technology professionals who use Java.

ONLY
$
69 99
ONE YEAR
12 ISSUES

Subscription Price Includes


FREE JDJ Digital Edition!

www.JDJ.SYS-CON.com
or 1-888-303-5282

OFFER SUBJECT TO CHANGE WITHOUT NOTICE


Book Review

Best Kept Secrets in .NET


Revealing the secrets to improve your productivity and code quality

l
ately, it seems that every tion development that Ms. Kurata
computer book that you touches upon in her book. In gen-
find is a weighty tome of eral, we tend to view stored pro-
at least 500 or 600 pages. cedures, views, and user-defined
You groan just thinking about hav- functions as “second class” code
ing to schlep another monster-size that does not require proper track-
book around. It is so nice then to ing through source code control.
inform you that sometimes good It is true that SQL Server does not
things do come in small packages. lend itself to placing these vital
This book, while only 200 pages, pieces of code under source code
contains lots of nuggets that will control. However, now that we
appeal to all levels of developers. have the ability to create database
Chapter one covers an exhaus- projects inside of Visual Studio and
tive list of navigation short cuts place them under source code con-
that you will find in Visual Studio trol, there is no longer an excuse
2003. If you want to master get- for not properly tracking changes
ting around in Visual Studio, this Title: Best Kept Secrets in .NET
made to “database” code that is just
is a great chapter to have nearby. as vital to your application as your
Author: Deborah Kurata
I would urge Ms. Kurata to update VB.NET or C# code.
Publisher: Apress
this chapter to include Visual Visual studio provides templates
ISBN #: 1-59059-426-6
Studio 2005 shortcuts as well. that you can use when creating new
Price: US $29.99
In chapter two’s topics on stored procedures, views, and udfs.
Windows Forms is an important These templates can be found in
BY STEVEN MANDEL discussion on how to use the to keep track of all your changes “C:\Program Files\Microsoft Visual
Windows Form’s error provider to using Visual Source Safe. In this Studio .NET 2003\Common7\
Steven Mandel has worked in do proper validation in a Winform chapter, she also provides a very Tools\Templates\Database Project
the IT industry for over 15 years setting. neat tip on viewing datasets as Items”. If you decide to modify
designing databases using Chapter three has code tips. XML which is very handy espe- the templates ,you should rename
Microsoft Access and SQL There are some terrific tables that cially when you are in the midst of them and leave them in the same
Server. He has developed Web outline the use of regular expres- debugging. directory. They will be included
and Windows applications sions that Apress should think In the last chapter, Ms. Kurata in the list of possible templates to
using VB.NET and has written about including in Nathan Good’s discusses myriad tips and tech- select when adding a new stored
numerous articles and reviews otherwise terrific book on regular niques to make your code more procedure in the project.
about ASP.NET and VB.NET. expressions Regular Expression durable such as creating a general While it may take a bit of time,
Recipes for Windows Developers: exception handler and ideas put I would highly recommend placing
4smandel7@yahoo.com A Problem-Solution Approach. forth by the advocates of extreme all of your existing stored proce-
Another interesting discussion programming. dures in database projects. You will
Ms. Kurata has in this chapter is Is this book worth having? You have to manually add some of the
the way you can go about marking bet ya and as Ms. Kurata notes, features that the template provides
your code as obsolete by using the “Did you say ‘I didn’t know that!’ at but it will be worth it. Also, the flow
Obsolete Attribute in your code. least one while reading this book. If of your development will always
Chapter four covers various so it met its object of revealing the begin and end with the database
ADO.NET topics. There is an addi- best-kept secrets of .NET.” project. You will check out the
tional benefit that using a database database “code” when you need to
project provides. It allows you to A Side Note modify it and you will check it back
organize your stored procedures I would like to discuss an often in with your modifications after
into meaningful folder names and overlooked aspect of applica- you have revised it.

“While
only 200 pages this book contains lots of
nuggets that will appeal to all levels of developers”

44 May 2006 • dotnetdevelopersjournal.com


�������������
��������������� ������� ��������������
�������������������������
��
����������������
������������������������������
� �����������������
��������������������������������

�� ���������������������������
�������������������������

� �������������������������
� �������������������
� ������������ �
���������������������������������2�3���� ���������������
�� ��������������������������������������������
��������������������������� ��
��
�����������������������
���������������������������
�� ��������������������������������������������
�� ������������
���������������������� ��
��
�������������������������������������������������
����������������������������
������������������������������������������������� �� ��������������������
���������������������������������������������������������������� �� ������������
�� �������������
�������������������������������������������������������������������������������������������������������� �� ����������������������������������
�������������������������������������������������������������������������������������������������������� �� ���������������������������
������������������������������������������������������������������������������������������������� �� �����������������������
��������������������������������������������������������������������������������� �� �����������������
�� �� ����������������������������������
��������������������������������������������������������������������������������������������������������� �� �������������������������������������
������������������������������������������������������������������������������������������������� �� �������������������������������
���������������������������������������������������������������������������������������������������������
�����������������������������������������������������������������������������������������������������������
���������������������������������������������������������� �������� ����������������������������������
ALL RIGHTS RESERVED

� ��������������������������
�����������������������������������������������������������������
�������� ����������������������������������
���������������������������������������������������������������������� � ����������������������������
��������������������������������
�� �������� ����������������������������������
COPYRIGHT ©2006 SYS-CON MEDIA

������������������������������������������������������������������ � ���������������������������
�������������
������������������������������������������������������������������������� �������� �����������������������������������������������
����������������������������
������������������������������������������������������������������ � ����������������������������������������������
������������������
������������������������������������������ �� ����������������������������������������������
����������� � ����������������������������������������������
���
����
���
��
���
�� ��
���

���
���

��
�����
���
���

���
��
���
��
����
����
��
��
��
�����
��


�������������
�����������
�����������
������������������
�������������������������������������

����������������������������������������������� �������������
���������������������������������������������������������������������������������������������������������
�������������������������������������������������������������������������������������������������������������
����������������
���������������������������������������������������������������������������������������������������������
���������������������������������������
������
�������������������
������������������������������������������������������������������������������������������������������������ ���������������������������������������������
��������������������������������������������������������������������������������������������������������������������
����������������������������������������������������������������������������������������������������� ���������������������������������������������������
�����������������������������������������������������
������������������������������������������������������������������������������������������������������
���������������������������������������������������
�����������������������������������������������������������������������������������������������������������
������������������������������������������������������������������������������������������������������������� ���������������������������������������������
��������������������������������������������������� ���������������������������������

���������������������������������������������������������������������������������������������������������
���������������������������������������������������������������������������������������������������������������
�������������������������������������������������������������������������������������������������������
�����������������������������������������������������������������

�����������������������������������������������������������������������������������������������������������������
������������������������������������������������������������������������������������������������������������
������������������������������������������������������������������������������������������

�����������
����������������������������
���������������������������

�����������������������������������
������������ ��������������� ����������� ������������
������ ��������� �������� ������
������������������������������������������������ ������������������������������������������������� ��������������������������������������������� �����������������������������������������������
��������������������������������������������� ����������������������������������������� ���������������������������������������������������� �������������������������������������
������������������������������������������� ������������������������������������������� ��������������������������������������������
������������������������������������������ ��������������������������������������������� ���������������������������������������������������
����������������������������������������������� ����������������� ���������������������������������������������
������������������������������������������������������������ �������������������������������������������������������������������
���������������������������������������������������������������������� ���������������������������������������������������������������
����������������������������������������������������������������� ������������������������������������������������������������������
����������������������������������������������������������������� ��������������������������������������������������������������������
������������������������������������������������������������������� �����������������������������������������������������������������
����������������������������������������������������� ����������������������������������������������������������������
�����������������������������������������������������������

�������������� ���������� ���������������� �����������


����� ���� ��������� �����
�������������������������������������������������� ����������������������������������������������� �������������������������������������������������� ���������������������������������������������������
������������������������������������������ ���������������������������������������������� ������������������������������������������������� ��������������������������������������������������
���������������������������������������������� �������������������������������������������� ������������������������������������������������� ������������������������������������������������
������������������������������������������������� ���������������������������������������������� ������������������������������������������� ����������������������������������������������
������������������������������������������������� �������������������������������������������� �������������������������������������������� ������������������������������������������������
����������������������������������������������������������������� ����������������������������������������������������������������� �������������������������������������������������������������������� �����������������������������������������������������������������
��������������������������������������������������������������� ��������������������������������������������������������������� ������������������������������������������������������������������������ �������������������������������������������������������������������
���������������������������������������������������������������������� ��������������������������������������������������������������� ��������������������������������������������������������������������� �����������������������������������������������������������������
����������������������������������������������������������������������� ������������������������������������������������������������������� ������������������������������������������������������������� ������������������������������������������������������������������������
����������������������������������������������������������� ��������������������������������������������������������������� ������������������������������������������������������������������� ��������������������������������������
���������������������������������������������� ���������������������������������������������������������������� ������������������������������������������������������������������������
������������������������������������������������������������������ �����������������������

���������� ���������������� ����������� ������������


������������ ����������� ���������� ������
�������������������������������������������� ����������������������������������������� �������������������������������������������������� ���������������������������������������������������
���������������������������������������������� ������������������������������������������������� ������������������������������������������������ ����������������������������������������������
�������������������������������������������� ������������������������������������������������ ��������������������������������������������������� ������������������������������������������
�������������������������������������������� ���������������������������������������������� ������������������������������������������������ ���������������������������������������������������
����������������������������������������� �������������������������������������������������� ��������������������������������������������������� �����������������������������������������������
����������������������������������������������������������������� ��������������������������������������������������������������� ��������������������������������������������������������������� ��������������������������������������������������������������������
������������������������������������������������������������������ ������������������������������������������������������������������� ������������������������������������������������������������������� ����������������������������������������������������������������������
�������������������������������������������������������������� ����������������������������������������������������������������� ���������������������������������������������������������������� �������������������������������������������������������������������
�������������������������������������������������������������������� ����������������������������� ��������������������������������������������������������������������� ���������������������������������������������������������������
����������������������������������������������������������������� ������������������������������������������������������������������ �����������������������������������������������������������������
�������������������������������������������� ������������������������������������������������������������������� �����������������������������������������������������������������
������������������������������������������������ �������������������������������������

������������ ��������� ������������� �������������


����� ������� ������ ��������
������������������������������������������������ ����������������������������������������������� ����������������������������������������������� ����������������������������������������������
������������������������������������������������� ������������������������������������������������� �������������������������������������������������� �����������������������������������������������
��������������������������������������������������� ����������������������������������������������� �������������������������������������������� ����������������������������������������������
���������������������������������������������������� ���������������������������������������������� ��������������������������������������������� ��������������������������������������������
��������������������������������������������������� ����������������������������������������������� ������������������������������������������ ��������������������������������������������������
���������������������������������������������������������������� �������������������������������������������������������������� ����������������������� �����������������������������������������������������������������
������������������������������������������������ ���������������������������������������������������������������������� ��������������������������������������������������������������������
������������������������������������������������������������� �����������������������������������������������������������������
����������������������������������������������������������������
�������������������������������������������������������������
���������������������������������������������������������������

�����������������������������������
���������������
������������������������������

��������������������������� �����������������
����������������
�����������������
��������������������������������������
������������������������������������������������ ������� ���������������������� ����������������������� ���������������������
����������������������������������� ����������������������� �����������������������������
������������������������������������
ALL RIGHTS RESERVED

������� ����������������������� �������������������������


��������������� ������������ ������������������������
��������������������������������������
������������������������������������������������ ������� ��������������������������� ������������������� ����������������
��������������������� ������������������������ �����������������
������������������������������������������ ������������������������� ������������������ ������������������
������������������������� ���������� �������������������
���������������������������������������� ����������������� �����������������������������
������������������������� ������������������������� �����������������������������������
COPYRIGHT ©2006 SYS-CON MEDIA

� ��������������������� ������������������������� �������������������� �������������������


� ��������������������������������������������� ���������� ��������������������������� ��������������
� ����������������������������������� ��������������������� �����������������������������
� ���������������������������������� ���������������� �������������������������������
����������������������������� ���������������� ����������������������

��������������������������������������
Book Review

Practical Mono All about Mono on Linux and Windows

m
ark Mamone is a program namespace classes. It gives a quick
lead and solutions architect example of how to read a Web page from
for British Telecom, and he’s a server and describes what a proxy
been involved in .NET since server is, and how to connect to one. It
Beta 1; he’s presently spearheading a then shows how to add network connec-
Mono-driven project for BT. Mamone tivity to the RSS aggregator application
has co-authored several books, includ- using the .NET networking classes. It
ing Beginning Fedora 2, Beginning Red closes, like most chapters in this book,
Hat Linux 9, and Professional Windows with a description of the new .NET 2.0
Forms. classes, including the NetworkInterface
The first chapter of this book gives class that retrieves information on all
an overview of .NET, a history of the the network cards in the system, and the
Mono project, and instructions on Ping and FTP classes that support ping
downloading and installing Mono on and FTP protocols and functions.
Linux and Windows. OSX is mentioned, Chapter 11 covers ASP.NET, includ-
but specific instructions aren’t included. ing installing and using both the Mono
Moppix, the “live” version of Mono that XSP ASP server, and installing and
Title: Practical Mono
runs from a bootable CD (based on configuring Apache to be an ASP.NET
Author: Mark Mamone
the Konppix Linux distro), is also men- server using Mono on both Windows and
Publisher: Apress
tioned. Linux. The book gives an example of how
ISBN #: 1-59059-548-3
The second chapter gives an to set up your own Web server and create
introduction to installing and using Price: US $49.99 a WebForm application. It also covers
MonoDevelop, an IDE for .NET develop- creating and consuming Web services. It
ment under Linux that’s closely associ- the Glade design tool for user interface again closes with a description of the ASP.
ated with the Mono project. layout. The author does this by recreat- NET changes in .NET 2.0; however these
Chapter three gives a quick overview ing the same RSS aggregator user inter- changes are so great I would recommend
of basic C#, and chapter four continues face produced in chapter six. using this book to see how to set up ASP.
this covering classes, attributes, inter- Chapter eight covers database con- NET using Mono with XSP and Apache,
faces, delegates, and exceptions, closing nections using ADO.NET, concentrating but continue with another book on ASP.
BY DENNIS HAYES with a short section on what’s new in C# on MySQL. Mono and .NET can use a NET 2.0 such as Pro ASP.NET 2.0 Website
2.0. number of different databases, but here Programming, also from Apress.
Dennis Hayes is an independent Chapter five gives a high-level view the author concentrates on MySQL Chapter 12, the last chapter is
software consultant in Atlanta, GA, of .NET and its advantages, including because it’s one of the most popular divided into two parts. The first part cov-
and has been involved with the the intermediate language, assemblies, open source databases, and it is avail- ers profiling using the Mono profiler and
Mono project for over three years. the GAC (Global Assembly Cache), able on many platforms. Another advan- the low-level OProfile tool that comes as
memory management and garbage tage is that by limiting the discussion to part of Linux. It points out that you can
4dennisdotnet@yahoo.com collection, and application domains. It a single database, he can go into details use other profilers, such as the one for
closes with a short paragraph on each of such as how to install and set up MySQL. the Nermele programming language, by
the system namespaces (IO, Collections, This chapter gives an excellent overview using the Mono profiler flag.
Security, etc.). of using a database with .NET, but if you The second section gives a few good
Chapter six covers creating graph- want to have a deep and wide under- tips on how to write faster programs, such
ics programs using System.Windows. standing of databases under .NET, check as using StringBuilder instead of String
Forms by creating a user interface for out Pro ADO.NET 2.0, also from Apress; when several strings have to be concat-
a RSS aggregator application that uses it covers .NET databases in detail. enated, and using structures instead of
menus, dialog boxes, panels, ListBoxes, Chapter nine covers XML. It starts classes where appropriate. These are
datagrids, and events. The code is cre- with a good overview of XML and all good tips, but are too few and basic to
ated manually without using an IDE of its parts. Since RSS uses XML for its help an experienced .NET programmer,
graphic layout designer so the reader document format, this chapter shows but could be helpful to a beginner.
can understand how a .NET program how to read and write RSS XML docu- This is a great book for anyone who
works. Using System.Windows.Forms, ments, and parse out the information for wants to use .NET on Linux. It gives .NET
this is not that difficult. The chapter clos- the application created in chapter six and programmers everything they need to
es by giving an overview of the advances seven. use Linux, and it gives the Linux gurus
in System.Windows.Forms 2.0. Chapter 10 gives a quick overview of everything they need to use .NET. It is a
Chapter seven covers creating appli- networking, including the OSI model, must have for anyone doing cross-plat-
cations by using the GTK# library and and then introduces the System.Net form .NET.

48 May 2006 • dotnetdevelopersjournal.com


Visit the���
���������������

Website Today!
���������������������������������
���������������������������

24/7
����������������
������������������������������������������
���������������������������������������������������

����������
�������������������������������������������������������������������������������������

�������������
����������������������������������������������������������������������������������������

��������
������������������������������������������������������������������
��������������������
����������
���������������������� ��������������������������������������������������
������������������ ����������������������
������������������������������������ ������������������������������ ��������
��� ����������� �������������������������������������������������������������
�������������������� ������������������������������ �
������������������������ ��������������������������� ����������
������������������� ����������������� ������������������������������������������������������������������������������
������������������� ����
��������������������������� ��������������������������������
��������������������
�����������������������������������������������������������������������

������������������������������������������
Mono

Mono Beta for 1.2 Released... And more from the Mono archives

m
ono has released version some have long been 2.0-compliant,
1.1.13.5 and 1.1.14. Version while others still struggle to be 1.0/1.1-
1.1.13.5 is actually the compliant. Once a library is written,
first release since 1.1.13, it’s easier to keep up with changes in
even though there were four internal new versions, so this should improve
releases in between. The purpose of over time.
this release is to document the chang-
es in those releases; there are no new Commercial Use of Mono
features in this release, just bug fixes in Early in Mono’s development, a
all areas of the project. One reason for number of small companies used
multiple releases was to keep testers it to move their .NET applications
current during the run-up to the major to Linux and Mac. This did several
1.2 release. Release notes are at http:// things for the Mono project: it gave
go-mono.com/archive/1.1.13.5. it credibility and it provided a lot
The 1.1.14 release is considered the of real-life test code that pushed
first beta for the upcoming 1.2 release. improvements in several parts of
This will be Mono’s third major release, Mono, especially its Web Services
the first two being the 1.0 and 1.1 and remoting technologies. Several
releases. The biggest visible addition in companies also paid developers
this release is full support for the Mac- to help with critical parts of Mono.
on-Intel. Another big advance that isn’t hand, it prevents deep compatibility SourceGear and Winfessor are two
visible is the new version of the Boehm with the real SWF, because only a companies that bet on Mono during
garbage collector that Mono uses. The minimum set of WinProc messages the early days.
garbage collector currently doesn’t can be hooked from SWF controls, Not a big a milestone, but Mono
support compacting or moving, which and standard Windows Pinvokes that has now been incorporated into
can cause memory problems on long could have been made won’t work Fedora Core 5. Until now, Mono has
running programs. The new version of with the managed SWF. On the other been never been included in any Red
the garbage collector includes a lot of hand, removing the WINE dependency Hat-related product, and it still won’t
internal changes in preparation for a freed Mono from changes that the be included in Red Hat Enterprise
BY DENNIS HAYES future version, which will do moving WINE project was going through, and Linux (RHEL), the official Red Hat
and compacting. let SWF be ported to non-Intel archi- release.
Dennis Hayes is an independent Included in this release are System. tectures (including Mac), which would
software consultant in Atlanta, GA, Transaction, better support for the Boo have been far more difficult with a What the Future Holds for Mono
and has been involved with the and IronPython languages, improve- WINE-based implementation. I think The biggest headlines in Mono’s
Mono project for over three years. ments in libgdiplus, and more optimi- that as more applications and SWF future are likely to be the comple-
zations in the JIT compiler. controls become fully managed, this tion of SWF, followed by the release
4dennisdotnet@yahoo.com Separately, IronPython is rapidly decision will look better and better. of Mono 1.2. These are tied together
releasing betas for testers and getting and should happen in the next few
ready to release version 1.0; see the Mono Keeps Up With .NET months. Completing the .NET 2.0
IronPython homepage at http://www. Version 2 libraries, and the release of a Visual
gotdotnet.com/workspaces/work- In the early days of Mono, a com- Basic.NET complier are the other big
space.aspx?id=ad7acff7-ab1e-4bcb- mon question was whether Mono milestones down the road. Currently
99c0-57ac5a3a9742 for details. could keep up with changes in there are no dates forecast for finish-
Microsoft’s .NET specification. The ing VB.NET or the 2.0 libraries.
Great Moments in Mono fact that the Mono C# compiler and
This month I’ll finish my take on .NET runtime were compatible with Odds and Ends
the six most important events in the .NET 2.0 within days of its release MonoDevelop, an IDE for Linux,
history of the Mono project and the pretty much answered this question; has released version 0.10. This is
next big milestones. but there are still questions about a big release with a lot of features,
some of the newer technologies such including a GUI designer for GTK#,
Mono Launches a New Version as Microsoft’s Avalon and WinFX, one of the most popular graphics
of SWF but the Open Source community is tool kits on Linux. The full release
Switching from the old WINE- working on them. The class libraries notes can be found at http://www.
based SWF to the new managed SWF are a mixed bag. Depending on the monodevelop.org/Release_notes_
was a big move for Mono. On one difficulty of implementing the library, for_MonoDevelop_0.10.

50 May 2006 • dotnetdevelopersjournal.com


AD
AD

You might also like