Tampa User Experience (TUX) User Group


My colleague and ex coworker, Jay Kimble from the Run Time is starting a new User Group in Tampa called "Tampa User Experience" with Bill Reiss, Shawn Cady, and Perry Panagopoulos. Their first meeting will be on September 10th, 2008 and it will about MS Ajax Scripting by Jay Kimble. Jay usually charges for this session and he will give it for free. Plus there will be Pizza and a raffle for an MSDN Universal Subscription. It is a great opportunity to network and win some prices, so if you are in the Tampa area I don't see a reason to miss this meeting.

author: Jonas Stawski | posted @ Friday, July 18, 2008 11:15 AM | Feedback (0)

Make Your Business Layer a Data Component


One of the cool features of ASP.NET 2.0 is the new Object Data Source, which lets you bind your business entities/objects to your ASP.NET controls. What I hate about this control is imagethat when you open the dropdown you get a list of all the classes that are referenced in your project, which in some cases in can be a lot of them. If you check the Show only data components box then most of the time the dropdown empties out.

So how do you get your business layer classes to show as Data Components? All you have to do is add the attribute DataObject to the class. According to the MSDN documentation: "Identifies a type as an object suitable for binding to an ObjectDataSource object."

 

 

 

[DataObject]
public class manager
{
  //methods go here
}
<DataObject()> _
Public Class Manager
   'Methods go here
End Class

If your Business Layer is in a separate layer (project) from your UI then you will need to recompile. Now when you check image"Show only data components" you get a smaller list with your Business Layer class.

Furthermore, you can decorate your methods with the DataObjectMethod attribute which "Identifies a data operation method exposed by a type, what type of operation the method performs, and whether the method is the default data method."

 

 

[DataObjectMethod(DataObjectMethodType.Select, false)]
public static List<User> GetUsers()
{
    //Implementation goes here
}
<DataObjectMethod(DataObjectMethodType.Select, false)> _
Public Shared Function GetUsers() as List(Of User)
    'Implementation goes here
End Function

Happy Data Binding!

author: Jonas Stawski | posted @ Monday, July 14, 2008 11:05 AM | Feedback (2)

LINQ To SQL Generic Detach


Anyone who has been trying to use LINQ To SQL with ASP.NET would know of the problems of dealing with state. Since LINQ To SQL does require to maintain state of the entities and the DataContext, the stateless behavior of the web leaves us with a lot of problems that we have to deal with. One of the patterns I have seen over and over again is to keep the entity in memory (through cache, session, viewstate, etc) during postbacks, create a new context, and reattach the entity to the new context. The problem with that is that the entity still holds some information that it was previously created by another datacontext and the moment you want to attach it an exception is thrown. People have been dealing with this problem by detaching the entity and the way you do that is by setting all the Association Properties to default(EntityRef<PropertyType>). So people are extending all their entities and creating a Detach method which detaches each Association Property one by one. So now maintainability is a pain in the you know what. The moment you add a new association you will have to remember to detach it in the Detach method.

After looking at the code created by LINQ to SQL I noticed the following:

private void Initialize()
{
    this._SalesOrderDetails = new EntitySet<SalesOrderDetail>(new Action<SalesOrderDetail>(this.attach_SalesOrderDetails), new Action<SalesOrderDetail>(this.detach_SalesOrderDetails));
    this._SalesPerson = default(EntityRef<SalesPerson>);
    OnCreated();
}

That's exactly what we need to detach each entity: reinitialize it again. So you can simply fully detach an entity by calling the Initialize method which SqlMetal automatically generates for us. So next time we modify our model and add a new association SqlMetal or Visual Studio will recreate the Initialize method with all the initialization of all the associations for us, which solves the maintainability problem.

A huge warning is that if you are using the partial method OnCreated on your partial class the method will be invoked again.

To go a little further you can extend every entity by creating a partial class and make it inherit from a base class. I called it BaseEntity. This base class can have a Detach method which can invoke the Initialize method of it's inheritor through reflection by doing this:

GetType().GetMethod("Initialize", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(this, null);

Please note that reflection does add overhead, but I think this solution uses the least amount of reflection possible to accomplish something that will otherwise require a lot of maintainability.

I am working on an article on how to use LINQ to SQL in an N-Tier environment with ASP.NET (without WCF). So keep posted as I will notify everyone when the article is published.

Happy Programming!

author: Jonas Stawski | posted @ Wednesday, July 09, 2008 12:05 AM | Feedback (1)

Component Art Web.UI Client Script Deployment


I was doing some research on Component Art's Web.UI suite and I came across this post by Milos. Basically Component Art added a new feature in the 2007.2 version to allow all the client script references to be downloaded all at once. Why? Because the roundtrip during the request for the scripts adds a lot of overhead. The problem with this is that now all the Web.UI scripts are downloaded with one big request, which according to Milos is about 300K. They resolve the size issue by allowing you to specify which scripts to get based on your needs. So if you only use the menu, then you would only get the scripts necessary for the menu and thus avoiding the extra overhead. Please note this is an application level change so if you're going to specify which scripts to get then you must select all the controls used on your application.

Milos also explains how to set your app to use the new feature. I tried it out and of course it didn't work for me. Why? Because I'm running IIS 7 under Windows Vista. What's the difference? IIS 7 uses the HTTP Handlers in another section of the web.config, so if you're using Windows Vista add the HTTP Handler under <systen.webServer><handlers> section. And if you're like me where your production server is running IIS 6, then add the handler in both sections.

So I decided to give it a shot to see if there was any performance increase so I fired up FireFox and FireBug and inspected the network traffic. Without the new feature turned on I had 22 requests with a total of 314 KB worth of data and it took 159 ms.

image

The results with the new feature turned on are very promising. I'm only bringing down the scripts for the Menu, Grid, and Upload controls. The request goes down to 137 ms and there are only 11 requests (half of what it used to be) with a total of 101 KB.

image

Please note that on the first screen shot (feature turned off) there 11 requests to WebResource.axd. This is the handler used by ASP.NET Ajax and the Web.UI utilizes the ScriptManager to register the ComponentArt scripts. In the second screen shot (feature turned on) there is only one request to ComponentArtScript.axd which weights 73 KB in total and that request is the one that gets the script files.

So not only will your application respond faster, but you will also save a ton on bandwidth.

This is a very cool implementation from the guys at Component Art and I think they are doing a great job with their controls, keep up the good work!

author: Jonas Stawski | posted @ Monday, July 07, 2008 2:28 PM | Feedback (0)

2008 MVP


Thanks to the MVP program for renewing my MVP award for one more year. The real people I need to thank are the people that attend my sessions, read my blog, and read my articles. Without them there would be no reason for me to keep on going in the community.

Thank you all and I look forward for another great year.

 

MVPLogo

author: Jonas Stawski | posted @ Tuesday, July 01, 2008 3:59 PM | Feedback (1)

LINQ to SQL Debug Visualizer


One of the cool features about Visual Studio is that you can extend it. One of the many things you can extend are the debugging Visualizers. While you're debugging an application with Visual Studio 2005 and 2008 you can hover over a variable and you can see it's value. Sometimes, depending on the type, you will see a magnifying glass icon and that icon is the Visualizer. The reason why sometimes you get a magnifying glass and sometimes you don't is because a specific type might not have a Visualizer associated with it. You are free to create your own Visualizer for any type.

image 

When you click on the magnifying glass the Visualizer opens. In the case of the string you have a dropdown where you can select whether you should use the Text, XML, or HTML Visualizer and if you click on the magnifying glass you should see something like this.

image

Now that you know what a Visualizer is let's get to the point of the post. Today I was browsing through some LINQ to SQL blogs and articles and I found out there is a LINQ to SQL Debug Visualizer. You can read all about it on Scott Guthrie's blog (the download link is also there). So I gave it a shot and I think it's pretty cool. Although Visual Studio does a decent job at displaying the SQL that will be executed it's nice to have a tool that takes it one step further.

Happy Debugging!

author: Jonas Stawski | posted @ Thursday, June 26, 2008 12:35 AM | Feedback (0)

Schedule Back Ups with SQL Server Express 2005


One of the limitations of SQL Server Express 2005 is that it doesn't have a built in way to schedule jobs. There are tools out there that let's you run jobs on the express version, but if you're like me who don't like to install a lot of things on your servers then you would try to avoid that route. I was in need of running scheduled back ups of my SQL Server Express databases, but I couldn't find a way to schedule them through any built in SQL Server functionality. A simple search yielded me to this excellent article which shows how to schedule backups through the use of SQL Server and Windows Scheduler. Stay tune for a future blog post to see my implementation of Scheduled Back Ups with SQL Server Express.

Happy Backing!

author: Jonas Stawski | posted @ Tuesday, June 24, 2008 11:54 PM | Feedback (0)

email2face with SubText


If you haven't read it yet I recently switched to SubText. One of the things I've done was to set up SubText to use email2face to display pictures of the people leaving the comments. It is very easy to do.

In the Web.Config you have to change the appsettings and change the GravatarUrlFormatString to point to http://www.email2face.com/lookup/{0}. You also need to change the GravatarEmailFormat to plain so the email doesn't get encrypted.

<add key="GravatarUrlFormatString" value="http://www.email2face.com/lookup/{0}" />
<add key="GravatarEmailFormat" value="plain"/>

Happy Configuring!

author: Jonas Stawski | posted @ Monday, June 23, 2008 5:09 PM | Feedback (0)

New Server, New Blog


The previous server I had was getting too small for the payload so I decided to get a dedicated server with much more horsepower. One of the things that was making my old server slow was Community Server (CS). Don't get me wrong Community Server is a great tool, but was too much for hosting one blog only. So I decided to use SubText instead.

New Look

One of the things I've been meaning to do for a while was change the look and feel of my blog and now with this huge change of new server and new blog engine it was the perfect excuse to also change the look. I have been following the Go Green initiative for a while now so I decided to use a nice green theme. One of the things I was looking for was for a theme that expanded 100% of the width, that looked nice, and that was easy to read. The current theme had it all.

image

Please note that there is a small menu on the top, which is not very visible and I might change later on, where you can personalize the look based on your needs. For example you can change the layout to "Jello" (Min 770px / Max 1200px), "Fluid" (100%), "Fixed" (760px). You can also change the font size to Medium, large, or X-Large and lastly, but not least you can place the menu on the right (default) or the left.

 

 

 

 

 

 

 

 

 

 

 

 

The Move

The migration from CS 2007.1 to SubText 1.9.5b was not as smooth as I wanted to be, but it was not bad at all. Both engines conform to BlogML standards. CS 2007 doesn't have the support for BlogML right out of the box, but you can use Keyvan Nayyeri's, a CS MVP and Architect and Team Lead of the BlogML project, CS BlogML Converter. SubText 1.9.5b has support for BlogML right out of the box by loging into the admin site and going to the import/export section.

I installed the BlogML converter for CS 2007 and when I was exporting the content of my blog I was getting a Page Cannot be Displayed in Internet Explorer and something about a Malformed XML in FireFox. I tried to change the code of the converter to write the XML to a file in the web server instead of writing it to the response and found out that the XML file was blank. I re read the readme.txt file 20 times and figured out that the problem was that all the posts were written by my user who is an admin, but that user was not the owner of the blog. To tell you the truth it was not very intuitive. You have to go to the Administration tab and view all blogs. Select the blog you want to modify and in the Owner field you have to enter the username of the user who wrote all the posts. The weird part is that field is optional and CS doesn't check for a valid username. Since I never knew what it was I had my name "Jonas Stawski" in there. Anyway, I changed my name with my username, ran the export again and all worked perfectly.

Now I had a BlogML file (XML) I uploaded the file to the web server, used RDC to connect to the web server, browsed the blog locally and imported the file. I did all this because the file was too big and didn't want to have to deal with other possible issues. Please note that this is not necessary as you can import the file from your local PC.

Of course the import was blowing up with an Illegal Character exception which I discovered was that I had JavaScript in the content of my posts (SubText doesn't allow it). I got rid of all the JS and was able to import correctly.

I also tried to set Gmail as my MailProvider, but I was unable to do so because the connection needed to be secured and SubText was not prepared for that. Like the forum posts mentions I had to change the source code and recompile it.

The last thing I needed to do was set up Windows Live Writer (WLW) with SubText so a simple search yield me to this post. I just discovered that you can't add categories from within WLW because SubText doesn't contain that functionality within the MetWeblog. New feature request anyone?

The Reward

I am very happy with SubText so far. It is very intuitive, straightforward, and easy to use. I can find things within seconds, while with CS I had to spend anywhere from 5 minutes to hours when I wanted to set something up. Don't get me wrong I don't think CS is a bad product, as a matter of fact it is a great product and that is why companies like Microsoft use it for their blogs, but I just think it was my fault for picking the wrong tool for the job. All I needed was a single blog and nothing else.

So hopefully you guys are also rewarded with a nicer and more readable look, a faster blog engine, and an even faster server.

Stay tune for my next post on how to use Email2Face.com with SubText.

Happy Reading!

author: Jonas Stawski | posted @ Saturday, June 21, 2008 12:45 PM | Feedback (1)

Be Careful When You Turn Windows Firewall On


So there I was setting up a Windows Server 2003 Standard sitting in a remote location and I had the security hat on and decided to turn Windows Firewall On. Apparently by default there are no exceptions so I was immediately kicked off of my Remote Desktop session. I can't browse any of the websites in that server nor can I ping it. As a matter of fact I don't think I can do anything with it sitting here thousands of miles away from the server. All I can do is open a ticket for someone to physically log in to the server and either turn the firewall off or allow port 3389 (RDC). So if you're thinking of turning that firewall on remotely make sure you allow port 3389 before hitting the OK key.

Hope other people learn from my mistakes.

Happy Firewalling!

author: Jonas Stawski | posted @ Friday, June 20, 2008 3:10 PM | Feedback (0)