Reorganized Net namespace, made SharpRest inherit from RestClient.

This commit is contained in:
RogueException
2015-10-18 18:54:23 -03:00
parent 2969361333
commit ee44caf6ab
19 changed files with 91 additions and 70 deletions

View File

@@ -244,41 +244,47 @@
<Compile Include="..\Discord.Net\Models\User.cs"> <Compile Include="..\Discord.Net\Models\User.cs">
<Link>Models\User.cs</Link> <Link>Models\User.cs</Link>
</Compile> </Compile>
<Compile Include="..\Discord.Net\Net\DataWebSocket.cs">
<Link>Net\DataWebSocket.cs</Link>
</Compile>
<Compile Include="..\Discord.Net\Net\DataWebSockets.Events.cs">
<Link>Net\DataWebSockets.Events.cs</Link>
</Compile>
<Compile Include="..\Discord.Net\Net\HttpException.cs"> <Compile Include="..\Discord.Net\Net\HttpException.cs">
<Link>Net\HttpException.cs</Link> <Link>Net\HttpException.cs</Link>
</Compile> </Compile>
<Compile Include="..\Discord.Net\Net\RestClient.cs"> <Compile Include="..\Discord.Net\Net\Rest\RestClient.cs">
<Link>Net\RestClient.cs</Link> <Link>Net\Rest\RestClient.cs</Link>
</Compile> </Compile>
<Compile Include="..\Discord.Net\Net\RestClient.Events.cs"> <Compile Include="..\Discord.Net\Net\Rest\RestClient.Events.cs">
<Link>Net\RestClient.Events.cs</Link> <Link>Net\Rest\RestClient.Events.cs</Link>
</Compile> </Compile>
<Compile Include="..\Discord.Net\Net\RestClient.SharpRest.cs"> <Compile Include="..\Discord.Net\Net\Rest\SharpRestRestClient.cs">
<Link>Net\RestClient.SharpRest.cs</Link> <Link>Net\Rest\SharpRestRestClient.cs</Link>
</Compile> </Compile>
<Compile Include="..\Discord.Net\Net\VoiceBuffer.cs"> <Compile Include="..\Discord.Net\Net\Voice\IDiscordVoiceBuffer.cs">
<Link>Net\VoiceBuffer.cs</Link> <Link>Net\Voice\IDiscordVoiceBuffer.cs</Link>
</Compile> </Compile>
<Compile Include="..\Discord.Net\Net\VoiceWebSocket.cs"> <Compile Include="..\Discord.Net\Net\Voice\IDiscordVoiceClient.cs">
<Link>Net\VoiceWebSocket.cs</Link> <Link>Net\Voice\IDiscordVoiceClient.cs</Link>
</Compile> </Compile>
<Compile Include="..\Discord.Net\Net\VoiceWebSocket.Events.cs"> <Compile Include="..\Discord.Net\Net\Voice\VoiceBuffer.cs">
<Link>Net\VoiceWebSocket.Events.cs</Link> <Link>Net\Voice\VoiceBuffer.cs</Link>
</Compile> </Compile>
<Compile Include="..\Discord.Net\Net\WebSocket.cs"> <Compile Include="..\Discord.Net\Net\WebSockets\DataWebSocket.cs">
<Link>Net\WebSocket.cs</Link> <Link>Net\WebSockets\DataWebSocket.cs</Link>
</Compile> </Compile>
<Compile Include="..\Discord.Net\Net\WebSocket.Events.cs"> <Compile Include="..\Discord.Net\Net\WebSockets\DataWebSockets.Events.cs">
<Link>Net\WebSocket.Events.cs</Link> <Link>Net\WebSockets\DataWebSockets.Events.cs</Link>
</Compile> </Compile>
<Compile Include="..\Discord.Net\Net\WebSocket.WebSocketSharp.cs"> <Compile Include="..\Discord.Net\Net\WebSockets\VoiceWebSocket.cs">
<Link>Net\WebSocket.WebSocketSharp.cs</Link> <Link>Net\WebSockets\VoiceWebSocket.cs</Link>
</Compile>
<Compile Include="..\Discord.Net\Net\WebSockets\VoiceWebSocket.Events.cs">
<Link>Net\WebSockets\VoiceWebSocket.Events.cs</Link>
</Compile>
<Compile Include="..\Discord.Net\Net\WebSockets\WebSocket.cs">
<Link>Net\WebSockets\WebSocket.cs</Link>
</Compile>
<Compile Include="..\Discord.Net\Net\WebSockets\WebSocket.Events.cs">
<Link>Net\WebSockets\WebSocket.Events.cs</Link>
</Compile>
<Compile Include="..\Discord.Net\Net\WebSockets\WebSocket.WebSocketSharp.cs">
<Link>Net\WebSockets\WebSocket.WebSocketSharp.cs</Link>
</Compile> </Compile>
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup> </ItemGroup>

