Messaging and logging (sending email, keeping track of what's going on to help fix things, etc.) on this Website now uses the Inner Drive Extensible Architecture™—the Idea™. The Idea gives the site exceptional flexibility and control over how and when the site handles communications to you and to the site administrators.
The trick is that we've divided messaging up into three parts:
IdtMessage),
that have additional data and behaviors depending on where they should end up;MessageSink, each one publishing
a specific kind of message; andIPackager, that take any object and
re-package the object as a specific type of message.
There is also a well-known singleton Publisher class that has static
methods any application can use to send a message with minimal code. For more advanced
applications, the Idea™ also has a publisher service that uses the
Microsoft Message Queue (MSMQ) service to send messages asynchronously. All
of this, of course, is transparent to the application sending messages.
This division of labor allows a site administrator to configure which packagers handle which kinds of message, which messages get used or ignored, and how to translate system objects (like exceptions) into messages that can be sent transparently.
For example, the basic type of message that a website uses is the WebMessage
object. In addition to having the same characteristics as all other messages, it
can deal with some extra information that it would likely encounter in a web application:
the IP address of the sender, what browser the sender was using, what page sent
the message, etc.
The WebMessage object is handled by the WebMessageSink
class. This class has its own configuration information that tells it how to re-publish
the WebMessage object as any other kind of message object.
Here's how the code-behind file for the Feedback page sends a feedback message:
private void SendFeedback()
{
string senderName = SenderName.Text;
string senderEmail = SenderEmail.Text;
string body = Feedback.MessageBody(senderName, senderEmail, SubjectText.Text, MessageText.Text);
// The ThisSite.AppTitle uniquely identifies the application to the
// message sinks.
WebMessage webMessage = new WebMessage(
ThisSite.AppTitle,
ThisSite.AppTitle,
body,
WebMessageType.Feedback,
Session,
Request
);
if (senderEmail.Length > 0)
{
webMessage.Source =
string.Format(CultureInfo.CurrentUICulture, "{0} <{1}>", senderName, senderEmail.ToLower());
}
Publisher.Instance.Publish(message);
}
Inside the message sink, the interesting code looks like this (with tracing and exception handling removed):
protected void PackageItems(
object obj,
string severity)
{
Type objType = obj.GetType();
List<string> publishList = GetPublishList(objType, severity);
const string delimiter = " ,;";
char[] delimArray = delimiter.ToCharArray();
// Avoid duplicate packagers--send the message only once to each
List<string> finalList = new List<string>();
foreach (string packagerKey in publishList)
{
// Allow multiple packagers for each combination of object and severity
string[] multiPacks = packagerKey.Split(delimArray);
foreach (string packer in multiPacks)
{
if (_packagers.ContainsKey(packer) && !(finalList.Contains(packer)))
{
finalList.Add(packer);
}
}
}
foreach (string finalPacker in finalList)
{
PublishItem(finalPacker, obj);
}
}
The configuration file looks like this:
<?xml version="1.0" encoding="utf-8" ?>
<messageConfig>
<messageSinks>
<sink
type="InnerDrive.Messages.NtEventLogSink"
assembly="InnerDrive.Messages, Version=0.99.0.0, Culture=neutral, PublicKeyToken=null"/>
<sink
type="InnerDrive.Messages.NullMessageSink"
assembly="InnerDrive.Messages, Version=0.99.0.0, Culture=neutral, PublicKeyToken=null"/>
<sink
type="InnerDrive.Messages.SmtpMessageSink"
assembly="InnerDrive.Messages, Version=0.99.0.0, Culture=neutral, PublicKeyToken=null"/>
<sink
type="InnerDrive.Messages.TextFileSink"
assembly="InnerDrive.Messages, Version=0.99.0.0, Culture=neutral, PublicKeyToken=null"/>
<sink
type="InnerDrive.Web.WebMessageSink"
assembly="InnerDrive.Web, Version=0.99.0.0, Culture=neutral, PublicKeyToken=null"/>
</messageSinks>
<packagers>
<packager
assembly="InnerDrive.Messages, Version=0.99, Culture=neutral, PublicKeyToken=null"
class="InnerDrive.Messages.NtLogPackager"
>NtLogPackager</packager>
<packager
assembly="InnerDrive.Messages, Version=0.99, Culture=neutral, PublicKeyToken=null"
class="InnerDrive.Messages.SmtpPackager"
smtpServer="localhost"
sender="servername@inner-drive.com"
destination="admin1@inner-drive.com;admin2@inner-drive.com"
>SmtpPackager</packager>
<packager
assembly="InnerDrive.Messages, Version=0.99, Culture=neutral, PublicKeyToken=null"
class="InnerDrive.Messages.NullPackager"
>NullPackager</packager>
</packagers>
<items>
<!-- Any item not otherwise mapped, use the NullPackager -->
<item packager="NullPackager" severity="*">*</item>
<item packager="SmtpPackager,NtLogPackager" severity="ApplicationStart">InnerDrive.Idea.Web.WebMessage</item>
<item packager="SmtpPackager" severity="Feedback">InnerDrive.Idea.Web.WebMessage</item>
<item packager="SmtpPackager" severity="Trouble">InnerDrive.Idea.Web.WebMessage</item>
</items>
</messageConfig>
This configuration file shows that Feedback, Trouble, and Application Start messages will be emailed to the designated recipients, and Application Start messages will also be logged in the server's NT Application Log. All other messages will be sent to the Null Packager, which accepts all types of objects and does absolutely nothing with them.
For more information, send us some feedback (using these classes) and someone will get right back to you.
Page info
Page last modified 2007-07-11. Legal information is current as of 2006-04-09.
Copyright ©2008 Inner Drive Technology. Purveyors of fine, hand-crafted computer software.
Copyright ©2008 Inner Drive Technology. Purveyors of fine, hand-crafted computer software. Legal information. Page printed 2008-11-21T18:31:59 UTC.