Ejemplo n.º 1
0
        Task IGangMember.ConnectAsync(
            IGangController controller, Func <Task> _onDisconnectAsync)
        {
            return(Task.Run(async() =>
            {
                do
                {
                    using var data = new MemoryStream();
                    WebSocketReceiveResult result;
                    do
                    {
                        result = await _webSocket
                                 .ReceiveAsync(_buffer, CancellationToken.None);

                        if (result.MessageType != WebSocketMessageType.Binary)
                        {
                            break;
                        }

                        await data.WriteAsync(_buffer.AsMemory(0, result.Count));
                    } while (!result.EndOfMessage);

                    if (data.Length > 0)
                    {
                        await controller.ReceiveAsync(data.ToArray());
                    }
                } while (_webSocket.State == WebSocketState.Open);

                if (_onDisconnectAsync != null)
                {
                    await _onDisconnectAsync();
                }
            }));
        }
Ejemplo n.º 2
0
 public static IGangMember GetMember(
     this IGangController controller,
     byte[] memberId
     )
 {
     return(controller.GetGang().MemberById(memberId));
 }
Ejemplo n.º 3
0
 public static Task DisconnectAsync(
     this IGangController controller,
     string memberId,
     string reason = null)
 {
     return(controller.DisconnectAsync(memberId.GangToBytes(), reason));
 }
Ejemplo n.º 4
0
 Task IGangMember.ConnectAsync(
     IGangController controller, Func <Task> onDisconnectAsync)
 {
     Controller        = controller;
     OnDisconnectAsync = onDisconnectAsync;
     Connected         = true;
     return(Task.CompletedTask);
 }
Ejemplo n.º 5
0
        async Task IGangMember.ConnectAsync(
            IGangController controller,
            Func <Task> onDisconnectAsync)
        {
            _onDisconnectAsync = onDisconnectAsync;
            Controller         = controller;

            await OnConnectAsync();
        }
Ejemplo n.º 6
0
        public static Task SendCommandAsync(
            this IGangController controller,
            object data,
            IEnumerable <byte[]> memberIds = null,
            uint?replySequence             = null)
        {
            if (data is null)
            {
                throw new ArgumentNullException(nameof(data));
            }

            return(controller.SendCommandAsync(
                       data.GetType().GetCommandTypeName(), data,
                       memberIds, replySequence));
        }