Removed System.Net.Http dependency
This commit is contained in:
@@ -40,7 +40,11 @@ namespace Discord
|
|||||||
config.VoiceClientId = unchecked(++_nextVoiceClientId);
|
config.VoiceClientId = unchecked(++_nextVoiceClientId);
|
||||||
return new DiscordWSClient(config, server.Id);
|
return new DiscordWSClient(config, server.Id);
|
||||||
});
|
});
|
||||||
client.LogMessage += (s, e) => RaiseOnLog(e.Severity, e.Source, $"(#{client.Config.VoiceClientId}) {e.Message}", e.Exception);
|
client.LogMessage += (s, e) =>
|
||||||
|
{
|
||||||
|
if (e.Source != LogMessageSource.DataWebSocket)
|
||||||
|
RaiseOnLog(e.Severity, e.Source, $"(#{client.Config.VoiceClientId}) {e.Message}", e.Exception);
|
||||||
|
};
|
||||||
await client.Connect(_gateway, _token).ConfigureAwait(false);
|
await client.Connect(_gateway, _token).ConfigureAwait(false);
|
||||||
return client;
|
return client;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -132,9 +132,9 @@ namespace Discord
|
|||||||
_api.RestClient.OnRequest += (s, e) =>
|
_api.RestClient.OnRequest += (s, e) =>
|
||||||
{
|
{
|
||||||
if (e.Payload != null)
|
if (e.Payload != null)
|
||||||
RaiseOnLog(LogMessageSeverity.Verbose, LogMessageSource.Rest, $"{e.Method.Method} {e.Path}: {Math.Round(e.ElapsedMilliseconds, 2)} ms ({e.Payload})");
|
RaiseOnLog(LogMessageSeverity.Verbose, LogMessageSource.Rest, $"{e.Method} {e.Path}: {Math.Round(e.ElapsedMilliseconds, 2)} ms ({e.Payload})");
|
||||||
else
|
else
|
||||||
RaiseOnLog(LogMessageSeverity.Verbose, LogMessageSource.Rest, $"{e.Method.Method} {e.Path}: {Math.Round(e.ElapsedMilliseconds, 2)} ms");
|
RaiseOnLog(LogMessageSeverity.Verbose, LogMessageSource.Rest, $"{e.Method} {e.Path}: {Math.Round(e.ElapsedMilliseconds, 2)} ms");
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
if (_config.LogLevel >= LogMessageSeverity.Debug)
|
if (_config.LogLevel >= LogMessageSeverity.Debug)
|
||||||
|
|||||||
@@ -79,15 +79,12 @@ namespace Discord
|
|||||||
if (e.WasUnexpected)
|
if (e.WasUnexpected)
|
||||||
await socket.Reconnect(_token).ConfigureAwait(false);
|
await socket.Reconnect(_token).ConfigureAwait(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!_config.VoiceOnly)
|
socket.LogMessage += (s, e) => RaiseOnLog(e.Severity, LogMessageSource.DataWebSocket, e.Message, e.Exception);
|
||||||
|
if (_config.LogLevel >= LogMessageSeverity.Info)
|
||||||
{
|
{
|
||||||
socket.LogMessage += (s, e) => RaiseOnLog(e.Severity, LogMessageSource.DataWebSocket, e.Message, e.Exception);
|
socket.Connected += (s, e) => RaiseOnLog(LogMessageSeverity.Info, LogMessageSource.DataWebSocket, "Connected");
|
||||||
if (_config.LogLevel >= LogMessageSeverity.Info)
|
socket.Disconnected += (s, e) => RaiseOnLog(LogMessageSeverity.Info, LogMessageSource.DataWebSocket, "Disconnected");
|
||||||
{
|
|
||||||
socket.Connected += (s, e) => RaiseOnLog(LogMessageSeverity.Info, LogMessageSource.DataWebSocket, "Connected");
|
|
||||||
socket.Disconnected += (s, e) => RaiseOnLog(LogMessageSeverity.Info, LogMessageSource.DataWebSocket, "Disconnected");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
socket.ReceivedEvent += async (s, e) => await OnReceivedEvent(e).ConfigureAwait(false);
|
socket.ReceivedEvent += async (s, e) => await OnReceivedEvent(e).ConfigureAwait(false);
|
||||||
@@ -96,7 +93,6 @@ namespace Discord
|
|||||||
internal virtual VoiceWebSocket CreateVoiceSocket()
|
internal virtual VoiceWebSocket CreateVoiceSocket()
|
||||||
{
|
{
|
||||||
var socket = new VoiceWebSocket(this);
|
var socket = new VoiceWebSocket(this);
|
||||||
socket.LogMessage += (s, e) => RaiseOnLog(e.Severity, LogMessageSource.VoiceWebSocket, e.Message, e.Exception);
|
|
||||||
socket.Connected += (s, e) => RaiseVoiceConnected();
|
socket.Connected += (s, e) => RaiseVoiceConnected();
|
||||||
socket.Disconnected += async (s, e) =>
|
socket.Disconnected += async (s, e) =>
|
||||||
{
|
{
|
||||||
@@ -104,11 +100,14 @@ namespace Discord
|
|||||||
if (e.WasUnexpected)
|
if (e.WasUnexpected)
|
||||||
await socket.Reconnect().ConfigureAwait(false);
|
await socket.Reconnect().ConfigureAwait(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
socket.LogMessage += (s, e) => RaiseOnLog(e.Severity, LogMessageSource.VoiceWebSocket, e.Message, e.Exception);
|
||||||
if (_config.LogLevel >= LogMessageSeverity.Info)
|
if (_config.LogLevel >= LogMessageSeverity.Info)
|
||||||
{
|
{
|
||||||
socket.Connected += (s, e) => RaiseOnLog(LogMessageSeverity.Info, LogMessageSource.VoiceWebSocket, "Connected");
|
socket.Connected += (s, e) => RaiseOnLog(LogMessageSeverity.Info, LogMessageSource.VoiceWebSocket, "Connected");
|
||||||
socket.Disconnected += (s, e) => RaiseOnLog(LogMessageSeverity.Info, LogMessageSource.VoiceWebSocket, "Disconnected");
|
socket.Disconnected += (s, e) => RaiseOnLog(LogMessageSeverity.Info, LogMessageSource.VoiceWebSocket, "Disconnected");
|
||||||
}
|
}
|
||||||
|
|
||||||
return socket;
|
return socket;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
using System.Net.Http;
|
using System.Threading;
|
||||||
using System.Threading;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace Discord.Net.Rest
|
namespace Discord.Net.Rest
|
||||||
@@ -7,7 +6,7 @@ namespace Discord.Net.Rest
|
|||||||
internal interface IRestEngine
|
internal interface IRestEngine
|
||||||
{
|
{
|
||||||
void SetToken(string token);
|
void SetToken(string token);
|
||||||
Task<string> Send(HttpMethod method, string path, string json, CancellationToken cancelToken);
|
Task<string> Send(string method, string path, string json, CancellationToken cancelToken);
|
||||||
Task<string> SendFile(HttpMethod method, string path, string filePath, CancellationToken cancelToken);
|
Task<string> SendFile(string method, string path, string filePath, CancellationToken cancelToken);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Net.Http;
|
|
||||||
|
|
||||||
namespace Discord.Net.Rest
|
namespace Discord.Net.Rest
|
||||||
{
|
{
|
||||||
@@ -7,11 +6,11 @@ namespace Discord.Net.Rest
|
|||||||
{
|
{
|
||||||
public class RequestEventArgs : EventArgs
|
public class RequestEventArgs : EventArgs
|
||||||
{
|
{
|
||||||
public HttpMethod Method { get; }
|
public string Method { get; }
|
||||||
public string Path { get; }
|
public string Path { get; }
|
||||||
public string Payload { get; }
|
public string Payload { get; }
|
||||||
public double ElapsedMilliseconds { get; }
|
public double ElapsedMilliseconds { get; }
|
||||||
public RequestEventArgs(HttpMethod method, string path, string payload, double milliseconds)
|
public RequestEventArgs(string method, string path, string payload, double milliseconds)
|
||||||
{
|
{
|
||||||
Method = method;
|
Method = method;
|
||||||
Path = path;
|
Path = path;
|
||||||
@@ -21,7 +20,7 @@ namespace Discord.Net.Rest
|
|||||||
}
|
}
|
||||||
|
|
||||||
public event EventHandler<RequestEventArgs> OnRequest;
|
public event EventHandler<RequestEventArgs> OnRequest;
|
||||||
private void RaiseOnRequest(HttpMethod method, string path, string payload, double milliseconds)
|
private void RaiseOnRequest(string method, string path, string payload, double milliseconds)
|
||||||
{
|
{
|
||||||
if (OnRequest != null)
|
if (OnRequest != null)
|
||||||
OnRequest(this, new RequestEventArgs(method, path, payload, milliseconds));
|
OnRequest(this, new RequestEventArgs(method, path, payload, milliseconds));
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using System;
|
using System;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Net.Http;
|
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
@@ -27,69 +26,64 @@ namespace Discord.Net.Rest
|
|||||||
public void SetToken(string token) => _engine.SetToken(token);
|
public void SetToken(string token) => _engine.SetToken(token);
|
||||||
|
|
||||||
//DELETE
|
//DELETE
|
||||||
private static readonly HttpMethod _delete = HttpMethod.Delete;
|
|
||||||
internal Task<ResponseT> Delete<ResponseT>(string path, object data) where ResponseT : class
|
internal Task<ResponseT> Delete<ResponseT>(string path, object data) where ResponseT : class
|
||||||
=> Send<ResponseT>(_delete, path, data);
|
=> Send<ResponseT>("DELETE", path, data);
|
||||||
internal Task<ResponseT> Delete<ResponseT>(string path) where ResponseT : class
|
internal Task<ResponseT> Delete<ResponseT>(string path) where ResponseT : class
|
||||||
=> Send<ResponseT>(_delete, path);
|
=> Send<ResponseT>("DELETE", path);
|
||||||
internal Task Delete(string path, object data)
|
internal Task Delete(string path, object data)
|
||||||
=> Send(_delete, path, data);
|
=> Send("DELETE", path, data);
|
||||||
internal Task Delete(string path)
|
internal Task Delete(string path)
|
||||||
=> Send(_delete, path);
|
=> Send("DELETE", path);
|
||||||
|
|
||||||
//GET
|
//GET
|
||||||
private static readonly HttpMethod _get = HttpMethod.Get;
|
|
||||||
internal Task<ResponseT> Get<ResponseT>(string path) where ResponseT : class
|
internal Task<ResponseT> Get<ResponseT>(string path) where ResponseT : class
|
||||||
=> Send<ResponseT>(_get, path);
|
=> Send<ResponseT>("GET", path);
|
||||||
internal Task Get(string path)
|
internal Task Get(string path)
|
||||||
=> Send(_get, path);
|
=> Send("GET", path);
|
||||||
|
|
||||||
//PATCH
|
//PATCH
|
||||||
private static readonly HttpMethod _patch = new HttpMethod("PATCH");
|
|
||||||
internal Task<ResponseT> Patch<ResponseT>(string path, object data) where ResponseT : class
|
internal Task<ResponseT> Patch<ResponseT>(string path, object data) where ResponseT : class
|
||||||
=> Send<ResponseT>(_patch, path, data);
|
=> Send<ResponseT>("PATCH", path, data);
|
||||||
internal Task Patch(string path, object data)
|
internal Task Patch(string path, object data)
|
||||||
=> Send(_patch, path, data);
|
=> Send("PATCH", path, data);
|
||||||
|
|
||||||
private static readonly HttpMethod _post = HttpMethod.Post;
|
|
||||||
internal Task<ResponseT> Post<ResponseT>(string path, object data) where ResponseT : class
|
internal Task<ResponseT> Post<ResponseT>(string path, object data) where ResponseT : class
|
||||||
=> Send<ResponseT>(_post, path, data);
|
=> Send<ResponseT>("POST", path, data);
|
||||||
internal Task<ResponseT> Post<ResponseT>(string path) where ResponseT : class
|
internal Task<ResponseT> Post<ResponseT>(string path) where ResponseT : class
|
||||||
=> Send<ResponseT>(_post, path);
|
=> Send<ResponseT>("POST", path);
|
||||||
internal Task Post(string path, object data)
|
internal Task Post(string path, object data)
|
||||||
=> Send(_post, path, data);
|
=> Send("POST", path, data);
|
||||||
internal Task Post(string path)
|
internal Task Post(string path)
|
||||||
=> Send(_post, path);
|
=> Send("POST", path);
|
||||||
|
|
||||||
private static readonly HttpMethod _put = HttpMethod.Put;
|
|
||||||
internal Task<ResponseT> Put<ResponseT>(string path, object data) where ResponseT : class
|
internal Task<ResponseT> Put<ResponseT>(string path, object data) where ResponseT : class
|
||||||
=> Send<ResponseT>(_put, path, data);
|
=> Send<ResponseT>("PUT", path, data);
|
||||||
internal Task<ResponseT> Put<ResponseT>(string path) where ResponseT : class
|
internal Task<ResponseT> Put<ResponseT>(string path) where ResponseT : class
|
||||||
=> Send<ResponseT>(_put, path);
|
=> Send<ResponseT>("PUT", path);
|
||||||
internal Task Put(string path, object data)
|
internal Task Put(string path, object data)
|
||||||
=> Send(_put, path, data);
|
=> Send("PUT", path, data);
|
||||||
internal Task Put(string path)
|
internal Task Put(string path)
|
||||||
=> Send(_put, path);
|
=> Send("PUT", path);
|
||||||
|
|
||||||
internal Task<ResponseT> PostFile<ResponseT>(string path, string filePath) where ResponseT : class
|
internal Task<ResponseT> PostFile<ResponseT>(string path, string filePath) where ResponseT : class
|
||||||
=> SendFile<ResponseT>(_post, path, filePath);
|
=> SendFile<ResponseT>("POST", path, filePath);
|
||||||
internal Task PostFile(string path, string filePath)
|
internal Task PostFile(string path, string filePath)
|
||||||
=> SendFile(_post, path, filePath);
|
=> SendFile("POST", path, filePath);
|
||||||
|
|
||||||
internal Task<ResponseT> PutFile<ResponseT>(string path, string filePath) where ResponseT : class
|
internal Task<ResponseT> PutFile<ResponseT>(string path, string filePath) where ResponseT : class
|
||||||
=> SendFile<ResponseT>(_put, path, filePath);
|
=> SendFile<ResponseT>("PUT", path, filePath);
|
||||||
internal Task PutFile(string path, string filePath)
|
internal Task PutFile(string path, string filePath)
|
||||||
=> SendFile(_put, path, filePath);
|
=> SendFile("PUT", path, filePath);
|
||||||
|
|
||||||
private async Task<ResponseT> Send<ResponseT>(HttpMethod method, string path, object content = null)
|
private async Task<ResponseT> Send<ResponseT>(string method, string path, object content = null)
|
||||||
where ResponseT : class
|
where ResponseT : class
|
||||||
{
|
{
|
||||||
string responseJson = await Send(method, path, content, true).ConfigureAwait(false);
|
string responseJson = await Send(method, path, content, true).ConfigureAwait(false);
|
||||||
return DeserializeResponse<ResponseT>(responseJson);
|
return DeserializeResponse<ResponseT>(responseJson);
|
||||||
}
|
}
|
||||||
private Task Send(HttpMethod method, string path, object content = null)
|
private Task Send(string method, string path, object content = null)
|
||||||
=> Send(method, path, content, false);
|
=> Send(method, path, content, false);
|
||||||
private async Task<string> Send(HttpMethod method, string path, object content, bool hasResponse)
|
private async Task<string> Send(string method, string path, object content, bool hasResponse)
|
||||||
{
|
{
|
||||||
Stopwatch stopwatch = null;
|
Stopwatch stopwatch = null;
|
||||||
string requestJson = null;
|
string requestJson = null;
|
||||||
@@ -123,15 +117,15 @@ namespace Discord.Net.Rest
|
|||||||
return responseJson;
|
return responseJson;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<ResponseT> SendFile<ResponseT>(HttpMethod method, string path, string filePath)
|
private async Task<ResponseT> SendFile<ResponseT>(string method, string path, string filePath)
|
||||||
where ResponseT : class
|
where ResponseT : class
|
||||||
{
|
{
|
||||||
string responseJson = await SendFile(method, path, filePath, true).ConfigureAwait(false);
|
string responseJson = await SendFile(method, path, filePath, true).ConfigureAwait(false);
|
||||||
return DeserializeResponse<ResponseT>(responseJson);
|
return DeserializeResponse<ResponseT>(responseJson);
|
||||||
}
|
}
|
||||||
private Task SendFile(HttpMethod method, string path, string filePath)
|
private Task SendFile(string method, string path, string filePath)
|
||||||
=> SendFile(method, path, filePath, false);
|
=> SendFile(method, path, filePath, false);
|
||||||
private async Task<string> SendFile(HttpMethod method, string path, string filePath, bool hasResponse)
|
private async Task<string> SendFile(string method, string path, string filePath, bool hasResponse)
|
||||||
{
|
{
|
||||||
Stopwatch stopwatch = null;
|
Stopwatch stopwatch = null;
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ using Discord.API;
|
|||||||
using RestSharp;
|
using RestSharp;
|
||||||
using System;
|
using System;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Net.Http;
|
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
@@ -39,13 +38,13 @@ namespace Discord.Net.Rest
|
|||||||
_client.AddDefaultHeader("authorization", token);
|
_client.AddDefaultHeader("authorization", token);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<string> Send(HttpMethod method, string path, string json, CancellationToken cancelToken)
|
public Task<string> Send(string method, string path, string json, CancellationToken cancelToken)
|
||||||
{
|
{
|
||||||
var request = new RestRequest(path, GetMethod(method));
|
var request = new RestRequest(path, GetMethod(method));
|
||||||
request.AddParameter("application/json", json, ParameterType.RequestBody);
|
request.AddParameter("application/json", json, ParameterType.RequestBody);
|
||||||
return Send(request, cancelToken);
|
return Send(request, cancelToken);
|
||||||
}
|
}
|
||||||
public Task<string> SendFile(HttpMethod method, string path, string filePath, CancellationToken cancelToken)
|
public Task<string> SendFile(string method, string path, string filePath, CancellationToken cancelToken)
|
||||||
{
|
{
|
||||||
var request = new RestRequest(path, Method.POST);
|
var request = new RestRequest(path, Method.POST);
|
||||||
request.AddFile("file", filePath);
|
request.AddFile("file", filePath);
|
||||||
@@ -70,9 +69,9 @@ namespace Discord.Net.Rest
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Method GetMethod(HttpMethod method)
|
private Method GetMethod(string method)
|
||||||
{
|
{
|
||||||
switch (method.Method)
|
switch (method)
|
||||||
{
|
{
|
||||||
case "DELETE": return Method.DELETE;
|
case "DELETE": return Method.DELETE;
|
||||||
case "GET": return Method.GET;
|
case "GET": return Method.GET;
|
||||||
|
|||||||
@@ -35,18 +35,12 @@
|
|||||||
|
|
||||||
"frameworks": {
|
"frameworks": {
|
||||||
"net45": {
|
"net45": {
|
||||||
"frameworkAssemblies": {
|
|
||||||
"System.Net.Http": "4.0.0.0"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"RestSharp": "105.2.3",
|
"RestSharp": "105.2.3",
|
||||||
"WebSocketSharp": "1.0.3-rc9"
|
"WebSocketSharp": "1.0.3-rc9"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"dnx451": {
|
"dnx451": {
|
||||||
"frameworkAssemblies": {
|
|
||||||
"System.Net.Http": "4.0.0.0"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"RestSharp": "105.2.3",
|
"RestSharp": "105.2.3",
|
||||||
"WebSocketSharp": "1.0.3-rc9"
|
"WebSocketSharp": "1.0.3-rc9"
|
||||||
|
|||||||
Reference in New Issue
Block a user