Exemple #1
0
 /// <summary>
 /// 创建一个指定类型的委托。
 /// </summary>
 /// <typeparam name="T">委托类型</typeparam>
 /// <param name="methodInfo">需要创建委托的方法</param>
 /// <param name="throwExceptions">当参数或返回值类型不兼容时是否发生异常。</param>
 /// <returns>返回一个委托或 Null。</returns>
 public static T CreateDelegate <T>(MethodBase methodInfo, bool throwExceptions = true) where T : Delegate
 {
     return(Underlying.As <T>(CreateDelegate(typeof(T), methodInfo, throwExceptions)));
 }
Exemple #2
0
 public bool IsSupersetOf(IEnumerable <T> other) => Underlying.IsSupersetOf(other);
Exemple #3
0
 public bool SetEquals(IEnumerable <T> other) => Underlying.SetEquals(other);
Exemple #4
0
 /// <summary>
 /// TBD
 /// </summary>
 public override void Stop()
 {
     Underlying.Stop();
 }
Exemple #5
0
 /// <summary>
 /// TBD
 /// </summary>
 /// <param name="message">TBD</param>
 /// <param name="sender">TBD</param>
 protected override void TellInternal(object message, IActorRef sender)
 {
     Underlying.SendMessage(sender, message);
 }
Exemple #6
0
        private protected override void InitializeByValue(PropertyInfo propertyInfo, XBindingFlags flags)
        {
            base.InitializeByValue(propertyInfo, flags);

            if ((flags & XBindingFlags.RWAutoPropertyDirectRW) != 0 /* || !VersionDifferences.IsSupportEmit */)
            {
                if (TypeHelper.IsAutoProperty(propertyInfo, out var fieldInfo) && fieldInfo != null)
                {
                    try
                    {
                        var offset = TypeHelper.OffsetOf(fieldInfo);

                        _get = (obj) => Underlying.AddByteOffset(ref TypeHelper.Unbox <TValue>(obj), offset);
                        _set = (obj, value) => Underlying.AddByteOffset(ref TypeHelper.Unbox <TValue>(obj), offset) = value;

                        return;
                    }
                    catch
                    {
                    }
                }
            }

            if (_get is null)
            {
                var getMethod = propertyInfo.GetGetMethod((flags & XBindingFlags.NonPublic) != 0);

                if (getMethod != null)
                {
                    var __get = (GetValueHandler)Delegate.CreateDelegate(typeof(GetValueHandler), getMethod);

                    _get = VersionDifferences.IsSupportEmit ? __get : AOTCheck;

                    TValue AOTCheck(TClass obj)
                    {
                        try
                        {
                            return(__get(obj));
                        }
                        catch (ExecutionEngineException)
                        {
                            __get = AOT;

                            return(AOT(obj));
                        }
                        finally
                        {
                            _get = __get;
                        }
                    }

                    TValue AOT(TClass obj)
                    {
                        return((TValue)getMethod.Invoke(obj, null));
                    }
                }
            }

            if (_set is null)
            {
                var setMethod = propertyInfo.GetSetMethod((flags & XBindingFlags.NonPublic) != 0);

                if (setMethod != null)
                {
                    var __set = (SetValueHandler)Delegate.CreateDelegate(typeof(SetValueHandler), setMethod);

                    _set = VersionDifferences.IsSupportEmit ? __set : AOTCheck;

                    void AOTCheck(TClass obj, TValue value)
                    {
                        try
                        {
                            __set(obj, value);
                        }
                        catch (ExecutionEngineException)
                        {
                            __set = AOT;

                            AOT(obj, value);
                        }
                        finally
                        {
                            _set = __set;
                        }
                    }

                    void AOT(TClass obj, TValue value)
                    {
                        setMethod.Invoke(obj, new object[] { value });
                    }
                }
            }
        }
Exemple #7
0
 /// <summary>
 /// TBD
 /// </summary>
 /// <param name="message">TBD</param>
 public override void SendSystemMessage(ISystemMessage message)
 {
     Underlying.SendSystemMessage(message);
 }
