2using System.Collections.Generic;
4using System.Threading.Tasks;
24 public const string MqNamespace =
"http://lab.tagroot.io/Schema/ComSim/MQ.xsd";
29 public const string MqSchema =
"TAG.Simulator.MQ.Schema.ComSimMq.xsd";
34 private Task connectionTask;
35 private string queueManager;
36 private string channel;
37 private string userName;
38 private string password;
39 private string cipher;
40 private string cipherSuite;
41 private string certificateStore;
102 public override Task
FromXml(XmlElement Definition)
106 this.queueManager =
XML.
Attribute(Definition,
"queueManager");
111 this.cipherSuite =
XML.
Attribute(Definition,
"cipherSuite");
112 this.certificateStore =
XML.
Attribute(Definition,
"certificateStore");
114 return base.FromXml(Definition);
131 queueManager = this.queueManager,
132 channel = this.channel,
134 password = this.password,
135 cipher = this.cipher,
136 cipherSuite = this.cipherSuite,
137 certificateStore = this.certificateStore
140 return Task.FromResult<
Actor>(Result);
152 if (this.credentials is
null)
157 UserName = this.userName,
158 Password =
string.IsNullOrEmpty(this.password) ? string.Empty : await this.
Model.
GetKey(this.password, this.userName)
164 if (this.sniffer is
null)
165 this.client =
new MqClient(this.queueManager, this.channel, this.cipher, this.cipherSuite, this.certificateStore, this.host, this.port);
167 this.client =
new MqClient(this.queueManager, this.channel, this.cipher, this.cipherSuite, this.certificateStore, this.host, this.port, this.sniffer);
169 this.connectionTask = this.client.
ConnectAsync(this.credentials.
UserName,
this.credentials.Password);
177 await this.connectionTask;
179 if (
string.IsNullOrEmpty(this.credentials.
ObjectId))
184 List<SubscriptionState> Subscriptions =
new List<SubscriptionState>();
192 SubscriptionState Subscription =
new SubscriptionState()
198 Cancel =
new ManualResetEvent(
false),
199 Stopped =
new TaskCompletionSource<bool>()
202 Subscription.Subscribe(this.Client);
203 Subscriptions.Add(Subscription);
208 this.subscriptions = Subscriptions.ToArray();
211 private SubscriptionState[] subscriptions;
213 private class SubscriptionState : IDisposable
215 public string ExtEventName;
219 public ManualResetEvent Cancel;
220 public TaskCompletionSource<bool> Stopped;
222 public void Dispose()
232 private Task MessageReceived(
object Sender, MqMessageEventArgs e)
235 new KeyValuePair<string, object>(
"Message", e.Message),
236 new KeyValuePair<string, object>(
"Client",
this.Actor.client));
238 return Task.CompletedTask;
247 foreach (SubscriptionState State
in this.subscriptions)
250 foreach (SubscriptionState State
in this.subscriptions)
251 await State.Stopped.Task;
256 if (!(this.sniffer is
null))
258 if (this.sniffer is IDisposable Disposable)
259 Disposable.Dispose();
275 UserName = this.userName,
string UserName
Account user name
Object used in simulation activities.
MQ Actor connecting to the MQ network using traditional TCP.
override string Namespace
XML Namespace where the element is defined.
override Task< Actor > CreateInstanceAsync(int InstanceIndex, string InstanceId)
Creates an instance of the actor.
MqActorTcp(ISimulationNode Parent, Model Model, int InstanceIndex, string InstanceId)
Abstract base class for MQ actors.
override string SchemaResource
Points to the embedded XML Schema resource defining the semantics of the XML namespace.
override async Task FinalizeInstance()
Finalizes an instance of an actor.
const string MqNamespace
http://lab.tagroot.io/Schema/ComSim/MQ.xsd
override string LocalName
Local name of XML element defining contents of class.
override async Task StartInstance()
Starts an instance of an actor.
override ISimulationNode Create(ISimulationNode Parent, Model Model)
Creates a new instance of the node.
override async Task InitializeInstance()
Initializes an instance of an actor.
override object ActivityObject
Returns the object that will be used by the actor for actions during an activity.
override Task FromXml(XmlElement Definition)
Sets properties and attributes of class in accordance with XML definition.
const string MqSchema
TAG.Simulator.MQ.Schema.ComSimMq.xsd
MqActorTcp(ISimulationNode Parent, Model Model)
MQ Actor connecting to the MQ network using traditional TCP.
Represents a queue subscription
string ExtEvent
External Event Name
void Dispose()
IDisposable.Dispose
Task ConnectAsync(string UserName, string Password)
Connects to the Queue Manager asynchronously.
void SubscribeIncoming(string QueueName, MqMessageEventHandler Callback, object State)
Subscribes to incoming messages.
Root node of a simulation model
async Task< string > GetKey(string KeyName, string LookupValue)
Gets a key from the database. If it does not exist, it prompts the user for input.
ISniffer GetSniffer(string Actor)
Gets a sniffer, if sniffer output is desired.
bool ExternalEvent(IExternalEventsNode Source, string Name, params KeyValuePair< string, object >[] Arguments)
Method called when an external event has been received.
Abstract base class for actors
string InstanceId
ID of actor instance.
int InstanceIndex
Actor instance index.
Variables Variables
Collection of actor-variables.
Model Model
Model in which the node is defined.
Helps with common XML-related tasks.
static string Attribute(XmlElement E, string Name)
Gets the value of an XML attribute.
Static interface for database persistence. In order to work, a database provider has to be assigned t...
static async Task Insert(object Object)
Inserts an object into the default collection of the database.
This filter selects objects that conform to all child-filters provided.
This filter selects objects that have a named field equal to a given value.
Class managing a script expression.
static Task< string > TransformAsync(string s, string StartDelimiter, string StopDelimiter, Variables Variables)
Transforms a string by executing embedded script.
Basic interface for simulator nodes with child nodes.
Basic interface for simulator nodes. Implementing this interface allows classes with default contruct...
ISimulationNode Parent
Parent node in the simulation model.
Interface for sniffers. Sniffers can be added to ICommunicationLayer classes to eavesdrop on communic...