提交 00edcc18 编写于 作者: T tanghai

服务端加入mongodb操作

上级 5d76be8d
using MongoDB.Bson.Serialization.Attributes;
namespace Model
{
[BsonIgnoreExtraElements]
public class DBConfig : AConfigComponent
{
public string ConnectionString { get; set; }
public string DBName { get; set; }
}
}
\ No newline at end of file
using MongoDB.Bson.Serialization.Attributes;
namespace Model
{
[BsonIgnoreExtraElements]
public class HttpConfig : AConfigComponent
{
public string Url { get; set; } = "";
public int AppId { get; set; }
public string AppKey { get; set; } = "";
public string ManagerSystemUrl { get; set; } = "";
}
}
\ No newline at end of file
using System.Collections.Generic;
using System.Threading.Tasks;
namespace Model
{
[ObjectEvent]
public class DBCacheComponentEvent : ObjectEvent<DBCacheComponent>, IAwake
{
public void Awake()
{
this.Get().Awake();
}
}
/// <summary>
/// 用来缓存数据
/// </summary>
public class DBCacheComponent : Component
{
public Dictionary<string, Dictionary<long, Entity>> cache = new Dictionary<string, Dictionary<long, Entity>>();
public const int taskCount = 32;
public List<DBTaskQueue> tasks = new List<DBTaskQueue>(taskCount);
public void Awake()
{
for (int i = 0; i < taskCount; ++i)
{
DBTaskQueue taskQueue = new DBTaskQueue();
this.tasks.Add(taskQueue);
taskQueue.Start();
}
}
public Task<bool> Add(Entity entity, string collectionName = "")
{
TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>();
this.AddToCache(entity, collectionName);
if (collectionName == "")
{
collectionName = entity.GetType().Name;
}
DBSaveTask task = new DBSaveTask(entity, collectionName, tcs);
this.tasks[(int)((ulong)task.Id % taskCount)].Add(task);
return tcs.Task;
}
public Task<bool> AddBatch(List<Entity> entitys, string collectionName)
{
TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>();
DBSaveBatchTask task = new DBSaveBatchTask(entitys, collectionName, tcs);
this.tasks[(int)((ulong)task.Id % taskCount)].Add(task);
return tcs.Task;
}
public void AddToCache(Entity entity, string collectionName = "")
{
if (collectionName == "")
{
collectionName = entity.GetType().Name;
}
Dictionary<long, Entity> collection;
if (!this.cache.TryGetValue(collectionName, out collection))
{
collection = new Dictionary<long, Entity>();
this.cache.Add(collectionName, collection);
}
collection[entity.Id] = entity;
}
public Entity GetFromCache(string collectionName, long id)
{
Dictionary<long, Entity> d;
if (!this.cache.TryGetValue(collectionName, out d))
{
return null;
}
Entity result;
if (!d.TryGetValue(id, out result))
{
return null;
}
return result;
}
public void RemoveFromCache(string collectionName, long id)
{
Dictionary<long, Entity> d;
if (!this.cache.TryGetValue(collectionName, out d))
{
return;
}
d.Remove(id);
}
public Task<Entity> Get(string collectionName, long id)
{
Entity entity = GetFromCache(collectionName, id);
if (entity != null)
{
return Task.FromResult(entity);
}
TaskCompletionSource<Entity> tcs = new TaskCompletionSource<Entity>();
this.tasks[(int)((ulong)id % taskCount)].Add(new DBQueryTask(id, collectionName, tcs));
return tcs.Task;
}
public Task<List<Entity>> GetBatch(string collectionName, List<long> idList)
{
List <Entity> entitys = new List<Entity>();
bool isAllInCache = true;
foreach (long id in idList)
{
Entity entity = this.GetFromCache(collectionName, id);
if (entity == null)
{
isAllInCache = false;
break;
}
entitys.Add(entity);
}
if (isAllInCache)
{
return Task.FromResult(entitys);
}
TaskCompletionSource<List<Entity>> tcs = new TaskCompletionSource<List<Entity>>();
DBQueryBatchTask dbQueryBatchTask = new DBQueryBatchTask(idList, collectionName, tcs);
this.tasks[(int)((ulong)dbQueryBatchTask.Id % taskCount)].Add(dbQueryBatchTask);
return tcs.Task;
}
public Task<List<Entity>> GetJson(string collectionName, string json)
{
TaskCompletionSource<List<Entity>> tcs = new TaskCompletionSource<List<Entity>>();
DBQueryJsonTask dbQueryJsonTask = new DBQueryJsonTask(collectionName, json, tcs);
this.tasks[(int)((ulong)dbQueryJsonTask.Id % taskCount)].Add(dbQueryJsonTask);
return tcs.Task;
}
}
}
\ No newline at end of file
using MongoDB.Driver;
namespace Model
{
[ObjectEvent]
public class DBComponentEvent : ObjectEvent<DBComponent>, IAwake
{
public void Awake()
{
this.Get().Awake();
}
}
/// <summary>
/// 连接mongodb
/// </summary>
public class DBComponent : Component
{
public MongoClient mongoClient;
public IMongoDatabase database;
public void Awake()
{
DBConfig config = Game.Scene.GetComponent<StartConfigComponent>().StartConfig.GetComponent<DBConfig>();
string connectionString = config.ConnectionString;
mongoClient = new MongoClient(connectionString);
this.database = this.mongoClient.GetDatabase(config.DBName);
}
public IMongoCollection<Entity> GetCollection(string name)
{
return this.database.GetCollection<Entity>(name);
}
}
}
\ No newline at end of file
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
namespace Model
{
/// <summary>
/// 用来与数据库操作代理
/// </summary>
public class DBProxyComponent : Component
{
public string dbAddress;
public void Awake()
{
StartConfig dbStartConfig = Game.Scene.GetComponent<StartConfigComponent>().DBStartConfig;
dbAddress = dbStartConfig.GetComponent<InnerConfig>().Address;
}
public async Task Save(Entity entity, bool needCache = true)
{
Session session = Game.Scene.GetComponent<NetInnerComponent>().Get(dbAddress);
await session.Call<DBSaveRequest, DBSaveResponse>(new DBSaveRequest { Entity = entity, NeedCache = needCache});
}
public async Task SaveBatch(List<Entity> entitys, bool needCache = true)
{
Session session = Game.Scene.GetComponent<NetInnerComponent>().Get(dbAddress);
await session.Call<DBSaveBatchRequest, DBSaveBatchResponse>(new DBSaveBatchRequest { Entitys = entitys, NeedCache = needCache});
}
public async Task Save(Entity entity, bool needCache, CancellationToken cancellationToken)
{
Session session = Game.Scene.GetComponent<NetInnerComponent>().Get(dbAddress);
await session.Call<DBSaveRequest, DBSaveResponse>(new DBSaveRequest { Entity = entity, NeedCache = needCache}, cancellationToken);
}
public async void SaveLog(Entity entity)
{
Session session = Game.Scene.GetComponent<NetInnerComponent>().Get(dbAddress);
await session.Call<DBSaveRequest, DBSaveResponse>(new DBSaveRequest { Entity = entity, NeedCache = false, CollectionName = "Log" });
}
public async Task<T> Query<T>(long id, bool needCache = true) where T: Entity
{
Session session = Game.Scene.GetComponent<NetInnerComponent>().Get(dbAddress);
DBQueryResponse dbQueryResponse = await session.Call<DBQueryRequest, DBQueryResponse>(new DBQueryRequest { CollectionName = typeof(T).Name, Id = id, NeedCache = needCache });
return (T)dbQueryResponse.Entity;
}
public async Task<List<T>> QueryBatch<T>(List<long> ids, bool needCache = true) where T : Entity
{
List<T> list = new List<T>();
Session session = Game.Scene.GetComponent<NetInnerComponent>().Get(dbAddress);
DBQueryBatchResponse dbQueryBatchResponse = await session.Call<DBQueryBatchRequest, DBQueryBatchResponse>(new DBQueryBatchRequest { CollectionName = typeof(T).Name, IdList = ids, NeedCache = needCache});
foreach (Entity entity in dbQueryBatchResponse.Entitys)
{
list.Add((T)entity);
}
return list;
}
public async Task<List<T>> QueryJson<T>(string json, bool needCache = true) where T : Entity
{
List<T> list = new List<T>();
Session session = Game.Scene.GetComponent<NetInnerComponent>().Get(dbAddress);
DBQueryJsonResponse dbQueryJsonResponse = await session.Call<DBQueryJsonRequest, DBQueryJsonResponse>(new DBQueryJsonRequest { CollectionName = typeof(T).Name, Json = json, NeedCache = needCache});
foreach (Entity entity in dbQueryJsonResponse.Entitys)
{
list.Add((T)entity);
}
return list;
}
}
}
\ No newline at end of file
......@@ -22,6 +22,10 @@ namespace Model
public StartConfig StartConfig { get; private set; }
public StartConfig DBStartConfig { get; private set; }
public StartConfig RealmConfig { get; private set; }
public void Awake(string path, int appId)
{
string[] ss = File.ReadAllText(path).Split('\n');
......
......@@ -5,11 +5,11 @@
/// </summary>
public abstract class AConfig: Entity
{
protected AConfig(EntityType entityType): base(entityType)
protected AConfig()
{
}
protected AConfig(long id, EntityType entityType): base(id, entityType)
protected AConfig(long id): base(id)
{
}
}
......
......@@ -8,11 +8,11 @@ namespace Model
public string Name { get; set; }
public int Time { get; set; }
public BuffConfig(): base(EntityType.Config)
public BuffConfig()
{
}
public BuffConfig(long id): base(id, EntityType.Config)
public BuffConfig(long id): base(id)
{
}
}
......
......@@ -11,9 +11,5 @@ namespace Model
public AppType AppType { get; set; }
public string ServerIP { get; set; }
public StartConfig(): base(EntityType.Config)
{
}
}
}
\ No newline at end of file
using MongoDB.Bson.Serialization.Attributes;
namespace Model
{
[BsonIgnoreExtraElements]
[BsonKnownTypes(typeof(RechargeRecord))]
[BsonKnownTypes(typeof(Recharge))]
public class DBEntity: Entity
{
protected DBEntity()
{
}
protected DBEntity(long id): base(id)
{
}
}
}
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Base;
using Model;
using MongoDB.Bson;
using MongoDB.Driver;
namespace Model
{
public abstract class DBTask : Entity
{
protected DBTask()
{
}
protected DBTask(long id): base(id)
{
}
public abstract Task Run();
}
public sealed class DBSaveTask : DBTask
{
public Entity Entity;
public string CollectionName { get; }
public TaskCompletionSource<bool> Tcs;
public DBSaveTask(Entity entity, string collectionName, TaskCompletionSource<bool> tcs) : base(entity.Id)
{
this.Entity = entity;
this.CollectionName = collectionName;
this.Tcs = tcs;
}
public override async Task Run()
{
DBComponent dbComponent = Game.Scene.GetComponent<DBComponent>();
try
{
// 执行保存数据库任务
await dbComponent.GetCollection(this.CollectionName).ReplaceOneAsync(s => s.Id == this.Entity.Id, this.Entity, new UpdateOptions {IsUpsert = true});
this.Tcs.SetResult(true);
}
catch (Exception e)
{
this.Tcs.SetException(new Exception($"保存数据失败! {CollectionName} {Id}", e));
}
}
}
public sealed class DBSaveBatchTask : DBTask
{
public string CollectionName { get; }
public List<Entity> Entitys;
public TaskCompletionSource<bool> Tcs;
public DBSaveBatchTask(List<Entity> entitys, string collectionName, TaskCompletionSource<bool> tcs)
{
this.Entitys = entitys;
this.CollectionName = collectionName;
this.Tcs = tcs;
}
public override async Task Run()
{
DBComponent dbComponent = Game.Scene.GetComponent<DBComponent>();
foreach (Entity entity in this.Entitys)
{
if (entity == null)
{
continue;
}
try
{
// 执行保存数据库任务
await dbComponent.GetCollection(this.CollectionName).ReplaceOneAsync(s => s.Id == entity.Id, entity, new UpdateOptions { IsUpsert = true });
}
catch (Exception e)
{
Log.Debug($"{entity.GetType().Name} {entity.ToJson()}" + e.ToString());
this.Tcs.SetException(new Exception($"保存数据失败! {CollectionName} {this.Entitys.ListToString()}", e));
}
}
this.Tcs.SetResult(true);
}
}
public sealed class DBQueryTask : DBTask
{
public string CollectionName { get; }
public TaskCompletionSource<Entity> Tcs { get; }
public DBQueryTask(long id, string collectionName, TaskCompletionSource<Entity> tcs) : base(id)
{
this.CollectionName = collectionName;
this.Tcs = tcs;
}
public override async Task Run()
{
DBCacheComponent dbCacheComponent = Game.Scene.GetComponent<DBCacheComponent>();
DBComponent dbComponent = Game.Scene.GetComponent<DBComponent>();
// 执行查询前先看看cache中是否已经存在
Entity entity = dbCacheComponent.GetFromCache(this.CollectionName, this.Id);
if (entity != null)
{
this.Tcs.SetResult(entity);
return;
}
try
{
// 执行查询数据库任务
entity = await dbComponent.GetCollection(this.CollectionName).FindAsync((s) => s.Id == this.Id).Result.FirstOrDefaultAsync();
if (entity != null)
{
dbCacheComponent.AddToCache(entity);
}
this.Tcs.SetResult(entity);
}
catch (Exception e)
{
this.Tcs.SetException(new Exception($"查询数据库异常! {CollectionName} {Id}", e));
}
}
}
public sealed class DBQueryBatchTask : DBTask
{
public string CollectionName { get; }
public List<long> IdList { get; }
public TaskCompletionSource<List<Entity>> Tcs { get; }
public DBQueryBatchTask(List<long> list, string collectionName, TaskCompletionSource<List<Entity>> tcs)
{
this.IdList = list;
this.CollectionName = collectionName;
this.Tcs = tcs;
}
public override async Task Run()
{
DBCacheComponent dbCacheComponent = Game.Scene.GetComponent<DBCacheComponent>();
DBComponent dbComponent = Game.Scene.GetComponent<DBComponent>();
List<Entity> result = new List<Entity>();
try
{
// 执行查询数据库任务
foreach (long id in IdList)
{
Entity entity = dbCacheComponent.GetFromCache(this.CollectionName, id);
if (entity == null)
{
entity = await dbComponent.GetCollection(this.CollectionName).FindAsync((s) => s.Id == id).Result.FirstOrDefaultAsync();
dbCacheComponent.AddToCache(entity);
}
if (entity == null)
{
continue;
}
result.Add(entity);
}
this.Tcs.SetResult(result);
}
catch (Exception e)
{
this.Tcs.SetException(new Exception($"查询数据库异常! {this.CollectionName} {IdList.ListToString()}", e));
}
}
}
public sealed class DBQueryJsonTask : DBTask
{
public string CollectionName { get; }
public string Json { get; }
public TaskCompletionSource<List<Entity>> Tcs { get; }
public DBQueryJsonTask(string collectionName, string json, TaskCompletionSource<List<Entity>> tcs)
{
this.CollectionName = collectionName;
this.Json = json;
this.Tcs = tcs;
}
public override async Task Run()
{
DBComponent dbComponent = Game.Scene.GetComponent<DBComponent>();
try
{
// 执行查询数据库任务
FilterDefinition<Entity> filterDefinition = new JsonFilterDefinition<Entity>(this.Json);
List<Entity> entitys = await dbComponent.GetCollection(this.CollectionName).FindAsync(filterDefinition).Result.ToListAsync();
this.Tcs.SetResult(entitys);
}
catch (Exception e)
{
this.Tcs.SetException(new Exception($"查询数据库异常! {CollectionName} {this.Json}", e));
}
}
}
}
\ No newline at end of file
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Base;
using Model;
namespace Model
{
public sealed class DBTaskQueue : Entity
{
public Queue<DBTask> queue = new Queue<DBTask>();
private TaskCompletionSource<DBTask> tcs;
public async void Start()
{
while (true)
{
if (this.Id == 0)
{
return;
}
DBTask task = await this.Get();
try
{
await task.Run();
}
catch (Exception e)
{
Log.Error(e.ToString());
}
}
}
public void Add(DBTask task)
{
if (this.tcs != null)
{
var t = this.tcs;
this.tcs = null;
t.SetResult(task);
return;
}
this.queue.Enqueue(task);
}
public Task<DBTask> Get()
{
TaskCompletionSource<DBTask> t = new TaskCompletionSource<DBTask>();
if (this.queue.Count > 0)
{
DBTask task = this.queue.Dequeue();
t.SetResult(task);
}
else
{
this.tcs = t;
}
return t.Task;
}
}
}
\ No newline at end of file
namespace Model
{
// 充值流水
public sealed class RechargeRecord : DBEntity
{
// 充值玩家
public int PlayerNO { get; set; }
// 充值数量
public int CardNumber { get; set; }
// 充值时间
public long Time { get; set; }
public RechargeRecord(long id): base(id)
{
}
}
// 保存玩家充值记录, 每个玩家只有一条
public sealed class Recharge : DBEntity
{
public int CardNumber { get; set; }
public long UpdateTime { get; set; }
public Recharge(long id): base(id)
{
}
}
public class HttpResult
{
public int code;
public bool status;
public string msg = "";
}
public static class HttpErrorCode
{
public const int Exception = 999;
public const int Success = 1000;
public const int RpcFail = 1002;
}
}
\ No newline at end of file
using MongoDB.Bson.Serialization.Attributes;
using System.Collections.Generic;
using MongoDB.Bson.Serialization.Attributes;
// ڲϢ Opcode10000ʼ
namespace Model
{
[Message(10001)]
[BsonIgnoreExtraElements]
public class R2G_GetLoginKey: ARequest
{
}
[Message(10002)]
[BsonIgnoreExtraElements]
public class G2R_GetLoginKey: AResponse
{
public long Key;
public G2R_GetLoginKey()
{
}
public G2R_GetLoginKey(long key)
{
this.Key = key;
}
}
[Message(10003)]
[BsonIgnoreExtraElements]
public class M2A_Reload: ARequest
{
}
[Message(10004)]
[BsonIgnoreExtraElements]
public class A2M_Reload: AResponse
{
}
[Message(10005)]
[BsonIgnoreExtraElements]
public class G2G_LockRequest: ARequest
{
public long Id;
public string Address;
}
[Message(10006)]
[BsonIgnoreExtraElements]
public class G2G_LockResponse: AResponse
{
}
[Message(10007)]
[BsonIgnoreExtraElements]
public class G2G_LockReleaseRequest: ARequest
{
public long Id;
public string Address;
}
[Message(10008)]
[BsonIgnoreExtraElements]
public class G2G_LockReleaseResponse: AResponse
{
}
}
\ No newline at end of file
namespace Model{ [Message(Opcode.R2G_GetLoginKey)] [BsonIgnoreExtraElements] public class R2G_GetLoginKey : ARequest { }
[Message(Opcode.G2R_GetLoginKey)] [BsonIgnoreExtraElements] public class G2R_GetLoginKey : AResponse { public long Key;
public G2R_GetLoginKey() { }
public G2R_GetLoginKey(long key) { this.Key = key; } }
[Message(Opcode.M2A_Reload)] [BsonIgnoreExtraElements] public class M2A_Reload : ARequest { }
[Message(Opcode.A2M_Reload)] [BsonIgnoreExtraElements] public class A2M_Reload : AResponse { }
[Message(Opcode.G2G_LockRequest)] [BsonIgnoreExtraElements] public class G2G_LockRequest : ARequest { public string Address; }
[Message(Opcode.G2G_LockResponse)] [BsonIgnoreExtraElements]
public class G2G_LockResponse : AResponse { }
[Message(Opcode.G2G_LockReleaseRequest)] [BsonIgnoreExtraElements] public class G2G_LockReleaseRequest : ARequest { public string Address; }
[Message(Opcode.G2G_LockReleaseResponse)] [BsonIgnoreExtraElements] public class G2G_LockReleaseResponse : AResponse { }
[Message(Opcode.DBSaveRequest)] [BsonIgnoreExtraElements] public class DBSaveRequest : ARequest { public bool NeedCache = true;
public string CollectionName = "";
public Entity Entity; }
[Message(Opcode.DBSaveBatchResponse)] [BsonIgnoreExtraElements] public class DBSaveBatchResponse : AResponse { }
[Message(Opcode.DBSaveBatchRequest)] [BsonIgnoreExtraElements] public class DBSaveBatchRequest : ARequest { public bool NeedCache = true; public string CollectionName = ""; public List<Entity> Entitys = new List<Entity>(); }
[Message(Opcode.DBSaveResponse)] [BsonIgnoreExtraElements] public class DBSaveResponse : AResponse { }
[Message(Opcode.DBQueryRequest)] [BsonIgnoreExtraElements] public class DBQueryRequest : ARequest { public string CollectionName { get; set; } public bool NeedCache = true; }
[Message(Opcode.DBQueryResponse)] [BsonIgnoreExtraElements] public class DBQueryResponse : AResponse { public Entity Entity; }
[Message(Opcode.DBQueryBatchRequest)] [BsonIgnoreExtraElements] public class DBQueryBatchRequest : ARequest { public string CollectionName { get; set; } public List<long> IdList { get; set; } public bool NeedCache = true; }
[Message(Opcode.DBQueryBatchResponse)] [BsonIgnoreExtraElements] public class DBQueryBatchResponse : AResponse { public List<Entity> Entitys; }
[Message(Opcode.DBQueryJsonRequest)] [BsonIgnoreExtraElements] public class DBQueryJsonRequest : ARequest { public string CollectionName { get; set; } public string Json { get; set; } public bool NeedCache = true; }
[Message(Opcode.DBQueryJsonResponse)] [BsonIgnoreExtraElements] public class DBQueryJsonResponse : AResponse { public List<Entity> Entitys; }}
\ No newline at end of file
......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Model
namespace Model
{
public static class Opcode
{
public const ushort C2R_Login = 1;
public const ushort R2C_Login = 2;
public const ushort R2C_ServerLog = 3;
public const ushort C2G_LoginGate = 4;
public const ushort G2C_LoginGate = 5;
public const ushort C2G_GetPlayerInfo = 6;
public const ushort G2C_GetPlayerInfo = 7;
public const ushort C2M_Reload = 8;
public const ushort G2G_LockRequest = 10;
public const ushort G2G_LockResponse = 11;
public const ushort G2G_LockReleaseRequest = 12;
public const ushort G2G_LockReleaseResponse = 13;
public const ushort M2A_Reload = 20;
public const ushort A2M_Reload = 21;
public const ushort DBSaveRequest = 26;
public const ushort DBSaveResponse = 27;
public const ushort DBQueryRequest = 28;
public const ushort DBQueryResponse = 29;
public const ushort DBSaveBatchResponse = 37;
public const ushort DBSaveBatchRequest = 38;
public const ushort DBQueryBatchRequest = 61;
public const ushort DBQueryBatchResponse = 62;
public const ushort DBQueryJsonRequest = 65;
public const ushort DBQueryJsonResponse = 66;
public const ushort C2R_Login = 1000;
public const ushort R2C_Login = 1002;
public const ushort R2C_ServerLog = 1003;
public const ushort C2G_LoginGate = 1004;
public const ushort G2C_LoginGate = 1005;
public const ushort C2G_GetPlayerInfo = 1006;
public const ushort G2C_GetPlayerInfo = 1007;
public const ushort C2M_Reload = 1008;
public const ushort R2G_GetLoginKey = 10001;
public const ushort G2R_GetLoginKey = 10002;
}
}
......@@ -23,11 +23,11 @@
public SceneType SceneType { get; private set; }
public Scene(): base(EntityType.Scene)
public Scene()
{
}
public Scene(long id): base(id, EntityType.Scene)
public Scene(long id): base(id)
{
}
......
......@@ -20,7 +20,7 @@
base.Dispose();
}
public Unit(UnitType unitType): base(EntityType.UI)
public Unit(UnitType unitType)
{
this.UnitType = unitType;
}
......
......@@ -19,19 +19,11 @@ namespace Model
protected Entity()
{
this.Type = EntityType.None;
ObjectEvents.Instance.Add(this);
}
protected Entity(EntityType entityType)
protected Entity(long id): base(id)
{
this.Type = entityType;
ObjectEvents.Instance.Add(this);
}
protected Entity(long id, EntityType entityType): base(id)
{
this.Type = entityType;
ObjectEvents.Instance.Add(this);
}
......
......@@ -34,9 +34,16 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\Lib\CommandLine.dll</HintPath>
</Reference>
<Reference Include="MongoDB.Bson">
<Reference Include="MongoDB.Bson, Version=2.3.0.157, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\Lib\MongoDB.Bson.dll</HintPath>
</Reference>
<Reference Include="MongoDB.Driver">
<HintPath>..\Lib\MongoDB.Driver.dll</HintPath>
</Reference>
<Reference Include="MongoDB.Driver.Core">
<HintPath>..\Lib\MongoDB.Driver.Core.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
</ItemGroup>
......@@ -44,8 +51,13 @@
<Compile Include="Component\BenchmarkComponent.cs" />
<Compile Include="Component\ConfigComponent.cs" />
<Compile Include="Component\Config\ClientConfig.cs" />
<Compile Include="Component\Config\DBConfig.cs" />
<Compile Include="Component\Config\HttpConfig.cs" />
<Compile Include="Component\Config\InnerConfig.cs" />
<Compile Include="Component\Config\OuterConfig.cs" />
<Compile Include="Component\DBCacheComponent.cs" />
<Compile Include="Component\DBComponent.cs" />
<Compile Include="Component\DBProxyComponent.cs" />
<Compile Include="Component\EventComponent.cs" />
<Compile Include="Component\KVComponent.cs" />
<Compile Include="Component\MessageDispatherComponent.cs" />
......@@ -70,7 +82,11 @@
<Compile Include="Config\ICategory.cs" />
<Compile Include="Entity\Config\BuffConfig.cs" />
<Compile Include="Entity\Config\StartConfig.cs" />
<Compile Include="Entity\DBEntity.cs" />
<Compile Include="Entity\DBTask.cs" />
<Compile Include="Entity\DBTaskQueue.cs" />
<Compile Include="Entity\Game.cs" />
<Compile Include="Entity\Http.cs" />
<Compile Include="Entity\Message\InnerMessage.cs" />
<Compile Include="Entity\Message\Opcode.cs" />
<Compile Include="Entity\Message\OuterMessage.cs" />
......
......@@ -24,7 +24,7 @@ namespace MyEditor
private int copyNum = 1;
private AppType AppType = AppType.Manager;
private AppType AppType = AppType.None;
private readonly List<StartConfig> startConfigs = new List<StartConfig>();
......@@ -199,6 +199,8 @@ namespace MyEditor
{
GUILayout.Label($"OuterHost:");
outerConfig.Host = EditorGUILayout.TextField(outerConfig.Host);
GUILayout.Label($"OuterHost2:");
outerConfig.Host2 = EditorGUILayout.TextField(outerConfig.Host2);
GUILayout.Label($"OuterPort:");
outerConfig.Port = EditorGUILayout.IntField(outerConfig.Port);
}
......@@ -212,6 +214,29 @@ namespace MyEditor
clientConfig.Port = EditorGUILayout.IntField(clientConfig.Port);
}
HttpConfig httpConfig = startConfig.GetComponent<HttpConfig>();
if (httpConfig != null)
{
GUILayout.Label($"AppId:");
httpConfig.AppId = EditorGUILayout.IntField(httpConfig.AppId);
GUILayout.Label($"AppKey:");
httpConfig.AppKey = EditorGUILayout.TextField(httpConfig.AppKey);
GUILayout.Label($"Url:");
httpConfig.Url = EditorGUILayout.TextField(httpConfig.Url);
GUILayout.Label($"ManagerSystemUrl:");
httpConfig.ManagerSystemUrl = EditorGUILayout.TextField(httpConfig.ManagerSystemUrl);
}
DBConfig dbConfig = startConfig.GetComponent<DBConfig>();
if (dbConfig != null)
{
GUILayout.Label($"Connection:");
dbConfig.ConnectionString = EditorGUILayout.TextField(dbConfig.ConnectionString);
GUILayout.Label($"DBName:");
dbConfig.DBName = EditorGUILayout.TextField(dbConfig.DBName);
}
if (GUILayout.Button("删除"))
{
this.startConfigs.Remove(startConfig);
......@@ -227,6 +252,36 @@ namespace MyEditor
}
break;
}
if (i > 0)
{
if (GUILayout.Button("上移"))
{
StartConfig s = this.startConfigs[i];
this.startConfigs.RemoveAt(i);
this.startConfigs.Insert(i - 1, s);
for (int j = 0; j < startConfigs.Count; ++j)
{
this.startConfigs[j].AppId = j + 1;
}
break;
}
}
if (i < this.startConfigs.Count - 1)
{
if (GUILayout.Button("下移"))
{
StartConfig s = this.startConfigs[i];
this.startConfigs.RemoveAt(i);
this.startConfigs.Insert(i + 1, s);
for (int j = 0; j < startConfigs.Count; ++j)
{
this.startConfigs[j].AppId = j + 1;
}
break;
}
}
GUILayout.EndHorizontal();
}
......@@ -246,15 +301,29 @@ namespace MyEditor
if (this.AppType.Is(AppType.Gate | AppType.Realm | AppType.Manager))
{
newStartConfig.AddComponent<InnerConfig>();
newStartConfig.AddComponent<OuterConfig>();
}
if (this.AppType.Is(AppType.Gate | AppType.Realm | AppType.Manager | AppType.Http | AppType.DB))
{
newStartConfig.AddComponent<InnerConfig>();
}
if (this.AppType.Is(AppType.Benchmark))
{
newStartConfig.AddComponent<ClientConfig>();
}
if (this.AppType.Is(AppType.Http))
{
newStartConfig.AddComponent<HttpConfig>();
}
if (this.AppType.Is(AppType.DB))
{
newStartConfig.AddComponent<DBConfig>();
}
this.startConfigs.Add(newStartConfig);
}
GUILayout.EndHorizontal();
......
fileFormatVersion: 2
guid: f87d124589b266d41a4281a2a6ba3f63
timeCreated: 1476673528
licenseType: Pro
timeCreated: 1498900429
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
......
......@@ -6,9 +6,5 @@ namespace Model
public float x = 0;
public float y = 0;
public bool fold = false;
public NodeDesignerProto(): base(EntityType.Config)
{
}
}
}
\ No newline at end of file
......@@ -5,11 +5,11 @@
public string Name { get; set; }
public int Time { get; set; }
public BuffConfig(): base(EntityType.Config)
public BuffConfig()
{
}
public BuffConfig(long id): base(id, EntityType.Config)
public BuffConfig(long id): base(id)
{
}
}
......
using MongoDB.Bson.Serialization.Attributes;
namespace Model
{
[BsonIgnoreExtraElements]
public class DBConfig : AConfigComponent
{
public string ConnectionString { get; set; }
public string DBName { get; set; }
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: e8535ccd83c14ff44949812c618f7618
timeCreated: 1498901248
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using MongoDB.Bson.Serialization.Attributes;
namespace Model
{
[BsonIgnoreExtraElements]
public class HttpConfig : AConfigComponent
{
public string Url { get; set; } = "";
public int AppId { get; set; }
public string AppKey { get; set; } = "";
public string ManagerSystemUrl { get; set; } = "";
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: d1dc4ae9437263b4cb6956129ea85149
timeCreated: 1498901248
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
......@@ -8,6 +8,8 @@ namespace Model
public string Host { get; set; }
public int Port { get; set; }
public string Host2 { get; set; }
[BsonIgnore]
public string Address
{
......
namespace Model
using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes;
namespace Model
{
public class StartConfig: AConfig
{
public int AppId { get; set; }
[BsonRepresentation(BsonType.String)]
public AppType AppType { get; set; }
public string ServerIP { get; set; }
public StartConfig(): base(EntityType.Config)
{
}
}
}
\ No newline at end of file
using System.Collections.Generic;
using MongoDB.Bson.Serialization.Attributes;
using Newtonsoft.Json;
namespace Model
{
public class FileVersionInfo
{
public string File;
public string MD5;
public long Size;
}
public class VersionConfig : AConfig
{
public int Version;
[JsonIgnore]
public long TotalSize;
public List<FileVersionInfo> FileVersionInfos = new List<FileVersionInfo>();
[JsonIgnore]
public Dictionary<string, FileVersionInfo> FileInfoDict = new Dictionary<string, FileVersionInfo>();
public override void EndInit()
{
base.EndInit();
foreach (FileVersionInfo fileVersionInfo in FileVersionInfos)
{
this.FileInfoDict.Add(fileVersionInfo.File, fileVersionInfo);
this.TotalSize += fileVersionInfo.Size;
}
}
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: 2f62876308567a24b83b50edd38fe4c7
timeCreated: 1498901248
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
......@@ -5,11 +5,11 @@
/// </summary>
public abstract class AConfig: Entity
{
protected AConfig(EntityType entityType): base(entityType)
protected AConfig()
{
}
protected AConfig(long id, EntityType entityType): base(id, entityType)
protected AConfig(long id): base(id)
{
}
}
......
......@@ -11,7 +11,7 @@ namespace Model
private TaskCompletionSource<bool> tcs;
public AssetBundleLoaderAsync(AssetBundle assetBundle): base(EntityType.None)
public AssetBundleLoaderAsync(AssetBundle assetBundle)
{
this.assetBundle = assetBundle;
}
......
......@@ -21,11 +21,11 @@
public string Name { get; set; }
public Scene(): base(EntityType.Scene)
public Scene()
{
}
public Scene(long id): base(id, EntityType.Scene)
public Scene(long id): base(id)
{
}
......
......@@ -14,10 +14,6 @@ namespace Model
public TaskCompletionSource<bool> tcs;
public WWWAsync() : base(EntityType.None)
{
}
public float Progress
{
get
......
......@@ -10,13 +10,15 @@ namespace Model
Manager = 1,
Realm = 2,
Gate = 4,
Http = 8,
DB = 16,
Benchmark = 8,
Client = 16,
Robot = 32,
Benchmark = 64,
Client = 128,
// 7
AllServer = Manager | Realm | Gate
AllServer = Manager | Realm | Gate | Http | DB
}
public static class AppTypeHelper
......
namespace Model
using System;
namespace Model
{
public abstract class Disposer: Object
public abstract class Disposer: Object, IDisposable
{
protected Disposer(): base(IdGenerater.GenerateId())
{
......@@ -12,7 +14,7 @@
ObjectEvents.Instance.Add(this);
}
public override void Dispose()
public virtual void Dispose()
{
this.Id = 0;
}
......
......@@ -7,8 +7,6 @@ namespace Model
{
public class Entity: Disposer
{
public EntityType Type { get; set; }
[BsonElement]
private HashSet<Component> components = new HashSet<Component>();
......@@ -17,17 +15,10 @@ namespace Model
protected Entity()
{
this.Type = EntityType.None;
}
protected Entity(EntityType entityType)
{
this.Type = entityType;
}
protected Entity(long id, EntityType entityType): base(id)
protected Entity(long id): base(id)
{
this.Type = entityType;
}
public override void Dispose()
......
using System;
using System.ComponentModel;
namespace Model
{
public abstract class Object: IDisposable
public abstract class Object: ISupportInitialize
{
public long Id { get; protected set; }
......@@ -16,7 +16,11 @@ namespace Model
this.Id = id;
}
public virtual void Dispose()
public virtual void BeginInit()
{
}
public virtual void EndInit()
{
}
}
......
......@@ -107,24 +107,12 @@
<Reference Include="UnityEditor.Graphs">
<HintPath>Library\UnityAssemblies\UnityEditor.Graphs.dll</HintPath>
</Reference>
<Reference Include="UnityEditor.Android.Extensions">
<HintPath>Library\UnityAssemblies\UnityEditor.Android.Extensions.dll</HintPath>
</Reference>
<Reference Include="UnityEditor.iOS.Extensions">
<HintPath>Library\UnityAssemblies\UnityEditor.iOS.Extensions.dll</HintPath>
</Reference>
<Reference Include="UnityEditor.WindowsStandalone.Extensions">
<HintPath>Library\UnityAssemblies\UnityEditor.WindowsStandalone.Extensions.dll</HintPath>
</Reference>
<Reference Include="SyntaxTree.VisualStudio.Unity.Bridge">
<HintPath>Library\UnityAssemblies\SyntaxTree.VisualStudio.Unity.Bridge.dll</HintPath>
</Reference>
<Reference Include="UnityEditor.iOS.Extensions.Xcode">
<HintPath>Library\UnityAssemblies\UnityEditor.iOS.Extensions.Xcode.dll</HintPath>
</Reference>
<Reference Include="UnityEditor.iOS.Extensions.Common">
<HintPath>Library\UnityAssemblies\UnityEditor.iOS.Extensions.Common.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json">
<HintPath>Assets\JsonDotNet\Assemblies\Standalone\Newtonsoft.Json.dll</HintPath>
</Reference>
......
......@@ -74,12 +74,6 @@
<Reference Include="UnityEngine.HoloLens">
<HintPath>Library\UnityAssemblies\UnityEngine.HoloLens.dll</HintPath>
</Reference>
<Reference Include="UnityEditor.iOS.Extensions.Xcode">
<HintPath>Library\UnityAssemblies\UnityEditor.iOS.Extensions.Xcode.dll</HintPath>
</Reference>
<Reference Include="UnityEditor.iOS.Extensions.Common">
<HintPath>Library\UnityAssemblies\UnityEditor.iOS.Extensions.Common.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json">
<HintPath>Assets\JsonDotNet\Assemblies\Standalone\Newtonsoft.Json.dll</HintPath>
</Reference>
......
......@@ -12,15 +12,12 @@
<ProjectTypeGuids>{E097FAD1-6243-4DAD-9C02-E9B9EFC3FFC1};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<TargetFrameworkIdentifier>.NETFramework</TargetFrameworkIdentifier>
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
<TargetFrameworkProfile>
</TargetFrameworkProfile>
<CompilerResponseFile>
</CompilerResponseFile>
<TargetFrameworkProfile></TargetFrameworkProfile>
<CompilerResponseFile></CompilerResponseFile>
<UnityProjectType>Game:1</UnityProjectType>
<UnityBuildTarget>StandaloneWindows64:19</UnityBuildTarget>
<UnityVersion>2017.1.0f1</UnityVersion>
<RootNamespace>
</RootNamespace>
<RootNamespace></RootNamespace>
<LangVersion>6</LangVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
......@@ -77,12 +74,6 @@
<Reference Include="UnityEngine.HoloLens">
<HintPath>Library\UnityAssemblies\UnityEngine.HoloLens.dll</HintPath>
</Reference>
<Reference Include="UnityEditor.iOS.Extensions.Xcode">
<HintPath>Library\UnityAssemblies\UnityEditor.iOS.Extensions.Xcode.dll</HintPath>
</Reference>
<Reference Include="UnityEditor.iOS.Extensions.Common">
<HintPath>Library\UnityAssemblies\UnityEditor.iOS.Extensions.Common.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json">
<HintPath>Assets\JsonDotNet\Assemblies\Standalone\Newtonsoft.Json.dll</HintPath>
</Reference>
......@@ -436,6 +427,15 @@
<Compile Include="Assets\Scripts\BehaviorTreeNode\True.cs" />
<Compile Include="Assets\Scripts\BehaviorTreeNode\UIScale.cs" />
<Compile Include="Assets\Scripts\Component\BehaviorTreeComponent.cs" />
<Compile Include="Assets\Scripts\Component\Config\BuffConfig.cs" />
<Compile Include="Assets\Scripts\Component\Config\ClientConfig.cs" />
<Compile Include="Assets\Scripts\Component\Config\DBConfig.cs" />
<Compile Include="Assets\Scripts\Component\Config\HttpConfig.cs" />
<Compile Include="Assets\Scripts\Component\Config\InnerConfig.cs" />
<Compile Include="Assets\Scripts\Component\Config\OuterConfig.cs" />
<Compile Include="Assets\Scripts\Component\Config\RunServerConfig.cs" />
<Compile Include="Assets\Scripts\Component\Config\StartConfig.cs" />
<Compile Include="Assets\Scripts\Component\Config\VersionConfig.cs" />
<Compile Include="Assets\Scripts\Component\CrossComponent.cs" />
<Compile Include="Assets\Scripts\Component\EventComponent.cs" />
<Compile Include="Assets\Scripts\Component\NetInnerComponent.cs" />
......@@ -453,12 +453,6 @@
<Compile Include="Assets\Scripts\Define.cs" />
<Compile Include="Assets\Scripts\DllHelper.cs" />
<Compile Include="Assets\Scripts\Entity\AssetBundleLoaderAsync.cs" />
<Compile Include="Assets\Scripts\Entity\Config\BuffConfig.cs" />
<Compile Include="Assets\Scripts\Entity\Config\ClientConfig.cs" />
<Compile Include="Assets\Scripts\Entity\Config\InnerConfig.cs" />
<Compile Include="Assets\Scripts\Entity\Config\OuterConfig.cs" />
<Compile Include="Assets\Scripts\Entity\Config\RunServerConfig.cs" />
<Compile Include="Assets\Scripts\Entity\Config\StartConfig.cs" />
<Compile Include="Assets\Scripts\Entity\Game.cs" />
<Compile Include="Assets\Scripts\Entity\Message\InnerMessage.cs" />
<Compile Include="Assets\Scripts\Entity\Message\Opcode.cs" />
......@@ -526,4 +520,4 @@
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="GenerateTargetFrameworkMonikerAttribute" />
</Project>
\ No newline at end of file
</Project>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册