Exemple #8
0
        public async Task Flush(bool async)
        {
            if (_copyMode)
            {
                // In copy mode, we write CopyData messages. The message code has already been
                // written to the beginning of the buffer, but we need to go back and write the
                // length.
                if (_writePosition == 1)
                {
                    return;
                }
                var pos = _writePosition;
                _writePosition = 1;
                WriteInt32(pos - 1);
                _writePosition = pos;
            }
            else if (_writePosition == 0)
            {
                return;
            }

            try
            {
                if (async)
                {
                    await Underlying.WriteAsync(_buf, 0, _writePosition);
                }
                else
                {
                    Underlying.Write(_buf, 0, _writePosition);
                }
            }
            catch (Exception e)
            {
                Connector.Break();
                throw new NpgsqlException("Exception while writing to stream", e);
            }

            try
            {
                if (async)
                {
                    await Underlying.FlushAsync();
                }
                else
                {
                    Underlying.Flush();
                }
            }
            catch (Exception e)
            {
                Connector.Break();
                throw new NpgsqlException("Exception while flushing stream", e);
            }

            TotalBytesFlushed += _writePosition;
            _writePosition     = 0;
            if (CurrentCommand != null)
            {
                CurrentCommand.FlushOccurred = true;
                CurrentCommand = null;
            }
            if (_copyMode)
            {
                WriteCopyDataHeader();
            }
        }
Exemple #9
0
        private protected override void InitializeByValue(PropertyInfo propertyInfo, XBindingFlags flags)
        {
            base.InitializeByValue(propertyInfo, flags);

            if ((flags & XBindingFlags.RWAutoPropertyDirectRW) != 0 && TypeHelper.IsAutoProperty(propertyInfo, out var fieldInfo) && fieldInfo != null)
            {
                try
                {
                    var offset = TypeHelper.OffsetOf(fieldInfo);

                    _get = (ref TStruct obj) => Underlying.AddByteOffset(ref Underlying.As <TStruct, TValue>(ref obj), offset);
                    _set = (ref TStruct obj, TValue value) => Underlying.AddByteOffset(ref Underlying.As <TStruct, TValue>(ref obj), offset) = value;

                    return;
                }
                catch
                {
                }
            }

            if (_get is null)
            {
                var getMethod = propertyInfo.GetGetMethod((flags & XBindingFlags.NonPublic) != 0);

                if (getMethod != null)
                {
                    _get = MethodHelper.CreateDelegate <XStructGetValueHandler <TStruct, TValue> >(getMethod, false);
                }
            }

            if (_set is null)
            {
                var setMethod = propertyInfo.GetSetMethod((flags & XBindingFlags.NonPublic) != 0);

                if (setMethod != null)
                {
                    _set = MethodHelper.CreateDelegate <XStructSetValueHandler <TStruct, TValue> >(setMethod, false);
                }
            }
        }
 public ref TValue GetReference(object obj)
 => ref Underlying.AddByteOffset(ref TypeHelper.Unbox <TValue>(obj), offset);
 public new IEnumerator <T> GetEnumerator() => Underlying.GetEnumerator();
 /// <summary>
 /// 获取字段的值的引用。
 /// </summary>
 /// <param name="obj">对象的引用</param>
 /// <returns>返回字段的值的引用</returns>
 public ref TValue GetReference(ref TStruct obj)
 => ref Underlying.AddByteOffset(ref Underlying.As <TStruct, TValue>(ref obj), offset);
Exemple #13
0
 /// <summary>
 /// 将字节码转换为 16 进制字符串。
 /// </summary>
 /// <param name="bytes">字节码</param>
 /// <returns>返回一个字符串</returns>
 public static string ToHexString(this ReadOnlySpan <byte> bytes)
 {
     return(ToHexString(ref Underlying.AsRef(bytes[0]), bytes.Length));
 }
 protected override void TellInternal(object message, ActorRef sender)
 {
     Underlying.Post(sender, message);
 }
 public bool SetEquals(IEnumerable <T> other)
 {
     return(Underlying.SetEquals(other));
 }
Exemple #16
0
        public async Task Flush(bool async)
        {
            if (_copyMode)
            {
                // In copy mode, we write CopyData messages. The message code has already been
                // written to the beginning of the buffer, but we need to go back and write the
                // length.
                if (WritePosition == 1)
                {
                    return;
                }
                var pos = WritePosition;
                WritePosition = 1;
                WriteInt32(pos - 1);
                WritePosition = pos;
            }
            else if (WritePosition == 0)
            {
                return;
            }

            try
            {
                if (async)
                {
                    if (AwaitableSocket == null)  // SSL
                    {
                        await Underlying.WriteAsync(Buffer, 0, WritePosition);
                    }
                    else  // Non-SSL async I/O, optimized
                    {
                        AwaitableSocket.SetBuffer(Buffer, 0, WritePosition);
                        await AwaitableSocket.SendAsync();
                    }
                }
                else  // Sync I/O
                {
                    Underlying.Write(Buffer, 0, WritePosition);
                }
            }
            catch (Exception e)
            {
                Connector.Break();
                throw new NpgsqlException("Exception while writing to stream", e);
            }

            try
            {
                if (async)
                {
                    await Underlying.FlushAsync();
                }
                else
                {
                    Underlying.Flush();
                }
            }
            catch (Exception e)
            {
                Connector.Break();
                throw new NpgsqlException("Exception while flushing stream", e);
            }

            NpgsqlEventSource.Log.BytesWritten(WritePosition);
            //NpgsqlEventSource.Log.RequestFailed();

            WritePosition = 0;
            if (CurrentCommand != null)
            {
                CurrentCommand.FlushOccurred = true;
                CurrentCommand = null;
            }
            if (_copyMode)
            {
                WriteCopyDataHeader();
            }
        }
