Sorting custom data objects the easy way

by martin 28. September 2009 22:32

I recently had to implement custom sorting on couple of ASP.net pages that had to bind to a collection of custom data objects.  Not wanting to re-invent the wheel on every page, I looked for an easier solution online.  I ran across at least two worth mentioning: Generic Sorting Using Reflection in .NET By Jon Wojtowicz (http://www.eggheadcafe.com/articles/pfc/propertycomparer.asp) and Rocky Lhotka's MSDN article where he presents his Generics based PropertyComparer.  I liked Jon's solution in that it was written using recursion so that you could easily sort by properties of properties.  However Jon's implementation was not "Generics" based.  Rocky's implementation was generics based, but it lacked the recursion that my solution needed.  In the end, I ended up modifying Jon's code to be generics based.  I sent Jon an email asking for permission to share his modified code online, but unfortunately he never responded to my email.

Below is a link to my patch file to Jon's PropertyComparer.cs file.  You can download the original directly from Jon's project hosted on EggHeadCafe in the link above.

PropertyComparer.patch (2.99 kb)

Here is an example of how you would use this to support sorting in a Telerik RadGrid:

        protected void RadGrid1_SortCommand(object source, GridSortCommandEventArgs e)
        {
            List<Employee> employees = (List<Employee>)RadGrid1.DataSource;
            CompareOrder cmpOrder;
            GridSortExpression expression = new GridSortExpression(); 

            if (e.NewSortOrder.Equals(GridSortOrder.Ascending))
            {
                cmpOrder = CompareOrder.Ascending;
                expression.SortOrder = GridSortOrder.Ascending;
            }
            else
            {
                cmpOrder = CompareOrder.Descending;
                expression.SortOrder = GridSortOrder.Descending;
            }

            employees.Sort(new PropertyComparer<Employee>(e.SortExpression, cmpOrder));

            expression.FieldName = e.SortExpression;

            e.Item.OwnerTableView.SortExpressions.Clear();
            e.Item.OwnerTableView.SortExpressions.AddSortExpression(expression);
            e.Item.OwnerTableView.Rebind();
            e.Canceled = true;
        } 
 

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , , , ,

ASP.Net | C#

Anonymous HTTP PUT with IIS 7

by martin 22. June 2009 21:32
From googling around in trying to get HTTP put enabled on IIS 7, I have concluded that turning on HTTP PUT verb support requires the installation of the WebDAV handler extension and that even then it only works in integrated authentication mode.  If this is not true, please let me know as I was forced to write my own put HTTP handler.  It actually turned out to be a lot easier than I thought it was going to be though.  Implementing IHttpHandler, I ended up just having to binaryread the request into a byte array and then use a binarywriter to write it to a file after validating the PhysicalPath of the request for user permissions and validating that the "pattern" is safe (ex. file extension, path).  I haven't tested the performance against the IIS 6 native solution, but it seems quite fast on today's server hardware.

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , ,

ASP.Net | C# | Windows

Service Oriented Programming and DSLs?

by martin 19. November 2008 22:20

I recently attended Dev Connections and was shown the benefits of decoupling business logic from aspects such as authentication, authorization, security, transaction support, threading model, instantiation model, encoding, and transport mechanism.  In Juval Lowy's Windows Communication Framework (WCF) seminar, I was exposed to the idea of our software tools and runtime environments evolving to allow us to utilize these functionalities in business application without even doing anything additional.  Juval reiterated that WCF is not just about web service and explained many of the benefits that you would get for using WCF even on an application that does not span CPUs.  These benefits include fault tolerance, fault screening (or formal fault contracts), contract first development, and the benefit of a thought out framework that provides separation of concerns for many aspects of enterprise software development.

At PDC at the end of October, Microsoft announced Azure, Oslo, and Dublin.  So Azure, or the "cloud", will let you deploy and run your production applications easily and supposedly allow them to dynamically scale up on-the-fly as demand warrants.  I heard this maybe being accomplished by dynamically spawning new virtualized servers from software and data that are stored in a massive partitioned and redundant sql server cluster (or I may have dreamt all this).  Oslo is the hybrid (both visual (Quadrant) and textual) programming environment for creating and using custom Domain Specific Languages (DSL) and Dublin is a SQL server based repository and runtime environment for the resulting Oslo DSL programs and data structures.  The DSLs are written in Mgrammer ("Mg") and the modeling language itself is just called "M".  There is a silverlight video from MS on http://modelsremixed.com/ that shows the history of "modeling", starting with prehistoric times.  In it, you will notice that one of the process models that they show is comprised of a component with the tiny logo that reads "Wcf" in its top left corner.

So that is a lot of new information to absorb.... but what does this all mean?  Will we all really be orchestrating business process workflows written in "vertical" DSLs?  Where does BPEL fit in?  Is this Microsoft's killer-app ESB?

http://msdn.microsoft.com/en-us/oslo/default.aspx

 

 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , , ,

ASP.Net | C# | Windows

Update on site rebuild

by martin 27. August 2008 01:26
Update - I just added a page for the PIV and for my open source AJAX World Web Chat Client and web services Server.

Currently rated 3.7 by 3 people

  • Currently 3.666667/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , ,

AJAX | ASP.Net | C# | JavaScript | PIV

Horray!

by martin 24. August 2008 09:51

Krolik.net is finally back up (sort of).  Most of the content is missing right now, but I hope to have most things re-added within a week or so.

 

Currently rated 4.3 by 3 people

  • Currently 4.333333/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , ,

ASP.Net | Mono

Welcome

Please contact me if you have a great idea for a project and need technical expertise in designing, developing, or integrating a custom software solution. 

Recent Comments

Comment RSS