Example #1
0
        public IColumn FindColumnByName(string columnName, bool nullReturnEnable)
        { // There isn't default parameter value, so this function is wrote same as previous function, because this way is quicker then call it only with name parameter.
            if (String.IsNullOrWhiteSpace(columnName))
            {
                throw new ArgumentNullException("columnName");
            }

            var column = _columns.FirstOrDefault(c => (String.Compare(c.name, columnName, true) == 0)); // case insensitive

            if (column == null)
            {
                if (!nullReturnEnable)
                {
                    throw ExceptionFactory.CreateArgumentOutOfRangeException("columnName", "Column {0} not found.", columnName);
                }
            }

            return(column);
        }
Example #2
0
        private void Resize(int newPageCount)
        {
            if (newPageCount > MAXCACHESIZE)
            {
                newPageCount = MAXCACHESIZE;
            }
            else if (newPageCount < 0)
            {
                newPageCount = 0;

        #if DEBUG
                throw ExceptionFactory.CreateArgumentOutOfRangeException("newPageCount", "Count of pages must greater or equal then 0!");
        #endif
            }

            if (items.Count > newPageCount)
            { // Shrink size, remove oldest/not-used items
                RemovePages(items.Count - newPageCount);
            }

            _pageCount = newPageCount;
        }
Example #3
0
        /// <summary>
        /// Read content of memo field.
        /// (multithread calls enabled)
        /// </summary>
        /// <param name="blockNo">Pointer of first block in memo (DBT) file, readed from DBF's memo field.</param>
        /// <returns></returns>
        public override byte[] ReadMemoBytes(int blockNo)
        {
            byte[] retBytes = null;

            if (blockNo < 1)
            {
                throw ExceptionFactory.CreateArgumentException("blockNo", "ReadMemoBytes({0}) invalid block number!",
                                                               blockNo);
            }

            if ((blockNo * blockSize) >= stream.Length)
            {
                throw ExceptionFactory.CreateArgumentException("blockNo",
                                                               "ReadMemoBytes({0}) out of dbt stream length!", blockNo);
            }

            lock (lockObject)
            {
                switch (memoType)
                {
                case MemoFileType.DBT_Ver3:
                    retBytes = ReadMemoArray3(blockNo);
                    break;

                case MemoFileType.DBT_Ver4:
                    retBytes = ReadMemoArray4(blockNo);
                    break;

                case MemoFileType.FPT_Ver3:
                    retBytes = ReadMemoArrayFPT(blockNo);
                    break;

                default:
                    throw new Exception("MemoFileDBT/ReadMemoBytes: invalid switch case!");
                }
            }

            return(retBytes);
        }
Example #4
0
        internal void AtachedToAnotherTable(DbfTable dbfTable, int recNo)
        {
            this._dbfTableClassID = (dbfTable == null) ? Guid.Empty : dbfTable.dbfTableClassID;
            this._recNo           = recNo;

            //

            if (dbfTable != null)
            {
                if (!IsIdenticalColumnsDefinition(this._columns, dbfTable._columns))
                {
                    throw ExceptionFactory.CreateArgumentException("dbfTable", "DbfRow.AtachedToAnotherTable/this.columns and dbfTable.columns aren't identical !");
                }
            }

            //

            foreach (var item in memoCache)
            {
                item.modified = ((item.data != null) && (item.data.Length > 0));

                (item.column as Column).SetNull(_buffer);
            }
        }