View File

@@ -1,5 +1,6 @@
using Discord.API; using Discord.API;
using Discord.Net; using Discord.Net;
using Discord.Net.Rest;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@@ -19,7 +20,7 @@ namespace Discord
public DiscordAPIClient(DiscordAPIClientConfig config = null) public DiscordAPIClient(DiscordAPIClientConfig config = null)
{ {
_config = config ?? new DiscordAPIClientConfig(); _config = config ?? new DiscordAPIClientConfig();
_rest = new RestClient(_config); _rest = new SharpRestRestClient(_config);
} }
private string _token; private string _token;

View File

@@ -1,6 +1,8 @@
using Discord.API; using Discord.API;
using Discord.Collections; using Discord.Collections;
using Discord.Net; using Discord.Net;
using Discord.Net.Voice;
using Discord.Net.WebSockets;
using Newtonsoft.Json; using Newtonsoft.Json;
using System; using System;
using System.Collections.Concurrent; using System.Collections.Concurrent;

View File

@@ -1,28 +1,9 @@
using System; using Discord.Net.Voice;
using System;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Discord namespace Discord
{ {
public interface IDiscordVoiceBuffer
{
int FrameSize { get; }
int FrameCount { get; }
ushort ReadPos { get; }
ushort WritePos { get; }
}
public interface IDiscordVoiceClient
{
IDiscordVoiceBuffer OutputBuffer { get; }
Task JoinChannel(string channelId);
void SendVoicePCM(byte[] data, int count);
void ClearVoicePCM();
Task WaitVoice();
}
public partial class DiscordWebSocketClient : IDiscordVoiceClient public partial class DiscordWebSocketClient : IDiscordVoiceClient
{ {
IDiscordVoiceBuffer IDiscordVoiceClient.OutputBuffer => _voiceSocket.OutputBuffer; IDiscordVoiceBuffer IDiscordVoiceClient.OutputBuffer => _voiceSocket.OutputBuffer;

View File

@@ -1,4 +1,5 @@
using Discord.Net; using Discord.Net;
using Discord.Net.WebSockets;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;

View File

@@ -1,9 +1,9 @@
using System; using System;
using System.Net.Http; using System.Net.Http;
namespace Discord.Net namespace Discord.Net.Rest
{ {
internal partial class RestClient internal abstract partial class RestClient
{ {
public class RequestEventArgs : EventArgs public class RequestEventArgs : EventArgs
{ {

View File

@@ -6,19 +6,21 @@ using System.Net.Http;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Discord.Net namespace Discord.Net.Rest
{ {
internal partial class RestClient internal abstract partial class RestClient
{ {
private readonly DiscordAPIClientConfig _config; protected readonly DiscordAPIClientConfig _config;
private CancellationToken _cancelToken; protected CancellationToken _cancelToken;
public RestClient(DiscordAPIClientConfig config) public RestClient(DiscordAPIClientConfig config)
{ {
_config = config; _config = config;
Initialize();
} }
partial void Initialize();
protected internal abstract void SetToken(string token);
protected abstract Task<string> SendInternal(HttpMethod method, string path, string json, CancellationToken cancelToken);
protected abstract Task<string> SendFileInternal(HttpMethod method, string path, string filePath, CancellationToken cancelToken);
//DELETE //DELETE
private static readonly HttpMethod _delete = HttpMethod.Delete; private static readonly HttpMethod _delete = HttpMethod.Delete;

View File

@@ -6,13 +6,14 @@ using System.Net.Http;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Discord.Net namespace Discord.Net.Rest
{ {
internal partial class RestClient internal sealed class SharpRestRestClient : RestClient
{ {
private RestSharp.RestClient _client; private readonly RestSharp.RestClient _client;
partial void Initialize() public SharpRestRestClient(DiscordAPIClientConfig config)
: base(config)
{ {
_client = new RestSharp.RestClient(Endpoints.BaseApi) _client = new RestSharp.RestClient(Endpoints.BaseApi)
{ {
@@ -26,20 +27,20 @@ namespace Discord.Net
_client.AddDefaultHeader("accept-encoding", "gzip,deflate"); _client.AddDefaultHeader("accept-encoding", "gzip,deflate");
} }
internal void SetToken(string token) protected internal override void SetToken(string token)
{ {
_client.RemoveDefaultParameter("authorization"); _client.RemoveDefaultParameter("authorization");
if (token != null) if (token != null)
_client.AddDefaultHeader("authorization", token); _client.AddDefaultHeader("authorization", token);
} }
private Task<string> SendInternal(HttpMethod method, string path, string json, CancellationToken cancelToken) protected override Task<string> SendInternal(HttpMethod 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);
} }
private Task<string> SendFileInternal(HttpMethod method, string path, string filePath, CancellationToken cancelToken) protected override Task<string> SendFileInternal(HttpMethod 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);

View File

@@ -0,0 +1,10 @@
namespace Discord.Net.Voice
{
public interface IDiscordVoiceBuffer
{
int FrameSize { get; }
int FrameCount { get; }
ushort ReadPos { get; }
ushort WritePos { get; }
}
}

View File

@@ -0,0 +1,16 @@
using System.Threading.Tasks;
namespace Discord.Net.Voice
{
public interface IDiscordVoiceClient
{
IDiscordVoiceBuffer OutputBuffer { get; }
Task JoinChannel(string channelId);
void SendVoicePCM(byte[] data, int count);
void ClearVoicePCM();
Task WaitVoice();
}
}

View File

@@ -1,7 +1,7 @@
using System; using System;
using System.Threading; using System.Threading;
namespace Discord.Net namespace Discord.Net.Voice
{ {
internal class VoiceBuffer : IDiscordVoiceBuffer internal class VoiceBuffer : IDiscordVoiceBuffer
{ {

View File

@@ -4,7 +4,7 @@ using Newtonsoft.Json.Linq;
using System; using System;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Discord.Net namespace Discord.Net.WebSockets
{ {
internal partial class DataWebSocket : WebSocket internal partial class DataWebSocket : WebSocket
{ {

View File

@@ -1,7 +1,7 @@
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using System; using System;
namespace Discord.Net namespace Discord.Net.WebSockets
{ {
internal sealed class WebSocketEventEventArgs : EventArgs internal sealed class WebSocketEventEventArgs : EventArgs
{ {

View File

@@ -1,6 +1,6 @@
using System; using System;
namespace Discord.Net namespace Discord.Net.WebSockets
{ {
internal sealed class IsTalkingEventArgs : EventArgs internal sealed class IsTalkingEventArgs : EventArgs
{ {

View File

@@ -1,6 +1,7 @@
#define USE_THREAD #define USE_THREAD
using Discord.API; using Discord.API;
using Discord.Interop; using Discord.Interop;
using Discord.Net.Voice;
using Newtonsoft.Json; using Newtonsoft.Json;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using System; using System;
@@ -14,7 +15,7 @@ using System.Text;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Discord.Net namespace Discord.Net.WebSockets
{ {
internal partial class VoiceWebSocket : WebSocket internal partial class VoiceWebSocket : WebSocket
{ {

View File

@@ -9,7 +9,7 @@ using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using State = System.Net.WebSockets.WebSocketState; using State = System.Net.WebSockets.WebSocketState;
namespace Discord.WebSockets namespace Discord.Net.WebSockets
{ {
internal class BuiltInWebSocketEngine : IWebSocketEngine internal class BuiltInWebSocketEngine : IWebSocketEngine
{ {

View File

@@ -1,6 +1,6 @@
using System; using System;
namespace Discord.Net namespace Discord.Net.WebSockets
{ {
internal abstract partial class WebSocket internal abstract partial class WebSocket
{ {

View File

@@ -6,7 +6,7 @@ using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using WSSharpNWebSocket = WebSocketSharp.WebSocket; using WSSharpNWebSocket = WebSocketSharp.WebSocket;
namespace Discord.Net namespace Discord.Net.WebSockets
{ {
internal class WSSharpWebSocketEngine : IWebSocketEngine internal class WSSharpWebSocketEngine : IWebSocketEngine
{ {

View File

@@ -6,7 +6,7 @@ using System.Runtime.ExceptionServices;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Discord.Net namespace Discord.Net.WebSockets
{ {
public enum WebSocketState : byte public enum WebSocketState : byte
{ {