Ejemplo n.º 1
0
        public void EventCounts(byte[] buffer)
        {
            int     pos     = 1;
            Charset charset = this.db.Charset;

            if (buffer != null)
            {
                if (this.initialCounts)
                {
                    this.previousCounts = this.actualCounts;
                }

                this.actualCounts = new int[this.events.Count];

                while (pos < buffer.Length)
                {
                    int    length    = buffer[pos++];
                    string eventName = charset.GetString(buffer, pos, length);

                    pos += length;

                    int index = this.events.IndexOf(eventName);
                    if (index != -1)
                    {
                        this.actualCounts[index] = BitConverter.ToInt32(buffer, pos) - 1;
                    }

                    pos += 4;
                }

                if (!this.initialCounts)
                {
                    this.QueueEvents();
                    this.initialCounts = true;
                }
                else
                {
                    if (this.EventCountsCallback != null)
                    {
                        this.EventCountsCallback();
                    }
                }
            }
        }
Ejemplo n.º 2
0
        internal void EventCounts(byte[] buffer)
        {
            if (Volatile2.Read(ref _running) == 0)
            {
                return;
            }

            _previousCounts = _currentCounts;
            _currentCounts  = new int[_events.Count];

            var pos = 1;

            while (pos < buffer.Length)
            {
                var length    = buffer[pos++];
                var eventName = _charset.GetString(buffer, pos, length);

                pos += length;

                var index = _events.IndexOf(eventName);
                if (index == -1)
                {
                    Debugger.Break();
                }
                Debug.Assert(index != -1);
                _currentCounts[index] = BitConverter.ToInt32(buffer, pos) - 1;

                pos += 4;
            }

            for (var i = 0; i < _events.Count; i++)
            {
                var count = _currentCounts[i] - _previousCounts[i];
                if (count == 0)
                {
                    continue;
                }
                EventCountsCallback(_events[i], count);
            }

            QueueEventsImpl();
        }
Ejemplo n.º 3
0
        public void EventCounts(byte[] buffer)
        {
            int     pos     = 1;
            Charset charset = _db.Charset;

            if (buffer != null)
            {
                if (_initialCounts)
                {
                    _previousCounts = _actualCounts;
                }

                _actualCounts = new int[_events.Count];

                while (pos < buffer.Length)
                {
                    int    length    = buffer[pos++];
                    string eventName = charset.GetString(buffer, pos, length);

                    pos += length;

                    int index = _events.IndexOf(eventName);
                    if (index != -1)
                    {
                        _actualCounts[index] = BitConverter.ToInt32(buffer, pos) - 1;
                    }

                    pos += 4;
                }

                if (!_initialCounts)
                {
                    QueueEvents();
                    _initialCounts = true;
                }
                else
                {
                    EventCountsCallback?.Invoke();
                }
            }
        }
        internal Task EventCounts(byte[] buffer, AsyncWrappingCommonArgs async)
        {
            if (Volatile.Read(ref _running) == 0)
            {
                return(Task.CompletedTask);
            }

            _previousCounts = _currentCounts;
            _currentCounts  = new int[_events.Count];

            var pos = 1;

            while (pos < buffer.Length)
            {
                var length    = buffer[pos++];
                var eventName = _charset.GetString(buffer, pos, length);

                pos += length;

                var index = _events.IndexOf(eventName);
                Debug.Assert(index != -1);
                _currentCounts[index] = BitConverter.ToInt32(buffer, pos) - 1;

                pos += 4;
            }

            for (var i = 0; i < _events.Count; i++)
            {
                var count = _currentCounts[i] - _previousCounts[i];
                if (count == 0)
                {
                    continue;
                }
                EventCountsCallback(_events[i], count);
            }

            return(QueueEventsImpl(async));
        }
		private string GetString(Charset charset, byte[] buffer)
		{
			string value = charset.GetString(buffer);

			return value.TrimEnd('\0', ' ');
		}
