Beispiel #1
0
        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;
        }
Beispiel #2
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 #3
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="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.");
            }
            ;
        }
Beispiel #4
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)
            {
            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.");
            }
        }
Beispiel #5
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.");
            }
        }
Beispiel #6
0
        public IEnumerator <Movie> GetEnumerator()
        {
            if (m_filter_set == null)
            {
                if (m_filter_predicate == null)
                {
                    foreach (var cellInfo in m_storage)
                    {
                        if (cellInfo.CellType == (ushort)CellType.Movie)
                        {
                            var accessor = Movie_Accessor.AllocIterativeAccessor(cellInfo);
                            yield return(accessor);

                            accessor.Dispose();
                        }
                    }
                }
                else
                {
                    foreach (var cellInfo in m_storage)
                    {
                        if (cellInfo.CellType == (ushort)CellType.Movie)
                        {
                            var accessor = Movie_Accessor.AllocIterativeAccessor(cellInfo);
                            if (m_filter_predicate(accessor))
                            {
                                yield return(accessor);
                            }
                            accessor.Dispose();
                        }
                    }
                }
            }
            else if (m_is_positive_filtering)
            {
                if (m_filter_predicate == null)
                {
                    foreach (var cellID in m_filter_set)
                    {
                        using (var accessor = m_storage.UseMovie(cellID))
                        {
                            yield return(accessor);
                        }
                    }
                }
                else
                {
                    foreach (var cellID in m_filter_set)
                    {
                        using (var accessor = m_storage.UseMovie(cellID))
                        {
                            if (m_filter_predicate(accessor))
                            {
                                yield return(accessor);
                            }
                        }
                    }
                }
            }
            else
            {
                throw new NotImplementedException("Negative filtering not supported.");
            }
        }