Merge branch 'release/AddTopicMan01'
This commit is contained in:
@@ -76,6 +76,14 @@ namespace Eqn.Sender.Controllers
|
||||
return answ;
|
||||
}
|
||||
|
||||
[HttpPost("sendTopic")]
|
||||
public async Task<string> SendTopic([FromBody] MsgPayload rawData)
|
||||
{
|
||||
string answ = await DoSendTopic(rawData);
|
||||
// restituisco esito...
|
||||
return answ;
|
||||
}
|
||||
|
||||
[HttpPost("test")]
|
||||
public async Task<string> Test(int numTest = 10, int numParall = 1, bool dryRun = true)
|
||||
{
|
||||
@@ -136,6 +144,14 @@ namespace Eqn.Sender.Controllers
|
||||
return answ;
|
||||
}
|
||||
|
||||
[HttpPost("topicUnsub")]
|
||||
public async Task<string> TopicUnsubs([FromBody] TopicPayload rawData)
|
||||
{
|
||||
string answ = await TopicUnsubTokens(rawData.tokenList, rawData.topic);
|
||||
// restituisco esito...
|
||||
return answ;
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
#region Private Fields
|
||||
@@ -157,7 +173,9 @@ namespace Eqn.Sender.Controllers
|
||||
/// </summary>
|
||||
/// <param name="rawData">Dati payload</param>
|
||||
/// <param name="fullReturn">Indica se ritornare per intero il messaggio firebase</param>
|
||||
/// <param name="doDelay">Indica se mettere delay causale 15-25 ms tra ogni send (deault true)</param>
|
||||
/// <param name="doDelay">
|
||||
/// Indica se mettere delay causale 15-25 ms tra ogni send (deault true)
|
||||
/// </param>
|
||||
/// <param name="isAndroid">Booleano: true = Android / false=iOS</param>
|
||||
/// <param name="maxToken">Num max di token x singolo invio FireBase</param>
|
||||
/// <param name="numParall">Parallelismo send ammesso</param>
|
||||
@@ -239,8 +257,7 @@ namespace Eqn.Sender.Controllers
|
||||
}
|
||||
messageList.Add(newMessage);
|
||||
}
|
||||
int iter = 0;
|
||||
int bDelay = 30;
|
||||
int bDelay = 60;
|
||||
List<BatchResponse> listBResp = new List<BatchResponse>();
|
||||
if (numParall > 1)
|
||||
{
|
||||
@@ -250,9 +267,8 @@ namespace Eqn.Sender.Controllers
|
||||
// eventuale delay se richiesto
|
||||
if (doDelay)
|
||||
{
|
||||
await Task.Delay(bDelay * iter + rnd.Next(10, 30));
|
||||
await Task.Delay(rnd.Next(0, bDelay));
|
||||
}
|
||||
iter++;
|
||||
Stopwatch lsw = new Stopwatch();
|
||||
var currData = new BStatData();
|
||||
lsw.Start();
|
||||
@@ -262,11 +278,6 @@ namespace Eqn.Sender.Controllers
|
||||
currData.Size = message.Tokens.Count;
|
||||
currData.TimeSec = lsw.Elapsed.TotalSeconds;
|
||||
elapsedTime.Add(currData);
|
||||
// eventuale delay se richiesto
|
||||
if (doDelay)
|
||||
{
|
||||
await Task.Delay(bDelay * iter + rnd.Next(10, 30));
|
||||
}
|
||||
});
|
||||
}
|
||||
else
|
||||
@@ -276,9 +287,8 @@ namespace Eqn.Sender.Controllers
|
||||
// eventuale delay se richiesto
|
||||
if (doDelay)
|
||||
{
|
||||
await Task.Delay(bDelay * iter + rnd.Next(10, 30));
|
||||
await Task.Delay(rnd.Next(0, bDelay));
|
||||
}
|
||||
iter++;
|
||||
Stopwatch lsw = new Stopwatch();
|
||||
var currData = new BStatData();
|
||||
lsw.Start();
|
||||
@@ -288,11 +298,6 @@ namespace Eqn.Sender.Controllers
|
||||
currData.Size = item.Tokens.Count;
|
||||
currData.TimeSec = lsw.Elapsed.TotalSeconds;
|
||||
elapsedTime.Add(currData);
|
||||
// eventuale delay se richiesto
|
||||
if (doDelay)
|
||||
{
|
||||
await Task.Delay(bDelay * iter + rnd.Next(10, 30));
|
||||
}
|
||||
}
|
||||
}
|
||||
sw.Stop();
|
||||
@@ -315,7 +320,7 @@ namespace Eqn.Sender.Controllers
|
||||
if (sw.Elapsed.TotalSeconds > 5)
|
||||
{
|
||||
int numSend = elapsedTime.Count;
|
||||
string logVal = $"Warnng soglia, durata: {sw.Elapsed.TotalSeconds:N3} sec | chiamate: {numCall} | batch: {numSend}";
|
||||
string logVal = $"Warning soglia, durata: {sw.Elapsed.TotalSeconds:N3} sec | chiamate: {numCall} | batch: {numSend}";
|
||||
_logger.LogWarning(logVal);
|
||||
// scrivo tutte le righe
|
||||
int idx = 1;
|
||||
@@ -335,6 +340,54 @@ namespace Eqn.Sender.Controllers
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Funzione di invio messaggi a topic
|
||||
/// </summary>
|
||||
/// <param name="rawData">Dati payload</param>
|
||||
/// <returns></returns>
|
||||
private async Task<string> DoSendTopic(MsgPayload rawData)
|
||||
{
|
||||
string answ = "";
|
||||
Stopwatch sw = new Stopwatch();
|
||||
sw.Start();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
// preparo messaggio al topic
|
||||
Message newMessage = new Message()
|
||||
{
|
||||
Data = rawData.varData
|
||||
,
|
||||
Topic = rawData.topic
|
||||
};
|
||||
var currData = new BStatData();
|
||||
answ = await fbService.TopicSend(newMessage);
|
||||
sw.Stop();
|
||||
string logVal = $"Invio a topic {rawData.topic} | durata: {sw.Elapsed.TotalSeconds:N3} sec";
|
||||
_logger.LogWarning(logVal);
|
||||
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Funzione di rimoziione token da topic
|
||||
/// </summary>
|
||||
/// <param name="tokenList">elenco token da rimuovere</param>
|
||||
/// <param name="topic">topic da cui rimuovere</param>
|
||||
/// <returns></returns>
|
||||
private async Task<string> TopicUnsubTokens(List<string> tokenList, string topic)
|
||||
{
|
||||
string answ = "";
|
||||
Stopwatch sw = new Stopwatch();
|
||||
sw.Start();
|
||||
var currData = new BStatData();
|
||||
var resp = await fbService.TopicUnsub(tokenList, topic);
|
||||
answ = JsonConvert.SerializeObject(resp, Formatting.Indented);
|
||||
sw.Stop();
|
||||
string logVal = $"Rimozione da topic {topic} | num token: {tokenList.Count} | durata: {sw.Elapsed.TotalSeconds:N3} sec";
|
||||
_logger.LogWarning(logVal);
|
||||
|
||||
return answ;
|
||||
}
|
||||
|
||||
#endregion Private Methods
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<Version>1.0.2405.1715</Version>
|
||||
<Version>1.0.2405.1810</Version>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<UserSecretsId>352f62a7-3b7d-40cd-ab21-b55a5fefae44</UserSecretsId>
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
public string notifySound { get; set; } = "default";
|
||||
public int secTTL { get; set; } = 3600;
|
||||
public string title { get; set; } = "body";
|
||||
public string topic { get; set; } = "";
|
||||
public List<string> tokenList { get; set; } = new List<string>();
|
||||
public Dictionary<string, string> varData { get; set; } = new Dictionary<string, string>();
|
||||
|
||||
|
||||
@@ -51,16 +51,16 @@ namespace Eqn.Sender.Services
|
||||
BatchResponse answ = await fbMServ.SendEachForMulticastAsync(message, dryRun);
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Restituisce UserRecord dato num telefonico
|
||||
/// Restituisce NomeApp
|
||||
/// </summary>
|
||||
/// <param name="phoneNumber"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<UserRecord> GetUserByNumber(string phoneNumber)
|
||||
public string GetAppInfo()
|
||||
{
|
||||
UserRecord userRec = await fbAuth.GetUserByPhoneNumberAsync(phoneNumber);
|
||||
return userRec;
|
||||
return fbApp.Name;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Restituisce UserRecord dato email
|
||||
/// </summary>
|
||||
@@ -73,14 +73,38 @@ namespace Eqn.Sender.Services
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Restituisce NomeApp
|
||||
/// Restituisce UserRecord dato num telefonico
|
||||
/// </summary>
|
||||
/// <param name="phoneNumber"></param>
|
||||
/// <returns></returns>
|
||||
public string GetAppInfo()
|
||||
public async Task<UserRecord> GetUserByNumber(string phoneNumber)
|
||||
{
|
||||
return fbApp.Name;
|
||||
UserRecord userRec = await fbAuth.GetUserByPhoneNumberAsync(phoneNumber);
|
||||
return userRec;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Disiscrive dal topic un elenco di token destinatari
|
||||
/// </summary>
|
||||
/// <param name="tokenList">Elenco token interessati</param>
|
||||
/// <param name="topic">Topic da disiscrivere</param>
|
||||
/// <returns></returns>
|
||||
public async Task<TopicManagementResponse> TopicUnsub(List<string> tokenList, string topic)
|
||||
{
|
||||
TopicManagementResponse answ = await fbMServ.UnsubscribeFromTopicAsync(tokenList, topic);
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Invia una notifica ad un topic (e quindi ai device i cui token sono sottoscritti)
|
||||
/// </summary>
|
||||
/// <param name="message">Messaggio da inviare</param>
|
||||
/// <returns></returns>
|
||||
public async Task<string> TopicSend(Message message)
|
||||
{
|
||||
string answ = await fbMServ.SendAsync(message);
|
||||
return answ;
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
namespace Eqn.Sender
|
||||
{
|
||||
public class TopicPayload
|
||||
{
|
||||
#region Public Properties
|
||||
|
||||
public string topic { get; set; } = "";
|
||||
public List<string> tokenList { get; set; } = new List<string>();
|
||||
|
||||
#endregion Public Properties
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<body>
|
||||
<i>EqnSender - Gestione invio messaggi piattaforma EQN</i>
|
||||
<h4>Versione: 1.0.2405.1715</h4>
|
||||
<h4>Versione: 1.0.2405.1810</h4>
|
||||
<br /> Note di rilascio:
|
||||
<ul>
|
||||
<li>
|
||||
|
||||
@@ -1 +1 @@
|
||||
1.0.2405.1715
|
||||
1.0.2405.1810
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<item>
|
||||
<version>1.0.2405.1715</version>
|
||||
<version>1.0.2405.1810</version>
|
||||
<url>http://nexus.steamware.net/repository/SWS/EqnSender/stable/0/EqnSender.zip</url>
|
||||
<changelog>http://nexus.steamware.net/repository/SWS/EqnSender/stable/0/ChangeLog.html</changelog>
|
||||
<mandatory>false</mandatory>
|
||||
|
||||
Reference in New Issue
Block a user