<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" media="screen" href="/styles/xslt/rss.xslt"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:media="http://search.yahoo.com/mrss/" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:c9="http://channel9.msdn.com">
<channel>
	<title>Channel 9</title>
    <atom:link rel="self" type="application/rss+xml" href="http://channel9.msdn.com/Niners/c4f.Robert-Witoff/Posts/RSS"></atom:link>
    <itunes:summary></itunes:summary>
    <itunes:author>Microsoft</itunes:author>
    <itunes:subtitle></itunes:subtitle>
    <image>
      <url>http://mschnlnine.vo.llnwd.net/d1/Dev/App_Themes/C9/images/feedimage.png</url>
      <title>Channel 9</title>
      <link>http://channel9.msdn.com/Niners/c4f.Robert-Witoff/Posts</link>
    </image>
    <itunes:image href=""></itunes:image>
    <itunes:category text="Technology"></itunes:category>
    <description>Channel 9 keeps you up to date with the latest news and behind the scenes info from Microsoft that developers love to keep up with. From LINQ to SilverLight – Watch videos and hear about all the cool technologies coming and the people behind them.</description>
    <link>http://channel9.msdn.com/Niners/c4f.Robert-Witoff/Posts</link>
    <language>en</language>
    <pubDate>Wed, 19 Jun 2013 13:15:58 GMT</pubDate>
    <lastBuildDate>Wed, 19 Jun 2013 13:15:58 GMT</lastBuildDate>
    <generator>Rev9</generator>
    <c9:totalResults>1</c9:totalResults>
    <c9:pageCount>1</c9:pageCount>
    <c9:pageSize>25</c9:pageSize>
  <item>
      <title>Inherited Message Distributing</title>
      <description><![CDATA[<span id="c4fmetadata">
<table cellspacing="0" cellpadding="1" width="100%" border="0">
<tbody>
<tr class="entry_overview">
<td width="50">&nbsp;</td>
<td><span class="entry_description">Given a week off of school I found the time to start designing a system that had been thought up in a school class. The idea was simple, a webapp that lets a user reach the widest possible audience by distributing messages
 across many mediums. One message could be delivered to each recipient as an email, text message, instant message, or phone call to name a few possibilities. With this system, an already overworked teacher could take 30 seconds to send one message that was
 delivered to each student and parent instantly across multiple mediums. A sports coach could finally reach everyone on the team, without trying to post news on a site that was rarely checked and poorly maintained.</span></td>
</tr>
<tr>
<td colspan="2">
<div class="entry_author">Robert Witoff</div>
<a title="http://www.chalk2me.com/" href="http://www.chalk2me.com/">http://www.chalk2me.com/</a>
<br>
<div class="entry_details"><b></b></div>
<div class="entry_details"><b>Difficulty: </b><span class="entry_details_input">Intermediate</span></div>
<div class="entry_details"><b>Time Required:</b> <span class="entry_details_input">
3-6 hours</span></div>
<div class="entry_details"><b>Cost: </b><span class="entry_details_input">Free</span></div>
<div class="entry_details"><b>Software: </b><span class="entry_details_input"><a href="http://msdn.com/express/">Visual Basic or Visual C# Express Editions</a></span></div>
<div class="entry_details"><b>Hardware: </b><span class="entry_details_input"></span></div>
<div class="entry_details"><b>Download: </b><a href="http://codeplex.com/chalk2me">Download</a>
</div>
<div class="entry_details">&nbsp;</div>
<div class="entry_details"><strong>Disclaimer: </strong>Currently this article is C# only.&nbsp; If you want it in Visual Basic.Net, please comment and tell us so we can transcode it to VB.</div>
</td>
</tr>
</tbody>
</table>
</span>
<p><b>Starting Out:</b></p>
<p>We thought we had come up with a cool concept, and I knew it wouldn't be that difficult to build. After calling our dev-team into the office I started on it, by myself in my apartment. My goal was to have a single method to send any type of message that
 would then be picked up by an appropriate thread to deliver the message. As the whole idea here was to create and deliver messages, a logical place to start was a struct to hold our message fields. It's always good to keep other services in mind while you're
 building your own. I started off with the first 4 fields in any email. This covered message content and we only needed a bit more info to deliver the message. The medium type, along with an identifier field for your address (or screen name etc.), would cover
 this. Just in case a service we end up using needs a second identifier, I added one more. Check it out:</p>
<pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">struct</span> ctMessage
{
    <span class="kwrd">public</span> ctMessage(<span class="kwrd">string</span> sendToUser, <span class="kwrd">string</span> fromUser, <span class="kwrd">string</span> subj, <span class="kwrd">string</span> msg, <span class="kwrd">string</span>

    mediumType, <span class="kwrd">string</span> mediumArg1, <span class="kwrd">string</span> mediumArg)
    {
        <span class="kwrd">this</span>.toUser = sendToUser;
        <span class="kwrd">this</span>.fromUser = fromUser;
        <span class="kwrd">this</span>.subject = subj;
        <span class="kwrd">this</span>.message = msg;
        <span class="kwrd">this</span>.mediumType = mediumType;
        <span class="kwrd">this</span>.mediumArg1 = mediumArg1;
        <span class="kwrd">this</span>.mediumArg2 = mediumArg2;
    }

    <span class="kwrd">public</span> <span class="kwrd">string</span> toUser; <span class="rem">//name of recipient</span>
    <span class="kwrd">public</span> <span class="kwrd">string</span> fromUser; <span class="rem">//name of sender</span>
    <span class="kwrd">public</span> <span class="kwrd">string</span> subject;
    <span class="kwrd">public</span> <span class="kwrd">string</span> message;
    <span class="kwrd">public</span> <span class="kwrd">string</span> mediumType; <span class="rem">//which node should deliver this</span>
    <span class="kwrd">public</span> <span class="kwrd">string</span> mediumArg1; <span class="rem">//varies, to identify the recipient</span>
    <span class="kwrd">public</span> <span class="kwrd">string</span> mediumArg2; <span class="rem">//varies, to identify the recipient</span>
}</pre>
<style type="text/css">
<!--
.csharpcode, .csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{background-color:#f4f4f4;
	width:100%;
	margin:0em}
.csharpcode .lnum
	{color:#606060}
-->
</style>
<p>Once we had a message designed I, of course, wanted to be able to send one! Eventually I wanted a bunch of different types of messages being sent, so a solid base class would save a ton of time later. Although all of the messaging services, or ‘nodes' would
 undoubtedly send the messages completely different, they would all need to run in a similar thread that sent messages coming from a single location. By doing a good job writing an abstract base class, we could add new services by only overriding the 'send'
 method later.</p>
<p>This abstract class would have a field identifying the type of messages it will handle, and call an external send method whenever messages of that type existed. A continuous loop to poll for messages, given a modest polling frequency would do the trick.
 Notice the protected methods and fields that we'll want to override.</p>
<pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">abstract</span> <span class="kwrd">class</span> ctNode
{
    <span class="kwrd">public</span> ctNode()
    {
        <span class="kwrd">this</span>.maxQueueSize = 100; <span class="rem">//Set the size according to how long it will take to reach the Nth message</span>
        <span class="kwrd">this</span>.msgQueue = <span class="kwrd">new</span> Queue(maxQueueSize);
        <span class="kwrd">this</span>.msPauseAfterRun = 10000; <span class="rem">//If using a DB, polling it with no pause b/w queries is an unnecessary load</span>
        <span class="kwrd">this</span>.runnerThread = <span class="kwrd">new</span> Thread(<span class="kwrd">new</span> ThreadStart(<span class="kwrd">this</span>.run));
    }

    <span class="kwrd">private</span> Thread runnerThread;
    <span class="kwrd">protected</span> <span class="kwrd">int</span> msPauseAfterRun;
    <span class="kwrd">protected</span> Queue msgQueue;
    <span class="kwrd">public</span> <span class="kwrd">int</span> maxQueueSize;

    <span class="kwrd">void</span> run()
    {
        <span class="kwrd">while</span> (<span class="kwrd">true</span>)
        {
            <span class="kwrd">while</span> (<span class="kwrd">this</span>.msgQueue.Count &gt; 0)
            {
                <span class="rem">//pop a message and send it</span>
                ctMessage ctm = (ctMessage)msgQueue.Dequeue();

                <span class="kwrd">try</span>
                {
                    sendSingleMessage(ctm);
                }
                <span class="kwrd">catch</span> (Exception e)
                {
                    <span class="rem">//Write a more detailed error log here</span>
                    Console.writeLine(<span class="str">&quot;the message could not be sent!&quot;</span> &#43; e.toString());
                }
            }

            <span class="rem">//get new messages</span>
            ctNode ctn = <span class="kwrd">this</span>;
            ctMessage[] newMessages = messageSender.getMessages(<span class="kwrd">ref</span> ctn, getRoomInQueue());

            <span class="rem">//Wait some time before checking for more messages!</span>
            <span class="kwrd">if</span> (newMessages.Length == 0)
                Thread.Sleep(msPauseAfterRun);
            <span class="kwrd">else</span>
                <span class="kwrd">this</span>.EnqueueMessages(newMessages);
        }
    }

    <span class="kwrd">public</span> <span class="kwrd">virtual</span> <span class="kwrd">void</span> EnqueueMessages(ctMessage[] messagesToSend)
    {
        <span class="kwrd">int</span> roomInQueue = maxQueueSize - msgQueue.Count;

        <span class="kwrd">if</span> (messagesToSend.Length &gt; roomInQueue)
            <span class="kwrd">throw</span> <span class="kwrd">new</span> Exception(<span class="str">&quot;Too many Messages have been inserted&quot;</span>);

        <span class="kwrd">for</span> (<span class="kwrd">int</span> i = 0; i &lt; messagesToSend.Length; i&#43;&#43;)
        {
            msgQueue.Enqueue(messagesToSend[i]);
        }
    }

    <span class="kwrd">public</span> <span class="kwrd">virtual</span> <span class="kwrd">void</span> EnqueueMessages(ctMessage messageToSend)
    {
        ctMessage[] ctm = <span class="kwrd">new</span> ctMessage[1];
        ctm[0] = messageToSend;
        <span class="kwrd">this</span>.EnqueueMessages(ctm);
    }

    <span class="kwrd">protected</span> <span class="kwrd">virtual</span> <span class="kwrd">void</span> sendSingleMessage(ctMessage ctm)
    {
        <span class="rem">//code to send an individual message</span>
    }

    <span class="kwrd">public</span> <span class="kwrd">void</span> startThread()
    {
        runnerThread.Name = <span class="kwrd">this</span>.nodeType;
        runnerThread.Start();
    }

    <span class="kwrd">protected</span> <span class="kwrd">string</span> nodeType;

    <span class="kwrd">public</span> <span class="kwrd">string</span> getNodeType()
    {
        <span class="kwrd">return</span> <span class="kwrd">this</span>.nodeType;
    }
}</pre>
<style type="text/css">
<!--
.csharpcode, .csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{background-color:#f4f4f4;
	width:100%;
	margin:0em}
.csharpcode .lnum
	{color:#606060}
-->
</style>
<p>You might have noticed the big thing missing from these classes, a place to store, and retrieve messages! I initially put our message storage into an external static class. This made them centralized, easily accessible from any other objects that might need
 to access them, simple to ensure thread safety, and gave us room to move to a smarter mechanism later (or database. Notice the simplicity:</p>
<pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">static</span> <span class="kwrd">class</span> messageSender
{
    <span class="kwrd">private</span> <span class="kwrd">static</span> List&lt;ctMessage&gt; messagesToSend = <span class="kwrd">new</span> List&lt;ctMessage&gt;();

    <span class="kwrd">public</span> <span class="kwrd">static</span> ctMessage[] getMessages(<span class="kwrd">ref</span> ctNode nodeRef, <span class="kwrd">int</span> numberOfMessages)
    {
        <span class="rem">//We'll do this in a database later, but for now this works similarly</span>
        List&lt;ctMessage&gt; returnMessages = <span class="kwrd">new</span> List&lt;ctMessage&gt;();

        <span class="kwrd">lock</span> (messagesToSend)
            <span class="kwrd">for</span> (<span class="kwrd">int</span> i = 0; i &lt; messagesToSend.Count; i&#43;&#43;)
                <span class="kwrd">if</span> (messagesToSend[i].mediumArgs == nodeRef.getNodeType())
                {
                    returnMessages.Add(messagesToSend[i]);
                    messagesToSend.RemoveAt(i);
                    i--;
                }

        <span class="kwrd">return</span> returnMessages.ToArray();
    }

    <span class="kwrd">public</span> <span class="kwrd">static</span> <span class="kwrd">void</span> sendMessage(ctMessage message)
    {
        <span class="kwrd">lock</span> (messagesToSend)
            messagesToSend.Add(message);
    }
}</pre>
<style type="text/css">
<!--
.csharpcode, .csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{background-color:#f4f4f4;
	width:100%;
	margin:0em}
.csharpcode .lnum
	{color:#606060}
-->
</style>
<p>Now that the groundwork was done, I grabbed some eye drops and an energy drink to refresh for the best part, function! I started simple with an email node, and if you've played with email before in .net, you've definitely seen and loved the SmtpClient class
 in the System.Net.Mail Namespace. If you don't already have a local SMTP client set up, you can easily use a Gmail account as an SMTP server. Check out the following implementation, notice we only had to set the node type, initialize the SmtpClient and override
 the send method. Send a message through our message sender, and watch the node pick up the message and deliver it. Inheritance rocks!</p>
<pre class="csharpcode">ctMessage ctm = <span class="kwrd">new</span> ctMessge(<span class="str">&quot;Friend&quot;</span>, <span class="str">&quot;Developer&quot;</span>, <span class="str">&quot;testing&quot;</span>, <span class="str">&quot;My first message&quot;</span>, <span class="str">&quot;email&quot;</span>, <span class="str">&quot;yourEmail@yourDomain.com&quot;</span>, <span class="str">&quot;&quot;</span>);
messageSender.sendMessage(ctm);

<span class="kwrd">public</span> <span class="kwrd">class</span> ctNodeEmail : ctNode
{
    <span class="kwrd">public</span> ctNodeEmail() : <span class="kwrd">base</span>()
    {
        <span class="kwrd">this</span>.nodeType = <span class="str">&quot;email&quot;</span>;

        <span class="rem">//</span>
        <span class="rem">//SET UP SMTP CLIENT</span>
        <span class="rem">//</span>

        <span class="rem">//GMAIL SERVER</span>
        <span class="kwrd">this</span>.mSmtpClient = <span class="kwrd">new</span> SmtpClient(<span class="str">&quot;gmail.com/mail&quot;</span>, 25);
        <span class="kwrd">this</span>.mSmtpClient.Host = <span class="str">&quot;smtp.gmail.com&quot;</span>;
        <span class="kwrd">this</span>.mSmtpClient.Port = 25;
        <span class="kwrd">this</span>.mSmtpClient.EnableSsl = <span class="kwrd">true</span>;
        <span class="kwrd">this</span>.mSmtpClient.Credentials = <span class="kwrd">new</span> System.Net.NetworkCredential(<span class="str">&quot;YOURADDRESS@gmail.com&quot;</span>, <span class="str">&quot;YOUR_PASSWORD&quot;</span>);

        <span class="rem">//LOCAL SERVER</span>
        <span class="rem">//this.mSmtpClient = new SmtpClient(&quot;localhost&quot;, 25);</span>
    }

    SmtpClient mSmtpClient;

    <span class="kwrd">protected</span> <span class="kwrd">override</span> <span class="kwrd">void</span> sendSingleMessage(ctMessage ctm)
    {
        MailMessage msgMail = <span class="kwrd">new</span> MailMessage(<span class="kwrd">new</span> MailAddress(ctm.fromUser &#43; <span class="str">&quot;@ChalkTalkNow.com&quot;</span>), <span class="kwrd">new</span> MailAddress(ctm.mediumArgs));
        msgMail.Subject = ctm.subject;
        <span class="kwrd">string</span> msg = ctm.message;
        msgMail.Body = msg;

        <span class="rem">// Send the mail message</span>
        mSmtpClient.Send(msgMail);
    }
}</pre>
<style type="text/css">
<!--
.csharpcode, .csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{background-color:#f4f4f4;
	width:100%;
	margin:0em}
.csharpcode .lnum
	{color:#606060}
-->
</style>
<p>After writing this so quickly I wanted something a bit more than email, and knew text messages were only a step away. It's no secret that all major cell companies give your phone an email address, you just need to append the proper domain to your number.
 Building off of our email node, we used the first mediumArg to hold a phone number, and put the carrier into the second mediumArg.
</p>
<pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">class</span> ctNodeTextMessage : ctNode
{
    <span class="kwrd">public</span> ctNodeTextMessage() : <span class="kwrd">base</span>()
    {
        <span class="kwrd">this</span>.nodeType = <span class="str">&quot;textmessage&quot;</span>;

        <span class="rem">//</span>
        <span class="rem">//SET UP SMTP CLIENT</span>
        <span class="rem">//</span>
        <span class="kwrd">this</span>.mSmtpClient = <span class="kwrd">new</span> SmtpClient(<span class="str">&quot;gmail.com/mail&quot;</span>, 25);
        <span class="kwrd">this</span>.mSmtpClient.Host = <span class="str">&quot;smtp.gmail.com&quot;</span>;
        <span class="kwrd">this</span>.mSmtpClient.Port = 25;
        <span class="kwrd">this</span>.mSmtpClient.EnableSsl = <span class="kwrd">true</span>;
        <span class="kwrd">this</span>.mSmtpClient.Credentials = <span class="kwrd">new</span> System.Net.NetworkCredential(<span class="str">&quot;GMAIL@gmail.com&quot;</span>, <span class="str">&quot;PASSWORD&quot;</span>);

    }
    SmtpClient mSmtpClient;

    <span class="kwrd">private</span> <span class="kwrd">string</span> getEmailAddress(<span class="kwrd">string</span> phoneNumber, <span class="kwrd">string</span> provider)
    {
        <span class="kwrd">switch</span> (provider)
        {
            <span class="kwrd">case</span> <span class="str">&quot;t-mobile&quot;</span>:
                <span class="kwrd">return</span> phoneNumber &#43; <span class="str">&quot;@tmomail.net&quot;</span>;
            <span class="kwrd">case</span> <span class="str">&quot;virginmobile&quot;</span>:
                <span class="kwrd">return</span> phoneNumber &#43; <span class="str">&quot;@vmobl.com&quot;</span>;
            <span class="kwrd">case</span> <span class="str">&quot;cingular&quot;</span>:
                <span class="kwrd">return</span> phoneNumber &#43; <span class="str">&quot;@cingularme.com&quot;</span>;
            <span class="kwrd">case</span> <span class="str">&quot;att&quot;</span>:
                <span class="kwrd">return</span> phoneNumber &#43; <span class="str">&quot;@cingularme.com&quot;</span>;
            <span class="kwrd">case</span> <span class="str">&quot;sprint&quot;</span>:
                <span class="kwrd">return</span> phoneNumber &#43; <span class="str">&quot;@messaging.sprintpcs.com&quot;</span>;
            <span class="kwrd">case</span> <span class="str">&quot;verizon&quot;</span>:
                <span class="kwrd">return</span> phoneNumber &#43; <span class="str">&quot;@vtext.com&quot;</span>;
            <span class="kwrd">case</span> <span class="str">&quot;nextel&quot;</span>:
                <span class="kwrd">return</span> phoneNumber &#43; <span class="str">&quot;@messaging.nextel.com&quot;</span>;
            <span class="kwrd">default</span>:
                <span class="rem">//assume cingular/att is the most popular</span>
                <span class="kwrd">return</span> phoneNumber &#43; <span class="str">&quot;@cingularme.com&quot;</span>;
        }
    }

    <span class="kwrd">protected</span> <span class="kwrd">override</span> <span class="kwrd">void</span> sendSingleMessage(ctMessage ctm)
    {
        <span class="rem">//send a single message</span>
        <span class="kwrd">string</span> emailAddress = getEmailAddress(ctm.mediumArg1, ctm.mediumArg2);

        MailMessage msgMail = <span class="kwrd">new</span> MailMessage(<span class="kwrd">new</span> MailAddress(ctm.fromUser &#43; <span class="str">&quot;@chalktalk.net&quot;</span>, ctm.fromUser), <span class="kwrd">new</span> MailAddress(emailAddress));
        msgMail.Subject = ctm.subject;
        msgMail.Body = ctm.message;
        sendEmail(msgMail);
    }

    <span class="kwrd">private</span> <span class="kwrd">void</span> sendEmail(MailMessage msgMail)
    {
        <span class="rem">// Send the mail message</span>
        <span class="kwrd">this</span>.mSmtpClient.Send(msgMail);
    }
}</pre>
<style type="text/css">
<!--
.csharpcode, .csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{background-color:#f4f4f4;
	width:100%;
	margin:0em}
.csharpcode .lnum
	{color:#606060}
-->
</style>
<p>Now to test this out, just like we sent the email we'll send a text. Cool!</p>
<pre class="csharpcode">ctMessage ctm = <span class="kwrd">new</span> ctMessge(<span class="str">&quot;Friend&quot;</span>, <span class="str">&quot;Developer&quot;</span>, <span class="str">&quot;testing&quot;</span>, <span class="str">&quot;hello world via text&quot;</span>, <span class="str">&quot;textmessage&quot;</span>, <span class="str">&quot;#########&quot;</span>, <span class="str">&quot;verizon&quot;</span>);
messageSender.sendMessage(ctm);</pre>
<style type="text/css">
<!--
.csharpcode, .csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{background-color:#f4f4f4;
	width:100%;
	margin:0em}
.csharpcode .lnum
	{color:#606060}
-->
</style>
<h3>Conclusion:</h3>
<p>When you're working on a project with a small team, it's especially important to build a good foundation like this so you can focus on easily added functionality without getting bogged down in complexity. This portion of the project was written over the
 course of a week and later on allowed us to focus almost exclusively on adding new services like Instant Messengers and interactive phone calling. Having functionality so quickly was crucial, along with a UI built by my brother, in getting the attention and
 support of others to build a business around this.</p>
<h3>Next Steps:</h3>
<ul>
<li>Build a UI to manage content and run your messaging! </li><li>Rewrite your messageSender class to store messages in a database. This will make your app much more extensible, and you can save a record of the messages sent in an ‘outbox'.
</li><li>Strongly type all textual identifiers in enumerations to avoid any frustrating mistakes.
</li><li>Find an SDK for your favorite messenger, and build a node for it </li><li>Join our team and continue to build with us! </li></ul>
 <img src="http://m.webtrends.com/dcs1wotjh10000w0irc493s0e_6x1g/njs.gif?dcssip=channel9.msdn.com&dcsuri=http://channel9.msdn.com/Niners/c4f.Robert-Witoff/Posts/RSS&WT.dl=0&WT.entryid=Entry:RSSView:ac39f35957c84be1b0619e7600ce550e">]]></description>
      <comments>http://channel9.msdn.com/coding4fun/articles/Inherited-Message-Distributing</comments>
      <itunes:summary>



&amp;nbsp;
Given a week off of school I found the time to start designing a system that had been thought up in a school class. The idea was simple, a webapp that lets a user reach the widest possible audience by distributing messages
 across many mediums. One message could be delivered to each recipient as an email, text message, instant message, or phone call to name a few possibilities. With this system, an already overworked teacher could take 30 seconds to send one message that was
 delivered to each student and parent instantly across multiple mediums. A sports coach could finally reach everyone on the team, without trying to post news on a site that was rarely checked and poorly maintained.



Robert Witoff
http://www.chalk2me.com/


Difficulty: Intermediate
Time Required: 
3-6 hours
Cost: Free
Software: Visual Basic or Visual C# Express Editions
Hardware: 
Download: Download

&amp;nbsp;
Disclaimer: Currently this article is C# only.&amp;nbsp; If you want it in Visual Basic.Net, please comment and tell us so we can transcode it to VB.





Starting Out: 
We thought we had come up with a cool concept, and I knew it wouldn&#39;t be that difficult to build. After calling our dev-team into the office I started on it, by myself in my apartment. My goal was to have a single method to send any type of message that
 would then be picked up by an appropriate thread to deliver the message. As the whole idea here was to create and deliver messages, a logical place to start was a struct to hold our message fields. It&#39;s always good to keep other services in mind while you&#39;re
 building your own. I started off with the first 4 fields in any email. This covered message content and we only needed a bit more info to deliver the message. The medium type, along with an identifier field for your address (or screen name etc.), would cover
 this. Just in case a service we end up using needs a second identifier, I added one more. Check it out: 
public struct ctMessage
{
    public ctMessage(stri</itunes:summary>
      <link>http://channel9.msdn.com/coding4fun/articles/Inherited-Message-Distributing</link>
      <pubDate>Thu, 11 Sep 2008 18:35:05 GMT</pubDate>
      <guid isPermaLink="false">http://channel9.msdn.com/coding4fun/articles/Inherited-Message-Distributing</guid>      
      <dc:creator>Robert Witoff</dc:creator>
      <itunes:author>Robert Witoff</itunes:author>
      <slash:comments>14</slash:comments>
      <wfw:commentRss>http://channel9.msdn.com/coding4fun/articles/Inherited-Message-Distributing/RSS</wfw:commentRss>
      <category>Productivity</category>
      <category>utility</category>
      <category>Web</category>
    </item>    
</channel>
</rss>