Three times a column

March 26, 2008 17:09 by Rob

For a client i needed a ASP.Net control that showed its contents in multiple columns. The CSS requirements forced me to develop a custom repeater for it, since the normal ASP.Net controls didn't suit me. I decided to share it with you, so here it is:

This templated databound control will collect items in multiple css div's when rendering. Provide a collection of css classes to indicate the columns (in this example, 3 divs). Rendering will be done from left to right, top to bottom while iterating over the div's.

+------++-------++-------+
| one  || two   || three |
| four || five  ||       |
+------++-------++-------+

[code] public class MultiColumnRepeater : Repeater
    {
        private string _columnClasses;

        /// <summary>
        /// Specifies the amount of columns and their css classes
        /// </summary>
        /// <example>
        /// To create 2 columns, specify "column_left,column_right".
        /// </example>
        public string ColumnClasses
        {
            get { return _columnClasses;  }
            set { _columnClasses = value;  }
        }

        protected override void RenderChildren(HtmlTextWriter writer)
        {
            //iterate over the different items.
            string[] classes = _columnClasses.Split(',');
            for (int column = 0; column < classes.Length; column++)
            {
                writer.AddAttribute(HtmlTextWriterAttribute.Class, classes[column]);
                writer.RenderBeginTag(HtmlTextWriterTag.Div);
               
                //iterate over all children, and only write the ones for the current columns.
                int index = 0;
                foreach (Control control in this.Controls)
                {
                    if (index % classes.Length == column)
                    {
                        control.RenderControl(writer);
                    }
                    index++;
                }

                writer.RenderEndTag();
                writer.Write(writer.NewLine);
            }
        }
    } [/code]


Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags:
Categories: ASP.Net | C#
Actions: E-mail | Permalink | Comments (0) | Comment RSSRSS comment feed

Why don't you use those expressions regularly?

January 21, 2008 15:45 by Rob
I found a very nice tutorial on Regular Expressions. If you're still a bit uncertain how it al works, or want to brush up on your RegEx skillz, check it out.

Currently rated 4.0 by 1 people

  • Currently 4/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags:
Categories: ASP.Net | C# | Software Engineering
Actions: E-mail | Permalink | Comments (0) | Comment RSSRSS comment feed

EntityPool 2.0 beta

December 4, 2007 14:53 by Rob

Hear! Hear!

The first beta release of EntityPool 2.0.

New features:

  • Support for nullable types
  • Support for orderby filters
  • Compiled against 2.0 framework
  • Added Generic method with lazy-loading interators.
  • Added CreateEntity event for custom entity factories

Here are the downloads.


Currently rated 5.0 by 2 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags:
Categories: C# | EntityPool
Actions: E-mail | Permalink | Comments (0) | Comment RSSRSS comment feed

No More Silverlight 1.1 - I am as amazed as you are.

December 1, 2007 16:19 by Rob

UPDATE: Now that silverlight 2 beta has arrived, I'm feeling a lot better. 

It seems that things are moving faster than I've expected. There has only been an alpha release of Silverlight 1.1, but since it is becoming bigger and bigger the branding people at Microsoft have decided that it is such a huge step forward they've rebranded it to SilverLight 2.0

...We now have a extensible control framework, two-way data binding, templates, styles, all the standard controls (TextBox, ScrollBar, CheckBox, RadioButton etc.), multiple layout containers (Grid, StackPanel, Canvas). In short, if you're familiar with WPF today, you'll be right at home with Silverlight 2.0.

With regards to the Rich Internet Application stuff, here's an interesting quote from the article on Tim Sneath's blog:

Moving forward, if you want to build a rich Internet application, Silverlight should absolutely be at the top of your list for consideration. No other platform will offer such a rich UI framework, and all the data templates and styling capabilities, coupled with the power of the .NET Framework and base class libraries, along with an easy migration path to a full unrestricted Windows desktop solution.

