Ejemplo n.º 1
0
        public unsafe ICell LoadGenericCell(Trinity.Storage.LocalMemoryStorage storage, long cellId)
        {
            ushort type;
            int    size;
            byte * cellPtr;
            int    entryIndex;

            var err = storage.GetLockedCellInfo(cellId, out size, out type, out cellPtr, out entryIndex);

            if (err != TrinityErrorCode.E_SUCCESS)
            {
                throw new CellNotFoundException("Cannot access the cell.");
            }

            switch ((CellType)type)
            {
            /*FOREACH*/
            case CellType.t_cell_name:
                var t_cell_name_accessor = new t_cell_name_Accessor(cellPtr);
                var t_cell_name_cell     = (t_cell_name)t_cell_name_accessor;
                storage.ReleaseCellLock(cellId, entryIndex);
                t_cell_name_cell.CellID = cellId;
                return(t_cell_name_cell);

                break;

            /*END*/
            default:
                throw new CellTypeNotMatchException("Cannot determine cell type.");
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Loads the content of the cell with the specified cell Id.
        /// </summary>
        /// <param name="storage">A <see cref="Trinity.Storage.MemoryCloud"/> instance.</param>
        /// <param name="cellId">A 64-bit cell Id.</param>
        /// <returns></returns>
        public unsafe ICell LoadGenericCell(Trinity.Storage.MemoryCloud storage, long cellId)
        {
            ushort type;

            byte[] buff;
            var    err = storage.LoadCell(cellId, out buff, out type);

            if (err != TrinityErrorCode.E_SUCCESS)
            {
                switch (err)
                {
                case TrinityErrorCode.E_CELL_NOT_FOUND:
                    throw new CellNotFoundException("Cannot access the cell.");

                case TrinityErrorCode.E_NETWORK_SEND_FAILURE:
                    throw new System.IO.IOException("Network error while accessing the cell.");

                default:
                    throw new Exception("Cannot access the cell. Error code: " + err.ToString());
                }
            }

            switch ((CellType)type)
            {
            /*FOREACH*/
            case CellType.t_cell_name:
                fixed(byte *t_cell_name_ptr = buff)
                {
                    t_cell_name_Accessor t_cell_name_accessor = new t_cell_name_Accessor(t_cell_name_ptr);

                    t_cell_name_accessor.CellID = cellId;
                    return((t_cell_name)t_cell_name_accessor);
                }

                break;

            /*END*/
            default:
                throw new CellTypeNotMatchException("Cannot determine cell type.");
            }
        }