|
@@ -13,6 +13,7 @@ using System.Net.Http;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.Configuration;
|
|
using TEAMModelOS.SDK.Models.Service;
|
|
using TEAMModelOS.SDK.Models.Service;
|
|
using System.Threading;
|
|
using System.Threading;
|
|
|
|
+using TEAMModelOS.SDK.Extension;
|
|
|
|
|
|
namespace TEAMModelOS.Controllers
|
|
namespace TEAMModelOS.Controllers
|
|
{
|
|
{
|
|
@@ -70,49 +71,50 @@ namespace TEAMModelOS.Controllers
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(stu?.channel) && !string.IsNullOrWhiteSpace(stu?.userid))
|
|
if (!string.IsNullOrWhiteSpace(stu?.channel) && !string.IsNullOrWhiteSpace(stu?.userid))
|
|
{
|
|
{
|
|
- var serviceManager = _azureSignalR.GetServiceManager();
|
|
|
|
- var cancel = new CancellationToken();
|
|
|
|
- var hub = await serviceManager.CreateHubContextAsync($"C{stu.channel}", cancel);
|
|
|
|
- try
|
|
|
|
|
|
+ // 處理單例復用,提高請求效率,避免ServiceTransportType.Persistent websocket斷線在Azure偶發的消息遺失
|
|
|
|
+ // TODO 尚須注意釋放的問題,後續須處理
|
|
|
|
+ var hub = _azureSignalR.GetServiceManager().GetHubContext($"C{stu.channel}");
|
|
|
|
+ // 下面註解寫法會造成Azure上消息偶發遺失,Localhost不會發生
|
|
|
|
+ //var serviceManager = _azureSignalR.GetServiceManager();
|
|
|
|
+ //using var hub = await serviceManager.CreateHubContextAsync($"C{stu.channel}", CancellationToken.None);
|
|
|
|
+
|
|
|
|
+ var con = content.GetString();
|
|
|
|
+ var ans = con switch
|
|
{
|
|
{
|
|
- var con = content.GetString();
|
|
|
|
- var ans = con switch
|
|
|
|
- {
|
|
|
|
- string _ when con.Length == 1 => new string[] { con },
|
|
|
|
- string _ when con.Contains('+', StringComparison.OrdinalIgnoreCase) => con.Split('+'),
|
|
|
|
- string _ when con.Equals("true", StringComparison.OrdinalIgnoreCase) => new string[] { "A" },
|
|
|
|
- string _ when con.Equals("false", StringComparison.OrdinalIgnoreCase) => new string[] { "B" },
|
|
|
|
- _ => throw new ArgumentNullException(nameof(content))
|
|
|
|
- };
|
|
|
|
|
|
+ string _ when con.Length == 1 => new string[] { con },
|
|
|
|
+ string _ when con.Contains('+', StringComparison.OrdinalIgnoreCase) => con.Split('+'),
|
|
|
|
+ string _ when con.Equals("true", StringComparison.OrdinalIgnoreCase) => new string[] { "A" },
|
|
|
|
+ string _ when con.Equals("false", StringComparison.OrdinalIgnoreCase) => new string[] { "B" },
|
|
|
|
+ _ => throw new ArgumentNullException(nameof(content))
|
|
|
|
+ };
|
|
|
|
|
|
- var common = JsonSerializer.Serialize(new
|
|
|
|
- {
|
|
|
|
- action = "DirectIRS.Answer",
|
|
|
|
- clientType = "DI",
|
|
|
|
- sender = stu.stuid,
|
|
|
|
- timestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
|
|
|
|
- waitReturn = false,
|
|
|
|
- payload = new { irsno = "", answer = ans }
|
|
|
|
- });
|
|
|
|
|
|
+ var common = JsonSerializer.Serialize(new
|
|
|
|
+ {
|
|
|
|
+ action = "DirectIRS.Answer",
|
|
|
|
+ clientType = "DI",
|
|
|
|
+ sender = stu.stuid,
|
|
|
|
+ timestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
|
|
|
|
+ waitReturn = false,
|
|
|
|
+ payload = new { irsno = "", answer = ans }
|
|
|
|
+ });
|
|
|
|
|
|
- await hub.Clients.User(stu.userid).SendCoreAsync("onMessage", new[]{new {
|
|
|
|
|
|
+ await hub.Clients.User(stu.userid).SendCoreAsync("onMessage", new[]{new {
|
|
connectionId = (string)null,
|
|
connectionId = (string)null,
|
|
to = (string)null,
|
|
to = (string)null,
|
|
groupname = (string)null,
|
|
groupname = (string)null,
|
|
sender = stu.stuid,
|
|
sender = stu.stuid,
|
|
text = common
|
|
text = common
|
|
}});
|
|
}});
|
|
- }
|
|
|
|
- finally
|
|
|
|
- {
|
|
|
|
- hub.Dispose();
|
|
|
|
- }
|
|
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
+ await _dingDing.SendBotMsg($"IES5,{_option.Location},tianbo/api/course/cardUploadData()\n{stu?.ToJsonString()}", GroupNames.醍摩豆服務運維群組);
|
|
}
|
|
}
|
|
|
|
+
|
|
return Ok(new { code = 200, msg = "成功", data = (string)null });
|
|
return Ok(new { code = 200, msg = "成功", data = (string)null });
|
|
}
|
|
}
|
|
- catch
|
|
|
|
|
|
+ catch (Exception ex)
|
|
{
|
|
{
|
|
|
|
+ await _dingDing.SendBotMsg($"IES5,{_option.Location},tianbo/api/course/cardUploadData()\n{ex.Message}\n{ex.StackTrace}{request.ToJsonString()}", GroupNames.醍摩豆服務運維群組);
|
|
return Ok(new { code = 200, msg = "成功", data = (string)null });
|
|
return Ok(new { code = 200, msg = "成功", data = (string)null });
|
|
}
|
|
}
|
|
|
|
|