/// <summary> /// Sends the given <see cref="ModelAction"/> output. /// </summary> public void SendModelOutput(ModelAction modelOutput) { lock (locker) { // Pre-filter incompatible types. if (modelOutput is null) { throw new ArgumentNullException(nameof(modelOutput)); } if (!ModelOutputs.Contains(modelOutput.GetType())) { return; } Log.Debug(this, nameof(SendModelOutput) + ": " + modelOutput); string serialized = modelOutput.Serialize(); TorXakisAction output = TorXakisAction.FromOutput(TorXakisModel.OutputChannel, serialized); Connector.SendOutput(output); } }
/// <summary> /// Indexes the <see cref="ModelInputs"/> and <see cref="SystemEvents"/>, /// plus <see cref="ModelOutputs"/> and <see cref="SystemCommands"/>, /// whenever a <see cref="TransitionSystem"/> is added or removed. /// </summary> private void IndexSystems() { ModelInputs.Clear(); ModelOutputs.Clear(); SystemCommands.Clear(); SystemEvents.Clear(); foreach (TransitionSystem system in Systems) { foreach (Transition transition in system.Transitions) { if (transition is ReactiveTransition reactive) { if (typeof(ModelAction).IsAssignableFrom(reactive.Action)) { ModelInputs.Add(reactive.Action); } else if (typeof(ISystemAction).IsAssignableFrom(reactive.Action)) { SystemEvents.Add(reactive.Action); } } else if (transition is ProactiveTransition proactive) { if (typeof(ModelAction).IsAssignableFrom(proactive.Action)) { ModelOutputs.Add(proactive.Action); } else if (typeof(ISystemAction).IsAssignableFrom(proactive.Action)) { SystemCommands.Add(proactive.Action); } } } } }
/// <summary><see cref="object.ToString"/></summary> public override string ToString() { return(GetType().Name + "\n" + nameof(Connector) + ": " + Connector + "\n" + nameof(Systems) + " (" + Systems.Count + "): " + string.Join(", ", Systems.Select(x => x.ModelAction.Name).ToArray()) + "\n" + nameof(CurrentSystem) + ": " + CurrentSystem + "\n" + nameof(ModelInputs) + " (" + ModelInputs.Count + "): " + string.Join(", ", ModelInputs.Select(x => x.Name).ToArray()) + "\n" + nameof(ModelOutputs) + " (" + ModelOutputs.Count + "): " + string.Join(", ", ModelOutputs.Select(x => x.Name).ToArray()) + "\n" + nameof(SystemCommands) + " (" + SystemCommands.Count + "): " + string.Join(", ", SystemCommands.Select(x => x.Name).ToArray()) + "\n" + nameof(SystemEvents) + " (" + SystemEvents.Count + "): " + string.Join(", ", SystemEvents.Select(x => x.Name).ToArray())); }