123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- using System.Collections.Generic;
- using System.Linq;
- using System.Reflection;
- using System.Threading.Tasks;
- using CSScriptLib;
- using Newtonsoft.Json;
- using WingInterfaceLibrary.DB.Request;
- using WingInterfaceLibrary.DTO.DistributedServerInfo;
- using WingInterfaceLibrary.Interface.DBInterface;
- using WingInterfaceLibrary.OpLog;
- using WingInterfaceLibrary.Request.DBRequest;
- using WingInterfaceLibrary.Result;
- using WingServerCommon.Config;
- using WingServerCommon.Service;
- namespace WingCloudServer.InteractionCenter
- {
- public partial class MasterInteractionCenterService : IMasterInteractionCenterService
- {
- /// <summary>
- /// 实时同步业务数据到主服务器
- /// </summary>
- /// <param name="request"></param>
- /// <returns></returns>
- public async Task<bool> SyncReceiveSlaveServiceDataAsync(SyncReceiveServiceDataRequest request)
- {
- //todo 判断是当前服务器并且是主服务器 则只需要发送oplogs到其他副服务器
- var localServerUrl = ConfigurationManager.Host;
- var baseLiveConsultation = JsonConvert.DeserializeObject<BaseLiveConsultationJson>(request.ServiceDataJson);
- // 调用manager
- // 判断是否存在其他服务器的用户
- var getLiveRoomByCodeDBRequest = new GetLiveRoomByCodeDBRequest();
- getLiveRoomByCodeDBRequest.LiveRoomCode = baseLiveConsultation.RoomCode;
- var roomDTO = await _liveRoomDBService.GetLiveRoomByCodeAsync(getLiveRoomByCodeDBRequest);
- var users = roomDTO.UserInfos;
- //操作人所在服务器
- var operatorUser = users.FirstOrDefault(x => x.Code == baseLiveConsultation.OperatorCode);
- //连接其他副服务器的用户
- var usersConnectOtherSlave = users.Where(x => x.LoginServerHost != operatorUser.LoginServerHost && x.LoginServerHost != localServerUrl);
- if (usersConnectOtherSlave != null && usersConnectOtherSlave.Count() > 0)
- {
- //获取oplogs
- var getOpLogsByCodesFormMasterRequest = new GetOpLogsByCodesFormMasterRequest();
- getOpLogsByCodesFormMasterRequest.Codes = new List<string> { baseLiveConsultation.ConsultationRecordCode, baseLiveConsultation.RoomCode };
- var oplogs = await _opLogDBService.GetOpLogsByCodesAsync(getOpLogsByCodesFormMasterRequest);
- //通知副服务器
- var otherSlaves = usersConnectOtherSlave.Select(x => x.LoginServerHost).Distinct();
- if (otherSlaves.Count() > 0)
- {
- //动态注册副服务器服务
- var otherSlaveHosts = new List<string>();
- foreach (var item in otherSlaves)
- {
- var slaveHost = item.Replace("http:", "").Replace(".", "").Replace("/", "");
- DynamicSlaveService(request, slaveHost);
- }
- }
- }
- return true;
- }
- public void DynamicSlaveService(SyncReceiveServiceDataRequest request, string host)
- {
- var eval = CSScript.Evaluator.ReferenceDomainAssemblies(DomainAssemblies.AllStaticNonGAC);
- var str = @"using System;
- using System.Threading.Tasks;
- using WingServerCommon.Service;
- using WingInterfaceLibrary.OpLog;
- using System.Collections.Generic;
- using JsonRpcLite.Rpc;
- using WingInterfaceLibrary.Interface.DBInterface;
- public class DynamicSlaveServiceClass : JsonRpcService
- {
- public void DynamicSlaveMethod(SyncReceiveServiceDataRequest request, IEnumerable<string> otherSlaveHosts)
- {
- var _dynamicService = GetProxy<IDynamicSlaveService" + host + @">();
- _dynamicService.DynamicSlaveAsync(request);
- }
- }";
- Assembly compilecode = eval.CompileCode(str);
- var ps = compilecode.GetType("css_root+DynamicSlaveServiceClass");
- var obj = compilecode.CreateInstance("css_root+DynamicSlaveServiceClass");
- var mes = ps.GetMethod("DynamicSlaveMethod");
- mes.Invoke(obj, new object[] { request, host });
- }
- }
- }
|