2using System.Collections.Generic;
3using System.Net.NetworkInformation;
4using System.Threading.Tasks;
17 private Dictionary<string, Parameter> parameters =
null;
18 private IEvent eventReference;
21 private string eventId;
22 private string actorName;
37 public string Name => this.name;
67 public IEnumerable<Parameter>
Parameters => this.parameters?.Values;
84 public override Task
FromXml(XmlElement Definition)
90 return base.FromXml(Definition);
100 while (!(Loop is
null))
113 throw new Exception(
"External event registered on a node that is not hosted by an actor.");
115 return Task.CompletedTask;
124 throw new Exception(
"Event node not found: " + this.eventId);
139 if (this.parameters is
null)
140 this.parameters =
new Dictionary<string, Parameter>();
142 if (this.parameters.ContainsKey(
Name))
143 throw new Exception(
"A parameter named " +
Name +
" has already been registered for external event " + this.eventId);
154 public void Trigger(
IActor Source, params KeyValuePair<string, object>[] Arguments)
158 if (!
string.IsNullOrEmpty(this.actorName))
161 if (!(this.parameters is
null))
165 foreach (KeyValuePair<string, object> P
in Arguments)
167 if (this.parameters.TryGetValue(P.Key, out
Parameter P2))
170 if (
string.IsNullOrEmpty(
Name))
Root node of a simulation model
Variables GetEventVariables(IActor Actor)
Gets a collection of variables for a new event.
bool TryGetEvent(string Id, out IEvent Event)
Tries to get a registered event from the model.
Abstract base class for events
Handles an incoming event raised from an external source
override Task Initialize()
Initialized the node before simulation.
string EventId
Optional name for variable, if different from Name
string ActorName
Optional name for actor variable reference of sender of external event.
override Task FromXml(XmlElement Definition)
Sets properties and attributes of class in accordance with XML definition.
override ISimulationNode Create(ISimulationNode Parent, Model Model)
Creates a new instance of the node.
void Trigger(IActor Source, params KeyValuePair< string, object >[] Arguments)
Method called when an external event has been received.
ExternalEvent(ISimulationNode Parent, Model Model)
Handles an incoming event raised from an external source
string Name
Name of external event
void Register(Parameter Parameter)
Registers a parameter with the external event.
IExternalEventsNode Events
Reference to collection of external events.
IEnumerable< Parameter > Parameters
Parameters
override Task Start()
Starts the node.
override string LocalName
Local name of XML element defining contents of class.
Sets a variable to the value of an event parameter.
string Name
Name of external event
Abstract base class for simulation nodes with children
Helps with common XML-related tasks.
static string Attribute(XmlElement E, string Name)
Gets the value of an XML attribute.
Basic interface for simulator nodes. Implementing this interface allows classes with default contruct...
ISimulationNode Parent
Parent node in the simulation model.
Basic interface for simulator nodes. Implementing this interface allows classes with default contruct...
object ActivityObject
Returns the object that will be used by the actor for actions during an activity.
Task Trigger(Variables Variables, Expression Guard=null, int GuardLimit=int.MaxValue)
Triggers the event.
void Register(IEventPreparation PreparationNode)
Registers an event preparation node.
Interface for external events.
Interface for nodes that can register external events.
void Register(IExternalEvent ExternalEvent)
Registers an external event on the actor.