Ejemplo n.º 6
0
        public void SetValue(byte[] buffer)
        {
            if (buffer == null || NullFlag == -1)
            {
                Value = DBNull.Value;
            }
            else
            {
                switch (SqlType)
                {
                case IscCodes.SQL_TEXT:
                case IscCodes.SQL_VARYING:
                    if (DbDataType == DbDataType.Guid)
                    {
                        Value = TypeDecoder.DecodeGuid(buffer);
                    }
                    else
                    {
                        if (Charset.IsOctetsCharset)
                        {
                            Value = buffer;
                        }
                        else
                        {
                            var s = Charset.GetString(buffer, 0, buffer.Length);

                            if ((Length % Charset.BytesPerCharacter) == 0 &&
                                s.Length > CharCount)
                            {
                                s = s.Substring(0, CharCount);
                            }

                            Value = s;
                        }
                    }
                    break;

                case IscCodes.SQL_SHORT:
                    if (_numericScale < 0)
                    {
                        Value = TypeDecoder.DecodeDecimal(
                            BitConverter.ToInt16(buffer, 0),
                            _numericScale,
                            _dataType);
                    }
                    else
                    {
                        Value = BitConverter.ToInt16(buffer, 0);
                    }
                    break;

                case IscCodes.SQL_LONG:
                    if (NumericScale < 0)
                    {
                        Value = TypeDecoder.DecodeDecimal(
                            BitConverter.ToInt32(buffer, 0),
                            _numericScale,
                            _dataType);
                    }
                    else
                    {
                        Value = BitConverter.ToInt32(buffer, 0);
                    }
                    break;

                case IscCodes.SQL_FLOAT:
                    Value = BitConverter.ToSingle(buffer, 0);
                    break;

                case IscCodes.SQL_DOUBLE:
                case IscCodes.SQL_D_FLOAT:
                    Value = BitConverter.ToDouble(buffer, 0);
                    break;

                case IscCodes.SQL_QUAD:
                case IscCodes.SQL_INT64:
                case IscCodes.SQL_BLOB:
                case IscCodes.SQL_ARRAY:
                    if (NumericScale < 0)
                    {
                        Value = TypeDecoder.DecodeDecimal(
                            BitConverter.ToInt64(buffer, 0),
                            _numericScale,
                            _dataType);
                    }
                    else
                    {
                        Value = BitConverter.ToInt64(buffer, 0);
                    }
                    break;

                case IscCodes.SQL_TIMESTAMP:
                    var date = TypeDecoder.DecodeDate(BitConverter.ToInt32(buffer, 0));
                    var time = TypeDecoder.DecodeTime(BitConverter.ToInt32(buffer, 4));

                    Value = date.Add(time);
                    break;

                case IscCodes.SQL_TYPE_TIME:
                    Value = TypeDecoder.DecodeTime(BitConverter.ToInt32(buffer, 0));
                    break;

                case IscCodes.SQL_TYPE_DATE:
                    Value = TypeDecoder.DecodeDate(BitConverter.ToInt32(buffer, 0));
                    break;

                case IscCodes.SQL_BOOLEAN:
                    Value = TypeDecoder.DecodeBoolean(buffer);
                    break;

                default:
                    throw TypeHelper.InvalidDataType(SqlType);
                }
            }
        }
        public async Task <string> ReadString(AsyncWrappingCommonArgs async)
        {
            var buffer = await Read(async).ConfigureAwait(false);

            return(_charset.GetString(buffer, 0, buffer.Length));
        }
