WeOnlineAppMsgClientManager.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Configuration;
  4. using System.Linq;
  5. using System.Reflection;
  6. using System.Threading.Tasks;
  7. using Abp.Configuration;
  8. using Abp.Dependency;
  9. using Abp.Domain.Repositories;
  10. using Abp.Domain.Uow;
  11. using Abp.Runtime.Caching;
  12. using IwbZero.ToolCommon;
  13. using IwbZero.ToolCommon.LogHelpers;
  14. using IwbZero.ToolCommon.StringModel;
  15. using Microsoft.AspNet.SignalR;
  16. using uPLibrary.Networking.M2Mqtt.Messages;
  17. using WeEngine.CommonDto;
  18. using WeEngine.Enum;
  19. using WeEngine.Message;
  20. using WeEngine.Packages;
  21. using WeMessageService;
  22. using WeOnlineApp.Configuration;
  23. using WeOnlineApp.Configuration.Cache;
  24. using WeOnlineApp.Hubs;
  25. using WeOnlineApp.TrainingCamp;
  26. namespace WeOnlineApp.MqttClient
  27. {
  28. public class WeOnlineAppMsgClientManager : ISingletonDependency
  29. {
  30. public WeOnlineAppMsgClientManager(ISettingManager settingManager, IUnitOfWorkManager unitOfWorkManager, ICacheManager cacheManager, IRepository<CampInfo, string> campRepository, IRepository<CampPlayInfo, string> playRepository, IRepository<CampPlayLogInfo> plRepository, IRepository<CampPlayScoreInfo> psRepository, IRepository<CampPlayUserInfo> puRepository)
  31. {
  32. SettingManager = settingManager;
  33. UnitOfWorkManager = unitOfWorkManager;
  34. CacheManager = cacheManager;
  35. CampRepository = campRepository;
  36. PlayRepository = playRepository;
  37. PlRepository = plRepository;
  38. PsRepository = psRepository;
  39. PuRepository = puRepository;
  40. IwbHubContext = GlobalHost.ConnectionManager.GetHubContext<IwbHub>();
  41. if (!Client.IsConnected)
  42. {
  43. RegisterClient();
  44. }
  45. HasStartPushSender = false;
  46. }
  47. private static readonly Dictionary<string, ScenePusher> _scenePushes = new Dictionary<string, ScenePusher>();
  48. private string _url => SettingManager.GetSettingValue(IwbSettingNames.WeDataCenterIp);
  49. private string _engineUrl => SettingManager.GetSettingValue(IwbSettingNames.WeEngineIp);
  50. private static M2MqttMsgClient Client = new M2MqttMsgClient();
  51. private IUnitOfWorkManager UnitOfWorkManager { get; }
  52. private ISettingManager SettingManager { get; }
  53. private ICacheManager CacheManager { get; }
  54. private IRepository<CampInfo, string> CampRepository { get; }
  55. private IRepository<CampPlayInfo, string> PlayRepository { get; }
  56. private IRepository<CampPlayScoreInfo> PsRepository { get; }
  57. private IRepository<CampPlayLogInfo> PlRepository { get; }
  58. private IRepository<CampPlayUserInfo> PuRepository { get; }
  59. protected IHubContext IwbHubContext { get; }
  60. public bool HasStartPushSender { get; set; }
  61. #region MSG-CLIENT
  62. public string ClientId { get; set; }
  63. /// <summary>
  64. /// 强制刷新客户端
  65. /// </summary>
  66. public void RefreshClient()
  67. {
  68. this.LogInfo($"客户端{ClientId}开始强制刷新!");
  69. Client.DisConnect();
  70. Client = new M2MqttMsgClient();
  71. RegisterClient();
  72. SendMessage(ClientId, $"客户端{ClientId}已强制刷新!");
  73. SendMessage("WeEngine", $"客户端{ClientId}已强制刷新!");
  74. }
  75. /// <summary>
  76. /// 注册客户端
  77. /// </summary>
  78. public void RegisterClient()
  79. {
  80. ClientId = IwbConsts.ClientName;
  81. this.LogDebug($"ClientId-{ClientId}");
  82. MsgClientDto result;
  83. if (IwbConsts.IsDebug)
  84. {
  85. result = new MsgClientDto()
  86. {
  87. AppId = ClientId,
  88. Name = "在线分布式智慧演练系统",
  89. SecretKey = "WePlatformWeOnlineApp",
  90. ServerIp = "localhost",
  91. ServerPort = 1885,
  92. };
  93. }
  94. else
  95. {
  96. result = CacheManager.GetMsgClientDto(ClientId, _url);
  97. if (result == null)
  98. {
  99. //throw new UserFriendlyException("未查询到消息客户端配置!");
  100. this.LogError($"未查询到消息客户端{ClientId}的配置!");
  101. return;
  102. }
  103. }
  104. this.LogDebug($"Client-{result.Obj2String()}");
  105. Client.SetOptions(result.ServerIp, result.ServerPort, ClientId, result.Name, result.SecretKey);
  106. Client.SetReceivedHandler(ReceivedHandler);
  107. Subscribe();
  108. }
  109. private void Subscribe()
  110. {
  111. if (Client.CheckClient())
  112. {
  113. Client.SubscribeTopic(ClientId, false);
  114. IwbHubContext.Clients.Group(ClientId).getMqttMsg(new { topic = ClientId, msg = "订阅主题" });
  115. Client.SubscribeTopic("Heartbeat");
  116. IwbHubContext.Clients.Group(ClientId).getMqttMsg(new { topic = $"{ClientId}/Heartbeat", msg = "订阅主题" });
  117. var t = typeof(MessageType);
  118. var fts = t.GetFields(BindingFlags.Static | BindingFlags.Public);
  119. foreach (var f in fts)
  120. {
  121. string name = f.Name;
  122. Client.SubscribeTopic($"{name}/+");
  123. IwbHubContext.Clients.Group(ClientId).getMqttMsg(new { topic = $"{ClientId}/{name}/+", msg = "订阅主题" });
  124. //AsyncHelper.RunSync(() => Client.SubscribeTopic(name));
  125. }
  126. }
  127. }
  128. public void SendMessage(WeMessage message, MessageType type, string clientId = null)
  129. {
  130. if (Client.NotValidate)
  131. {
  132. RegisterClient();
  133. }
  134. var msg = message.Obj2String();
  135. Client.SendMsg(type.ToString(), msg, clientId);
  136. IwbHubContext.Clients.Group(ClientId).getSendMqttMsg(new { topic = $"{ClientId}/{type}/", msg });
  137. }
  138. public void SendMessage(WeMessage message)
  139. {
  140. if (Client.NotValidate)
  141. {
  142. RegisterClient();
  143. }
  144. var msg = message.Obj2String();
  145. Client.SendMsg(message.Type.ToString(), msg, message.TargetClientId);
  146. IwbHubContext.Clients.Group(ClientId).getSendMqttMsg(new { topic = $"{message.TargetClientId}/{message.Type}/", msg });
  147. }
  148. public void SendMessage(string msg)
  149. {
  150. if (Client.NotValidate)
  151. {
  152. RegisterClient();
  153. }
  154. Client.SendMessage(ClientId, msg);
  155. IwbHubContext.Clients.Group(ClientId).getSendMqttMsg(new { topic = $"{ClientId}", msg });
  156. }
  157. public void SendMessage(string topic, string msg)
  158. {
  159. if (Client.NotValidate)
  160. {
  161. RegisterClient();
  162. }
  163. Client.SendMessage(topic, msg);
  164. IwbHubContext.Clients.Group(ClientId).getSendMqttMsg(new { topic, msg });
  165. }
  166. /// <summary>
  167. /// 消息接受回调处理
  168. /// </summary>
  169. /// <param name="msg"></param>
  170. private void ReceiveMsgHandler(string msg)
  171. {
  172. try
  173. {
  174. var message = msg.Str2Obj<WeMessage>();
  175. if (message != null)
  176. {
  177. switch (message.Type)
  178. {
  179. case MessageType.Start:
  180. ReceiveStart(message);
  181. break;
  182. case MessageType.End:
  183. ReceiveEnd(message);
  184. break;
  185. case MessageType.RunningInfo:
  186. ReceiveRunningInfo(message);
  187. break;
  188. case MessageType.RoundScore:
  189. ReceiveRoundScore(message);
  190. break;
  191. case MessageType.SceneInfo:
  192. ReceiveScene(message);
  193. break;
  194. case MessageType.GuideInfo:
  195. ReceiveGuide(message);
  196. break;
  197. case MessageType.Environment:
  198. ReceiveEnvironment(message);
  199. break;
  200. case MessageType.CommandMatchSuccess:
  201. ReceiveMatchSuccess(message);
  202. break;
  203. case MessageType.CommonMessage:
  204. ReceiveCommonMsg(message);
  205. break;
  206. }
  207. }
  208. else
  209. {
  210. typeof(WeOnlineAppMsgClientManager).LogError("MSG ERROR:" + msg);
  211. }
  212. }
  213. catch (Exception e)
  214. {
  215. typeof(WeOnlineAppMsgClientManager).LogError(e);
  216. }
  217. }
  218. /// <summary>
  219. /// 消息接受回调处理
  220. /// </summary>
  221. /// <param name="sender"></param>
  222. /// <param name="e"></param>
  223. private void ReceivedHandler(object sender, MqttMsgPublishEventArgs e)
  224. {
  225. string msg = System.Text.Encoding.UTF8.GetString(e.Message);
  226. IwbHubContext.Clients.Group(IwbConsts.ClientName).getMqttMsg(new { topic = e.Topic, msg });
  227. if (e.Topic == ClientId || e.Topic == $"{ClientId}/Heartbeat")
  228. {
  229. return;
  230. }
  231. ReceiveMsgHandler(msg);
  232. }
  233. //private IMqttApplicationMessageReceivedHandler ReceivedHandler =>
  234. // new MqttApplicationMessageReceivedHandlerDelegate(
  235. // (arg) =>
  236. // {
  237. // string payload = System.Text.Encoding.UTF8.GetString(arg.ApplicationMessage.Payload);
  238. // var message = payload.Str2Obj<WeMessage>();
  239. // if (message != null)
  240. // {
  241. // switch (message.MsgType)
  242. // {
  243. // case MessageType.Environment:
  244. // break;
  245. // case MessageType.RunningInfo:
  246. // ReceiveRunningInfo(message);
  247. // break;
  248. // case MessageType.RoundScore:
  249. // ReceiveRoundScore(message);
  250. // break;
  251. // case MessageType.CommonMessage:
  252. // break;
  253. // case MessageType.GuideInfo:
  254. // break;
  255. // }
  256. // }
  257. // else
  258. // {
  259. // typeof(WeAppMsgClientManager).LogError("Message ERROR:" + payload);
  260. // }
  261. // });
  262. #endregion MSG-CLIENT
  263. public static string GetTargetClient()
  264. {
  265. var str = IwbConsts.ClientName;
  266. var others = ConfigurationManager.AppSettings["ThirdMessageClientIds"] ?? "";
  267. if (others.IsNotEmpty())
  268. {
  269. str += $"@{others}";
  270. }
  271. return str;
  272. }
  273. [UnitOfWork]
  274. protected virtual void ReceiveStart(WeMessage message)
  275. {
  276. var playNo = message.RunningId;
  277. var play = PlayRepository.GetAllIncluding(a => a.CampInfo).FirstOrDefault(a => a.Id == playNo);
  278. if (play != null)
  279. {
  280. var date = DateTime.Now;
  281. play.PlayState = CampPlayStateDefinition.Run;
  282. play.StartDate = date;
  283. var users = PuRepository.GetAllList(a => a.PlayNo == play.Id);
  284. if (users.Any())
  285. {
  286. foreach (var pu in users)
  287. {
  288. pu.PlayerState = CampPlayUserStateDefinition.Run;
  289. PuRepository.Update(pu);
  290. }
  291. UnitOfWorkManager.Current.SaveChanges();
  292. }
  293. CacheManager.SetPlayInfo(play);
  294. IwbHubContext.Clients.Group(play.InvitationCode).getReloadPage(new { no = play.Id }.Obj2String());
  295. //ScenePusher scenePusher = new ScenePusher();
  296. //scenePusher.SendMsg += (msg) => { PushMessage(msg, play.InvitationCode); };
  297. //_scenePushes[playNo] = scenePusher;
  298. PlayRepository.Update(play);
  299. UnitOfWorkManager.Current.SaveChanges();
  300. }
  301. }
  302. [UnitOfWork]
  303. protected virtual void ReceiveEnd(WeMessage message)
  304. {
  305. var playNo = message.RunningId;
  306. var play = PlayRepository.GetAllIncluding(a => a.CampInfo).FirstOrDefault(a => a.Id == playNo);
  307. if (play != null)
  308. {
  309. var date = DateTime.Now;
  310. //try
  311. //{
  312. // new TaskFactory().StartNew(() => { CacheManager.GetFullPackageDataNode(play.CampInfo.PackageNo, _url); });
  313. //}
  314. //catch
  315. //{
  316. // //
  317. //}
  318. play.PlayState = CampPlayStateDefinition.End;
  319. play.EndDate = date;
  320. play.TrainingMinute = play.StartDate?.GetTimeSpanMinute(date) ?? 0;
  321. var users = PuRepository.GetAllList(a => a.PlayNo == play.Id);
  322. if (users.Any())
  323. {
  324. foreach (var pu in users)
  325. {
  326. pu.PlayerState = CampPlayUserStateDefinition.End;
  327. PuRepository.Update(pu);
  328. }
  329. }
  330. CacheManager.SetPlayInfo(play);
  331. PlayRepository.Update(play);
  332. UnitOfWorkManager.Current.SaveChanges();
  333. IwbHubContext.Clients.Group(play.InvitationCode).getReloadPage(new { no = play.Id }.Obj2String());
  334. StopPushScene(playNo);
  335. }
  336. }
  337. [UnitOfWork]
  338. protected virtual void ReceiveRunningInfo(WeMessage message)
  339. {
  340. var playNo = message.RunningId;
  341. //var runningInfo = message.Content.Str2Obj<RunningInfo>();
  342. var runningInfo = GetRunningInfo(playNo);
  343. if (runningInfo != null)
  344. {
  345. var play = PlayRepository.FirstOrDefault(a => a.Id == playNo);
  346. if (play != null)
  347. {
  348. runningInfo.Name = play.Name;
  349. CacheManager.GetCache(IwbCacheNames.PlayRunningInfoCache).Set(playNo, runningInfo);
  350. play.RunningInfo = runningInfo.Obj2String();
  351. play.RoundIndex = runningInfo.CurrentRoundIndex;
  352. IwbHubContext.Clients.Group(play.InvitationCode).getRunningChange(new { no = playNo }.Obj2String());
  353. CacheManager.SetPlayInfo(play);
  354. PlayRepository.Update(play);
  355. UnitOfWorkManager.Current.SaveChanges();
  356. }
  357. }
  358. }
  359. private PackageDataNode GetRunningInfo(string no)
  360. {
  361. var url =
  362. $"{_engineUrl.Ew("/")}api/services/Engine/Run/QueryPackageDataNode?id={no}";
  363. var result = url.RequestPost("");
  364. var info = result.Str2Obj<PackageDataNode>();
  365. if (info != null)
  366. {
  367. CacheManager.SetGroupRunningInfo(no, info);
  368. }
  369. return info;
  370. }
  371. [UnitOfWork]
  372. protected virtual void ReceiveRoundScore(WeMessage message)
  373. {
  374. var playNo = message.RunningId;
  375. var roundScoreInfo = message.Content.Str2Obj<RoundScoreInfo>();
  376. if (roundScoreInfo == null)
  377. {
  378. return;
  379. }
  380. var play = PlayRepository.FirstOrDefault(a => a.Id == playNo);
  381. if (play == null)
  382. {
  383. return;
  384. }
  385. //var gs = await GsRepository.FirstOrDefaultAsync(a =>
  386. // a.GroupNo == groupNo && a.RoundIndex == roundScoreInfo.RoundIndex);
  387. var ps = CacheManager.GetGroupRoundScore(playNo, roundScoreInfo.RoundIndex, PsRepository);
  388. var tagScores = new List<TagScoreInfo>();
  389. var oldTagScores = ps?.BehaviorTagScoreInfo.Str2Obj<List<TagScoreInfo>>();
  390. var activeTag = CacheManager.GetCampTags(play.CampNo, CampRepository).Result;
  391. //var pushScores = new List<TagScoreInfo>();
  392. if (roundScoreInfo.TagScores != null && activeTag != null)
  393. {
  394. foreach (var tNo in activeTag)
  395. {
  396. var tagScore = roundScoreInfo.TagScores.FirstOrDefault(a => a.TagNo.Trim() == tNo.Trim());
  397. if (tagScore != null)
  398. {
  399. //pushScores.Add(new TagScoreInfo()
  400. //{
  401. // TagNo = tNo,
  402. // SystemScore = tagScore.SystemScore,
  403. // TotalScore = tagScore.TotalScore
  404. //});
  405. var oldTagScore = oldTagScores?.FirstOrDefault(a => a.TagNo.Trim() == tagScore.TagNo.Trim());
  406. if (oldTagScore != null)
  407. {
  408. tagScore.SystemScore = oldTagScore.SystemScore + tagScore.SystemScore;
  409. tagScore.CorrectionScore = oldTagScore.CorrectionScore == 0
  410. ? 0
  411. : oldTagScore.CorrectionScore + tagScore.SystemScore;
  412. tagScore.SystemScore = tagScore.SystemScore > tagScore.TotalScore
  413. ? tagScore.TotalScore
  414. : tagScore.SystemScore;
  415. }
  416. }
  417. else
  418. {
  419. tagScore = oldTagScores?.FirstOrDefault(a => a.TagNo.Trim() == tNo.Trim()) ?? new TagScoreInfo()
  420. {
  421. TagNo = tNo,
  422. CorrectionScore = 0,
  423. SystemScore = 0,
  424. TotalScore = 0
  425. };
  426. }
  427. tagScores.Add(tagScore);
  428. }
  429. }
  430. if (roundScoreInfo.KeyWords.IsNotEmpty())
  431. {
  432. var arr = roundScoreInfo.KeyWords.Split('|');
  433. if (int.TryParse(arr[0], out var logId))
  434. {
  435. var log = PlRepository.FirstOrDefault(a => a.Id == logId);
  436. if (log != null)
  437. {
  438. log.LogState = LogStateDefinition.HasMatch;
  439. PlRepository.Update(log);
  440. }
  441. }
  442. }
  443. if (ps == null)
  444. {
  445. ps = new CampPlayScoreInfo()
  446. {
  447. CampNo = play.CampNo,
  448. PlayNo = playNo,
  449. RoundIndex = roundScoreInfo.RoundIndex,
  450. SystemScore = roundScoreInfo.RoundScore,
  451. BehaviorTagScoreInfo = tagScores.Obj2StringCamelCase()
  452. };
  453. PsRepository.Insert(ps);
  454. }
  455. else
  456. {
  457. ps.CampPlayInfo = null;
  458. ps.PlayNo = playNo;
  459. ps.SystemScore = roundScoreInfo.RoundScore;
  460. ps.BehaviorTagScoreInfo = tagScores.Obj2StringCamelCase();
  461. PsRepository.Update(ps);
  462. }
  463. CacheManager.SetGroupRoundScore(playNo, roundScoreInfo.RoundIndex, ps);
  464. IwbHubContext.Clients.Group(play.InvitationCode)
  465. .getRoundScore(new
  466. {
  467. no = playNo,
  468. round = roundScoreInfo.RoundIndex,
  469. roundIndex = roundScoreInfo.RoundIndex,
  470. systemScore = roundScoreInfo.RoundScore,
  471. tagScores
  472. }.Obj2StringCamelCase());
  473. }
  474. [UnitOfWork]
  475. protected virtual void ReceiveScene(WeMessage message)
  476. {
  477. var playNo = message.RunningId;
  478. var scene = message.Content.Str2Obj<SceneDto>();
  479. if (scene != null)
  480. {
  481. var play = PlayRepository.FirstOrDefault(a => a.Id == playNo);
  482. if (play != null)
  483. {
  484. var scenePathList = CacheManager.GetScenePathList(playNo, PlayRepository);
  485. scenePathList.hasChange = true;
  486. scenePathList.PathList = scenePathList.PathList ?? new List<string>();
  487. if (!scenePathList.PathList.Contains(scene.Path))
  488. {
  489. scenePathList.PathList.Add(scene.Path);
  490. }
  491. CacheManager.SetScenePathList(playNo, scenePathList);
  492. SendScenePusher(playNo, play.InvitationCode, new ScenePushMessage(playNo, scene.Path));
  493. }
  494. }
  495. }
  496. [UnitOfWork]
  497. protected virtual void ReceiveGuide(WeMessage message)
  498. {
  499. var playNo = message.RunningId;
  500. var play = PlayRepository.FirstOrDefault(a => a.Id == playNo);
  501. if (play == null)
  502. {
  503. return;
  504. }
  505. SendScenePusher(playNo, play.InvitationCode, new ScenePushMessage(PushMessageDefinition.Guide) { content = message.Content });
  506. }
  507. [UnitOfWork]
  508. protected virtual void ReceiveEnvironment(WeMessage message)
  509. {
  510. var playNo = message.RunningId;
  511. var play = PlayRepository.FirstOrDefault(a => a.Id == playNo);
  512. if (play == null)
  513. {
  514. return;
  515. }
  516. SendScenePusher(playNo, play.InvitationCode, new ScenePushMessage(PushMessageDefinition.Environment) { content = message.Content });
  517. }
  518. [UnitOfWork]
  519. protected virtual void ReceiveMatchSuccess(WeMessage message)
  520. {
  521. var playNo = message.RunningId;
  522. var play = PlayRepository.FirstOrDefault(a => a.Id == playNo);
  523. if (play == null)
  524. {
  525. return;
  526. }
  527. IwbHubContext.Clients.Group(play.InvitationCode).getMatchSuccess(message.Content);
  528. }
  529. [UnitOfWork]
  530. protected virtual void ReceiveCommonMsg(WeMessage message)
  531. {
  532. var playNo = message.RunningId;
  533. var play = PlayRepository.FirstOrDefault(a => a.Id == playNo);
  534. if (play == null)
  535. {
  536. return;
  537. }
  538. SendScenePusher(playNo, play.InvitationCode, new ScenePushMessage(PushMessageDefinition.CommonMsg) { content = message.Content });
  539. }
  540. /// <summary>
  541. /// 开始推送情景(解决页面还未加载时就推送情景)
  542. /// 需要页面第一次加载打开推送开关后再开始推送
  543. /// </summary>
  544. /// <param name="playNo"></param>
  545. public static bool StartPushScene(string playNo)
  546. {
  547. ScenePusher scenePusher = _scenePushes.ContainsKey(playNo) ? _scenePushes[playNo] : new ScenePusher();
  548. _scenePushes[playNo] = scenePusher;
  549. return scenePusher.Start();
  550. }
  551. public static void StopPushScene(string no)
  552. {
  553. if (_scenePushes.ContainsKey(no))
  554. {
  555. _scenePushes[no].Stop();
  556. }
  557. }
  558. private void SendScenePusher(string no, string code, ScenePushMessage pushMsg)
  559. {
  560. ScenePusher scenePusher;
  561. if (_scenePushes.ContainsKey(no))
  562. {
  563. scenePusher = _scenePushes[no];
  564. if (scenePusher.NeedHandel)
  565. {
  566. scenePusher.SendMsg += (msg) => { PushMessage(msg, code); };
  567. }
  568. }
  569. else
  570. {
  571. scenePusher = new ScenePusher();
  572. scenePusher.SendMsg += (msg) => { PushMessage(msg, code); };
  573. _scenePushes[no] = scenePusher;
  574. }
  575. scenePusher.Push(pushMsg);
  576. }
  577. private void PushMessage(ScenePushMessage msg, string code)
  578. {
  579. switch (msg.type)
  580. {
  581. case PushMessageDefinition.Scene:
  582. IwbHubContext.Clients.Group(code).getNewScene(msg);
  583. break;
  584. case PushMessageDefinition.Guide:
  585. IwbHubContext.Clients.Group(code).getGuide(msg.content);
  586. break;
  587. case PushMessageDefinition.Environment:
  588. IwbHubContext.Clients.Group(code).getEnvironment(msg.content);
  589. break;
  590. case PushMessageDefinition.CommonMsg:
  591. IwbHubContext.Clients.Group(code).getCommonMsg(msg.content);
  592. break;
  593. }
  594. }
  595. }
  596. }