Dave Burke : Freelance .NET Web Developer specializing in Online Communities

A Great Code Day with DotText Components and CodeSmith

Yeah, you heard me right.  DotText.  It's still a classic, ya know.  It was two blog sites ago for me (CS 1.1<--CS 1.0<--DotText 95), but I still fire it up in Visual Studio occasionally because its great code and I find it useful.

I was writing an app today that took data from Access, processed and imported it into SQL Server.  I started with ADO.NET DataTables and passing a few parameters around, but I quickly realized I needed to go with Data Objects and Collections...just like in DotText.    Building a few DotText-like objects and collections along with spending some time in CodeSmith made this a very good code day.

I'm displaying DotText components in a Solutions Window below as a trip down memory lane for many of us.  These are empty object containers with their own generic collection containers.  Its a straightforward architecture (once you get it) that I used in my pre-CS days to add a Comments Notification feature to my DotText blog.  Just for fun I thought I'd run through the process of how data objects and collections were created and used in DotText to cap off my DotText Day.

As for the CodeSmith fun, I wanted to share my DotText Business Objects and Collections CodeSmith Templates.  These generate data objects and generic collections as used in DotText.  Still good stuff.  I used them today and they were a big time saver, plus they gave my app a clean Data Object Model. 

// IN DOTTEXT THE WEB PAGE OR CONTROL DOES SOMETHING WITH THE DATA OBJECT COLLECTION

private void SendNotification(int postID, int commentID, int userID)
{
    NotificationCollection nc = Notices.GetNotifyList(postID);
    Entry entry = Cacher.SingleEntry(commentID, CacheTime.Short, Context);       
    if (nc != null)
    {
        foreach (Notification n in nc)
        {
            Dottext.Framework.DBVT.Email.SendNotification(entry, n.Email);
        }
    }
}

// WHICH COMES FROM THE OBJECT HANDLING CLASS (HERE, NOTICES.CS)

public static NotificationCollection GetNotifyList(int PostID)
{
    return DTOProvider.Instance().GetNotificationsByPost(PostID);
}

// WHICH RETRIEVES THE COLLECTION FROM THE DTOPROVIDER
// THROUGH THE IDTOPROVIDER INTERFACE

public NotificationCollection GetNotificationsByPost(int PostID)
{
    IDataReader reader = DbProvider.Instance().GetNotificationsByPost(PostID);
    try
    {
        NotificationCollection nc = DataHelper.LoadNotificationCollection(reader);
        return nc;
    }
    finally
    {
        reader.Close();
    }
}

// THE READER IS CREATED FROM THE SQLDATAPROVIDER
// THROUGH THE IDBPROVIDER INTERFACE

public IDataReader GetNotificationsByPost(int PostID)
{
    NotificationCollection nc = new NotificationCollection();

        SqlParameter[] p =
    {
        SqlHelper.MakeInParam("@PostID",SqlDbType.Int,4,PostID)
    };
        return GetReader("blog_DBVTGetNotificationsByPostID",p);
}

    
// WHICH USES THE READER TO TO POPULATE THE COLLECTION IN THE DATAHELPER CLASS

public static NotificationCollection LoadNotificationCollection(IDataReader reader)
{
    NotificationCollection nc = new NotificationCollection();
    while(reader.Read())
    {
        nc.Add(LoadSingleNotification(reader));
    }
    return nc;   
}

public static Notification LoadSingleNotification(IDataReader reader)
{
    Notification n = new Notification();
    n.NoticeID = (int)reader["NoticeID"];
    n.PostID = (int)reader["PostID"];
    n.UserID = (int)reader["UserID"];
    n.Email = (string)reader["Email"];
    n.FirstName = (string)reader["FirstName"];
    n.LastName = (string)reader["LastName"];
    n.CommentDateTime = (DateTime)reader["CommentDateTime"];
    return n;
}




Technorati Tags: ,

Comments (2) | Post RSS RSS comment feed

Posted on 2/20/2006 8:26:00 PM by Dave Burke
Categories: .NET | CodeSmith
Tags: no tags for this post

Related posts

Comments (2) -

2/21/2006 11:05:00 AM Permalink

I love that type of model and use it quite often.  You are correct, once you get it, its straightforward and clean.  Yep, good stuff.

Erik Lane |

2/21/2006 11:08:11 AM Permalink

Erik, it means a lot for you to comment on having similar affections for that model.  Hey, I'm glad you visited.  I LOVE your CS 2.0 blog.  VERY nice!  Once problem, there's no way to contact you (I lost your email address) and you don't have comments enabled (or at least you didn't last night.)  Thanks for sharing the dotText love and showing the CS 2.0 dazzle at your blog.  

daveburke |


Powered by BlogEngine.NET 2.0.0.36
Theme by Dave Burke