TimRayburn.CustomFunctoids - Logical String Functoids

This will be the first drop of the functoids to add more the one functoid, and with good reason.  Today we add a set of three functoids based on methods of the System.String class in .NET. Logical Contains Logical Starts With Logical Ends With These functoids, as you expect, determine if the first parameter provided either contains, starts with or ends with the second parameter provided.  Like the previous functoids we've kept the coloring the same as the other Logical functoids, except that they have a blue border to indicate they are in an external assembly.  The code can be downloaded below, as always, but this is one portion which I want to call out.  I implemented Logical Contains in a non-standard way:   public string LogicalContains(string fullString, string subString){// I realize this could be fullString.Contains(subString)// but doing that means this could not be compiled// under .NET 1.1 for BizTalk 2004if (fullString.IndexOf(subString) > 0)return "true";elsereturn "false";}As noted in the comments, this could be done as String.Contains() in .NET 2.0, but that method is not available in .NET 1.1 and one of my goals is to make these functoids backwards compatible to BizTalk 2004 whenever possible.Download TimRayburn.CustomFunctoids v1.0

Model View Presenter

I recently had the pleasure of attending a talk (twice) by Scott Cate about the Model View Presenter design pattern as implemented in .NET. I had never worked with this design pattern before and must say it was a joy to listen to Scott give this talk. He style is very natural, code oriented, and he stays very connected to the audience. The concept of this pattern is one of seperation of UI from Implementation. Most N-Tier implementations believe they do this well, but in fact still fill their code-behind (for ASP.NET) or form class (for WinForms) with logic which retrieves data, validates, etc. The Model View Presenter (MVP) suggests a different way, in which you do not place this in your application, but rather in a presenter object. But before we go further, let's define some of the terms. Model - The model is your business objects, or data access layer, which provides the data which needs to be presented. View - The view is an Interface which defines how information is both retrieved and set. Presenter - The presenter is a class which requires a "view" object to be constructed and can then present methods which will act upon the view. As a simple example, let's take the concept of a simple blogging software which stores all of the posts in an XML file. The XML file will look like this : <Posts><Post id=1><Title>Model View Presenter Rocks!</Title><Body>Lots of cool text goes here</Body></Post><Post id=2><Title>BizTalk Rocks!</Title><Body>Lots of cool text goes here</Body></Post><Post id=3><Title>Dot Net Rocks!</Title><Body>Will this get me in trouble with Cory?</Body></Post></Posts>Given this, which we keep in a "posts.xml" file, we will implement a super simple Model object. public class Post{private Post() { }// Private Constructorinternal string _Title;public string Title{get{return _Title;}}internal string _Body;public string Body{get{return _Body;}}public static Post GetPostById(int id){XmlDocument posts = new XmlDocument();posts.Load("posts.xml");string strXpath = "/Posts/Post[@id={0}]/{1}";XmlNode titleNode = posts.SelectSingleNode(String.Format(strXpath,id,"Title"));XmlNode bodyNode = posts.SelectSingleNode(String.Format(strXpath, id, "Body"));Post retPost = new Post();retPost._Title = titleNode.InnerText;retPost._Body = bodyNode.InnerText;return retPost;}} Now that we can get data from the file, we need to create our view. Our view is an Interface which supports "get"ing the post id, and "set"ing the title and body. public interface IPostView{int PostId { get; }string Title { set; }string Body { set; }}Finally, we have our presenter. Our presenter requires an implementation of our interface to be constructed and offers a method which allows retrieval. public class PostPresenter{private readonly IPostView view;public PostPresenter(IPostView view){this.view = view;}public void RetrievePost(){Post myPost = Post.GetPostById(view.PostId);view.Title = myPost.Title;view.Body = myPost.Body;}}If you want to see all of this implemented as a Windows Form application, then grab the download here. Technorati tags: design patterns, model view presenter, C#, scott cate

Speaking at the Little Rock .NET User Group

I've just confirmed I will be speaking at the Little Rock .NET User Group in January on Black Belt Xml.  If you're in the Little Rock area, please plan to attend, and if there is something you've always wanted to know about XML and the System.Xml namespace, drop me a line and let me know!