/// <summary> /// Pushes the command. /// </summary> /// <param name="command">The text command to send.</param> public void PushCommand([NotNull] Command command) { Assert.ArgumentNotNull(command, "command"); try { if (ConveyorUnitsByCommandType.ContainsKey(command.CommandType)) { foreach (var conveyorUnit in ConveyorUnitsByCommandType[command.CommandType]) { conveyorUnit.HandleCommand(command); if (command.Handled) { break; } } } if (!command.Handled) { foreach (var commandSerializer in _currentCommandSerializers) { commandSerializer.SerializeAndSendCommand(command); if (command.Handled) { break; } } } } catch (Exception ex) { ErrorLogger.Instance.Write(string.Format("Error push command: {0}\r\n{1}", ex.Message, ex.StackTrace)); } }
/// <summary> /// Adds the conveyor unit. /// </summary> public void AddConveyorUnit([NotNull] ConveyorUnit conveyorUnit, bool addToTop = false) { Assert.ArgumentNotNull(conveyorUnit, "conveyorUnit"); foreach (var handledMessageType in conveyorUnit.HandledMessageTypes) { if (!ConveyorUnitsByMessageType.ContainsKey(handledMessageType)) { ConveyorUnitsByMessageType[handledMessageType] = new List <ConveyorUnit>(); } if (addToTop) { ConveyorUnitsByMessageType[handledMessageType].Insert(0, conveyorUnit); } else { ConveyorUnitsByMessageType[handledMessageType].Add(conveyorUnit); } } foreach (var handledCommandType in conveyorUnit.HandledCommandTypes) { if (!ConveyorUnitsByCommandType.ContainsKey(handledCommandType)) { ConveyorUnitsByCommandType[handledCommandType] = new List <ConveyorUnit>(); } if (addToTop) { ConveyorUnitsByCommandType[handledCommandType].Insert(0, conveyorUnit); } else { ConveyorUnitsByCommandType[handledCommandType].Add(conveyorUnit); } } if (addToTop) { _allConveyorUnits.Insert(0, conveyorUnit); } else { _allConveyorUnits.Add(conveyorUnit); } }
public void ImportJMC(string line, RootModel rootModel) { var command = new TextCommand(line); if (ConveyorUnitsByCommandType.ContainsKey(command.CommandType)) { foreach (var conveyorUnit in ConveyorUnitsByCommandType[command.CommandType]) { try { conveyorUnit.HandleCommand(command, true); } catch { } if (command.Handled) { break; } } } }