Exemple #17
0
        internal Task Ensure(int count, bool async, bool dontBreakOnTimeouts)
        {
            return(count <= ReadBytesLeft ? PGUtil.CompletedTask : EnsureLong());

            async Task EnsureLong()
            {
                Debug.Assert(count <= Size);
                Debug.Assert(count > ReadBytesLeft);
                count -= ReadBytesLeft;
                if (count <= 0)
                {
                    return;
                }

                if (ReadPosition == FilledBytes)
                {
                    Clear();
                }
                else if (count > Size - FilledBytes)
                {
                    Array.Copy(Buffer, ReadPosition, Buffer, 0, ReadBytesLeft);
                    FilledBytes  = ReadBytesLeft;
                    ReadPosition = 0;
                }

                try
                {
                    while (count > 0)
                    {
                        var toRead = Size - FilledBytes;

                        int read;
                        if (async)
                        {
                            if (AwaitableSocket == null)  // SSL
                            {
                                read = await Underlying.ReadAsync(Buffer, FilledBytes, toRead);
                            }
                            else  // Non-SSL async I/O, optimized
                            {
                                AwaitableSocket.SetBuffer(Buffer, FilledBytes, toRead);
                                await AwaitableSocket.ReceiveAsync();

                                read = AwaitableSocket.BytesTransferred;
                            }
                        }
                        else    // Sync I/O
                        {
                            read = Underlying.Read(Buffer, FilledBytes, toRead);
                        }

                        if (read == 0)
                        {
                            throw new EndOfStreamException();
                        }
                        count       -= read;
                        FilledBytes += read;
                    }
                }
                // We have a special case when reading async notifications - a timeout may be normal
                // shouldn't be fatal
                // Note that mono throws SocketException with the wrong error (see #1330)
                catch (IOException e) when(
                    dontBreakOnTimeouts && (e.InnerException as SocketException)?.SocketErrorCode ==
                    (Type.GetType("Mono.Runtime") == null ? SocketError.TimedOut : SocketError.WouldBlock)
                    )
                {
                    throw new TimeoutException("Timeout while reading from stream");
                }
                catch (Exception e)
                {
                    Connector.Break();
                    throw new NpgsqlException("Exception while reading from stream", e);
                }
            }
        }
 /// <summary>
 /// Sets the enumerator to its initial position, which is before the first element in the collection.
 /// </summary>
 public void Reset()
 {
     Underlying.Reset();
     _needNewCurrent = true;
 }
Exemple #19
0
 /// <summary>
 /// TBD
 /// </summary>
 public override void Suspend()
 {
     Underlying.Suspend();
 }
 /// <summary>
 /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
 /// </summary>
 public void Dispose()
 {
     Underlying.Dispose();
 }
