Out with MagicOnion, in with LiteNetLib

Removed MagicOnion
Added LiteNetLib
Created client and server abstractions
Fixed serialization bugs
This commit is contained in:
hyperion51 2020-03-24 14:36:22 +00:00
commit e96146b7bb
869 changed files with 59401 additions and 16812 deletions

View file

@ -0,0 +1,77 @@
#pragma warning disable 1591 // Missing XML comment for publicly visible type or member
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using RethinkDb.Driver.Ast;
namespace RethinkDb.Driver.Model
{
public class Arguments : List<ReqlAst>
{
public Arguments()
{
}
public Arguments(object arg)
{
var list = arg as IList;
if( list != null )
{
this.CoerceAndAddAll(list);
}
else
{
this.CoerceAndAdd(arg);
}
}
public Arguments(Arguments args)
{
this.AddRange(args);
}
public Arguments(ReqlAst arg)
{
this.Add(arg);
}
public Arguments(object[] args)
{
CoerceAndAddAll(args);
}
public Arguments(IList<object> args)
{
var ast = args.Select(Util.ToReqlAst);
this.AddRange(ast);
}
public void CoerceAndAdd(object o)
{
this.Add(Util.ToReqlAst(o));
}
public void CoerceAndAddAll(object[] args)
{
CoerceAndAddAll(args as ICollection);
}
public void CoerceAndAddAll(ICollection list)
{
foreach( var item in list )
{
this.Add(Util.ToReqlAst(item));
}
}
public void CoerceAndAddAll<T>(ICollection<T> list)
{
CoerceAndAddAll(list as ICollection);
}
public static Arguments Make(params object[] args)
{
return new Arguments(args);
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 7a6361c097b401a4a968784484049e65
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,25 @@
#pragma warning disable 1591 // Missing XML comment for publicly visible type or member
using Newtonsoft.Json.Linq;
namespace RethinkDb.Driver.Model
{
public class Backtrace
{
public JArray RawBacktrace { get; }
private Backtrace(JArray rawBacktrace)
{
this.RawBacktrace = rawBacktrace;
}
public static Backtrace FromJsonArray(JArray rawBacktrace)
{
if( rawBacktrace == null || rawBacktrace.Count == 0 )
{
return null;
}
return new Backtrace(rawBacktrace);
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c0280ab9d22969845826b973b0619be9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,107 @@
using System.Collections.Generic;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Linq;
namespace RethinkDb.Driver.Model
{
/// <summary>
/// Change feed states
/// </summary>
public enum ChangeState
{
/// <summary>
/// {state: 'initializing'} indicates the following documents represent
/// initial values on the feed rather than changes. This will be the first
/// document of a feed that returns initial values.
/// </summary>
Initializing = 1,
/// <summary>
/// {state: 'ready'} indicates the following documents represent changes.
/// This will be the first document of a feed that does not return initial
/// values; otherwise, it will indicate the initial values have all been sent.
/// </summary>
Ready
}
/// <summary>
/// If the change feed query contains the include_types opt arg, every result on a changefeed
/// will include a type field with a string that indicates the kind of change the result
/// represents: add, remove, change, initial, uninitial, state.
/// </summary>
public enum ChangeType
{
/// <summary>
/// Document was added.
/// </summary>
Add,
/// <summary>
/// Document was removed
/// </summary>
Remove,
/// <summary>
/// Document was changed.
/// </summary>
Change,
/// <summary>
/// Initial document.
/// </summary>
Initial,
/// <summary>
/// If an initial result for a document has been sent and a change is made to that
/// document that would move it to the unsent part of the result set
/// (e.g., a changefeed monitors the top 100 posters, the first 50 have been sent,
/// and poster 48 has become poster 52), an 'uninitial' notification will be sent,
/// with an old_val field but no new_val field.
/// </summary>
Uninitial,
/// <summary>
/// A state document.
/// </summary>
State
}
/// <summary>
/// Change Document Helper
/// </summary>
/// <typeparam name="T"></typeparam>
public class Change<T>
{
/// <summary>
/// When a document is deleted, new_val will be null; when a document is inserted, old_val will be null.
/// </summary>
[JsonProperty("old_val")]
public T OldValue { get; set; }
/// <summary>
/// When a document is deleted, new_val will be null; when a document is inserted, old_val will be null.
/// </summary>
[JsonProperty("new_val")]
public T NewValue { get; set; }
/// <summary>
/// If include_states = true optional argument was specified, the changefeed stream
/// will include special status documents consisting of the state
/// indicating a change in the feed’s state. These states can occur at any point
/// in the feed between the notifications. If includeStates = false (the default),
/// the state status will not be set. See <see cref="ChangeState"/>.
/// </summary>
[JsonConverter(typeof(StringEnumConverter))]
public ChangeState? State { get; set; }
/// <summary>
/// If an include_types opt arg is set, every result on a changefeed will include a type
/// field with a string that indicates the kind of change the result represents:
/// add, remove, change, initial, uninitial, state.
/// </summary>
[JsonConverter(typeof(StringEnumConverter))]
public ChangeType? Type { get; set; }
/// <summary>
/// Extra metadata that couldn't be parsed, if any.
/// </summary>
[JsonExtensionData]
public IDictionary<string, JToken> ExtraData { get; set; }
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 7dfde85157ad7174faf905003053c842
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,153 @@
namespace RethinkDb.Driver.Model
{
/// <summary>
/// Extension method Result helpers.
/// </summary>
public static class ExtensionsForResult
{
/// <summary>
/// Ensures no errors occurs during the processing of the result.
/// </summary>
/// <exception cref="ReqlAssertFailure">Thrown when the assertion applies</exception>
public static Result AssertNoErrors(this Result result)
{
if( result.Errors > 0 )
{
throw new ReqlAssertFailure(result.FirstError);
}
return result;
}
/// <summary>
/// Ensures a number of deleted documents.
/// </summary>
/// <exception cref="ReqlAssertFailure">Thrown when the assertion applies</exception>
public static Result AssertDeleted(this Result result, ulong deleted)
{
if( result.Deleted != deleted )
{
throw AssertFail(nameof(AssertDeleted), result.Deleted, deleted);
}
return result;
}
/// <summary>
/// Ensures a number of inserted documents.
/// </summary>
/// <exception cref="ReqlAssertFailure">Thrown when the assertion applies</exception>
public static Result AssertInserted(this Result result, ulong inserted)
{
if( result.Inserted != inserted )
{
throw AssertFail(nameof(AssertInserted), result.Inserted, inserted);
}
return result;
}
/// <summary>
/// Ensures a number of replaced documents.
/// </summary>
/// <exception cref="ReqlAssertFailure">Thrown when the assertion applies</exception>
public static Result AssertReplaced(this Result result, ulong replaced)
{
if( result.Replaced != replaced )
{
throw AssertFail(nameof(AssertReplaced), result.Replaced, replaced);
}
return result;
}
/// <summary>
/// Ensures a number of skipped documents.
/// </summary>
/// <exception cref="ReqlAssertFailure">Thrown when the assertion applies</exception>
public static Result AssertSkipped(this Result result, ulong skipped)
{
if( result.Skipped != skipped )
{
throw AssertFail(nameof(AssertSkipped), result.Skipped, skipped);
}
return result;
}
/// <summary>
/// Ensures a number of unchanged documents.
/// </summary>
/// <exception cref="ReqlAssertFailure">Thrown when the assertion applies</exception>
public static Result AssertUnchanged(this Result result, ulong unchanged)
{
if( result.Unchanged != unchanged )
{
throw AssertFail(nameof(AssertUnchanged), result.Unchanged, unchanged);
}
return result;
}
/// <summary>
/// Ensures a number of tables created.
/// </summary>
/// <exception cref="ReqlAssertFailure">Thrown when the assertion applies</exception>
public static Result AssertTablesCreated(this Result result, ulong tablesCreated)
{
if( result.TablesCreated != tablesCreated )
{
throw AssertFail(nameof(AssertTablesCreated), result.TablesCreated, tablesCreated);
}
return result;
}
/// <summary>
/// Ensures a number of tables deleted.
/// </summary>
/// <exception cref="ReqlAssertFailure">Thrown when the assertion applies</exception>
public static Result AssertTablesDropped(this Result result, ulong tablesDropped)
{
if( result.TablesDropped != tablesDropped )
{
throw AssertFail(nameof(AssertTablesDropped), result.TablesDropped, tablesDropped);
}
return result;
}
/// <summary>
/// Ensures a number of databases created.
/// </summary>
/// <exception cref="ReqlAssertFailure">Thrown when the assertion applies</exception>
public static Result AssertDatabasesCreated(this Result result, ulong databasesCreated)
{
if( result.DatabasesCreated != databasesCreated )
{
throw AssertFail(nameof(AssertDatabasesCreated), result.DatabasesCreated, databasesCreated);
}
return result;
}
/// <summary>
/// Ensures a number of databases deleted.
/// </summary>
/// <exception cref="ReqlAssertFailure">Thrown when the assertion applies</exception>
public static Result AssertDatabasesDropped(this Result result, ulong databasesDropped)
{
if( result.DatabasesDropped != databasesDropped )
{
throw AssertFail(nameof(AssertDatabasesDropped), result.DatabasesDropped, databasesDropped);
}
return result;
}
private static ReqlAssertFailure AssertFail(string op, ulong got, ulong expected)
{
return new ReqlAssertFailure($"The result was {got}, but {op} expected {expected}");
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 0f439e07981b4034f8962a0116bdfbeb
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,69 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json.Linq;
using RethinkDb.Driver.Net;
namespace RethinkDb.Driver.Model
{
/// <summary>
/// A grouped result helper.
/// </summary>
/// <typeparam name="TKey">The KEY type</typeparam>
/// <typeparam name="TElement">The VALUE type</typeparam>
public class GroupedResult<TKey, TElement> : IGrouping<TKey, TElement>
{
#pragma warning disable 1591 // Missing XML comment for publicly visible type or member
public GroupedResult(JToken key, JArray items)
{
this.Key = key.ToObject<TKey>(Converter.Serializer);
this.Items = items.ToObject<List<TElement>>(Converter.Serializer);
}
public GroupedResult(JToken key, JValue item)
{
this.Key = key.ToObject<TKey>(Converter.Serializer);
var value = item.ToObject<TElement>(Converter.Serializer);
this.Items = new List<TElement>() {value};
}
public IEnumerator<TElement> GetEnumerator()
{
return this.Items.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
#pragma warning restore 1591 // Missing XML comment for publicly visible type or member
/// <summary>
/// The Key
/// </summary>
public TKey Key { get; }
/// <summary>
/// The list of items grouped by <see cref="Key"/>
/// </summary>
public List<TElement> Items { get; set; }
}
/// <summary>
/// A typed grouped result helper.
/// </summary>
/// <typeparam name="TKey">The KEY type</typeparam>
/// <typeparam name="TItem">The VALUE type</typeparam>
public class GroupedResultSet<TKey, TItem> : List<GroupedResult<TKey, TItem>>
{
/// <summary>
/// Item type
/// </summary>
public Type ItemType => typeof(TItem);
/// <summary>
/// Key type
/// </summary>
public Type KeyType => typeof(TKey);
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 30fc2d0c473e8c34e96cc204d81fb07e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,49 @@
using System.Collections.Generic;
using RethinkDb.Driver.Ast;
namespace RethinkDb.Driver.Model
{
/// <summary>
/// Just a dictionary of (object,object)
/// </summary>
public class MapObject : Dictionary<object, object>
{
/// <summary>
/// Fluent helper for setting dictionary[key] = value.
/// </summary>
public virtual MapObject With(object key, object value)
{
this[key] = value;
return this;
}
internal virtual MapObject with(object key, object value)
{
return With(key, value);
}
/// <summary>
/// Fluent helper for setting all key,value pairs of an anonymous type
/// and loading them into the MapObject.
/// </summary>
public virtual MapObject With(object anonType)
{
var anonDict = PropertyHelper.ObjectToDictionary(anonType);
foreach( var kvp in anonDict )
{
this.With(kvp.Key, kvp.Value);
}
return this;
}
/// <summary>
/// Creates a new MapObject from an anonymous type.
/// </summary>
internal static MapObject FromAnonType(object anonType)
{
var map = new MapObject();
map.With(anonType);
return map;
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: fa52891b17f130841b4afa7b4f2db01e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,101 @@
using System.Collections.Generic;
using RethinkDb.Driver.Ast;
namespace RethinkDb.Driver.Model
{
/// <summary>
/// Dictionary of string,ReqlAst
/// </summary>
public class OptArgs : Dictionary<string, ReqlAst>
{
/// <summary>
/// Fluent helper for setting dictionary[key] = value.
/// </summary>
public virtual OptArgs With(string key, object value)
{
if( key != null )
{
this[key] = Util.ToReqlAst(value);
}
return this;
}
internal OptArgs with(string key, object value)
{
return With(key, value);
}
/// <summary>
/// Fluent helper for setting dictionary[key] = List.
/// </summary>
public virtual OptArgs With(string key, IList<object> value)
{
if( key != null )
{
this[key] = Util.ToReqlAst(value);
}
return this;
}
internal virtual OptArgs with(string key, IList<object> value)
{
return With(key, value);
}
/// <summary>
/// Fluent helper for setting dictionary[key] = value multiple times
/// for each Property=Value in the anonType.
/// </summary>
public virtual OptArgs With(object anonType)
{
var anonDict = PropertyHelper.ObjectToDictionary(anonType);
foreach( var kvp in anonDict )
{
this.with(kvp.Key, kvp.Value);
}
return this;
}
internal virtual OptArgs with(object anonType)
{
return With(anonType);
}
/// <summary>
/// Fluent helper to copy all key value pairs from <paramref name="args"/>
/// </summary>
public virtual OptArgs With(OptArgs args)
{
foreach( var kvp in args )
this.with(kvp.Key, kvp.Value);
return this;
}
/// <summary>
/// Creates a new OptArg from all key value pairs in <paramref name="map"/>
/// </summary>
public static OptArgs FromMap(IDictionary<string, ReqlAst> map)
{
OptArgs oa = new OptArgs();
foreach( var kvp in map )
oa.Add(kvp.Key, kvp.Value);
return oa;
}
/// <summary>
/// Creates a new OptArg from all Property = Value pairs in <paramref name="anonType"/> anonymous type.
/// </summary>
public static OptArgs FromAnonType(object anonType)
{
OptArgs oa = new OptArgs();
oa.with(anonType);
return oa;
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 421ac9beb7bd91b4f823ee35f288d3b3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,41 @@
#pragma warning disable 1591 // Missing XML comment for publicly visible type or member
using System;
using Newtonsoft.Json.Linq;
namespace RethinkDb.Driver.Model
{
/*
r.path("contact", "phone", "work");
r.path("contact", "phone", r.paths("work", "home"));
r.path("contact",
r.paths(
r.path("phone",
r.paths("work", "home")),
r.paths(
r.path("im", "skype")),
);
*/
//not sure what this is about.. so ignore it for now.
public class PathSpec
{
private readonly JObject root = new JObject();
private PathSpec()
{
}
public virtual PathSpec path(string start, params PathSpec[] specs)
{
throw new Exception("not implemented");
}
public virtual PathSpec path(params string[] strings)
{
throw new Exception("not implemented");
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 51cc1e5d29e390d44aaccabec4192263
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,25 @@
#pragma warning disable 1591 // Missing XML comment for publicly visible type or member
using Newtonsoft.Json.Linq;
namespace RethinkDb.Driver.Model
{
public class Profile
{
public Profile(JArray profileObj)
{
this.ProfileObj = profileObj;
}
public JArray ProfileObj { get; }
public static Profile FromJsonArray(JArray profileObj)
{
if( profileObj == null || profileObj.Count == 0 )
{
return null;
}
return new Profile(profileObj);
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b826fdf2446c89749bd5e39a6989c956
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,9 @@
namespace RethinkDb.Driver.Model
{
/// <summary>
/// Root function interface for a lambda expression.
/// </summary>
public interface ReqlLambda
{
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 04f768fe8816a41409c11796000d7eaf
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,102 @@
using System;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace RethinkDb.Driver.Model
{
/// <summary>
/// A typed helper for reading response meta data.
/// </summary>
public class Result
{
/// <summary>
/// A list of generated primary keys for inserted documents whose primary keys were not specified (capped to 100,000).
/// </summary>
[JsonProperty("generated_keys")]
public Guid[] GeneratedKeys { get; set; }
/// <summary>
/// The number of documents successfully inserted.
/// </summary>
public ulong Inserted { get; set; }
/// <summary>
/// The number of documents updated when conflict is set to "replace" or "update".
/// </summary>
public ulong Replaced { get; set; }
/// <summary>
/// The number of documents whose fields are identical to existing documents with the same primary key when conflict is set to "replace" or "update".
/// </summary>
public ulong Unchanged { get; set; }
/// <summary>
/// The number of errors encountered while performing the insert.
/// </summary>
public ulong Errors { get; set; }
/// <summary>
/// If errors were encountered, contains the text of the first error.
/// </summary>
[JsonProperty("first_error")]
public string FirstError { get; set; }
/// <summary>
/// Deleted: 0 for an insert operation.
/// </summary>
public ulong Deleted { get; set; }
/// <summary>
/// Skipped: 0 for an insert operation.
/// </summary>
public ulong Skipped { get; set; }
/// <summary>
/// If the field generated_keys is truncated, you will get the warning “Too many generated keys (...), array truncated to 100000.”.
/// </summary>
public string[] Warnings { get; set; }
/// <summary>
/// If returnChanges is set to true, this will be an array of objects, one for each objected affected by the insert operation. Each object will have two keys: {new_val: -new value-, old_val: null}.
/// </summary>
public JArray Changes { get; set; }
/// <summary>
/// If the query had return_changes set, get the changes as <typeparam name="T"></typeparam>.
/// </summary>
public Change<T>[] ChangesAs<T>()
{
return this.Changes?.ToObject<Change<T>[]>(Net.Converter.Serializer);
}
/// <summary>
/// The value is an integer indicating the number of tables waited for. It will always be 1 when wait is called on a table, and the total number of tables when called on a database.
/// </summary>
public uint? Ready { get; set; } //probably need to move this to something like AdminResult or DdlResult
/// <summary>
/// The number of databases created.
/// </summary>
[JsonProperty("dbs_created")]
public uint DatabasesCreated { get; set; }
/// <summary>
/// The number of databases dropped.
/// </summary>
[JsonProperty("dbs_dropped")]
public uint DatabasesDropped { get; set; }
/// <summary>
/// The number of tables created.
/// </summary>
[JsonProperty("tables_created")]
public uint TablesCreated { get; set; }
/// <summary>
/// The number of tables dropped.
/// </summary>
[JsonProperty("tables_dropped")]
public uint TablesDropped { get; set; }
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d254bda9f5abf774384e8d6d99cfe6d6
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using RethinkDb.Driver.Net;
namespace RethinkDb.Driver.Model
{
/// <summary>
/// A type helper that represents the result of <see cref="Connection.Server"/>
/// and <seealso cref="Connection.ServerAsync"/>.
/// </summary>
public class Server
{
/// <summary>
/// The server's id
/// </summary>
public string Id { get; set; }
/// <summary>
/// The server's name.
/// </summary>
public string Name { get; set; }
/// <summary>
/// True if the driver is connected to a proxy server. False if the driver is
/// connected to a RethinkDB server.
/// </summary>
public bool Proxy { get; set; }
/// <summary>
/// Extra metadata that couldn't be parsed, if any.
/// </summary>
[JsonExtensionData]
public IDictionary<string, JToken> ExtraData { get; set; }
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a4dc9f03b1554c240b8d6dae0a6a14f8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: