The MessageQueue property returns an ObservableCollection of strings for the messages sent by the runtime system as a response to a colon command. You can register for the CollectionChanged event on an ObservableCollection that notifies the client when an update has been performed on the collection; that is, when a new message has been received from the host application.
Namespace – ABSuite.AccessLayer.Connector.Core
Assembly – Unisys.ABSuite.AccessLayer.Connector.Core (in Unisys.ABSuite.AccessLayer.Connector.Core.dll)
Syntax
IEnumerable<string> MessageQueue { get; }Using the IUnsolicitedMessages Interface for the MessageQueue Property
The following code is an example of using the MessageQueue property for handling command responses:
// Declare a StringBuilder to hold the Command Responses
CommandResponesBuilder = new StringBuilder();
// Register for the CollectionChanged event for notification of
// new messages
ABSConnection.MessagesHandler.MessageQueue.CollectionChanged += (o, e) =>
{
this.QueueUpdate(e, ABSConnection.MessagesHandler.MessageQueue, this.CommandResponesBuilder);
};
// The QueueUpdate method handles changes in the
// ObeservableCollection of command and video report responses.
// When a message arrives, it is added to the
// StringBuilder parameter.
// If the Collection is Reset, the StringBuilder parameter is
// cleared and new messages are added.
private void QueueUpdate(NotifyCollectionChangedEventArgs e, IList<string> items, StringBuilder builder)
{
switch (e.Action)
{
case NotifyCollectionChangedAction.Add:
if (e.NewItems != null)
{
foreach (string item in e.NewItems)
{
if (item.Trim() == ">")
builder.Append(item);
else
builder.AppendLine(item);
}
}
break;
case NotifyCollectionChangedAction.Remove:
case NotifyCollectionChangedAction.Replace:
break;
case NotifyCollectionChangedAction.Reset:
{
builder.Clear();
foreach (string item in items)
builder.AppendLine(item);
}
break;
}
}