Ejemplo n.º 8
0
        public static IscException ParseStatusVector(IntPtr[] statusVector, Charset charset)
        {
            IscException exception = null;
            bool eof = false;

            for (int i = 0; i < statusVector.Length; )
            {
                IntPtr arg = statusVector[i++];

                switch (arg.ToInt32())
                {
                    case IscCodes.isc_arg_gds:
                        IntPtr er = statusVector[i++];
                        if (er != IntPtr.Zero)
                        {
                            if (exception == null)
                            {
                                exception = new IscException();
                            }
                            exception.Errors.Add(new IscError(arg.ToInt32(), er.ToInt32()));
                        }
                        break;

                    case IscCodes.isc_arg_end:
                        if (exception != null && exception.Errors.Count != 0)
                        {
							exception.BuildExceptionData();
                        }
                        eof = true;
                        break;

                    case IscCodes.isc_arg_interpreted:
                    case IscCodes.isc_arg_string:
                        {
                            IntPtr ptr = statusVector[i++];
                            string s = Marshal.PtrToStringAnsi(ptr);
                            string arg_value = charset.GetString(
                                System.Text.Encoding.Default.GetBytes(s));

                            exception.Errors.Add(new IscError(arg.ToInt32(), arg_value));
                        }
                        break;

                    case IscCodes.isc_arg_cstring:
                        {
                            i++;

                            IntPtr ptr = statusVector[i++];
                            string s = Marshal.PtrToStringAnsi(ptr);
                            string arg_value = charset.GetString(
                                System.Text.Encoding.Default.GetBytes(s));

                            exception.Errors.Add(new IscError(arg.ToInt32(), arg_value));
                        }
                        break;

                    case IscCodes.isc_arg_win32:
                    case IscCodes.isc_arg_number:
                        exception.Errors.Add(new IscError(arg.ToInt32(), statusVector[i++].ToInt32()));
                        break;

                    default:
						IntPtr e = statusVector[i++];
						if (e != IntPtr.Zero)
						{
							if (exception == null)
							{
								exception = new IscException();
							}
							exception.Errors.Add(new IscError(arg.ToInt32(), e.ToInt32()));
						}
                        break;
                }

                if (eof)
                {
                    break;
                }
            }

            return exception;
        }
