Out with MagicOnion, in with LiteNetLib
Removed MagicOnion Added LiteNetLib Created client and server abstractions Fixed serialization bugs
This commit is contained in:
parent
433a7b4ae4
commit
e96146b7bb
869 changed files with 59401 additions and 16812 deletions
|
|
@ -0,0 +1,38 @@
|
|||
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
|
||||
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using RethinkDb.Driver.Net;
|
||||
|
||||
namespace RethinkDb.Driver.Utils
|
||||
{
|
||||
public class CancellableTask : TaskCompletionSource<Response>, IDisposable
|
||||
{
|
||||
private readonly CancellationToken cancelToken;
|
||||
private CancellationTokenRegistration registration;
|
||||
|
||||
|
||||
public CancellableTask(CancellationToken cancelToken)
|
||||
{
|
||||
this.cancelToken = cancelToken;
|
||||
this.registration = this.cancelToken.Register(OnCancellation, false);
|
||||
}
|
||||
|
||||
private void OnCancellation()
|
||||
{
|
||||
this.TrySetCanceled();
|
||||
|
||||
//if the user successfully signaled they want to
|
||||
//cancel, remove the registration because
|
||||
//the task status = canceled has been set.
|
||||
//don't need the registration any more.
|
||||
this.Dispose();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
this.registration.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 2c46e3badab9d1c4da1358e0b2b248d6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
using System;
|
||||
|
||||
namespace RethinkDb.Driver.Utils
|
||||
{
|
||||
internal static class ExtensionsForEvent
|
||||
{
|
||||
public static void FireEvent<T>(this EventHandler<T> eve, object sender, T arg)
|
||||
{
|
||||
var handlers = eve?.GetInvocationList();
|
||||
if( handlers != null )
|
||||
{
|
||||
foreach( var del in handlers )
|
||||
{
|
||||
var callback = (EventHandler<T>)del;
|
||||
try
|
||||
{
|
||||
callback(sender, arg);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: d2ff8775ebc53614ba53b975e2e8ba9c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
namespace RethinkDb.Driver.Utils
|
||||
{
|
||||
internal static class ExtensionsForString
|
||||
{
|
||||
internal static bool IsNullOrEmpty(this string str)
|
||||
{
|
||||
return string.IsNullOrEmpty(str);
|
||||
}
|
||||
internal static bool IsNullOrWhiteSpace(this string str)
|
||||
{
|
||||
return string.IsNullOrWhiteSpace(str);
|
||||
}
|
||||
|
||||
internal static bool IsNotNullOrEmpty(this string str)
|
||||
{
|
||||
return !string.IsNullOrEmpty(str);
|
||||
}
|
||||
internal static bool IsNotNullOrWhiteSpace(this string str)
|
||||
{
|
||||
return !string.IsNullOrWhiteSpace(str);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 0349f1a79d169754dbfc24add5630c97
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
using System.Net.Sockets;
|
||||
|
||||
namespace RethinkDb.Driver.Utils
|
||||
{
|
||||
internal static class ExtensionsForTcpClient
|
||||
{
|
||||
public static void Shutdown(this TcpClient tcp)
|
||||
{
|
||||
#if STANDARD
|
||||
tcp.Dispose();
|
||||
#else
|
||||
tcp.Close();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: df2d017543cdc024295a68784a96888a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
using System;
|
||||
using System.Reflection;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace RethinkDb.Driver.Utils
|
||||
{
|
||||
internal static class ExtensionsForType
|
||||
{
|
||||
public static bool IsASubclassOf(this Type type, Type other)
|
||||
{
|
||||
return type.GetTypeInfo().IsSubclassOf(other);
|
||||
}
|
||||
public static bool IsJToken(this Type type)
|
||||
{
|
||||
return typeof(JToken) == type || type.IsASubclassOf(typeof(JToken));
|
||||
}
|
||||
|
||||
public static bool IsGenericType(this Type type)
|
||||
{
|
||||
return type.GetTypeInfo().IsGenericType;
|
||||
}
|
||||
|
||||
public static Type BaseType(this Type type)
|
||||
{
|
||||
return type.GetTypeInfo().BaseType;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: fd0d996d5b0d8b442af4d7bc1de9c4a8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
using System.Reflection;
|
||||
using RethinkDb.Driver.Net;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
|
||||
namespace RethinkDb.Driver.Utils
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides methods that assist in the translation of linq queries.
|
||||
/// </summary>
|
||||
public static class QueryHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the name of the database field that corresponds to the given class member.
|
||||
/// The mapping can be configured by setting <see cref="Converter.Serializer"/> to a custom Serializer.
|
||||
/// </summary>
|
||||
public static string GetJsonMemberName(MemberInfo member)
|
||||
{
|
||||
if ( !(Converter.Serializer?.ContractResolver is DefaultContractResolver contractResolver) )
|
||||
{
|
||||
return member.Name;
|
||||
}
|
||||
|
||||
var namingStrategy = contractResolver.NamingStrategy;
|
||||
if ( namingStrategy == null )
|
||||
{
|
||||
return member.Name;
|
||||
}
|
||||
|
||||
return namingStrategy.GetPropertyName( member.Name, false );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 501368105dcc0f742a4ab62f3cdfec45
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
using System;
|
||||
|
||||
namespace RethinkDb.Driver.Utils
|
||||
{
|
||||
internal static class StringHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the hex representation of a byte[], in lower case.
|
||||
/// </summary>
|
||||
public static string GetHexString(byte[] bytes)
|
||||
{
|
||||
return BitConverter.ToString(bytes).Replace("-", "").ToLowerInvariant();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 82c97aeaf79e08a44802c1e8b96248c6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,72 @@
|
|||
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
|
||||
|
||||
using System;
|
||||
using System.Runtime.ExceptionServices;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using RethinkDb.Driver.Net;
|
||||
|
||||
namespace RethinkDb.Driver.Utils
|
||||
{
|
||||
public static class TaskHelper
|
||||
{
|
||||
// Proper Library Sync usage
|
||||
// https://channel9.msdn.com/Series/Three-Essential-Tips-for-Async/Async-library-methods-should-consider-using-Task-ConfigureAwait-false-
|
||||
// http://blogs.msdn.com/b/lucian/archive/2013/11/23/talk-mvp-summit-async-best-practices.aspx
|
||||
public static T WaitSync<T>(this Task<T> task)
|
||||
{
|
||||
try
|
||||
{
|
||||
task.Wait();
|
||||
}
|
||||
catch( AggregateException ae )
|
||||
{
|
||||
ExceptionDispatchInfo.Capture(ae.InnerException).Throw();
|
||||
}
|
||||
return task.Result;
|
||||
}
|
||||
|
||||
public static void WaitSync(this Task task)
|
||||
{
|
||||
try
|
||||
{
|
||||
task.Wait();
|
||||
}
|
||||
catch( AggregateException ae )
|
||||
{
|
||||
ExceptionDispatchInfo.Capture(ae.InnerException).Throw();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static TaskHelper()
|
||||
{
|
||||
CompletedTask = Task.FromResult(true);
|
||||
CompletedTaskTrue = Task.FromResult(true);
|
||||
CompletedTaskFalse = Task.FromResult(false);
|
||||
CompletedResponse = Task.FromResult<Response>(null);
|
||||
}
|
||||
|
||||
public static Task CompletedTask { get; }
|
||||
public static Task<bool> CompletedTaskTrue { get; }
|
||||
public static Task<bool> CompletedTaskFalse { get; }
|
||||
public static Task<Response> CompletedResponse { get; }
|
||||
|
||||
//Loosely based on: https://stackoverflow.com/a/22078975/9275
|
||||
public static async Task<bool> WaitOrTimeout<TResult>(this Task<TResult> task, TimeSpan timeout, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var completedTask = await Task.WhenAny(task, Task.Delay(timeout, cancellationToken))
|
||||
.ConfigureAwait(false);
|
||||
|
||||
if (completedTask == task)
|
||||
{
|
||||
await task; // Very important in order to propagate exceptions
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: cd36cd92997a40b4299f9778875a08e5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Loading…
Reference in a new issue