Posts

Showing posts from April, 2010

Reflections on Style for Shrink Wrap Web Sites

My main bread and butter is commercial software designed to be installed on customer sites (with the host of environmental variations that may occur). One aspect is build websites that may be easily branded by the customers with the use of CSS.   One of the first steps  is moving CSS to resource files so pages may be style in a culturally aware manner.  Sentence length can be doubled or halved in different languages so layouts may need to change.   Once that step is done – then there’s the issue of how to factor the page for branding. Often folks go for a cheap solution – allow only a few things to be branded; I prefer to support comprehensive branding.   Often the page delivered by a developer may look like this: 1: < div style ="display: table-row block; border-bottom: solid thin red;" > 2: < div style ="display: table-cell; whitespace: nowrap" > 3: < font: Arial > 4:

Working Around The Yield Restriction In Try/Catch

The code below is a workaround for the restriction that you can’t yield from inside a try/catch statement that contains a catch. Note: you can yield from inside a try/catch statement that only has a finally clause (no catch). What I need to do was: Call Microsoft SQL Server and return a result set. Support IEnumerable so I could take advantage of SQL Servers forward only cursors and Linq. Catch any exceptions of type SQLException and clear the connection pool. Here is the code I would like to have compile (THIS DOES NOT WORK): static public IEnumerable<DbDataRecord> Execute( String connectionString, String statement) { using (SqlConnection sqlConnection = new SqlConnection(connectionString)) { try { sqlConnection.Open(); SqlCommand sqlCommand = new SqlCommand(statement, sqlConnection); using (SqlDataReader sqlDataReader = sqlCommand.ExecuteReader())

A mystery: AnteMeridiem and PostMeridiem

I was working with resource files (RESX) and been getting these obtuse messages.   Warning    4    The resource name 'AnteMeridiem ' is not a valid identifier.    \ContentPage.be.Resx Warning    4    The resource name 'PostMeridiem ' is not a valid identifier.    \ContentPage.be.Resx   Both are proper latin (for AM and PM) – and it’s a mystery why they are deemed to be invalid. To add more mystery to it – it only objects is some cultureinfo (languages). Is this an easter egg????

A new code review item: Initializers in Alphabetical Order

I’ve been using MZTools Visual Studio add-in for a few years. The original reason I acquired it was because of it’s sorting of code ability: Sorting a collection of lines Sorting the elements in a class by type and then alphabetical. I had gotten frustrated by manual re-organizing  of code and fighting the random dropping of code where it fell into the file. I love the use of initializers – it keeps code cleaner and easier to read (visually chunking), but with rapid evolution of code, we can often end up with something like: 1: deposit.CreditCard.AccountHolder = new AccountHolderDetail() 2: { 3: AddressLine1 = GetString(CreditCardAddressLine1), 4: AddressLine2 = GetString(CreditCardAddressLine2), 5: Company = GetString(CreditCardCompany), 6: FirstName = GetString(CreditCardFirstName), 7: LastName = GetString(CreditCardLastName),

The New SQL Azure DBA

Image
Compared to SQL Server here is the list of things that you can be completely ignorant about and still be a SQL Azure DBA: Hard Drives : You don’t have to purchase hard drives, hot swap them, care about hard drive speed, the number of drives your server will hold , the speed of SANs or motherboard bus, fiber connection, hard drive size . No more SATA vs. SCSI debate. Don’t care about latest solid state drive news . Everything you know about Hard Drives and SQL Server – you don’t need it. RAID : How to Implement RAID, choose a RAID type , divide physical drives on a RAID – don’t care. RAID is for hornets now. Backup and Restore: You need to know nothing about Back up SQL Server data files , transaction logs, or how the database model effects your backup. You don’t need a backup plan/strategy – nor answer questions the about risk factor for tsunami in Idaho. No tapes, tape swapping, or tape mailing to three locations including a hollowed-out mountain in the Ozarks. R

USB hard drives going the way of 8” and 5.25” floppies….

Image
I am a convert to eSATA drives, external SATA docking bays where you can just drop in a raw SATA drive.  On my new machines, the port is already there. On my older machines with SATA on the motherboard, it’s just a matter of buying something like Vantec NexStar NST-D100SU 2.5-Inch/3.5-Inch SATA to USB 2.0 and eSATA Hard Drive Dock which comes with a card tab with eSata and the cable to connect it to the motherboard sata connectors. For older machines, you need to buy an eSATA card, or Sata card with eSata Connector. There are also eSata cards for laptops (but not for Netbooks, since the only ports seem to be USB ports on most netbooks.  You want to make sure that the eSATA is SATA 2… why?  Bus speed… BUS Maximum speed in MB/Sec USB 1 1.5 USB 2 60 SATA 1 150 SATA 2 300 SCSI-320 320   So you can see why I am a convert: 5

Mirror, Mirror on the drive, who is the smartest of them all?

Image
At today’s Bellingham DotNet meeting we got into a discussion of software mirroring (built into Server 2003, 2008, Vista and Windows 7).  The consensus was that every desktop system should have all of the drives mirrored (by OS mirroring or hardware mirroring). An older machine may have 3 smaller SATA/IDE drives and the cost to mirror is $100 or less. Just buy a big drive (1-2TB) and drop it into the machine.   You can then mirror all of the existing drives to this one big drive (you do not need 1 physical drive to 1 physical drive), you can use a dynamic drive to mirror each drive on one drive. The drives do not have to be the same – you can mirror from an IDE to a SATA drive.   The second item discussed was buying a spare laptop/netbook hard drive, drop it into a USB holder and periodically at night mirror the internal drive to the USB external drive. If the internal hard drive fails, it’s just minutes to put the former-USB drive into the machine and you are up with a reason

Using Google to translate resource files – code example

Often there is a need to create resource files in foreign language for code-testing purposes. The typical list of languages that I like to test are: Hebrew Arabic Simplified Chinese Spanish French German – text is often 2x longer then English (what you get with preciseness in expression) Hindi If the code/css works for all of the above then you are likely safe for other languages. There is two pieces of code and one manual process (cut and paste – Google usually makes it hard to automate the capture of the translation).   Converting the Resx to a Html page We put the Resx up – almost as is, just ditch the comments and place the items in <html> and <body> tags. private void WriteHtml(FileInfo infile, FileInfo outHtml) { XmlDocument sourceResx = new XmlDocument(); sourceResx.Load(infile.FullName); XmlDocument xHtml = new XmlDocument(); xHtml.LoadXml( " <html><body/></html> " ); XmlNo

Video: Starting an Windows ESB Instance on Amazon EC2

How to start a Windows ESB instance on Amazon EC2 using the Amazon Management Console is tricky.  Every time I do it  I find myself struggling to find just the right steps, so I made a screen capture of the process. {6230289B-5BEE-409e-932A-2F01FA407A92}

Cleaning Up Stored Procedures

Sometime ago, in reducing the scope of my community web site, I deleted a bunch of SQL Server tables no longer in use with names like Classifieds, Banners, Posts, and Weather. However, I didn’t clean up the stored procedures that called these tables. I have made a decision recently to move to SQL Azure and want to reduce the amount of “dead” code I am uploading into the cloud.   I embarked on the journey of figuring out which stored procedures called tables that no longer exist. This is next to impossible to determine because SQL Server does a poor job of tracking the dependencies of stored procedures. In fairness, SQL Server doesn’t really need to keep track of the dependencies – all it needs to do is to be able to run. The running of the stored procedure generates a runtime error if the table does not exist. It is the DBA that needs to track the validity of the stored procedure in the scope of the project. Example If you run the following on your favorite testing database in

An easy fix for the Xhtml compliance <span> problem with AspNet Controls

As I posted earlier, many AspNet controls makes it impossible to generate valid XHTML if normally used.  I had been resolving this in a non-elegant way in the past. Today, this method broke down in an odd way but it lead me to realize that there is a very simple way to fix this, override the TagKey property.   For example, asp:Panel renders with a <span> which prevents a lot of items from being placed on it if the page is be to Xhtml Compliant.   Well the solution is simple by creating a new version with just one little change as shown in the code below namespace Lassesen.Web.UI.WebControls { using System; using System.Web.UI; [ToolboxData( " <{0}:Panel runat=\"server\" /> " )] public class Panel : System.Web.UI.WebControls.Panel { /// <summary> /// Enhanced(Corrected) Panel that renders in a Div and not a Span /// </summary> public Panel() { } /// <summar

Improving Page Speed for Google Rankings

Image
Google announced that it will consider the speed of the web site as part of its search engine ranking ( Using site speed in web search ranking ) – something I suspect that it has been doing for some time. We have known for a while that page speed is very important to how the user perceives the quality of the web site. You can significantly lower your bounce rate by improving page speed – because users will look at more of your site if the first page they request returns quickly. Now, it is just not user experience that suffers from a slow site; it is site ranking on Google – which means with this announcement slow sites attract fewer viewers because your site will appear father down the search results. “Now slow performing code and slow database queries are a marketing issue.” For on of my major web site serving Google AdWords slowness means lower revenue. Page Caching On the web site serving AdWords I had some slow leaf pages (outlying lower pages with the majority of the