Ejemplo n.º 1
0
 internal KeyValue DeepCopy()
 {
     var keyBuffer = new byte[this.KeyBuffer.Length];
     Array.Copy(this.KeyBuffer, keyBuffer, this.KeyBuffer.Length);
     var result = new KeyValue(this.Key, keyBuffer);
     result.ComplementCount = this.ComplementCount;
     return result;
 }
Ejemplo n.º 2
0
 internal void CopyTo(KeyValue keyValue)
 {
     Array.Copy(this.KeyBuffer, keyValue.KeyBuffer, this.KeyBuffer.Length);
     keyValue.ComplementCount = this.ComplementCount;
 }
Ejemplo n.º 3
0
        IEnumerable <TRecord> OperateExtended(Operation operation, KeyValue keyValue, FilterAnd filter, bool skipCurrentPosition, int limit, LockBias lockBias, ushort rejectCount, bool overwrite = false)
        {
            if (_positionBlock == null)
            {
                throw new InvalidOperationException();
            }
            if (filter != null && !filter.Check(this.RecordInfo))
            {
                throw new ArgumentException();
            }
            if (keyValue != null && !overwrite)
            {
                keyValue = keyValue.DeepCopy();
            }
            var useLimit = limit > 0;

            rejectCount = rejectCount == 0 ? this.RecordInfo.RejectCount : rejectCount;
            var isFirst      = true;
            var bufferLength = Config.MaxBufferLength - Config.ExtendedOperationBufferMargin;

            for (; ;)
            {
                var dataBufferLength = (ushort)(filter == null ? 16 : filter.Length + 16);
                Array.Copy(BitConverter.GetBytes(dataBufferLength), 0, this.TemporaryBuffer, 0, 2);
                Array.Copy(Encoding.ASCII.GetBytes(!isFirst || skipCurrentPosition ? "EG" : "UC"), 0, this.TemporaryBuffer, 2, 2);
                isFirst             = false;
                skipCurrentPosition = true;
                Array.Copy(BitConverter.GetBytes(rejectCount), 0, this.TemporaryBuffer, 4, 2);
                Array.Copy(BitConverter.GetBytes(filter == null ? 0 : filter.Count), 0, this.TemporaryBuffer, 6, 2);
                if (filter != null)
                {
                    filter.SetDataBuffer(this.TemporaryBuffer);
                }
                var position = (ushort)(filter == null ? 8 : filter.Length + 8);
                var count    = (ushort)(bufferLength / (this.RecordInfo.DataBufferCapacity + 6));
                if (useLimit && count > limit)
                {
                    count = (ushort)limit;
                }
                if (count == 0)
                {
                    throw new InvalidOperationException();
                }
                Array.Copy(BitConverter.GetBytes(count), 0, this.TemporaryBuffer, position, 2);
                position += 2;
                Array.Copy(BitConverter.GetBytes((ushort)(1)), 0, this.TemporaryBuffer, position, 2);
                position += 2;
                Array.Copy(BitConverter.GetBytes(this.RecordInfo.DataBufferCapacity), 0, this.TemporaryBuffer, position, 2);
                position += 2;
                Array.Copy(BitConverter.GetBytes((ushort)(0)), 0, this.TemporaryBuffer, position, 2);
                var isBreak = false;
                try {
                    if (keyValue == null)
                    {
                        _nativeOperator.Operate(operation, _positionBlock, this.TemporaryBuffer, null, (sbyte)0, (ushort)lockBias);
                    }
                    else
                    {
                        _nativeOperator.Operate(operation, _positionBlock, this.TemporaryBuffer, keyValue.KeyBuffer, keyValue.Key.KeyNumber, (ushort)lockBias);
                    }
                } catch (OperationException e) {
                    if (e.StatusCode == 9 || e.StatusCode == 64)
                    {
                        isBreak = true;
                    }
                    else if (e.StatusCode != 60)
                    {
                        throw;
                    }
                }
                if (keyValue != null)
                {
                    keyValue.ComplementCount = 0;
                }

                count    = BitConverter.ToUInt16(this.TemporaryBuffer, 0);
                position = 2;
                ushort  length;
                TRecord record;
                for (var i = 0; i < count; i++)
                {
                    length = BitConverter.ToUInt16(this.TemporaryBuffer, position);
                    record = this.CreateRecord();
                    Array.Copy(this.TemporaryBuffer, position + 6, record.DataBuffer, 0, this.RecordInfo.DataBufferCapacity);
                    record.HasPhysicalPosition = true;
                    record.PhysicalPosition    = BitConverter.ToUInt32(this.TemporaryBuffer, position + 2);
                    yield return(record);

                    position += (ushort)(length + 6);
                }
                if (isBreak)
                {
                    yield break;
                }
                if (useLimit)
                {
                    limit -= count;
                    if (limit <= 0)
                    {
                        yield break;
                    }
                }
            }
        }
Ejemplo n.º 4
0
 public KeyValue GetKeyValue(params object[] segmentValues)
 {
     return(KeyValue.Create(this, segmentValues));
 }
Ejemplo n.º 5
0
 internal void CopyTo(KeyValue keyValue)
 {
     Array.Copy(this.KeyBuffer, keyValue.KeyBuffer, this.KeyBuffer.Length);
     keyValue.ComplementCount = this.ComplementCount;
 }