Table of Contents

Class MessageService

Namespace
Loehnert.Lisrt.Messaging
Assembly
Loehnert.Lisrt.dll

Class for the loggers and other messaging functions.

public class MessageService
Inheritance
MessageService
Inherited Members
Extension Methods

Remarks

This class has a Singleton-Pattern and is initialized with the first access. For using you have to use MessageService.Instance. ...

Properties

CurrentMessages

Gets a collection of IMessage items which were set or not acknowledged.

public MessageCollection CurrentMessages { get; }

Property Value

MessageCollection

ExceptionTranslator

Gets the exception translator.

public ExceptionTranslator ExceptionTranslator { get; }

Property Value

ExceptionTranslator

Instance

Gets the instance of MessageService.

public static MessageService Instance { get; }

Property Value

MessageService

Remarks

Initialize the LoggerFactory and complete the dictionary for the ExceptionTranslator. Adds event handler for AppDomain.CurrentDomain.FirstChanceException to do ShowException(Exception, ILogger).

LoggerFactory

Gets the logger factory.

public ILoggerFactory LoggerFactory { get; }

Property Value

ILoggerFactory

Remarks

Factory for producing a Logger. LoggerFactory must be set in the App.config, otherwise NLogLoggerFactory will be used.

RootModules

Gets or sets the root modules. Set this property to show module name in messages.

public IEnumerable<ILisrtModule> RootModules { get; set; }

Property Value

IEnumerable<ILisrtModule>

Methods

Acknowledge()

Clears all acknowledgeable messages from CurrentMessages .

public void Acknowledge()

AddStateMessage(IStateMessage)

public void AddStateMessage(IStateMessage message)

Parameters

message IStateMessage

The IMessage item to add.

Exceptions

ArgumentNullException

Thrown when message has value null.

LogCommunication(string, TransmissionDirection, byte[], string, ILogger)

Rise the CommunicationLogged and logs with ILogger.

public void LogCommunication(string moduleName, TransmissionDirection direction, byte[] data, string comment = "", ILogger logger = null)

Parameters

moduleName string

The communicating ILisrtModules full name.

direction TransmissionDirection

The communication direction.

data byte[]

The sent data.

comment string

Comment for the data.

logger ILogger

Logger instance, if null then set in MessageService.

LogCommunication(string, TransmissionDirection, string, string, ILogger)

Rise the CommunicationLogged and logs with ILogger.

public void LogCommunication(string moduleName, TransmissionDirection direction, string data, string comment = "", ILogger logger = null)

Parameters

moduleName string

The communicating ILisrtModules full name.

direction TransmissionDirection

The communication direction.

data string

The sent data.

comment string

Comment for the data.

logger ILogger

Logger instance. When it is null, the MessageService logger is used.

RemoveStateMessage(IStateMessage)

Remove a existing IStateMessage from CurrentMessages.

public bool RemoveStateMessage(IStateMessage message)

Parameters

message IStateMessage

IStateMessage which exists in CurrentMessages.

Returns

bool

True if the element is successfully found and removed; otherwise, false.

Exceptions

ArgumentNullException

Thrown when message has value null.

ShowException(Exception, ILogger)

Shows and logs an Exception.

public void ShowException(Exception ex, ILogger logger)

Parameters

ex Exception

Exception to show, if null then set in MessageService.

logger ILogger

Logger instance, if null then set in MessageService.

ShowMessage(IMessage, ILogger)

Log a IMessage and add it to the CurrentMessages.

public void ShowMessage(IMessage message, ILogger logger)

Parameters

message IMessage

Message with IMessage, if null then set to MessageBase.

logger ILogger

Logger instance with ILogger, if null then set in MessageService.

Events

Acknowledged

Occurs after acknowledgment.

public event EventHandler Acknowledged

Event Type

EventHandler

CommunicationLogged

Occurs when a communication transmission was logged.

public event EventHandler<CommunicationLoggedEventArgs> CommunicationLogged

Event Type

EventHandler<CommunicationLoggedEventArgs>

Remarks