Sunday, January 24, 2010

Mixing Business Logic and the Presentation Layer... Why do people do it?

In .NET Application Architecture Guide, 2nd Edition, the writers explicitly say:
Do not mix different types of components in the same logical layer. Start by identifying different areas of concern, and then group components associated with each area of concern into logical layers. For example, the UI layer should not contain business processing components, but instead should contain components used to handle user input and process user requests.
This is the standard way of developing today. However, I've seen time and again where a developer will do ALL of the business logic processing in the presentation layer. More than merely being annoying, this is wrong for a number of reasons including:
  • redundancy in code
  • "scattered" logic
  • poor abstraction
  • data access in the presentation layer
  • strong-coupling
That's just to name a few. Every time I see this coding snafu occur, I think to myself, "Do I just not know what I'm doing?" After all, it's much more seasoned developers doing this. Then, I remind myself that object-oriented programming has changed dramatically over the past 10 years.
I can understand some points of view "Too much abstraction is a bad thing!", "Keep the logic as close to where you're using it as possible!", "I don't understand what you mean by business logic." But, ignorance of norms and coding standards doesn't inherently and automagically produce good, clean, scalable code.
N-tier architecture has now become the norm, but is it too much to ask for some logical layering within a tier?

Tuesday, December 22, 2009

UpdatePanel won't AsycPostback for anything.

I spent a lot of time today and Friday trying to get my UpdatePanel to be handled properly. No matter what I did, my asynchronous triggers were only posting back. I searched and searched, and couldn't find anything. Then, I ran across a post on asp.net's forum which had the answer.
<xhtmlConformance mode="Legacy"/> :
Change Legacy to Strict or Transitional
Don't you love Microsoft?
Other things I searched for in order to find this answer:
"IsInAsyncPostBack false masterpage", "UpdatePanel only postback", "asp:AsyncPostBackTrigger won't work"

Sunday, December 20, 2009

Google Chrome Extension: New Tab Redirect!

Thanks to the blizzard this weekend, I've been alone and stuck inside long enough to write an extension for Google Chrome. It's called "New Tab Redirect!" and it allows you to customize the page displayed when you add a new tab (either with CTRL+T or clicking the (+) in the title bar).

A cool thing about the extension is that it allows you to specify about: pages, URLs, or local files.

The extension is available in the extension Gallery: http://bit.ly/info/8oNcya

Thursday, December 17, 2009

jQuery check/uncheck all Checkboxes in ASP.NET

For some odd reason, ASP.NET GridView wraps html elements in a span element. When you apply a CssClass to the asp:CheckBox for instance, you will have a span with that class and inside you'll have an input with type=checkbox.
So how do you access all of the checkboxes?

   1:              $('.chkAllSelector > input:checkbox').click(function() {
   2:                  $('.chkRowSelector > input:checkbox').each(
   3:                      function(){
   4:                          this.checked = $('.chkAllSelector > input:checkbox').attr('checked');
   5:                      }
   6:                  );
   7:              });
   8:              $('.chkRowSelector > input:checkbox').click(function() {
   9:              if ($('.chkAllSelector > input:checkbox').is(':checked') && !($(this).is(':checked')))
  10:                  { $('.chkAllSelector > input:checkbox').removeAttr('checked'); }
  11:              });

Wednesday, December 16, 2009

Extending IDataReader

I like to access my DataReader objects via column name. Unfortunately, IDataReader supports getting items via integer indexer.

To overcome this *obstacle*, I've written an extension method I'd like to share. It checks to see whether a column exists and has a value associated with it.

   1:      public static class IDataReaderExtension
   2:      {
   3:          /// <summary>
   4:          /// Adds the HasValue property to an IDataReader, which checks based on Column name
   5:          /// </summary>
   6:          /// <param name="reader">An IDataReader object</param>
   7:          /// <param name="column">The string column name</param>
   8:          /// <returns>boolean</returns>
   9:          public static bool HasValue(this IDataReader reader, string column)
  10:          {
  11:              if (reader.GetSchemaTable().Columns.Contains(column))
  12:                  return reader[column] != null || reader[column] != DBNull.Value;
  13:              else
  14:                  return false;
  15:          }
  16:      }

In order to use this method, you can now check:

   1:  if(reader.HasValue("MY_COLUMN"))
   2:  {
   3:      myObject.ColumnInfo = Convert.ToString(reader["MY_COLUMN"]);
   4:  }

Wednesday, November 4, 2009

Microsoft SQL Server's Database Publishing Wizard BatchParser error

http://download.microsoft.com/download/4/4/D/44DBDE61-B385-4FC2-A67D-48053B8F9FAD/SQLServer2005_XMO_x64.msi

Could not load file or assembly 'Microsoft.SqlServer.BatchParser, Version=9.0.242.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' or one of its dependencies. The system cannot find the file specified. Installing the above file will fix this problem on 64-bit machines!

I remember having a hard time finding the answer to this problem about a year ago, and I just ran into it again.

Tuesday, November 3, 2009

http://datacogs.com/datablogs/archive/2005/01/28/209.aspx
Recently, I converted a project from VS2003 to VS2008. The conversion deleted a file which wasn't needed in VS2008. When I tried to "rollback" the source from source control to run in VS2003, it wouldn't rung.
Taken from the link above:
If you have a project file c:\Inetpub\wwwroot\Folder\fred.csproj then you need a corresponding webinfo file fred.csproj.webinfo. The contents of the webinfo file looks like this:

<VisualStudioUNCWeb>



<Web URLPath = "http://localhost/Folder/fred.csproj" />

</VisualStudioUNCWeb>

Sunday, November 1, 2009

Free Subversion Book by O'Reilly

O'Reilly Media has released a free subversion book, located at http://svnbook.red-bean.com/
It's downloadable as a PDF, single-page HTML and multi-page HTML.

Archive