I'd better get up to speed with WPF...


Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags:
Categories: C# | Silverlight
Actions: E-mail | Permalink | Comments (0) | Comment RSSRSS comment feed

Another pool of entities

November 29, 2007 15:36 by Rob

Dear readers,

 I'm working on a new beta release of EntityPool. The previous releases used only framework 1.1 features and that's practically stoneage. This is the first major update since long time ago. Therefore I decided to call it version 2.0b. Here's a small summary of the changes:

  • 2.0 Generics support including dynamic iterators for dramatic speed increase when working on large collections (see below).
  • Configuration of the connection strings using the new <connectionStrings> settings.
  • Configuration of filters through the web.config/app.config instead of hardcoded attributes.
  • Additional interfaces and events:
    • IConstructedCallBack - an interface that is called after your entity has been constructed from storage
    • IPersistedCallBack - an interface that is called after your entity has been persisted.
    • IRelationBuilder - allows you to define a builder that is used to construct a relation property
    • ConverterAttribute - allows you to declaratively define a converter that is used to map Database values to Entities and vice versa.
  • Strangely enough, there are not that many bugfixes. Maybe the code worked as it should?

As said, you now can specify your query filter in the configuration file instead of using an attribute:

[EntityPool.DefineFilter("byCategory", "Category = @b", "@b")]

You now specify:

<entityPool>


....


 <types>


  <type class="Demo.Objects.Category" assembly="Demo">


   <filters>


    <defineFilter name="byCategory" where="Category = @b" arguments="@b"/>


    <defineFilter name="all" where="1=1 order by Category"/>


  </filters>


 </type>


</types>


</entityPool>

 


Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags:
Categories: C# | EntityPool
Actions: E-mail | Permalink | Comments (2) | Comment RSSRSS comment feed

Hola Barcelona!

November 7, 2007 15:07 by Rob

This week I am attending the Microsoft TechEd Developers in Barcelona. Amongst the first impressions where those of dissappointment. First of all it is not that big as the ones I used to attend in Amsterdam. Secondly these seems to be no real new stuff. There is no new product hype. We've all been playing around with the beta's and CTP's of most products for a couple of months now, including Visual Studio 2008, the 3.5 .Net framework and Silverlight 1.1.

What strikes me most are the number of sessions on Silverlight that show basic stuff in 1.0. I attended a couple of sessions on how to communicate with the webserver from 1.0 Silverlight applications using Javascript and AJAX. Why should I want to do that? It will be phased out anyway as soon as 1.1 'hits the shelves'. Even more so, they already have native webservice support built in and working on SL1.1? I do not intend to spend my time working on code that'll be useless in a couple of weeks. Come on TechEd, bring the good stuff !!

This is of course all very reasonable, but the bottom line was reached when a speaker explained how to do c# a ternary operator on a lvl3 advanced course. This would've been fine if it didn't take him 10 minutes.

But the wheather is nice and the evenings are cool, so what am I complaining about?


Be the first to rate this post

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

Health Monitoring in ASP.NET 2.0

October 12, 2007 16:22 by Rob

Now here's something interesting I didn't notice before: ASP.Net has health monitoring features built in. In Asp.net 1.1 I used to roll out our own code to catch web application errors and log them, but now they seem to be built in into the framework.