Ejemplo n.º 9
0
        public void SetValue(byte[] buffer)
        {
            if (buffer == null || NullFlag == -1)
            {
                DbValue.SetValue(DBNull.Value);
            }
            else
            {
                switch (SqlType)
                {
                case IscCodes.SQL_TEXT:
                case IscCodes.SQL_VARYING:
                    if (DbDataType == DbDataType.Guid)
                    {
                        DbValue.SetValue(TypeDecoder.DecodeGuid(buffer));
                    }
                    else
                    {
                        if (Charset.IsOctetsCharset)
                        {
                            DbValue.SetValue(buffer);
                        }
                        else
                        {
                            var s = Charset.GetString(buffer, 0, buffer.Length);

                            if ((Length % Charset.BytesPerCharacter) == 0 &&
                                s.Length > CharCount)
                            {
                                s = s.Substring(0, CharCount);
                            }

                            DbValue.SetValue(s);
                        }
                    }
                    break;

                case IscCodes.SQL_SHORT:
                    if (_numericScale < 0)
                    {
                        DbValue.SetValue(TypeDecoder.DecodeDecimal(BitConverter.ToInt16(buffer, 0), _numericScale, _dataType));
                    }
                    else
                    {
                        DbValue.SetValue(BitConverter.ToInt16(buffer, 0));
                    }
                    break;

                case IscCodes.SQL_LONG:
                    if (_numericScale < 0)
                    {
                        DbValue.SetValue(TypeDecoder.DecodeDecimal(BitConverter.ToInt32(buffer, 0), _numericScale, _dataType));
                    }
                    else
                    {
                        DbValue.SetValue(BitConverter.ToInt32(buffer, 0));
                    }
                    break;

                case IscCodes.SQL_FLOAT:
                    DbValue.SetValue(BitConverter.ToSingle(buffer, 0));
                    break;

                case IscCodes.SQL_DOUBLE:
                case IscCodes.SQL_D_FLOAT:
                    DbValue.SetValue(BitConverter.ToDouble(buffer, 0));
                    break;

                case IscCodes.SQL_QUAD:
                case IscCodes.SQL_INT64:
                case IscCodes.SQL_BLOB:
                case IscCodes.SQL_ARRAY:
                    if (_numericScale < 0)
                    {
                        DbValue.SetValue(TypeDecoder.DecodeDecimal(BitConverter.ToInt64(buffer, 0), _numericScale, _dataType));
                    }
                    else
                    {
                        DbValue.SetValue(BitConverter.ToInt64(buffer, 0));
                    }
                    break;

                case IscCodes.SQL_TIMESTAMP:
                {
                    var date = TypeDecoder.DecodeDate(BitConverter.ToInt32(buffer, 0));
                    var time = TypeDecoder.DecodeTime(BitConverter.ToInt32(buffer, 4));
                    DbValue.SetValue(date.Add(time));
                    break;
                }

                case IscCodes.SQL_TYPE_TIME:
                    DbValue.SetValue(TypeDecoder.DecodeTime(BitConverter.ToInt32(buffer, 0)));
                    break;

                case IscCodes.SQL_TYPE_DATE:
                    DbValue.SetValue(TypeDecoder.DecodeDate(BitConverter.ToInt32(buffer, 0)));
                    break;

                case IscCodes.SQL_BOOLEAN:
                    DbValue.SetValue(TypeDecoder.DecodeBoolean(buffer));
                    break;

                case IscCodes.SQL_TIMESTAMP_TZ:
                {
                    var date = TypeDecoder.DecodeDate(BitConverter.ToInt32(buffer, 0));
                    var time = TypeDecoder.DecodeTime(BitConverter.ToInt32(buffer, 4));
                    var tzId = BitConverter.ToUInt16(buffer, 8);
                    var dt   = DateTime.SpecifyKind(date.Add(time), DateTimeKind.Utc);
                    DbValue.SetValue(TypeHelper.CreateZonedDateTime(dt, tzId, null));
                    break;
                }

                case IscCodes.SQL_TIMESTAMP_TZ_EX:
                {
                    var date   = TypeDecoder.DecodeDate(BitConverter.ToInt32(buffer, 0));
                    var time   = TypeDecoder.DecodeTime(BitConverter.ToInt32(buffer, 4));
                    var tzId   = BitConverter.ToUInt16(buffer, 8);
                    var offset = BitConverter.ToInt16(buffer, 10);
                    var dt     = DateTime.SpecifyKind(date.Add(time), DateTimeKind.Utc);
                    DbValue.SetValue(TypeHelper.CreateZonedDateTime(dt, tzId, offset));
                    break;
                }

                case IscCodes.SQL_TIME_TZ:
                {
                    var time = TypeDecoder.DecodeTime(BitConverter.ToInt32(buffer, 0));
                    var tzId = BitConverter.ToUInt16(buffer, 4);
                    DbValue.SetValue(TypeHelper.CreateZonedTime(time, tzId, null));
                    break;
                }

                case IscCodes.SQL_TIME_TZ_EX:
                {
                    var time   = TypeDecoder.DecodeTime(BitConverter.ToInt32(buffer, 0));
                    var tzId   = BitConverter.ToUInt16(buffer, 4);
                    var offset = BitConverter.ToInt16(buffer, 6);
                    DbValue.SetValue(TypeHelper.CreateZonedTime(time, tzId, offset));
                    break;
                }

                case IscCodes.SQL_DEC16:
                    DbValue.SetValue(DecimalCodec.DecFloat16.ParseBytes(buffer));
                    break;

                case IscCodes.SQL_DEC34:
                    DbValue.SetValue(DecimalCodec.DecFloat34.ParseBytes(buffer));
                    break;

                case IscCodes.SQL_INT128:
                    if (_numericScale < 0)
                    {
                        DbValue.SetValue(TypeDecoder.DecodeDecimal(Int128Helper.GetInt128(buffer), _numericScale, _dataType));
                    }
                    else
                    {
                        DbValue.SetValue(Int128Helper.GetInt128(buffer));
                    }
                    break;

                default:
                    throw TypeHelper.InvalidDataType(SqlType);
                }
            }
        }
