public void AddConnection(LogicInput input) { if (input == null) throw new ArgumentNullException("input"); lock (input) { if (input.ConnectedBy == this) return; if (input.ConnectedBy != null) throw new ArgumentException("input is already connected"); //we need to check if type is compatible if (!input.InputType.IsAssignableFrom(OutputType)) throw new ArgumentException(String.Format("port-type mismatch: can't connect input-type '{0}' to output-type '{1}'", input.InputType, OutputType)); input.ConnectedBy = this; lock (connections) { connections.Add(input); } } SendValueToConnection(input, Value); }
private void SendValueToConnection(LogicInput connection, Value value) { House house = Component.House; if (house != null) { house.EnqueueTask(new UpdateValueTask(connection, value)); } }
public bool RemoveConnection(LogicInput input) { lock (input) { if (input.ConnectedBy != this) { return false; } lock (connections) { input.ConnectedBy = null; SendValueToConnection(input, null); return connections.Remove(input); } } }