コード例 #1
0
ファイル: Socket.cs プロジェクト: ByronMayne/Redux.DotNet
        public void Emit(string eventName, object data)
        {
            m_log.Information("Emit {EventName} {@Data}", eventName, data);

            SocketRequest request = new SocketRequest(GetNextCallId())
            {
                Data      = data,
                EventName = eventName,
            };

            request.Send(m_socket);
        }
コード例 #2
0
ファイル: Socket.cs プロジェクト: ByronMayne/Redux.DotNet
        /// <summary>
        /// Enqueues a new result object and waits for the servers response
        /// </summary>
        private async Task <Response <T> > SendRequestAsync <T>(SocketRequest request)
        {
            TaskCompletionSource <JToken> result = new TaskCompletionSource <JToken>();

            m_pendingResponses.Add(request.CallId, result);

            request.Send(m_socket);

            JObject response = (JObject)await result.Task;

            int    responseId = response["rid"].ToObject <int>();
            bool   okay       = !response.ContainsKey("error");
            string error      = okay ? "" : response["error"]["message"].ToString();
            T      value      = okay ? response["data"].ToObject <T>() : default(T);

            return(new Response <T>(responseId, value, okay, error));
        }
コード例 #3
0
ファイル: Socket.cs プロジェクト: ByronMayne/Redux.DotNet
        private void OnSocketOpened(object sender, EventArgs e)
        => Task.Run(async() =>
        {
            m_log.Information("Socket Closed");
            m_nextCallId = 0;

            SocketRequest request = new SocketRequest(GetNextCallId())
            {
                EventName = "#handshake",
            };

            Response <Authentication> response = await SendRequestAsync <Authentication>(request);

            request.Send(m_socket);

            m_connectedCompletionSource.SetResult(response);
        });