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: ,

Article written by

A long time developer, I was an early adopter of Linux in the mid-90's for a few years until I entered corporate environments and worked with Microsoft technologies like ASP, then .NET. In 2008 I released Sueetie, an Online Community Platform built in .NET. In late 2012 I returned to my Linux roots and locked in on Java development. Much of my work is available on GitHub.