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,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 67b37b717eafc6542b57ccd0eb51a695
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
using Newtonsoft.Json;
|
||||
|
||||
namespace RethinkDb.Driver.Extras.Dao
|
||||
{
|
||||
/// <summary>
|
||||
/// Interface for Document of IdT
|
||||
/// </summary>
|
||||
/// <typeparam name="IdT">Type of ID property</typeparam>
|
||||
public interface IDocument<IdT>
|
||||
{
|
||||
/// <summary>
|
||||
/// The Id of the document
|
||||
/// </summary>
|
||||
IdT Id { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// All Documents (aka. domain objects / entities) should derive from Document of IdT
|
||||
/// </summary>
|
||||
/// <typeparam name="IdT">Type of Id property</typeparam>
|
||||
public abstract class Document<IdT> : IDocument<IdT>
|
||||
{
|
||||
/// <summary>
|
||||
/// The Id of the document
|
||||
/// </summary>
|
||||
[JsonProperty("id",
|
||||
NullValueHandling = NullValueHandling.Ignore,
|
||||
DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
public virtual IdT Id { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 09071cad0d60ac147aa6867358676b9e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,84 @@
|
|||
using System.Threading.Tasks;
|
||||
|
||||
namespace RethinkDb.Driver.Extras.Dao
|
||||
{
|
||||
/// <summary>
|
||||
/// Document Access Object interface
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Document entity</typeparam>
|
||||
/// <typeparam name="IdT">Type of Id property</typeparam>
|
||||
public interface IDao<T, IdT>
|
||||
{
|
||||
/// <summary>
|
||||
/// Get a document by Id.
|
||||
/// </summary>
|
||||
T GetById(IdT id);
|
||||
|
||||
/// <summary>
|
||||
/// Get a document by Id.
|
||||
/// </summary>
|
||||
Task<T> GetByIdAsync(IdT id);
|
||||
|
||||
///// <summary>
|
||||
///// Get all documents by Id
|
||||
///// </summary>
|
||||
///// <param name="ids">The Ids of the documents</param>
|
||||
//IEnumerable<T> GetAllById(params IdT[] ids);
|
||||
|
||||
/// <summary>
|
||||
/// Save document. If the document exists, an exception will be thrown. Returns and deserializes the returned document.
|
||||
/// </summary>
|
||||
/// <returns>Returns and deserializes the returned document</returns>
|
||||
T Save(T doc);
|
||||
|
||||
/// <summary>
|
||||
/// Save document. If the document exists, an exception will be thrown. Returns and deserializes the returned document.
|
||||
/// </summary>
|
||||
/// <returns>Returns and deserializes the returned document</returns>
|
||||
Task<T> SaveAsync(T doc);
|
||||
|
||||
/// <summary>
|
||||
/// Updates an existing document. If the document does not exist, an exception will be thrown.
|
||||
/// </summary>
|
||||
void Update(T doc);
|
||||
|
||||
/// <summary>
|
||||
/// Updates an existing document. If the document does not exist, an exception will be thrown.
|
||||
/// </summary>
|
||||
Task UpdateAsync(T doc);
|
||||
|
||||
/// <summary>
|
||||
/// Saves or updates a document. If the document doesn't exist, it will be saved. If the document exists, it will be updated.
|
||||
/// </summary>
|
||||
/// <param name="doc"></param>
|
||||
T SaveOrUpdate(T doc);
|
||||
|
||||
/// <summary>
|
||||
/// Saves or updates a document. If the document doesn't exist, it will be saved. If the document exists, it will be updated.
|
||||
/// </summary>
|
||||
/// <param name="doc"></param>
|
||||
Task<T> SaveOrUpdateAsync(T doc);
|
||||
|
||||
/// <summary>
|
||||
/// Deletes a document.
|
||||
/// </summary>
|
||||
void Delete(T doc);
|
||||
|
||||
/// <summary>
|
||||
/// Deletes a document.
|
||||
/// </summary>
|
||||
Task DeleteAsync(T doc);
|
||||
|
||||
/// <summary>
|
||||
/// Delete a document by Id.
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
void DeleteById(IdT id);
|
||||
|
||||
/// <summary>
|
||||
/// Delete a document by Id.
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
Task DeleteByIdAsync(IdT id);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: b2c7d437869a40c418b05f65cff8eb6f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,209 @@
|
|||
using System.Threading.Tasks;
|
||||
using RethinkDb.Driver.Ast;
|
||||
using RethinkDb.Driver.Model;
|
||||
using RethinkDb.Driver.Net;
|
||||
using RethinkDb.Driver.Utils;
|
||||
|
||||
namespace RethinkDb.Driver.Extras.Dao
|
||||
{
|
||||
/// <summary>
|
||||
/// Generic Document Access Object for RethinkDB
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Type of Document (aka. domain object / entity)</typeparam>
|
||||
/// <typeparam name="IdT">The type of the Id property in Document</typeparam>
|
||||
public abstract class RethinkDao<T, IdT> : IDao<T, IdT> where T : IDocument<IdT>
|
||||
{
|
||||
/// <summary>
|
||||
/// RethinkDB query root.
|
||||
/// </summary>
|
||||
protected static readonly RethinkDB R = RethinkDB.R;
|
||||
/// <summary>
|
||||
/// RethinkDB connection
|
||||
/// </summary>
|
||||
protected readonly IConnection conn;
|
||||
/// <summary>
|
||||
/// RethinkDB database name
|
||||
/// </summary>
|
||||
protected readonly string DbName;
|
||||
/// <summary>
|
||||
/// RethinkDB table name
|
||||
/// </summary>
|
||||
protected readonly string TableName;
|
||||
/// <summary>
|
||||
/// Table AST term used to build queries stating at the table term.
|
||||
/// </summary>
|
||||
protected readonly Table Table;
|
||||
|
||||
private readonly object returnChanges;
|
||||
|
||||
/// <summary>
|
||||
/// Constructor for <see cref="RethinkDao{T,IdT}"/>
|
||||
/// </summary>
|
||||
/// <param name="conn">The connection</param>
|
||||
/// <param name="dbName">The database</param>
|
||||
/// <param name="tableName">The table</param>
|
||||
protected RethinkDao(IConnection conn, string dbName, string tableName)
|
||||
{
|
||||
this.conn = conn;
|
||||
this.DbName = dbName;
|
||||
this.TableName = tableName;
|
||||
this.Table = R.Db(dbName).Table(tableName);
|
||||
|
||||
this.returnChanges = new { return_changes = true};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a document by Id.
|
||||
/// </summary>
|
||||
public virtual T GetById(IdT id)
|
||||
{
|
||||
return GetByIdAsync(id).WaitSync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a document by Id.
|
||||
/// </summary>
|
||||
public virtual Task<T> GetByIdAsync(IdT id)
|
||||
{
|
||||
return this.Table.Get(id).RunAtomAsync<T>(conn);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Save document. If the document exists, an exception will be thrown. Returns and deserializes the returned document.
|
||||
/// </summary>
|
||||
/// <returns>Returns and deserializes the returned document</returns>
|
||||
public virtual T Save(T doc)
|
||||
{
|
||||
return SaveAsync(doc).WaitSync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Save document. If the document exists, an exception will be thrown. Returns and deserializes the returned document.
|
||||
/// </summary>
|
||||
/// <returns>Returns and deserializes the returned document</returns>
|
||||
public virtual async Task<T> SaveAsync(T doc)
|
||||
{
|
||||
var result = await this.Table
|
||||
.Insert(doc)[returnChanges].OptArg("conflict", "error")
|
||||
.RunWriteAsync(conn)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
result.AssertNoErrors();
|
||||
result.AssertInserted(1);
|
||||
return result.ChangesAs<T>()[0].NewValue;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates an existing document. If the document does not exist, an exception will be thrown.
|
||||
/// </summary>
|
||||
public virtual void Update(T doc)
|
||||
{
|
||||
//var result = this.Table
|
||||
// .Get(doc.Id)
|
||||
// .Update(doc)
|
||||
// .RunResult(conn);
|
||||
|
||||
//var result = this.Table
|
||||
// .Replace(doc)
|
||||
// .RunResult(conn);
|
||||
|
||||
//var result = this.Table
|
||||
// .Get(doc.Id)
|
||||
// .Replace(dbDoc =>
|
||||
// R.Branch(dbDoc == null,
|
||||
// R.Error("The document doesn't exist"),
|
||||
// doc
|
||||
// )).RunResult(conn);
|
||||
|
||||
UpdateAsync(doc).WaitSync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates an existing document. If the document does not exist, an exception will be thrown.
|
||||
/// </summary>
|
||||
public virtual async Task UpdateAsync(T doc)
|
||||
{
|
||||
var result = await this.Table
|
||||
.GetAll(doc.Id).OptArg("index", "id")
|
||||
.Replace(doc)
|
||||
.RunWriteAsync(conn)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
result.AssertNoErrors();
|
||||
result.AssertReplaced(1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Saves or updates a document. If the document doesn't exist, it will be saved. If the document exists, it will be updated.
|
||||
/// </summary>
|
||||
/// <param name="doc"></param>
|
||||
public virtual T SaveOrUpdate(T doc)
|
||||
{
|
||||
return SaveOrUpdateAsync(doc).WaitSync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Saves or updates a document. If the document doesn't exist, it will be saved. If the document exists, it will be updated.
|
||||
/// </summary>
|
||||
/// <param name="doc"></param>
|
||||
public virtual async Task<T> SaveOrUpdateAsync(T doc)
|
||||
{
|
||||
var result = await this.Table
|
||||
.Insert(doc)[returnChanges].OptArg("conflict", "replace")
|
||||
.RunWriteAsync(conn)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
result.AssertNoErrors();
|
||||
|
||||
if (result.Inserted != 0)
|
||||
{
|
||||
result.AssertInserted(1);
|
||||
return result.ChangesAs<T>()[0].NewValue;
|
||||
}
|
||||
if (result.Replaced != 0)
|
||||
{
|
||||
result.AssertReplaced(1);
|
||||
return result.ChangesAs<T>()[0].NewValue;
|
||||
}
|
||||
throw new ReqlAssertFailure($"{nameof(SaveOrUpdate)} failed.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes a document.
|
||||
/// </summary>
|
||||
public virtual void Delete(T doc)
|
||||
{
|
||||
DeleteAsync(doc).WaitSync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes a document.
|
||||
/// </summary>
|
||||
public virtual Task DeleteAsync(T doc)
|
||||
{
|
||||
return DeleteByIdAsync(doc.Id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Delete a document by Id.
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
public virtual void DeleteById(IdT id)
|
||||
{
|
||||
DeleteByIdAsync(id).WaitSync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Delete a document by Id.
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
public virtual async Task DeleteByIdAsync(IdT id)
|
||||
{
|
||||
var result = await this.Table.Get(id).Delete()
|
||||
.RunWriteAsync(conn)
|
||||
.ConfigureAwait(false);
|
||||
result.AssertDeleted(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 45ae3fa4f7844354da676c3514ffd884
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Loading…
Reference in a new issue