예제 #1
0
        /// <summary>
        ///		Read cell data from the data source and fill the passed cell list.  This
        ///		method will raise an exception if 1) a supercell ID in the database is not
        ///		found in the Background assigned to this class (ArgumentException exception) or
        ///		2) a cell is assigned a reference to a neighbour that does not exist
        ///		(ArgumentException exception).
        /// </summary>
        /// <param name="Cells">
        ///		The cell list to fill.  The cells are added to any that are already in the
        ///		list.  An ArgumentNullException exception is raised if Cells is null.
        /// </param>
        /// <param name="SuperCells">
        ///		A list of Supercells that these cells will belong to.  An ArgumentNullException
        ///		is raised if SuperCells is null.  An ArgumentException is raised if SuperCells
        ///		is an empty list.
        /// </param>
        public void GetCellData(cCellList Cells, cSuperCellList Supercells)
        {
            // make sure Cells is not null
            if (Cells == null)
            {
                throw new ArgumentNullException("Cells", "Cells must not be null.");
            }
            // make sure Supercells is not null
            if (Supercells == null)
            {
                ThrowSupercellsException();
            }
            // the supercell list must contain at least one super cell
            if (Supercells.Count == 0)
            {
                throw new ArgumentException("Supercell list must contain at least one supercell.",
                                            "Supercells");
            }
            // retrieve the name of this list of cells
            Cells.Name = this.GetName();
            // create a cell data object
            cCellData CellData = new cCellData();

            // loop, loading cell data one at a time
            this.Reset();
            while (this.GetNextCellRecord(CellData))
            {
                // create the new cell
                cCell Cell = new cCell(CellData.ID, Supercells[CellData.SuperCellID],
                                       CellData.K, CellData.XLoc, CellData.YLoc);
                Cells.Add(Cell);
            }
            // loop again, this time assigning neighbours.  If an invalid refence exception
            // is thrown, then the neighbour ID is invalid.
            this.Reset();
            while (this.GetNextCellRecord(CellData))
            {
                // loop through the six neighbour positions
                for (int i = 0; i < 6; i++)
                {
                    // note: if the neighbour value in the datasource is "b", this indicates
                    // that the neighbour is on the bouandary
                    if (CellData.Neighbours[i] == "b")
                    {
                        Cells[CellData.ID].SetNeighbour((enumNeighbourPosition)i, null);
                    }
                    else
                    {
                        Cells[CellData.ID].SetNeighbour((enumNeighbourPosition)i,
                                                        Cells[CellData.Neighbours[i]]);
                    }
                }
            }
        }
예제 #2
0
 /// <summary>
 ///		Retrieves a single cell record from the data source and places it in the
 ///		passed cell data object.
 /// </summary>
 /// <param name="Data">The cell data object that will contain the cell data.</param>
 /// <returns>
 ///		True if the retrieval was successful, False if there are no more records to
 ///		retrieve.
 ///	</returns>
 protected abstract bool GetNextCellRecord(cCellData Data);