public bool HasPower(IPlugable connection) { Grid grid; IsPluggedIn(connection, out grid); return(grid != null && grid.IsOperating); }
/// <summary> /// Determines whether the connection is plugged into this Grid. /// </summary> /// <returns><c>true</c> if the connection is plugged into this Grid; otherwise, <c>false</c>.</returns> public bool IsPluggedIn(IPlugable connection) { if (connection == null) { throw new ArgumentNullException("connection"); } return(connections.Contains(connection)); }
/// <summary> /// Determines whether the connection can plug into this grid. /// </summary> /// <returns><c>true</c> if the connection can plug into this grid; otherwise, <c>false</c>.</returns> public bool CanPlugIn(IPlugable connection) { if (connection == null) { throw new ArgumentNullException("connection"); } return(true); }
private float GetOutputRate(IPlugable connection, float outputRate = 0.0f) { if (outputRate.IsZero()) { outputRate = connection.OutputRate; } return(connection.AccumulatedAmount - outputRate < 0.0f ? connection.AccumulatedAmount : outputRate); }
/// <summary> /// Unplug the specified IPlugable from this Grid. /// </summary> /// <param name="connection">IPlugable to be unplugged.</param> public void Unplug(IPlugable connection) { if (connection == null) { throw new ArgumentNullException("connection"); } connections.Remove(connection); }
public bool CanPlugIn(IPlugable connection) { if (connection == null) { throw new ArgumentNullException("connection"); } return(powerGrids.Any(grid => grid.CanPlugIn(connection))); }
public bool PlugIn(IPlugable connection, Grid grid) { if (connection == null) { throw new ArgumentNullException("connection"); } return(grid != null && grid.PlugIn(connection)); }
public bool PlugIn(IPlugable connection, Grid grid) { if (connection == null) { throw new ArgumentNullException("connection"); } if (!powerGrids.Contains(grid)) { powerGrids.Add(grid); } return(grid != null && grid.PlugIn(connection)); }
public void Unplug(IPlugable connection, Grid grid) { if (connection == null) { throw new ArgumentNullException("connection"); } if (grid == null) { throw new ArgumentNullException("grid"); } grid.Unplug(connection); }
/// <summary> /// Plugs the IPlugable into this grid. /// </summary> /// <returns><c>true</c>, if in was plugged, <c>false</c> otherwise.</returns> /// <param name="connection">IPlugable to be plugged in.</param> public bool PlugIn(IPlugable connection) { if (connection == null) { throw new ArgumentNullException("connection"); } if (!CanPlugIn(connection)) { return(false); } connections.Add(connection); return(true); }
public bool IsPluggedIn(IPlugable connection, out Grid grid) { if (connection == null) { throw new ArgumentNullException("connection"); } if (IsEmpty) { grid = null; return(false); } grid = powerGrids.FirstOrDefault(powerGrid => powerGrid.IsPluggedIn(connection)); return(grid != null); }
public bool PlugIn(IPlugable connection) { if (connection == null) { throw new ArgumentNullException("connection"); } if (IsEmpty) { powerGrids.Add(new Grid()); } Grid powerGrid = powerGrids.First(grid => grid.CanPlugIn(connection)); return(PlugIn(connection, powerGrid)); }
public void Unplug(IPlugable connection) { if (connection == null) { throw new ArgumentNullException("connection"); } Grid grid; IsPluggedIn(connection, out grid); if (grid == null) { return; } Unplug(connection, grid); }