Listener Class

A thread safe abstract listener. It can be used to wait for unrequested incomming data and pass them to some communicator for dispatch. Or it can be used to fire an arbitrary action depending on receved data. This class is expected to be serialized in xml file.

Definition

Namespace: OddPrg.Communication
Assembly: OddPrg.Communication.Listeners (in OddPrg.Communication.Listeners.dll) Version: 1.0.0.0 (1.0.0.0)
C#
public abstract class Listener : IDisposable
Inheritance
Object    Listener
Derived
Implements
IDisposable

Constructors

Listener Used by a XmlSerializer to create a new instance of Listener descendant.

Properties

Active Indicates inf the listener is listening.
ActiveOnStartup Indicates whether the hosting service should start this listener on startup.
ByteDisplayMode Style to display data in a log.
Debug Indicates if debug log is created or not.
DisableEvents Whether the listener does not accept spontaneous events.
DisplayBytesLength Count of bytes to display on a single line in a log. It is applicable only if DefaultByteDisplayMode is set to ByteDisplayModes.Hex.
DisplaySystemChars Applies to ByteDisplayMode is Chars or Lines. Whether to display characters lower than 32. Their hex codes prefixed with '#' will be displayed in a log.
ID Unique listener identifier among all listeners used.
Info Returns a brief description including main parameters.
InputEncoding Encoding used to convert incomming bytes to string. It is used to display correct characters in a log if ByteDisplayMode is set to Chars or Lines.
InputEncodingCodePage Code page of InputEncoding used by xml serializer to store the code page.
InputLineSeparator Line separators to control displaying bytes if ByteDisplayMode is equal to ByteDisplayModes.Lines.
InputLineSeparatorStr InputLineSeparator as string used by xml serializer to store InputLineSeparator property.
InterfaceName Returns listener interface name.
IsNotResponding Indicates that listener is not responding although many rquests were done. It may indicate that listener driver is in failed state and wathdog file for this listener should not be updated. Applied especially for PLC. For all other listerens returns false.
ListenerParams Parameters of the listener.
ListenerParamValues Property used to store listener parameters.
LogDir Directory where listener logs should be stored. Listener creates every day one file. You have to initialize this property after listener is created or loaded otherwise no logging support will be provided.
Name Name of the listener displayed in the log.
OutputEncoding Encoding used to convert outgoing bytes to string. It is used to display correct characters in a log if ByteDisplayMode is set to Chars or Lines.
OutputEncodingCodePage Code page of OutputEncoding used by xml serializer to store the code page.
OutputLineSeparator Line separators to control displaying bytes if ByteDisplayMode is equal to ByteDisplayModes.Lines.
OutputLineSeparatorStr OutputLineSeparator as string used by xml serializer to store OutputLineSeparator property.
Setup Returns a string describing the current listener setup.
UpdateWatchdogFile Whethrer watchdog file should be created and regularly updated for this listener to check if this listener is active.

Methods

CreateLogDataLines Creates lines for communication log of incoming/outgoing data formatted according to the listener settings.
Dispose IDisposable.Dispose implementation
IsCommunicatorForSource Returns true if communicator passed as parameter is the one that can accept incoming data of this listener. Otherwise it returns false.
Load Loads a listener from xml file and returns it.
LoadLog(DateTime) Loads specified log files and returns their contents.
LoadLog(String, String, DateTime, DateTime) Loads specified log files and returns their contents.
ParseLogMessageLine Parses line stored in listener log.
RegisterCommunicator Registers a communicator to start receive incoming data of this listener.
ShutDown Stops listening and dispatching data.
Start Starts listening and dispatching incoming data.
Store Stores current listener to a xml file with file name indicated by FileName property.
UnregisterCommunicator Unregisters a communicator to stop receive incoming data of this listener.

Fields

AdditionalDispatch Procedure that is executed anytime some data are received by this listener. It allows to fire some additional action that is not requested by any communicator. This procedure is executed in listener waiting loop and therefore should return immediately. Time consuming operations (like database operations) should be executed in a new thread.
LogLineAdded Procedure that is executed anytime a new line is added to a listener log.
OnBuildExceptionMessage Procedure that builds error message for log. If it is not set, only exception message is logged.
OnConnected Procedure used to notify about remote client connection. This procedure is executed in listener waiting loop and therefore should return immediately. Time consuming operations (like database operations) should be executed in a new thread. Throwing an exception in this procedure could shut down the listener.
OnDisconnected Procedure used to notify about remote client disconnection. This procedure is executed in listener waiting loop and therefore should return immediately. Throwing an exception in this procedure could shut down the listener.
OnFailure Procedure used to notify about listener shutdown due to an error.
OnGetCurrentTime Procedure that returns current date/time. This procedure can be set if other time than DateTime.Now needs to be returned as current date/time. If this property is null, DateTime.Now is used as current date/time.
OnShutdown Procedure used to notify about successfull listener stop.
OnStartup Procedure used to notify about sucessfull listener startup.

See Also