Browse Source

Reorganized Net namespace, made SharpRest inherit from RestClient.

tags/docs-0.9
RogueException 9 years ago
parent
commit
ee44caf6ab
19 changed files with 91 additions and 70 deletions
  1. +30
    -24
      src/Discord.Net.Net45/Discord.Net.csproj
  2. +2
    -1
      src/Discord.Net/DiscordAPIClient.cs
  3. +2
    -0
      src/Discord.Net/DiscordClient.cs
  4. +2
    -21
      src/Discord.Net/DiscordWebSocketClient.Voice.cs
  5. +1
    -0
      src/Discord.Net/DiscordWebSocketClient.cs
  6. +2
    -2
      src/Discord.Net/Net/Rest/RestClient.Events.cs
  7. +8
    -6
      src/Discord.Net/Net/Rest/RestClient.cs
  8. +8
    -7
      src/Discord.Net/Net/Rest/SharpRestRestClient.cs
  9. +10
    -0
      src/Discord.Net/Net/Voice/IDiscordVoiceBuffer.cs
  10. +16
    -0
      src/Discord.Net/Net/Voice/IDiscordVoiceClient.cs
  11. +1
    -1
      src/Discord.Net/Net/Voice/VoiceBuffer.cs
  12. +1
    -1
      src/Discord.Net/Net/WebSockets/DataWebSocket.cs
  13. +1
    -1
      src/Discord.Net/Net/WebSockets/DataWebSockets.Events.cs
  14. +1
    -1
      src/Discord.Net/Net/WebSockets/VoiceWebSocket.Events.cs
  15. +2
    -1
      src/Discord.Net/Net/WebSockets/VoiceWebSocket.cs
  16. +1
    -1
      src/Discord.Net/Net/WebSockets/WebSocket.BuiltIn.cs.old
  17. +1
    -1
      src/Discord.Net/Net/WebSockets/WebSocket.Events.cs
  18. +1
    -1
      src/Discord.Net/Net/WebSockets/WebSocket.WebSocketSharp.cs
  19. +1
    -1
      src/Discord.Net/Net/WebSockets/WebSocket.cs

+ 30
- 24
src/Discord.Net.Net45/Discord.Net.csproj View File

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


+ 2
- 1
src/Discord.Net/DiscordAPIClient.cs View File

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

private string _token;


+ 2
- 0
src/Discord.Net/DiscordClient.cs View File

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


+ 2
- 21
src/Discord.Net/DiscordWebSocketClient.Voice.cs View File

@@ -1,28 +1,9 @@
using System;
using Discord.Net.Voice;
using System;
using System.Threading.Tasks;

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
{
IDiscordVoiceBuffer IDiscordVoiceClient.OutputBuffer => _voiceSocket.OutputBuffer;


+ 1
- 0
src/Discord.Net/DiscordWebSocketClient.cs View File

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


src/Discord.Net/Net/RestClient.Events.cs → src/Discord.Net/Net/Rest/RestClient.Events.cs View File

@@ -1,9 +1,9 @@
using System;
using System.Net.Http;

namespace Discord.Net
namespace Discord.Net.Rest
{
internal partial class RestClient
internal abstract partial class RestClient
{
public class RequestEventArgs : EventArgs
{

src/Discord.Net/Net/RestClient.cs → src/Discord.Net/Net/Rest/RestClient.cs View File

@@ -6,19 +6,21 @@ using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;

namespace Discord.Net
namespace Discord.Net.Rest
{
internal partial class RestClient
internal abstract partial class RestClient
{
private readonly DiscordAPIClientConfig _config;
private CancellationToken _cancelToken;
protected readonly DiscordAPIClientConfig _config;
protected CancellationToken _cancelToken;

public RestClient(DiscordAPIClientConfig 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
private static readonly HttpMethod _delete = HttpMethod.Delete;

src/Discord.Net/Net/RestClient.SharpRest.cs → src/Discord.Net/Net/Rest/SharpRestRestClient.cs View File

@@ -6,13 +6,14 @@ using System.Net.Http;
using System.Threading;
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)
{
@@ -26,20 +27,20 @@ namespace Discord.Net
_client.AddDefaultHeader("accept-encoding", "gzip,deflate");
}

internal void SetToken(string token)
protected internal override void SetToken(string token)
{
_client.RemoveDefaultParameter("authorization");
if (token != null)
_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));
request.AddParameter("application/json", json, ParameterType.RequestBody);
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);
request.AddFile("file", filePath);

+ 10
- 0
src/Discord.Net/Net/Voice/IDiscordVoiceBuffer.cs 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; }
}
}

+ 16
- 0
src/Discord.Net/Net/Voice/IDiscordVoiceClient.cs 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();
}
}