Exemple #21
0
 /// <summary>
 /// TBD
 /// </summary>
 /// <param name="causedByFailure">TBD</param>
 public override void Resume(Exception causedByFailure = null)
 {
     Underlying.Resume(causedByFailure);
 }
        /// <summary>
        /// Advances the enumerator to the next element of the collection.
        /// </summary>
        /// <returns>
        /// true if the enumerator was successfully advanced to the next element; false if the enumerator has passed the end of the collection.
        /// </returns>
        public bool MoveNext()
        {
            Underlying.MoveNext();

            if (Underlying.Current == null)
            {
                Current = null;
                return(true);
            }

            if (!_needNewCurrent)
            {
                // refresh on date change (in exchange time zone)
                _needNewCurrent = _timeProvider.GetUtcNow().ConvertFromUtc(_subscriptionRequest.Configuration.ExchangeTimeZone).Date != _lastEmitTime.Date;
            }

            if (_needNewCurrent)
            {
                if (!_universeProvider.CanPerformSelection())
                {
                    Current = null;
                    return(true);
                }

                var localTime = _timeProvider.GetUtcNow()
                                .RoundDown(_subscriptionRequest.Configuration.Increment)
                                .ConvertFromUtc(_subscriptionRequest.Configuration.ExchangeTimeZone);

                // loading the list of futures contracts and converting them into zip entries
                var symbols    = _universeProvider.LookupSymbols(_subscriptionRequest.Security.Symbol, false);
                var zipEntries = symbols.Select(x => new ZipEntryName {
                    Time = localTime, Symbol = x
                } as BaseData).ToList();
                _currentData = new BaseDataCollection
                {
                    Symbol     = _subscriptionRequest.Security.Symbol,
                    Underlying = Underlying.Current,
                    Data       = zipEntries,
                    Time       = localTime,
                    EndTime    = localTime
                };

                Log.Trace($"DataQueueOptionChainUniverseDataCollectionEnumerator({_currentData.Symbol}): Emitting data point: {_currentData.EndTime}. " +
                          $"Count: {_currentData.Data.Count}. Underlying: {_currentData.Underlying}");

                _lastEmitTime = localTime;

                Current         = _currentData;
                _needNewCurrent = false;
            }
            else
            {
                if (Current == null)
                {
                    Current = _currentData;
                }

                Current.Underlying = Underlying.Current;
                Current.Time       = Underlying.Current.EndTime;
                Current.EndTime    = Underlying.Current.EndTime;
            }

            return(true);
        }
Exemple #23
0
 /// <summary>
 /// TBD
 /// </summary>
 /// <param name="cause">TBD</param>
 public override void Restart(Exception cause)
 {
     Underlying.Restart(cause);
 }
 public bool IsProperSubsetOf(IEnumerable <T> other)
 {
     return(Underlying.IsProperSubsetOf(other));
 }
Exemple #25
0
 public bool IsProperSubsetOf(IEnumerable <T> other) => Underlying.IsProperSubsetOf(other);
 public bool IsSupersetOf(IEnumerable <T> other)
 {
     return(Underlying.IsSupersetOf(other));
 }
Exemple #27
0
 public bool Overlaps(IEnumerable <T> other) => Underlying.Overlaps(other);
 public bool Overlaps(IEnumerable <T> other)
 {
     return(Underlying.Overlaps(other));
 }
Exemple #29
0
        internal Task Ensure(int count, bool async, bool dontBreakOnTimeouts)
        {
            return(count <= ReadBytesLeft ? Task.CompletedTask : EnsureLong());

            async Task EnsureLong()
            {
                Debug.Assert(count <= Size);
                Debug.Assert(count > ReadBytesLeft);
                count -= ReadBytesLeft;
                if (count <= 0)
                {
                    return;
                }

                if (ReadPosition == FilledBytes)
                {
                    Clear();
                }
                else if (count > Size - FilledBytes)
                {
                    Array.Copy(Buffer, ReadPosition, Buffer, 0, ReadBytesLeft);
                    FilledBytes  = ReadBytesLeft;
                    ReadPosition = 0;
                }

                try
                {
                    var totalRead = 0;
                    while (count > 0)
                    {
                        var toRead = Size - FilledBytes;
                        var read   = async
                            ? await Underlying.ReadAsync(Buffer, FilledBytes, toRead)
                            : Underlying.Read(Buffer, FilledBytes, toRead);

                        if (read == 0)
                        {
                            throw new EndOfStreamException();
                        }
                        count       -= read;
                        FilledBytes += read;
                        totalRead   += read;
                    }

                    NpgsqlEventSource.Log.BytesRead(totalRead);
                }
                // We have a special case when reading async notifications - a timeout may be normal
                // shouldn't be fatal
                // Note that mono throws SocketException with the wrong error (see #1330)
                catch (IOException e) when(
                    dontBreakOnTimeouts && (e.InnerException as SocketException)?.SocketErrorCode ==
                    (Type.GetType("Mono.Runtime") == null ? SocketError.TimedOut : SocketError.WouldBlock)
                    )
                {
                    throw new TimeoutException("Timeout while reading from stream");
                }
                catch (Exception e)
                {
                    throw Connector.Break(new NpgsqlException("Exception while reading from stream", e));
                }
            }
        }
        public static bool IsSpecialValue(float value)
        {
            const uint SpecialValue = 0x7F800000;

            return((Underlying.As <float, uint>(ref value) & SpecialValue) == SpecialValue);
        }