コード例 #1
0
ファイル: GenericCell.cs プロジェクト: sefira/NeuralMovieQAQ
        public IEnumerable <ICellAccessor> EnumerateGenericCellAccessors(LocalMemoryStorage storage)
        {
            foreach (var cellInfo in Global.LocalStorage)
            {
                switch ((CellType)cellInfo.CellType)
                {
                case CellType.Movie:
                {
                    var Movie_accessor = Movie_Accessor.AllocIterativeAccessor(cellInfo);
                    yield return(Movie_accessor);

                    Movie_accessor.Dispose();
                    break;
                }

                case CellType.Celebrity:
                {
                    var Celebrity_accessor = Celebrity_Accessor.AllocIterativeAccessor(cellInfo);
                    yield return(Celebrity_accessor);

                    Celebrity_accessor.Dispose();
                    break;
                }

                default:
                    continue;
                }
            }
            yield break;
        }
コード例 #2
0
ファイル: GenericCell.cs プロジェクト: sefira/NeuralMovieQAQ
        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.");
            }
        }
コード例 #3
0
ファイル: GenericCell.cs プロジェクト: sefira/NeuralMovieQAQ
        /// <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.");
            }
            ;
        }
コード例 #4
0
ファイル: GenericCell.cs プロジェクト: sefira/NeuralMovieQAQ
        /// <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)
            {
            case CellType.Movie:
                fixed(byte *Movie_ptr = buff)
                {
                    Movie_Accessor /*_*/ Movie_accessor = new Movie_Accessor(Movie_ptr);

                    Movie_accessor.CellID = cellId;
                    return((Movie)Movie_accessor);
                }

                break;

            case CellType.Celebrity:
                fixed(byte *Celebrity_ptr = buff)
                {
                    Celebrity_Accessor /*_*/ Celebrity_accessor = new Celebrity_Accessor(Celebrity_ptr);

                    Celebrity_accessor.CellID = cellId;
                    return((Celebrity)Celebrity_accessor);
                }

                break;

            default:
                throw new CellTypeNotMatchException("Cannot determine cell type.");
            }
        }
コード例 #5
0
ファイル: GenericCell.cs プロジェクト: sefira/NeuralMovieQAQ
        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.");
            }
        }