src/Discord.Net/Net/VoiceBuffer.cs → src/Discord.Net/Net/Voice/VoiceBuffer.cs View File

@@ -1,7 +1,7 @@
using System;
using System.Threading;

namespace Discord.Net
namespace Discord.Net.Voice
{
internal class VoiceBuffer : IDiscordVoiceBuffer
{

src/Discord.Net/Net/DataWebSocket.cs → src/Discord.Net/Net/WebSockets/DataWebSocket.cs View File

@@ -4,7 +4,7 @@ using Newtonsoft.Json.Linq;
using System;
using System.Threading.Tasks;

namespace Discord.Net
namespace Discord.Net.WebSockets
{
internal partial class DataWebSocket : WebSocket
{

src/Discord.Net/Net/DataWebSockets.Events.cs → src/Discord.Net/Net/WebSockets/DataWebSockets.Events.cs View File

@@ -1,7 +1,7 @@
using Newtonsoft.Json.Linq;
using System;

namespace Discord.Net
namespace Discord.Net.WebSockets
{
internal sealed class WebSocketEventEventArgs : EventArgs
{

src/Discord.Net/Net/VoiceWebSocket.Events.cs → src/Discord.Net/Net/WebSockets/VoiceWebSocket.Events.cs View File

@@ -1,6 +1,6 @@
using System;

namespace Discord.Net
namespace Discord.Net.WebSockets
{
internal sealed class IsTalkingEventArgs : EventArgs
{

src/Discord.Net/Net/VoiceWebSocket.cs → src/Discord.Net/Net/WebSockets/VoiceWebSocket.cs View File

@@ -1,6 +1,7 @@
#define USE_THREAD
using Discord.API;
using Discord.Interop;
using Discord.Net.Voice;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
@@ -14,7 +15,7 @@ using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace Discord.Net
namespace Discord.Net.WebSockets
{
internal partial class VoiceWebSocket : WebSocket
{

src/Discord.Net/Net/WebSocket.BuiltIn.cs.old → src/Discord.Net/Net/WebSockets/WebSocket.BuiltIn.cs.old View File

@@ -9,7 +9,7 @@ using System.Threading;
using System.Threading.Tasks;
using State = System.Net.WebSockets.WebSocketState;

namespace Discord.WebSockets
namespace Discord.Net.WebSockets
{
internal class BuiltInWebSocketEngine : IWebSocketEngine
{

src/Discord.Net/Net/WebSocket.Events.cs → src/Discord.Net/Net/WebSockets/WebSocket.Events.cs View File

@@ -1,6 +1,6 @@
using System;

namespace Discord.Net
namespace Discord.Net.WebSockets
{
internal abstract partial class WebSocket
{

src/Discord.Net/Net/WebSocket.WebSocketSharp.cs → src/Discord.Net/Net/WebSockets/WebSocket.WebSocketSharp.cs View File

@@ -6,7 +6,7 @@ using System.Threading;
using System.Threading.Tasks;
using WSSharpNWebSocket = WebSocketSharp.WebSocket;

namespace Discord.Net
namespace Discord.Net.WebSockets
{
internal class WSSharpWebSocketEngine : IWebSocketEngine
{

src/Discord.Net/Net/WebSocket.cs → src/Discord.Net/Net/WebSockets/WebSocket.cs View File

@@ -6,7 +6,7 @@ using System.Runtime.ExceptionServices;
using System.Threading;
using System.Threading.Tasks;

namespace Discord.Net
namespace Discord.Net.WebSockets
{
public enum WebSocketState : byte
{

Loading…
Cancel
Save