コード例 #1
0
        public unsafe override WritableBufferAwaitable WriteAlert(AlertException alert)
        {
            ushort data = 0;
            var    span = new Span <byte>(&data, 2);

            span[0] = (byte)alert.Level;
            span[1] = (byte)alert.Description;
            var recordHeader = new RecordHeader()
            {
                RecordType = RecordType.Alert,
                Length     = (ushort)span.Length,
                Version    = _recordVersion
            };

            if (_connection?.WriteKey != null)
            {
                recordHeader.Length += (ushort)(8 + _connection.WriteKey.Overhead);
            }
            var writer = _output.Alloc(sizeof(RecordHeader));

            writer.Buffer.Span.Write(recordHeader);
            writer.Advance(sizeof(RecordHeader));
            if (_connection?.WriteKey != null)
            {
                _connection.WriteKey.Encrypt(ref writer, span, RecordType.Alert, _recordVersion);
            }
            else
            {
                writer.Write(span);
            }
            return(writer.FlushAsync());
        }
コード例 #2
0
        public static DataResult <TModel> ForException(Exception exception)
        {
            if (exception is AlertException)
            {
                AlertException alertException = exception as AlertException;

                return(new DataResult <TModel>(alertException.Message));
            }

            return(new DataResult <TModel>("系统错误,请重试"));
        }
コード例 #3
0
 public abstract WritableBufferAwaitable WriteAlert(AlertException alert);