예제 #1
0
        public async Task <T> APICallAsync <T>(
            HttpMethod method,
            APIEndpoint endpoint,
            object queryStringContent                        = null,
            object bodyContent                               = null,
            IDictionary <string, string> headers             = null,
            Func <HttpResponseMessage, Task <T> > onResponse = null,
            CancellationToken cancellationToken              = default(CancellationToken)
            )
        {
            using (var request = await RequestAsync(method, endpoint.Endpoint,
                                                    queryStringContent,
                                                    bodyContent,
                                                    headers: headers))
                using (var response = await Client.SendAsync(
                           request,
                           HttpCompletionOption.ResponseHeadersRead,
                           cancellationToken
                           ))
                {
                    if (onResponse != null)
                    {
                        return(await onResponse.Invoke(response));
                    }

                    return(await DefaultResponseHandler <T>(response));
                }
        }
예제 #2
0
        public async Task ConnectAsync(CancellationToken cancellationToken = default(CancellationToken))
        {
            Socket = await APIClient.ConnectWebSocket(
                APIEndpoint.PlayerConnect(WorldName), cancellationToken : cancellationToken
                );

            if (OnConnected != null)
            {
                await OnConnected();
            }
        }
예제 #3
0
 public Task <ClientWebSocket> ConnectWebSocket(
     APIEndpoint apiEndpoint,
     object querystring = null,
     Action <ClientWebSocket> configure  = null,
     CancellationToken cancellationToken = default(CancellationToken))
 => ConnectWebSocket(apiEndpoint.Endpoint, querystring, configure, cancellationToken);