Kevin Castle Dot Net
MyPicture.gif in content/binary
Navigation
RSS 2.0
Calendar View
<October 2008>
SunMonTueWedThuFriSat
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678
Categories
On this page....
Categories
Blogroll

Powered by: newtelligence dasBlog 1.9.6264.0

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2008 , Kevin Castle

Send mail to the author(s) E-mail

 Wednesday, March 21, 2007

About 3 months ago I had a need to do some in-memory sorting on a generic list of objects which were being bound to a GridView control. Due to the fact that we were not working with standard ADO.NET objects and that LINQ has not been fully released, we decided to get clever and come up with a simple sorting method which could handle the case where the a list of objects could be sorted by any one of the fields which was clicked on the GridView control. Note: For the sake of simplicity, I created a dumbed down version of both the object and the sorting method, such that all properties were strings.

For weeks I had heard Sasha talk about how neat anonymous methods were in .NET 2.0, so we sat down and wrote out this nice little SortBy() function. 1st we enumerated through the generic list. 2nd we took the passed propertyname and did a compare between the properties in the two different customer objects. 3rd we used the SortDirection to determine how we would return the compare results. The result, a great little method which is capable of sorting a generic collection with only the objects propertyname and the sortdirection supplied.

 

public class CustomerList : List<Customer>
{

/// <summary>
/// Sorts the CustomerList using Generics, Anonymous Methods, and Reflection 
/// </summary>
/// <param name="propertyName">Property Name to sort the List with</param>
/// <param name="sortDirection">Direction to sort the List</param>
public void SortBy(string propertyName, SortDirection sortDirection)
{
    this.Sort
    (
        //Anonymous method used sort the base generic list.
        delegate(Customer item1, Customer item2)  
        {
            //Use reflection to get the Properties
            PropertyInfo prop1 = item1.GetType().GetProperty(propertyName);
            PropertyInfo prop2 = item2.GetType().GetProperty(propertyName);

            if (prop1 == null || prop2 == null)
            {
                throw new ArgumentException("Invalid property name: " + 
                    propertyName + " specified.");
            }

            //Get the property values from each of the objects
            string value1 = (string)prop1.GetValue(item1, null);
            string value2 = (string)prop2.GetValue(item2, null);

            int compareVal = Comparer.Default.Compare(value1, value2);
            if (sortDirection == SortDirection.Ascending)
                return compareVal;
            else
                return compareVal * -1; //return the negated value
        }
    );

}

}

public class Customer
{
    private string _id;
    private string _firstName;
    private string _lastName;
    private string _age;

    public string ID
    {
        get { return _id; }
        set { _id = value; }
    }

    public string FirstName
    {
        get { return _firstName; }
        set { _firstName = value; }
    }

    public string LastName
    {
        get { return _lastName; }
        set { _lastName = value; }
    }

    public string Age
    {
        get { return _age; }
        set { _age = value; }
    }

}


kick it on DotNetKicks.com

Post Date: Wednesday, March 21, 2007 2:38:41 PM (Pacific Standard Time, UTC-08:00)
Disclaimer | Comments [3] | Trackback   #
 Friday, November 10, 2006

I've spent some time in the last couple of months getting cozy again with DotNetNuke (I've been working very slowly on a side project for a few months now). I used to work with DNN back in the 3.0 days but it has been almost a year now so when I downloaded the latest version, and fired up VS2005 I was overwhelmingly dissapointed with the fact that DNN 4 (ASP.NET 2.0) version uses the VS2005 website model as appossed to the VS2005 Web Application Project model. After searching around for a Web Application Version I came across this post by Shaun Walker (Mr. DotNetNuke) stating the following:

So if we now shift our focus to the DotNetNuke web application framework, even though we identified some serious deficiencies in ASP.NET 2.0, we were still able to release DotNetNuke 4.0 on November 7, 2005 with full support for VS2005. In addition we were able to provide backward compatibility for modules created in VS2003/ASP.NET 1.1 ( from a RUN-TIME perspective ). We did this by reorganizing our project structure to conform to the VS2005 Web Project model. This involved a lot of time and effort but it also paid dividends by providing a number of new project benefits including support for the new Express development tools and support for some new RAD development concepts. However, one thing which we were not able to provide ( due to the limitations in VS2005 ) was a simple method for migrating the development environment for a DotNetNuke Module which was developed as a VS2003 web project and built/deployed as a private assembly.

The lack of a decent migration strategy for early adopters of the DotNetNuke web application framework has created some confusion and frustration within the community. Although we were able to provide detailed tutorials and samples on how to create modules in DNN4, there is no simple method to convert an existing DNN3 module to DNN4. Luckily, developers have understood that the limitation is mainly related to the changes which Microsoft made in VS2005, an issue which is largely out of our hands. However with the recent announcements by Microsoft regarding the availability of the Web Application Projects, there is a large group of developers who think that their migration problems have been solved. Unfortunately, these conclusions are based more on marketing propaganda rather than fact.