Example #5
0
        public static NtxHeader GetHeader(Stream stream)
        {
            if (stream.Length < (pageSize * 2))
            {
                throw ExceptionFactory.CreateArgumentOutOfRangeException("stream", "NTX index stream length '{0}' < '{1}'!", stream.Length, (pageSize * 2));
            }

            if ((stream.Length % pageSize) != 0)
            {
                throw ExceptionFactory.CreateArgumentOutOfRangeException("stream", "NTX index stream length ({0}) isn't a multiple of '{1}'!", stream.Length, pageSize);
            }

            //

            NtxHeader header = new NtxHeader();

            stream.Position = 0;

            BinaryReader reader = new BinaryReader(stream);                     // don't use 'using (BinaryReader reader...' because 'using' dispose 'stream' too!

            header.signature = reader.ReadUInt16();
            header.version   = reader.ReadUInt16();
            header.root      = reader.ReadInt32();
            header.unused    = reader.ReadInt32();
            header.itemSize  = reader.ReadUInt16();
            header.keySize   = reader.ReadUInt16();
            header.keyDec    = reader.ReadUInt16();
            header.maxItem   = reader.ReadUInt16();
            header.halfPage  = reader.ReadUInt16();
            header.keyExpr   = reader.ReadBytes(maxKeyLen);

            byte uniqueFlag = reader.ReadByte();

            header.unique = (uniqueFlag != 0);

            Debug.Assert(reader.BaseStream.Position == 279);

            //

            byte sign1Byte = (byte)(header.signature >> 8);                       // get first byte

            if (!Array.Exists(validSignatures, s => (s == sign1Byte)))
            {
                throw ExceptionFactory.CreateArgumentOutOfRangeException("stream", "Signature byte of NTX index stream is invalid! '{0}'", sign1Byte);
            }

            byte sign2Byte = (byte)(header.signature);                            // cut off first byte

            if (sign2Byte != 0)
            {
                throw ExceptionFactory.CreateArgumentOutOfRangeException("stream", "Second signature byte in NTX index stream header is invalid!'{0}'", sign2Byte);
            }

            if ((header.keySize < 1) || (header.keySize > 250))
            {
                throw ExceptionFactory.CreateArgumentOutOfRangeException("stream", "Key size in NTX index stream header is invalid!");
            }

            if ((header.keySize + 8) != header.itemSize)
            {
                throw ExceptionFactory.CreateArgumentOutOfRangeException("stream", "Key size (+8) in NTX index stream header is invalid!");
            }

            if (ProcessKeyExpressionBuffer(header.keyExpr) == null)
            {
                throw ExceptionFactory.CreateNotSupportedException("Content of key expression bytes is envalid!");
            }

            if (!((uniqueFlag == 0) || (uniqueFlag == 1)))
            {
                throw ExceptionFactory.CreateArgumentOutOfRangeException("stream", "Unique flag in NTX index stream header is invalid!");
            }

            //

            return(header);
        }
Example #6
0
        public static bool IsIdenticalColumnsDefinition(ICollection <IColumn> columns1, ICollection <IColumn> columns2)
        {
            if (columns1 == null)
            {
                throw ExceptionFactory.CreateArgumentException("columns1", "Null parameter value not allowed!");
            }

            if (columns2 == null)
            {
                throw ExceptionFactory.CreateArgumentException("columns2", "Null parameter value not allowed!");
            }


            List <Column> cols1 = new List <Column>();
            List <Column> cols2 = new List <Column>();

            foreach (var item in columns1)
            {
                cols1.Add(item as Column);
            }

            foreach (var item in columns2)
            {
                cols2.Add(item as Column);
            }

            if (cols1.Count != cols2.Count)
            {
                return(false);
            }

            cols1.Sort((col1, col2) => String.Compare(col1.name, col2.name, true));     // Ignore case
            cols2.Sort((col1, col2) => String.Compare(col1.name, col2.name, true));     // Ignore case

            for (int i = 0; (i < cols1.Count); i++)
            {
                if (String.Compare(cols1[i].name, cols2[i].name, true) != 0)            // Ignore case
                {
                    return(false);
                }

                if (cols1[i].dbfType != cols2[i].dbfType)
                {
                    return(false);
                }

                if (cols1[i].size != cols2[i].size)
                {
                    return(false);
                }

                if (cols1[i].dec != cols2[i].dec)
                {
                    return(false);
                }

                if (cols1[i].type != cols2[i].type)
                {
                    return(false);
                }

                if (cols1[i].offset != cols2[i].offset)
                {
                    return(false);
                }
            }

            return(true);
        }