|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Configuration;
using System.Web.Security;
using MessageBoard.Properties;
namespace MessageBoard
{
/// <summary>
/// This class is used by the Asp.Net Object Data Source
/// </summary>
public static class MessageSource
{
private static IMessageProvider _actualMessageProvider = CreateMessageProvider();
private static IMessageProvider CreateMessageProvider()
{
string typeName = ConfigurationManager.AppSettings["MessageBoard-MessageProviderType"];
Type type = Type.GetType(typeName, true);
return (IMessageProvider)Activator.CreateInstance(type);
}
public static IEnumerable<Message> GetRecentMessages(int start, int count)
{
return GetRecentMessages(0, start, count);
}
public static IEnumerable<Message> GetRecentMessages(int idSince, int start, int count)
{
return _actualMessageProvider.GetRecentMessages(idSince, start, count);
}
public static int GetMessageCount()
{
return _actualMessageProvider.GetMessageCount();
}
public static void AddMessage(string subject, string text)
{
if (String.IsNullOrEmpty(subject))
throw new ArgumentException(Resources.SubjectEmpty, "subject");
if (String.IsNullOrEmpty(text))
throw new ArgumentException(Resources.TextEmpty, "text");
//Get the current membership user
MembershipUser user = Membership.GetUser();
string postedById = String.Empty;
string postedBy;
if (user == null)
{
postedBy = Resources.Anonymous;
}
else
{
postedById = user.ProviderUserKey.ToString();
postedBy = user.UserName;
}
_actualMessageProvider.AddMessage(subject, text, postedBy, postedById, DateTime.Now.ToUniversalTime());
}
/// <summary>
/// Finds a message given an Id and returns a collection of 1 element
/// </summary>
/// <param name="id">The id of the message</param>
/// <returns>A collection of 1 element. A collection is returned so that
/// end users can easily data bind
/// </returns>
public static IEnumerable<Message> GetMessageById(int id)
{
return _actualMessageProvider.GetMessageById(id);
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.