Recently, we have spent some time analyzing the Web Application Project model to determine its potential benefit to DotNetNuke. Almost immediately we ran into some serious technical challenges which we had not anticipated. It turns out that from a development perspective the two web project models are incompatible with one another. This means that within the same web project, you can only use one model or the other - not both. On the surface this may not seem like a big a deal but from a product development perspective, it certainly has an impact on the ways in which your developer audience will be able to use your application. Before we dig into the technical details, let's consider the high level business cases of the two project models:

1. Web Site Projects ( WSP ) - supported out-of-the-box in VS2005. Can be leveraged by ALL product SKUs from Express to Enterprise. Provides RAD development and deployment.

2. Web Application Projects ( WAP ) - supported as a separate download from the Microsoft site ( will be included as a fully supported model in VS2005 SP1 *official release date unspecified* ). Can only be leveraged in higher level SKUs - Standard Edition and above ( no support for Express Editions ).

As you can see, the developer tool support aspect of Web Application Projects is sorely lacking. This is unfortunate as the changes made in DotNetNuke 4.0 to support the Express tools resulted in a massive benefit to our community. It completely eliminated the barrier of entry for developers by providing a rich set of development tools at absolutely no cost. And the Web Site Project model used in DotNetNuke 4.0 provides a RAD development environment which satisfies the needs for 90% of the developer community. For the other 10%, a free development environment is not a critical requirement; therefore, the Web Application Project model is a viable alternative. So why can't we have one DotNetNuke code base which supports both Web Site Projects and Web Application Projects simutaneously - providing the maximum flexibility and benefit to all stakeholders? Here is where we dive into the technical details...

1. WSP uses the app_code folder for dynamic compilation. If you switch a project to use WAP and do not remove the app_code folder, you will get "double" compilation - as ASP.NET 2.0 will automatically compile anything in app_code whether there is a WAP project file present or not. So basically you will end up with assemblies that have namespace clashes in the /bin.

2. All user interface files ( ie. *.aspx, *.ascx ) have a different syntax in WAP than they do in WSP. WAP projects use the old "CodeBehind=" attribute and must have an associated *.designer file for each user interface file. WSP projects use the new code-beside model which does not require "CodeBehind=". You can not have a mixture of these 2 types within the same development solution. In order to support WAP for the DNN core, we would need to convert every user interface file to use the WAP syntax - producing a completely different code base ( one that no longer supports WSP ).

3. WAP has different settings in web.config than WSP, since they use totally different compilation models.

As a result of the technical issues noted above, we can not have a single DotNetNuke code base which supports both we project models. And since we feel that the Web Site Projects satisfy the needs of the majority of the developer community,

WE WILL NOT CONVERT DOTNETNUKE TO A WEB APPLICATION PROJECT

The first thing that I would like to say is that I understand that this is in now way an issue which DotNetNuke has created. This is a simple product of a new shift towards a lesser solution.

