Våra sajter
Litium Studio Knowledgecenter

Knowledge Center för Litium Studio

Litium Scensum Knowledge Center

Knowledge Center för Litium Scensum

Litium Partner

Återfinns information som partner till Litium.

Support In English

Reach your objectives with the web!

The Internet has created entirely new business possibilities. It is all about making your company alive and available, and to bring your business model, the heart and soul of your company to web! No matter if it is your public homepage, your external, or your internal business support. On Litium, we sell products and services within web and e-commerce. Our publishing tool Litium studio is for example, one of Sweden's leading tools with 700 customers and 1200 installations.


About Litium

Litium Affärskommunikation Ltd is a Swedish software company that develops, adjusts and sells web. The solutions can be found in the concept of ”Enterprise Content Management” that give you, as customer, cost-effective work processing, better marketing and new business possibilities through the Internet

The company was founded in 1998 by the entrepreneurs Emil Danielsson, Hans Börjesson, Magnus Gramming, Mathias Bransmo and Mattias Stark. The company is owned by the founders, personnel, and stock-market listed FastPartner. In addition to intelligent mobile solutions, application development, and portal solutions, the publishing tool Litium studio is our front product. The first modules were developed in 1998 and are today, one of Sweden's leading tools with over 700 customers and 1200 installations.

Among our customers are the Swedish trade and commerce industry, special interest organizations, public organizations and medium sized companies within different branches of the Swedish industry. They have all seen the possibility to generate more business and to reach company objectives with the web. Today we have 90 highly dedicated employees in our offices in Jönköping, Stockholm, Helsingborg and Göteborg.

Contacts 

 

Jönköping Stockholm
Parkgatan 2
SE-553 15 Jönköping
S:t Göransgatan 66, 6tr
SE-112 33 Stockholm
 +46-(0)36 – 210 33 00
 info@litium.se
 +46-(0)8 – 586 434 00
 info@litium.se
   
Göteborg

Helsingborg

Stora Badhusgatan 18-20
SE-411 21 Göteborg 
Järnvägsgatan 11
SE-252 24 Helsingborg
 +46-(0)31 - 350 35 00
 info@litium.se
 +46-(0)42-600 21 00
 info@litium.se

 

 

 

 

Framework - Messaging

Litium.Framework.Messaging

MessengerBase

To send a certain type of mail (for example tip a friend mail), you need to implement a messenger. This is done by extending the MessengerBase class.
When extending it, the generic type TMessageArgs must be specified. This should be an object to pass when sending the e-mail. An example of this could be an Order object which contains the customers e-mail and other things needed. But it could also be a specially made object like the TipAFriendMessageArgs-object used below.
Two methods/properties need to be implemented. They are MessengerName which can be used for settings and other things and CreateMessage which creates the actual message.
The example below doesn't show it, but there's no problem in making the messenger as a singleton.

Example

public class TipAFriendMessenger : MessengerBase<TipAFriendMessageArgs>
{
	protected override string MessengerName
	{
		get { return "TipAFriend"; }
	}

	protected override Message CreateMessage(TipAFriendMessageArgs messageArgs)
	{
		if (messageArgs == null) throw new ArgumentNullException("messageArgs");

		string body = ...snip...;
		string subject = ...snip...;

		var message = new EmailMessage
		              	{
		              		Body = body,
		              		ProviderName = "email",
		              		FromName = messageArgs.MyName,
		              		FromEmail = messageArgs.MyEmail,
		              		Subject = subject,
		              		Type = MessageType.Single
		              	};

		message.Recipients.Add(new EmailRecipient
		                       	{
		                       		Name = messageArgs.FriendName,
		                       		Address = messageArgs.FriendEmail
		                       	});

		return message;
	}
}

To call the send

Guid id = new TipAFriendMessenger().Send(new TipAFriendMessageArgs( ... )); 

Provider

To send a certain kind of message (e-mail, sms, mms etc.), a provider needs to be implemented. This is done by implementing the interface IMessageProvider. Two methods need to be implemented. They are ValidateMessage which validates the message before sending and SendMessage which sends the message to the recipients passed to it. The provider locator uses the Castle Windsor IoC container to resolve the implementation for a provider. App/Web.config needs to specify the path to the IoC-config file:

<add key="Messaging.IoCConfigPath" value="..\..\..\Setting\Messaging.IoC.xml" />

Example

An example of an e-mail provider:

public class EmailProvider : IMessageProvider
{
	public bool ValidateMessage(MessageTiny message, out string validationError)
	{
		if (string.IsNullOrEmpty(message.Body))
		{
			validationError = "Body is not set.";
			return false;
		}

		... more validation ...

		validationError = null;
		return true;
	}

	public void SendMessage(MessageTiny message, Collection<recipient> recipients)
	{
		var from = new MailAddress(
			message.CustomFields["FromEmail"],
			message.CustomFields["FromName"]);

		foreach (Recipient recipient in recipients)
		{
			SendMessageToRecipient(
				message.CustomFields["Subject"],
message.Body,
				from, recipient);
		}
	}

	private static void SendMessageToRecipient(
		string subject, string body, MailAddress from, Recipient recipient)
	{
		... send e-mail ...
	}
}

Settings

There are different kinds of settings. These are implemented with Litium.Framework.Setting. To get these working you need to specify the path to the XML-files:

<add key="SettingXmlFilePathTemplate" value="..\..\..\Setting\{0}.xml" />

MessageType

Message types are a way of categorize e-mails and send e-mails in separate categories simultaneously. E.g. if a news letter with 100 000 recipients is sending, it should not block forgot password e-mails. The message types are: Single, SmallBulk and LargeBulk It's also possible to have different settings for different types. Sending To send the mails placed in the queue, the sender must be started. This is done by calling:

MessageSender.Start();

This will start one background thread for each MessageType. This can be called from a separate windows service or be called from Application_Start in Global.asax in a web project. With settings you can change the sleep time between sends and the number of messages that should be sent in each batch. This can be different for the different message types.

Clean-up

The clean-up handles batches and messages stuck in an invalid state and also remove old sent messages. The clean-up is started by calling:

MessageCleaner.Start();

DeleteEmptyBatches

Deletes all batches with an end date and that doesn't have any messages or recipients connected to it.

FinishOldUnfinishedBatches

Sets end date on old batches that are missing an end date.
Uses the setting: HoursBeforeFinishingBatch

DeleteOldCompletedBatches

Deletes old batches.
Uses the setting: DaysBeforeDeletingBatch

ResetStatusOnMessages

Resets the status to ReadyToSend on old messages with the status InProgress.
Uses the setting: HoursBeforeResettingStatusFromInProgress

Logging

Log4net is used for logging.