Since I don't like typing very much, here's the link to the full article on 4GuysFromRolla:

  • Health Monitoring Basics - explores the concepts and advantages of the Health Monitoring system and looks at logging events to a Microsoft SQL Server database.
  • Notifications via Email - looks at security-related events and shows how to alert an administrator to failed authentication attempts by "logging" events to email.
  • Raising Custom Events - learn how to create and raise custom Health Monitoring events.

  • Be the first to rate this post

    • Currently 0/5 Stars.
    • 1
    • 2
    • 3
    • 4
    • 5
    Tags:
    Categories: ASP.Net | C#
    Actions: E-mail | Permalink | Comments (2) | Comment RSSRSS comment feed

    Strong-typed provisioning of custom lists in Sharepoint 2007

    October 11, 2007 16:05 by Rob

    In most of our latest Sharepoint projects we need a lot of customization. These customization generally mean that we develop webpparts and custom lists so that we use sharepoint as a sort of database. The list itself is rarely visible to end users and only to a extended sharepoint site that is used as a backoffice application.

    The development of the webparts go as follows:

    • For every webpart we develop we have:
      • The <webpart>.cs control
      • The <webpart>Control.asc User control
      • The <webpart>.wsp XML file that is used to package the webpart
      • A Test<webpart>.aspx file that is used to test the webpart standalone but is never deployed to the sharepoint application.
    • The webparts do not rely on sharepoint, but bind to strongly type objects and collection.
    • A Provider pattern is used for retrieving and updating of the data objects.

    This provider model allows us to test and verify functionality of the webparts without the need to upload/provision these webparts inside a Sharepoint hosted website. We all know this takes a lot of time. The provider is configured in the web.config of the webpart solution file.

    Here's a sample of one of these business objects:

    public class AppointmentObject
    {
      private string _description;

      public string Description
      {
        get { return _description; }
        set { _description = value; }
      }
    }

    The user control uses this class in codebehind like so:

    AppointmentCollection recentAppointments = ServiceProvider.GetRecentAppointments();

    RecentAppointments.DataSource  = recentAppointment;
    RecentAppointments.DataBind();

    You see this is basic ASP.Net stuff.

    I found this a pretty amazing thing; it cuts down on the time used for each development roundtrip, and it allows us to 'outsource' the development of the web parts to ASP.Net specialist who do not (yet) have the required Sharepoint knowledge. The knife cuts on two sides!

    This approach did have an enormous disadvantage however. The provider that implemented the mapping from the hard-coded business object to sharepoint needed a lot of custom code. It only paid of once the business object was used in multiple places. Another problem is that the code that provisioned the custom list was always a one-off piece of custom code. That code has NO relation to the business object.

    Now, my experiences with entitypool helped me in writing a library that solves all this:

    [SharepointList(Name="Appointments", ShowOnQuickLaunch=true)]
    [Description("Appointments"]
    public class AppointmentObject
    {
      private string _description;

      [SharepointTextField(Required=true,MaxLength=16)]
      public string Description
      {
        get { return _description; }
        set { _description = value; }
      }
    }

    To create the list in Sharepoint, all that is needed is the following statement:

    using(SPSite site = new SPSite("http://localhost:90"))
    {
      SharepointProvisioning.CreateList(site, typeof(AppointmentObject), true);
    }

    To retrieve all appointmentobjects we have a factory that converts a SPListItemCollection to AppointmentObject objects:

    ObjectFactory<AppointmentObject> factory = new ObjectFactory<AppointmentObject>();
    AppointmentObject object = factory.GetItem(spListItem);

    Easy? I think so.


    Currently rated 3.7 by 3 people

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

    Using MSBuild to deploy visual studio 2005 web applications (2)

    October 4, 2007 16:38 by Rob

    In my previous post I rambled about a bug in the Web Application .targets file. I found an easier solution which does not involve patching any existing files.

    The solution is to add the dependency projects to the msbuild target list like so:

    msbuild /t:ResolveAssemblyReferences;_CopyWebApplication
    
         /p:OutDir=..\Drop\bin\ /p:WebProjectOutputDir=..\Drop\
    

    Wow. Life CAN be easy.

    Update: Even more so, it is better to use ResolveReferences, which also copies any project assembly references you have in your project.

     Update 2: You actually need to add a 'bin' directory to the OutDir folder. 


    Currently rated 4.0 by 5 people

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

    Life's simple if you can analyse its complexity

    October 1, 2007 15:29 by Rob

    In my search for MSBuild tooling and software complexity analysis, I found the following tool: CCM 

    It is a very simple and fast commandline tool. More info later on.


    Be the first to rate this post

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