Ejemplo n.º 10
0
        public string ReadString()
        {
            var buffer = Read();

            return(_charset.GetString(buffer, 0, buffer.Length));
        }
		private static string GetString(Charset charset, byte[] buffer, short bufferLength)
		{
			return charset.GetString(buffer, 0, bufferLength);
		}
		public string ReadString(Charset charset, int length)
		{
			byte[] buffer = this.ReadOpaque(length);

			return charset.GetString(buffer, 0, buffer.Length);
		}
        public void SetValue(byte[] buffer)
        {
            if (buffer == null || NullFlag == -1)
            {
                Value = System.DBNull.Value;
            }
            else
            {
                switch (SqlType)
                {
                case IscCodes.SQL_TEXT:
                case IscCodes.SQL_VARYING:
                    if (DbDataType == DbDataType.Guid)
                    {
                        Value = new Guid(buffer);
                    }
                    else
                    {
                        if (Charset.IsOctetsCharset)
                        {
                            Value = buffer;
                        }
                        else
                        {
                            string s = Charset.GetString(buffer, 0, buffer.Length);

                            if ((Length % Charset.BytesPerCharacter) == 0 &&
                                s.Length > CharCount)
                            {
                                s = s.Substring(0, CharCount);
                            }

                            Value = s;
                        }
                    }
                    break;

                case IscCodes.SQL_SHORT:
                    if (_numericScale < 0)
                    {
                        Value = TypeDecoder.DecodeDecimal(
                            BitConverter.ToInt16(buffer, 0),
                            _numericScale,
                            _dataType);
                    }
                    else
                    {
                        Value = BitConverter.ToInt16(buffer, 0);
                    }
                    break;

                case IscCodes.SQL_LONG:
                    if (NumericScale < 0)
                    {
                        Value = TypeDecoder.DecodeDecimal(
                            BitConverter.ToInt32(buffer, 0),
                            _numericScale,
                            _dataType);
                    }
                    else
                    {
                        Value = BitConverter.ToInt32(buffer, 0);
                    }
                    break;

                case IscCodes.SQL_FLOAT:
                    Value = BitConverter.ToSingle(buffer, 0);
                    break;

                case IscCodes.SQL_DOUBLE:
                case IscCodes.SQL_D_FLOAT:
                    Value = BitConverter.ToDouble(buffer, 0);
                    break;

                case IscCodes.SQL_QUAD:
                case IscCodes.SQL_INT64:
                case IscCodes.SQL_BLOB:
                case IscCodes.SQL_ARRAY:
                    if (NumericScale < 0)
                    {
                        Value = TypeDecoder.DecodeDecimal(
                            BitConverter.ToInt64(buffer, 0),
                            _numericScale,
                            _dataType);
                    }
                    else
                    {
                        Value = BitConverter.ToInt64(buffer, 0);
                    }
                    break;

                case IscCodes.SQL_TIMESTAMP:
                    DateTime date = TypeDecoder.DecodeDate(BitConverter.ToInt32(buffer, 0));
                    TimeSpan time = TypeDecoder.DecodeTime(BitConverter.ToInt32(buffer, 4));

                    Value = new System.DateTime(
                        date.Year, date.Month, date.Day,
                        time.Hours, time.Minutes, time.Seconds, time.Milliseconds);
                    break;

                case IscCodes.SQL_TYPE_TIME:
                    Value = TypeDecoder.DecodeTime(BitConverter.ToInt32(buffer, 0));
                    break;

                case IscCodes.SQL_TYPE_DATE:
                    Value = TypeDecoder.DecodeDate(BitConverter.ToInt32(buffer, 0));
                    break;

                default:
                    throw new NotSupportedException("Unknown data type");
                }
            }
        }
		private	string GetString(Charset charset, byte[] buffer)
		{
			string value = charset.GetString(buffer);

			return value.Replace('\0', ' ').Trim();
		}
		public string ReadString(Charset charset, int length)
		{
			var buffer = ReadOpaque(length);
			return charset.GetString(buffer, 0, buffer.Length);
		}