Browse Source

Moved Frame models, added default providers

tags/1.0-rc
RogueException 8 years ago
parent
commit
d321ad3e5c
10 changed files with 81 additions and 8 deletions
  1. +3
    -0
      src/Discord.Net.Analyzers/AssemblyInfo.cs
  2. +1
    -1
      src/Discord.Net.Rest/DiscordRestConfig.cs
  3. +19
    -0
      src/Discord.Net.Rest/Net/DefaultRestClientProvider.cs
  4. +0
    -0
      src/Discord.Net.Rpc/API/RpcFrame.cs
  5. +0
    -0
      src/Discord.Net.WebSocket/API/SocketFrame.cs
  6. +1
    -1
      src/Discord.Net.WebSocket/DiscordShardedClient.cs
  7. +3
    -2
      src/Discord.Net.WebSocket/DiscordSocketClient.cs
  8. +27
    -0
      src/Discord.Net.WebSocket/Net/DefaultUdpSocketProvider.cs
  9. +0
    -4
      src/Discord.Net.WebSocket/Net/DefaultWebSocketClient.cs
  10. +27
    -0
      src/Discord.Net.WebSocket/Net/DefaultWebSocketClientProvider.cs

+ 3
- 0
src/Discord.Net.Analyzers/AssemblyInfo.cs View File

@@ -0,0 +1,3 @@
using System.Runtime.CompilerServices;

[assembly: InternalsVisibleTo("Discord.Net.Tests")]

+ 1
- 1
src/Discord.Net.Rest/DiscordRestConfig.cs View File

@@ -10,6 +10,6 @@ namespace Discord.Rest
internal const int WebSocketQueueInterval = 100; internal const int WebSocketQueueInterval = 100;


/// <summary> Gets or sets the provider used to generate new REST connections. </summary> /// <summary> Gets or sets the provider used to generate new REST connections. </summary>
public RestClientProvider RestClientProvider { get; set; } = url => new DefaultRestClient(url);
public RestClientProvider RestClientProvider { get; set; } = DefaultRestClientProvider.Instance;
} }
} }

+ 19
- 0
src/Discord.Net.Rest/Net/DefaultRestClientProvider.cs View File

@@ -0,0 +1,19 @@
using System;

namespace Discord.Net.Rest
{
public static class DefaultRestClientProvider
{
public static readonly RestClientProvider Instance = url =>
{
try
{
return new DefaultRestClient(url);
}
catch (PlatformNotSupportedException ex)
{
throw new PlatformNotSupportedException("The default RestClientProvider is not supported on this platform.", ex);
}
};
}
}

src/Discord.Net.Rest/API/RpcFrame.cs → src/Discord.Net.Rpc/API/RpcFrame.cs View File


src/Discord.Net.Rest/API/SocketFrame.cs → src/Discord.Net.WebSocket/API/SocketFrame.cs View File


+ 1
- 1
src/Discord.Net.WebSocket/DiscordShardedClient.cs View File

@@ -70,7 +70,7 @@ namespace Discord.WebSocket
} }
} }
private static API.DiscordSocketApiClient CreateApiClient(DiscordSocketConfig config) private static API.DiscordSocketApiClient CreateApiClient(DiscordSocketConfig config)
=> new API.DiscordSocketApiClient(config.RestClientProvider, DiscordRestConfig.UserAgent, config.WebSocketProvider);
=> new API.DiscordSocketApiClient(config.RestClientProvider, config.WebSocketProvider, DiscordRestConfig.UserAgent);


