Beispiel #1
0
        public unsafe ICellAccessor UseGenericCell(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)
            {
            case CellType.Movie:
                return(Movie_Accessor.New(CellId, cellPtr, entryIndex, CellAccessOptions.ThrowExceptionOnCellNotFound));

            case CellType.Celebrity:
                return(Celebrity_Accessor.New(CellId, cellPtr, entryIndex, CellAccessOptions.ThrowExceptionOnCellNotFound));

            default:
                storage.ReleaseCellLock(CellId, entryIndex);
                throw new CellTypeNotMatchException("Cannot determine cell type.");
            }
        }
Beispiel #2
0
        /// <inheritdoc/>
        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.");
            }
            try
            {
                var accessor = UseGenericCell(cellId, cellPtr, entryIndex, type);
                var cell     = accessor.Deserialize();
                accessor.Dispose();
                return(cell);
            }
            catch (Exception ex)
            {
                storage.ReleaseCellLock(cellId, entryIndex);
                ExceptionDispatchInfo.Capture(ex).Throw();
                throw;
            }
        }
Beispiel #3
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.");
            }
        }
Beispiel #4
0
        /// <inheritdoc/>
        public unsafe ICellAccessor UseGenericCell(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:
                return(t_cell_name_Accessor._get()._Setup(cellId, cellPtr, entryIndex, CellAccessOptions.ThrowExceptionOnCellNotFound));

            /*END*/
            default:
                storage.ReleaseCellLock(cellId, entryIndex);
                throw new CellTypeNotMatchException("Cannot determine cell type.");
            }
        }
Beispiel #5
0
        /// <summary>
        /// Allocate a generic cell accessor on the specified cell.
        /// If <c><see cref="Trinity.TrinityConfig.ReadOnly"/> == false</c>,
        /// on calling this method, it attempts to acquire the lock of the cell,
        /// and blocks until it gets the lock.
        /// </summary>
        /// <param name="storage">A <see cref="Trinity.Storage.LocalMemoryStorage"/> instance.</param>
        /// <param name="CellId">The id of the specified cell.</param>
        /// <param name="options">Specifies write-ahead logging behavior. Valid values are CellAccessOptions.StrongLogAhead(default) and CellAccessOptions.WeakLogAhead. Other values are ignored.</param>
        /// <returns>A <see cref="t_Namespace.GenericCellAccessor"/> instance.</returns>
        public unsafe ICellAccessor UseGenericCell(Trinity.Storage.LocalMemoryStorage storage, long CellId, CellAccessOptions options)
        {
            ushort type;
            int    size;
            byte * cellPtr;
            int    entryIndex;

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

            switch (err)
            {
            case TrinityErrorCode.E_SUCCESS:
                break;

            case TrinityErrorCode.E_CELL_NOT_FOUND:
            {
                if ((options & CellAccessOptions.ThrowExceptionOnCellNotFound) != 0)
                {
                    Throw.cell_not_found(CellId);
                }
                else if ((options & CellAccessOptions.CreateNewOnCellNotFound) != 0)
                {
                    throw new ArgumentException("CellAccessOptions.CreateNewOnCellNotFound is not valid for this method. Cannot determine new cell type.", "options");
                }
                else if ((options & CellAccessOptions.ReturnNullOnCellNotFound) != 0)
                {
                    return(null);
                }
                else
                {
                    Throw.cell_not_found(CellId);
                }
                break;
            }

            default:
                throw new CellNotFoundException("Cannot access the cell.");
            }

            switch ((CellType)type)
            {
            /*FOREACH*/
            case CellType.t_cell_name:
                return(t_cell_name_Accessor.New(CellId, cellPtr, entryIndex, options));

            /*END*/
            default:
                storage.ReleaseCellLock(CellId, entryIndex);
                throw new CellTypeNotMatchException("Cannot determine cell type.");
            }
            ;
        }
Beispiel #6
0
        /// <inheritdoc/>
        public unsafe ICellAccessor UseGenericCell(Trinity.Storage.LocalMemoryStorage storage, long cellId, CellAccessOptions options)
        {
            ushort type;
            int    size;
            byte * cellPtr;
            int    entryIndex;

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

            switch (err)
            {
            case TrinityErrorCode.E_SUCCESS:
                break;

            case TrinityErrorCode.E_CELL_NOT_FOUND:
            {
                if ((options & CellAccessOptions.ThrowExceptionOnCellNotFound) != 0)
                {
                    Throw.cell_not_found(cellId);
                }
                else if ((options & CellAccessOptions.CreateNewOnCellNotFound) != 0)
                {
                    throw new ArgumentException("CellAccessOptions.CreateNewOnCellNotFound is not valid for this method. Cannot determine new cell type.", "options");
                }
                else if ((options & CellAccessOptions.ReturnNullOnCellNotFound) != 0)
                {
                    return(null);
                }
                else
                {
                    Throw.cell_not_found(cellId);
                }
                break;
            }

            default:
                throw new CellNotFoundException("Cannot access the cell.");
            }

            try
            {
                return(UseGenericCell(cellId, cellPtr, entryIndex, type, options));
            }
            catch (Exception ex)
            {
                storage.ReleaseCellLock(cellId, entryIndex);
                ExceptionDispatchInfo.Capture(ex).Throw();
                // should never reach here
                throw;
            }
        }
Beispiel #7
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)
            {
            case CellType.Movie:
                var Movie_accessor = new Movie_Accessor(cellPtr);
                var Movie_cell     = (Movie)Movie_accessor;
                storage.ReleaseCellLock(cellId, entryIndex);
                Movie_cell.CellID = cellId;
                return(Movie_cell);

                break;

            case CellType.Celebrity:
                var Celebrity_accessor = new Celebrity_Accessor(cellPtr);
                var Celebrity_cell     = (Celebrity)Celebrity_accessor;
                storage.ReleaseCellLock(cellId, entryIndex);
                Celebrity_cell.CellID = cellId;
                return(Celebrity_cell);

                break;

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