Пример #1
0
        public bool HasPower(IPlugable connection)
        {
            Grid grid;

            IsPluggedIn(connection, out grid);
            return(grid != null && grid.IsOperating);
        }
Пример #2
0
        /// <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));
        }
Пример #3
0
        /// <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);
        }
Пример #4
0
        private float GetOutputRate(IPlugable connection, float outputRate = 0.0f)
        {
            if (outputRate.IsZero())
            {
                outputRate = connection.OutputRate;
            }

            return(connection.AccumulatedAmount - outputRate < 0.0f ? connection.AccumulatedAmount : outputRate);
        }
Пример #5
0
        /// <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);
        }
Пример #6
0
        public bool CanPlugIn(IPlugable connection)
        {
            if (connection == null)
            {
                throw new ArgumentNullException("connection");
            }

            return(powerGrids.Any(grid => grid.CanPlugIn(connection)));
        }
Пример #7
0
        public bool PlugIn(IPlugable connection, Grid grid)
        {
            if (connection == null)
            {
                throw new ArgumentNullException("connection");
            }

            return(grid != null && grid.PlugIn(connection));
        }
Пример #8
0
        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));
        }
Пример #9
0
        public void Unplug(IPlugable connection, Grid grid)
        {
            if (connection == null)
            {
                throw new ArgumentNullException("connection");
            }

            if (grid == null)
            {
                throw new ArgumentNullException("grid");
            }

            grid.Unplug(connection);
        }
Пример #10
0
        /// <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);
        }
Пример #11
0
        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);
        }
Пример #12
0
        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));
        }
Пример #13
0
        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);
        }