protected override async Task OnLoginAsync(TokenType tokenType, string token) protected override async Task OnLoginAsync(TokenType tokenType, string token)
{ {


+ 3
- 2
src/Discord.Net.WebSocket/DiscordSocketClient.cs View File

@@ -142,7 +142,7 @@ namespace Discord.WebSocket
_largeGuilds = new ConcurrentQueue<ulong>(); _largeGuilds = new ConcurrentQueue<ulong>();
} }
private static API.DiscordSocketApiClient CreateApiClient(DiscordSocketConfig config) private static API.DiscordSocketApiClient CreateApiClient(DiscordSocketConfig config)
=> new API.DiscordSocketApiClient(config.RestClientProvider, DiscordRestConfig.UserAgent, config.WebSocketProvider);
=> new API.DiscordSocketApiClient(config.RestClientProvider, config.WebSocketProvider, DiscordRestConfig.UserAgent);
protected override async Task OnLoginAsync(TokenType tokenType, string token) protected override async Task OnLoginAsync(TokenType tokenType, string token)
{ {
@@ -232,7 +232,8 @@ namespace Discord.WebSocket
ConnectionState = ConnectionState.Connected; ConnectionState = ConnectionState.Connected;
await _gatewayLogger.InfoAsync("Connected").ConfigureAwait(false); await _gatewayLogger.InfoAsync("Connected").ConfigureAwait(false);


await ProcessUserDownloadsAsync(_downloadUsersFor.Select(x => GetGuild(x)).Where(x => x != null).ToImmutableArray()).ConfigureAwait(false);
await ProcessUserDownloadsAsync(_downloadUsersFor.Select(x => GetGuild(x))
.Where(x => x != null).ToImmutableArray()).ConfigureAwait(false);
} }
catch (Exception) catch (Exception)
{ {


+ 27
- 0
src/Discord.Net.WebSocket/Net/DefaultUdpSocketProvider.cs View File

@@ -0,0 +1,27 @@
using System;

namespace Discord.Net.Udp
{
public static class DefaultUdpSocketProvider
{
#if NETSTANDARD1_3
public static readonly UdpSocketProvider Instance = () =>
{
try
{
return new DefaultUdpSocket();
}
catch (PlatformNotSupportedException ex)
{
throw new PlatformNotSupportedException("The default UdpSocketProvider is not supported on this platform.", ex);
}
};
#else
public static readonly UdpSocketProvider Instance = () =>
{
throw new PlatformNotSupportedException("The default UdpSocketProvider is not supported on this platform.\n" +
"You must specify a UdpSocketProvider or target a runtime supporting .NET Standard 1.3, such as .NET Framework 4.6+.");
};
#endif
}
}

+ 0
- 4
src/Discord.Net.WebSocket/Net/DefaultWebSocketClient.cs View File

@@ -206,15 +206,11 @@ namespace Discord.Net.WebSockets


//Use the internal buffer if we can get it //Use the internal buffer if we can get it
resultCount = (int)stream.Length; resultCount = (int)stream.Length;
#if NETSTANDARD1_3
ArraySegment<byte> streamBuffer; ArraySegment<byte> streamBuffer;
if (stream.TryGetBuffer(out streamBuffer)) if (stream.TryGetBuffer(out streamBuffer))
result = streamBuffer.Array; result = streamBuffer.Array;
else else
result = stream.ToArray(); result = stream.ToArray();
#else
result = stream.ToArray();
#endif
} }
} }
else else


+ 27
- 0
src/Discord.Net.WebSocket/Net/DefaultWebSocketClientProvider.cs View File

@@ -0,0 +1,27 @@
using System;

namespace Discord.Net.WebSockets
{
public static class DefaultWebSocketProvider
{
#if NETSTANDARD1_3
public static readonly WebSocketProvider Instance = () =>
{
try
{
return new DefaultWebSocketClient();
}
catch (PlatformNotSupportedException ex)
{
throw new PlatformNotSupportedException("The default WebSocketProvider is not supported on this platform.", ex);
}
};
#else
public static readonly WebSocketProvider Instance = () =>
{
throw new PlatformNotSupportedException("The default WebSocketProvider is not supported on this platform.\n" +
"You must specify a WebSocketProvider or target a runtime supporting .NET Standard 1.3, such as .NET Framework 4.6+.");
};
#endif
}
}

Loading…
Cancel
Save