示例#1
1
        internal void Write(DBFWriter aBase)
        {
            lock (_lockName)
            {
                if (!_new)
                {
                    return;
                }
                if (string.IsNullOrEmpty(aBase.DataMemoLoc))
                {
                    throw new Exception("No Memo Location Set");
                }

                var raf =
                    File.Open(aBase.DataMemoLoc,
                              FileMode.OpenOrCreate,
                              FileAccess.ReadWrite);

                /* before proceeding check whether the passed in File object
                 *  is an empty/non-existent file or not.
                 */


                using (var tWriter = new BinaryWriter(raf, aBase.CharEncoding))
                {
                    if (raf.Length == 0)
                    {
                        var tHeader = new DBTHeader();
                        tHeader.Write(tWriter);
                    }

                    var tValue = _value;
                    if ((tValue.Length + sizeof(int)) % aBase.BlockSize != 0)
                    {
                        tValue = tValue + MemoTerminator;
                    }

                    var tPosition  = raf.Seek(0, SeekOrigin.End); //Got To End Of File
                    var tBlockDiff = tPosition % aBase.BlockSize;
                    if (tBlockDiff != 0)
                    {
                        tPosition = raf.Seek(aBase.BlockSize - tBlockDiff, SeekOrigin.Current);
                    }
                    _block = tPosition / aBase.BlockSize;
                    var tData       = aBase.CharEncoding.GetBytes(tValue);
                    var tDataLength = tData.Length;
                    var tNewDiff    = (tDataLength % aBase.BlockSize);
                    tWriter.Write(tData);
                    if (tNewDiff != 0)
                    {
                        tWriter.Seek(aBase.BlockSize - (tDataLength % aBase.BlockSize), SeekOrigin.Current);
                    }
                }
            }
        }
示例#2
0
        internal void Write(DBFWriter aBase)
        {
            lock (_lockName)
            {
                if (!_new)
                {
                    return;
                }

                var raf = aBase.DataMemo;

                /* before proceeding check whether the passed in File object
                 *  is an empty/non-existent file or not.
                 */
                if (raf == null)
                {
                    throw new InvalidDataException("Null Memo Field Stream from Writer");
                }

                var tWriter = new BinaryWriter(raf, aBase.CharEncoding);     //Don't close the stream could be used else where;

                if (raf.Length == 0)
                {
                    var tHeader = new DBTHeader();
                    tHeader.Write(tWriter);
                }

                var tValue = _value;
                if ((tValue.Length + sizeof(int)) % aBase.BlockSize != 0)
                {
                    tValue = tValue + MemoTerminator;
                }

                var tPosition  = raf.Seek(0, SeekOrigin.End);    //Got To End Of File
                var tBlockDiff = tPosition % aBase.BlockSize;
                if (tBlockDiff != 0)
                {
                    tPosition = raf.Seek(aBase.BlockSize - tBlockDiff, SeekOrigin.Current);
                }
                _block = tPosition / aBase.BlockSize;
                var tData       = aBase.CharEncoding.GetBytes(tValue);
                var tDataLength = tData.Length;
                var tNewDiff    = (tDataLength % aBase.BlockSize);
                tWriter.Write(tData);
                if (tNewDiff != 0)
                {
                    tWriter.Seek(aBase.BlockSize - (tDataLength % aBase.BlockSize), SeekOrigin.Current);
                }
            }
        }
示例#3
0
        internal void Write(DBFWriter aBase)
        {
            lock (_lockName)
            {
                if (!_new)
                    return;
                if (string.IsNullOrEmpty(aBase.DataMemoLoc))
                    throw new Exception("No Memo Location Set");

                var raf =
                    File.Open(aBase.DataMemoLoc,
                              FileMode.OpenOrCreate,
                              FileAccess.ReadWrite);

                /* before proceeding check whether the passed in File object
                    is an empty/non-existent file or not.
                    */

                using (var tWriter = new BinaryWriter(raf, aBase.CharEncoding))
                {
                    if (raf.Length == 0)
                    {
                        var tHeader = new DBTHeader();
                        tHeader.Write(tWriter);
                    }

                    var tValue = _value;
                    if ((tValue.Length + sizeof(int)) % aBase.BlockSize != 0)
                    {
                        tValue = tValue + MemoTerminator;
                    }

                    var tPosition = raf.Seek(0, SeekOrigin.End); //Got To End Of File
                    var tBlockDiff = tPosition%aBase.BlockSize;
                    if (tBlockDiff != 0)
                    {
                        tPosition = raf.Seek(aBase.BlockSize - tBlockDiff, SeekOrigin.Current);
                    }
                    _block = tPosition/aBase.BlockSize;
                    var tData = aBase.CharEncoding.GetBytes(tValue);
                    var tDataLength = tData.Length;
                    var tNewDiff = (tDataLength%aBase.BlockSize);
                    tWriter.Write(tData);
                    if (tNewDiff != 0)
                        tWriter.Seek(aBase.BlockSize - (tDataLength % aBase.BlockSize), SeekOrigin.Current);
                }
            }
        }