using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using MongoDB.Bson;
using MongoDB.Driver;
namespace ConsoleAppQiongQiMtTTS
{
internal class MGDBHelper
{
IMongoDatabase db = null;
public MGDBHelper()
{
try
{
string MG_IP = ConfigHelper.func_get_viki_sys_config_by_var("MG_IP");
string MG_PORT = ConfigHelper.func_get_viki_sys_config_by_var("MG_PORT");
string MG_USER = ConfigHelper.func_get_viki_sys_config_by_var("MG_USER");
string MG_PASSWORD = ConfigHelper.func_get_viki_sys_config_by_var("MG_PASSWORD");
string MG_DATABASE = ConfigHelper.func_get_viki_sys_config_by_var("MG_DATABASE");
MongoClientSettings mongoSettings = new MongoClientSettings();
mongoSettings.ConnectTimeout = TimeSpan.FromMilliseconds(1000);
mongoSettings.MaxConnectionPoolSize = 100;
MongoCredential credentials = MongoCredential.CreateCredential(MG_DATABASE, MG_USER, MG_PASSWORD);
mongoSettings.Credential = credentials;
mongoSettings.Server = new MongoServerAddress(MG_IP, Convert.ToInt32(MG_PORT));
mongoSettings.ReadPreference = new ReadPreference(ReadPreferenceMode.Primary);
MongoClient mg_client = new MongoClient(mongoSettings);
db = mg_client.GetDatabase("vikiai_calllog");
}
catch (Exception ex) {
Console.WriteLine(ex.Message);
}
}
/// <param name="obj_uuid">唯一值</param>
/// <param name="obj_words">文字</param>
/// <param name="obj_voice">发音人</param>
/// <param name="obj_speed">语速</param>
/// <param name="obj_volume">音量</param>
/// <param name="obj_recode_file_path">地址</param>
public bool func_add_log(string obj_node , string obj_uuid, string obj_words, string obj_voice, int obj_speed, int obj_volume, string obj_recode_file_path)
{
try
{
IMongoCollection<BsonDocument> document = db.GetCollection<BsonDocument>("viki_tts_log");
var doc = new BsonDocument {
{ "obj_node", obj_node },
{ "obj_uuid", obj_uuid },
{ "obj_words", obj_words },
{ "obj_voice", obj_voice },
{ "obj_speed", obj_speed.ToString()},
{ "obj_volume", obj_volume.ToString() },
{ "obj_recode_file_path", obj_recode_file_path }
};
document.InsertOne(doc);
}
catch (Exception ex) {
Console.WriteLine(ex.Message);
}
return true;
}
}
}
发表评论