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."); } }
/// <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="GraphEngineServer.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 UseGenericCell. 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) { case CellType.Movie: return(Movie_Accessor.New(CellId, cellPtr, entryIndex, options)); case CellType.Celebrity: return(Celebrity_Accessor.New(CellId, cellPtr, entryIndex, options)); default: storage.ReleaseCellLock(CellId, entryIndex); throw new CellTypeNotMatchException("Cannot determine cell type."); } ; }