62 lines
2.4 KiB
C#
62 lines
2.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
|
|
using ServerCore;
|
|
|
|
|
|
namespace ServerBase;
|
|
|
|
public partial class MongoDbConnector : MongoDbConnectorBase, IModule, IInitializer
|
|
{
|
|
public class ConfigParam : IConfigParam
|
|
{
|
|
public string ServiceType { get; set; } = string.Empty;
|
|
public string DatabaseName { get; set; } = string.Empty;
|
|
public string ConnectionString { get; set; } = string.Empty;
|
|
public int MinConnectionPoolSize { get; set; } = 0;
|
|
public int MaxConnectionPoolSize { get; set; } = 100;
|
|
public int WaitQueueTimeoutSecs { get; set; } = 120;
|
|
|
|
public Result tryReadFromJsonOrDefault(JObject jObject)
|
|
{
|
|
var result = new Result();
|
|
var err_msg = string.Empty;
|
|
|
|
try
|
|
{
|
|
ServiceType = jObject["ServiceType"]?.Value<string>() ?? ServiceType;
|
|
|
|
var mongo_db = jObject["MongoDb"];
|
|
NullReferenceCheckHelper.throwIfNull(mongo_db, () => $"mongo_db is null !!!");
|
|
ConnectionString = mongo_db["ConnectionString"]?.Value<string>() ?? ConnectionString;
|
|
DatabaseName = mongo_db["DatabaseName"]?.Value<string>() ?? DatabaseName;
|
|
MinConnectionPoolSize = mongo_db["MinConnectionPoolSize"]?.Value<int>() ?? MinConnectionPoolSize;
|
|
MaxConnectionPoolSize = mongo_db["MaxConnectionPoolSize"]?.Value<int>() ?? MaxConnectionPoolSize;
|
|
WaitQueueTimeoutSecs = mongo_db["WaitQueueTimeoutSecs"]?.Value<int>() ?? WaitQueueTimeoutSecs;
|
|
|
|
return result;
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
var error_code = ServerErrorCode.TryCatchException;
|
|
err_msg = $"Exception !!!, Failed to perform in tryReadFromJsonOrDefault() !!! : errorCode:{error_code}, exception:{e} - {this.getTypeName()}";
|
|
result.setFail(error_code, err_msg);
|
|
Log.getLogger().error(err_msg);
|
|
return result;
|
|
}
|
|
}
|
|
|
|
public string toBasicString()
|
|
{
|
|
return $"ConfigParam: ServiceType:{ServiceType}, ConnectionStringOfMongoDb:{ConnectionString}, MinConnectionPoolSize:{MinConnectionPoolSize}, MaxConnectionPoolSize:{MaxConnectionPoolSize}, WaitQueueTimeoutSecs:{WaitQueueTimeoutSecs}";
|
|
}
|
|
};
|
|
}
|