Without losing all hope, I kept searching around on Google (after all this was posted last May of this year '06). I found a great article @ haacked.com describing how he created a C# Web Application from scratch and reconstructed a solution to run DNN in the new Project format. In addition, a zip download was provided so that you could could get a jump start on all of his hard work.

Im not quite sure how I feel about moving away from the standard DNN download. Ill probably stick to the stupid website model, just because upgrades will be much easier, but I think its great that someone has actually "fixed" this problem that the new VS2005 website model started.

If any reader has any additional info regarding this subject, your comments would be greatly appreciated.


Post Date: Friday, November 10, 2006 8:52:47 AM (Pacific Standard Time, UTC-08:00)
Disclaimer | Comments [1] | Trackback   #
 Tuesday, October 31, 2006

October 24th and 25th 2006 will go down as the most annoying days that I have had (for the better part of my software development life). Anyone who has seen this CS0433 error after converting a VS2005 website to a Web Application Project will feel my pain.

Here are the following events which had occurred:

  1. A VS2005 website was created and a small number of pages, controls, sitemaps, etc were added.
  2. A decision in the department was made to use the VS2005 Web Application Project for .Net 2.0 websites.
  3. Our group downloaded and installed the WAP Add-In (Download Here)
  4. I removed all of the VSS bindings (we are still waiting to receive our full Team Foundation Server edition)
  5. I followed steps to Upgrade a VS2005 Web Site Project to VS2005 Web Application Project tutorial.
  6. Everything went smoothly except that it was kind of a pain to add the namespaces to all of the source files. Nonetheless, I was happy because I was out of the horrific WebSite method of developing web applications. The application built correctly and I added to a separate project in VSS.

Everything seemed to be going great until I fired up the debugger and ran my application.

This is the error which I would stare in the face for the next 8 hours

Compilation Error

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS0433: The type 'AgencyPro.UserControl_NavTree' exists in both 'c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\3f88d5c8\5840425e\assembly\dl3\e396fa14\0b806043_51f8c601\AgencyPro.DLL' and 'c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\3f88d5c8\5840425e\App_Web_navtree.ascx.78d7338a.aftov38w.dll'

Better yet here is the actual screen so that you can have the image burned into your mind.

I did a search on Google and it turned out that tons of people had faced this similar issue. However, I was completely unable to find anything which directly gave me a fix.

Initially I thought this issue was caused for several different reasons.

  1. Maybe I needed to add the default namespace to all of the files in the project? - I did this and the issue continued.
  2. Maybe it was because I had the reserved directory App_Code in the project? - I removed this and the problem was still there.
  3. Maybe I needed to create an entire new project and add all of the files to that again? - I did this and the issue continued.

The obvious answer was that this error was being caused by the new ASP.NET compilation methods where a dll is generated for each of the pages (so lame in my opinion), but it was all a matter of trying to figure out how to override this behavior. After searching around in the web.config documentation, I felt stumped and due to the difficulty with generating a search phase which would turn up any real answers I was lacking documentation.

At this point I was getting a little desperate and frustrated but I knew that if I created the project from scratch and added all of the files from scratch as well, then this issue would go away. In fact, the only solutions that I had found for this issue had been describing doing just this. So, I gave up, and rebuilt everything from scratch (meaning copying and pasting all of the code into brand new files) but I still had to know what the fix was.

A buddy of mine @ work (Bruce Hoang) came over to my desk and told me to check out this article at DevX. Yes! All of my questions were answered.

Solution:

  1. Remove the App_Code directory from the project.
  2. Change the CodeFile attribute to CodeBehind on your .aspx, .ascx, .master, etc. pages.

Main Cause

  1. I followed all of the recommended steps in the VS Web Site to VS WAP conversion but now in hindsite I think that the issue was caused by the fact that my files were still ReadOnly from VSS. Therefore when I ran the conversion, it was not able to change the CodeFile attribute to the CodeBehind  attribute on all of the pages.

Above -  The Attribute that stole my time!

For an in depth article on ASP.NET 2.0 compilation and deployment issues I would recommend this as a must read.


Post Date: Tuesday, October 31, 2006 8:58:24 AM (Pacific Standard Time, UTC-08:00)
Disclaimer | Comments [1] | Trackback   #
 Thursday, October 05, 2006

Wow. Component Art has released one of the most impressive displays of AJAX enabled controls. I'm really getting anxious for Atlas to get out the door because I can't wait for the day that ASP.NET sites stop being the ugly red-headed step child of dynamic websites. Obviously that's an overstatement, but with this great release of Atlas I think we're all going to be blown away both by the third party control vendors as well as the home grown sites too.

Other AJAX Enabled control suites:


Post Date: Thursday, October 05, 2006 5:08:01 PM (Pacific Standard Time, UTC-08:00)
Disclaimer | Comments [1] | Trackback   #
 Monday, September 25, 2006

One of the things that I have noticed about LLBLGen Pro Version 2.0 is that, post installation, the LLBLGenProDataSource control is not added to your control. In my opnion one of the most important additions to the second version for LLBL is the fact that it supports the ObjectDataSource control model, but the control is only useful in your organization if people use it in development.

The following is a summary of how to add the DataSource control to your Toolbox:

1 .Right click toolbar and choose items. (Loading the choose items dialog may take a few moments)

 

2. On the choose items dialog click Browse

3.Locate the SD.LLBLGen.Pro.ORMSupportClasses.NET20.dll and select open.

4. The choose items list has now been updated.

Sort the list by name and check the box next to LLBLGenProDataSource. (note both of the Datasources will select automatically).

Select OK and view the new items on your toolbar.


Post Date: Monday, September 25, 2006 6:22:23 PM (Pacific Standard Time, UTC-08:00)
Disclaimer | Comments [1] | Trackback   #
 Tuesday, September 12, 2006

Here is an older post from Scott Guthrie with several tips, tricks, recipes, and gotchas regarding ASP.NET 2.0. Topics include:

  • User Interface
  • Data
  • Security
  • Visual Studio
  • Deployment
  • Performance

Click here to check it out.


Post Date: Tuesday, September 12, 2006 12:01:39 PM (Pacific Standard Time, UTC-08:00)
Disclaimer | Comments [0] | Trackback   #

Ive been waiting for quite some time to hear a proposed release date for Atlas. Early users adopters will need to change some of their existing code to accomidate for some of the naming changes. See Scott Guthrie's blog post here.

Links:


Post Date: Tuesday, September 12, 2006 11:51:39 AM (Pacific Standard Time, UTC-08:00)
Disclaimer | Comments [1] | Trackback   #
 Tuesday, September 05, 2006

Dont know about everyone else but I can't live without my intellisense, which is why I was so distraught when I first installed Visual Studio last Nov. '05 and noticed that intellisense was not supported in .skin files. So i've basically just been living with this for almost a year ago until I saw a post on how to fix this. (You can view it here)

Steps to enable

1. Go to Tools->Options menu.
2. Pick Text Editor -> File Extesion fom a tree at the left part of Options dialog.
3. Type skin in Extesion text box.
4. Select User Control Editor from Editor dropdown.
5. Click Add and then Ok to close dialog and re-open your skin files.


Figure 1 - Adding skin entry to file extension

 
Figure 2 - Proof

Now what I want to know is: why in the world wouldn't this be the default behavior?


Post Date: Tuesday, September 05, 2006 7:15:23 PM (Pacific Standard Time, UTC-08:00)
Disclaimer | Comments [0] | Trackback   #