diff --git a/Intento.MT.Plugin.PropertiesForm.Test/Intento.MT.Plugin.PropertiesForm.Test.csproj b/Intento.MT.Plugin.PropertiesForm.Test/Intento.MT.Plugin.PropertiesForm.Test.csproj index 9bfddc6..08e44c9 100644 --- a/Intento.MT.Plugin.PropertiesForm.Test/Intento.MT.Plugin.PropertiesForm.Test.csproj +++ b/Intento.MT.Plugin.PropertiesForm.Test/Intento.MT.Plugin.PropertiesForm.Test.csproj @@ -7,7 +7,7 @@ - + diff --git a/Intento.MT.Plugin.PropertiesForm/Intento.MT.Plugin.PropertiesForm.csproj b/Intento.MT.Plugin.PropertiesForm/Intento.MT.Plugin.PropertiesForm.csproj index d842380..a898465 100644 --- a/Intento.MT.Plugin.PropertiesForm/Intento.MT.Plugin.PropertiesForm.csproj +++ b/Intento.MT.Plugin.PropertiesForm/Intento.MT.Plugin.PropertiesForm.csproj @@ -39,8 +39,8 @@ intento_sn.snk - - ..\..\packages\IntentoSDK.1.5.3\lib\net45\IntentoSDK.dll + + ..\..\packages\IntentoSDK.1.5.4\lib\net45\IntentoSDK.dll ..\..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll diff --git a/Intento.MT.Plugin.PropertiesForm/Logs.cs b/Intento.MT.Plugin.PropertiesForm/Logs.cs index 0ca9a4e..697a46a 100644 --- a/Intento.MT.Plugin.PropertiesForm/Logs.cs +++ b/Intento.MT.Plugin.PropertiesForm/Logs.cs @@ -1,23 +1,44 @@ -using Intento.MT.Plugin.PropertiesForm; -using Newtonsoft.Json.Linq; +using Newtonsoft.Json.Linq; using System; +using System.Collections.Concurrent; using System.Collections.Generic; using System.IO; -using System.Linq; +using System.Net; using System.Net.Http; using System.Text; -using System.Threading.Tasks; +using System.Timers; namespace Intento.MT.Plugin.PropertiesForm { public static class Logs { + /// + /// Limiting the request rate, ms + /// + const int sleepTime = 5000; + /// + /// Limit of entries from the queue in one request + /// + const int maxEntries = 300; + static string _consumer_id; static string _session_id; public static string ApiKey { get; set; } public static string PluginName { get; set; } + /// + /// A stream instance that checks the data queue and sends it to the cloud + /// + static Timer sender; + + /// + /// Data queue + /// + static ConcurrentQueue> queue = new ConcurrentQueue>(); + + const string url = "https://api.inten.to/telemetry/upload_json"; + public static string ConsumerId { get @@ -119,7 +140,7 @@ public static IEnumerable LoggingEx(char identificator, Exception ex) return items; } - private static async void WriteRemoteLog(char identificator, string text) + private static void WriteRemoteLog(char identificator, string text) { if (!IsLogging()) return; @@ -130,22 +151,51 @@ private static async void WriteRemoteLog(char identificator, string text) if (string.IsNullOrWhiteSpace(ApiKey)) return; - dynamic jsonResult; - string url = "https://api.inten.to/telemetry/upload_json"; - JObject data = new JObject(); - data["plugin_name"] = string.Format("{0}-{1}", PluginName, identificator); - data["session_id"] = SessionId; - data["logs"] = text; - var content = new StringContent(data.ToString(), Encoding.UTF8, "application/json"); - // Call to Intento API - using (var conn = new HttpClient()) + queue.Enqueue(new KeyValuePair(identificator, text)); + if (sender == null) { - conn.DefaultRequestHeaders.Add("apikey", ApiKey); - conn.DefaultRequestHeaders.Add("x-consumer-id", ConsumerId); - jsonResult = await conn.PostAsync(url, content); + sender = new Timer(); + sender.Interval = sleepTime; + sender.Elapsed += OnTimedEvent; + sender.Start(); } } + private static async void OnTimedEvent(Object source, ElapsedEventArgs e) + { + try + { + Dictionary inprogress = new Dictionary(); + KeyValuePair item; + JObject data = new JObject(); + data["session_id"] = SessionId; + ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls; + dynamic jsonResult; + int entries = 0; + while (queue.TryDequeue(out item) && entries < maxEntries) + { + if (inprogress.ContainsKey(item.Key)) + inprogress[item.Key] += "\n" + item.Value; + else + inprogress.Add(item.Key, item.Value); + entries++; + } + foreach (KeyValuePair kp in inprogress) + { + data["plugin_name"] = string.Format("{0}-{1}", PluginName, kp.Key); + data["logs"] = kp.Value; + var content = new StringContent(data.ToString(), Encoding.UTF8, "application/json"); + // Call to Intento API + using (var conn = new HttpClient()) + { + conn.DefaultRequestHeaders.Add("apikey", ApiKey); + conn.DefaultRequestHeaders.Add("x-consumer-id", ConsumerId); + jsonResult = await conn.PostAsync(url, content); + } + } + } + catch { } + } } } \ No newline at end of file diff --git a/Intento.MT.Plugin.PropertiesForm/PluginHelper.cs b/Intento.MT.Plugin.PropertiesForm/PluginHelper.cs index 9a3c958..0cf34b4 100644 --- a/Intento.MT.Plugin.PropertiesForm/PluginHelper.cs +++ b/Intento.MT.Plugin.PropertiesForm/PluginHelper.cs @@ -8,92 +8,7 @@ namespace Intento.MT.Plugin.PropertiesForm { public static class PluginHelper { - private static IReadOnlyDictionary specialCodesIn - = new Dictionary - { - { "&gt;" , "" }, - { "&lt;" , "" }, - { "<" , "" }, - { ">" , "" } - }; - - private static IReadOnlyDictionary specialCodesOut - = new Dictionary - { - { "" , "&gt;" }, - { "" , "&lt;" }, - { "" , "<" }, - { "" , ">" }, - { "", "&gt;" }, - { "", "&lt;" }, - { "", "<" }, - { "", ">" }, - { "", "&gt;" }, - { "", "&lt;" }, - { "", "<" }, - { "", ">" }, - { "", "" }, - { "", "" }, - { "", "" }, - { "", "" } - }; - - public static string PrepareText(string format, string data) - { - // Remove parasite character for memoq - data = new string(data.Where(c => (int)c != 9727).ToArray()); - - // Replacing some HTML codes with special tags - foreach (KeyValuePair pair in specialCodesIn) - { - data = data.Replace(pair.Key, pair.Value); - } - if (format == "xml") - return string.Format("{0}", data); - return data; - } - - public static string PrepareResult(string format, string text) - { - // Return HTML codes instead of special tags - foreach (KeyValuePair pair in specialCodesOut) - { - text = text.Replace(pair.Key, pair.Value); - } - if (format == "xml") - { - // Remove tag - int n1 = text.IndexOf(""); - text2 = text.Substring(n2 + 1); - } - - // Remove and tags - string text3 = text2.Replace("", "").Replace("", ""); - return text3; - } - - if (format == "html") - { - // Remove and tags - int n1 = text.IndexOf(""); - text2 = text.Substring(n2 + 1); - } - - return text2; - } - - return text; - } - - public class ErrorInfo + public class ErrorInfo { public bool isError; public string visibleErrorText; diff --git a/Intento.MT.Plugin.PropertiesForm/Properties/Intento.MT.Plugin.PropertiesForm.nuspec b/Intento.MT.Plugin.PropertiesForm/Properties/Intento.MT.Plugin.PropertiesForm.nuspec index e5b623a..d9c2218 100644 --- a/Intento.MT.Plugin.PropertiesForm/Properties/Intento.MT.Plugin.PropertiesForm.nuspec +++ b/Intento.MT.Plugin.PropertiesForm/Properties/Intento.MT.Plugin.PropertiesForm.nuspec @@ -2,14 +2,14 @@ Intento.MT.Plugin.PropertiesForm - 2.2.23.0 + 2.2.24.0 Intento Intento false A library with a settings form used in Intento momoQ plugin and Intento Trados plugin. Copyright © Intento 2018-2021 - + diff --git a/Intento.MT.Plugin.PropertiesForm/WinForms/IntentoFormOptonsMain.Designer.cs b/Intento.MT.Plugin.PropertiesForm/WinForms/IntentoFormOptonsMain.Designer.cs index 16187c7..63503d5 100644 --- a/Intento.MT.Plugin.PropertiesForm/WinForms/IntentoFormOptonsMain.Designer.cs +++ b/Intento.MT.Plugin.PropertiesForm/WinForms/IntentoFormOptonsMain.Designer.cs @@ -87,7 +87,7 @@ private void InitializeComponent() this.textBoxLabel1.Name = "textBoxLabel1"; this.textBoxLabel1.Size = new System.Drawing.Size(118, 13); this.textBoxLabel1.TabIndex = 20; - this.textBoxLabel1.Tag = "https://console.inten.to"; + this.textBoxLabel1.Tag = "https://console.inten.to?utm_campaign=Localization&utm_source=appstore_trados"; this.textBoxLabel1.Text = "https://console.inten.to"; this.textBoxLabel1.Click += new System.EventHandler(this.linkLabel_LinkClicked); // diff --git a/Intento.MT.Plugin.PropertiesForm/packages.config b/Intento.MT.Plugin.PropertiesForm/packages.config index fc88c2e..d3baada 100644 --- a/Intento.MT.Plugin.PropertiesForm/packages.config +++ b/Intento.MT.Plugin.PropertiesForm/packages.config @@ -1,7 +1,5 @@ - - - - - - + + + + \ No newline at end of file diff --git a/TestForm/App.config b/TestForm/App.config index 4a35d1b..15708c5 100644 --- a/TestForm/App.config +++ b/TestForm/App.config @@ -7,7 +7,7 @@ - + diff --git a/TestForm/TestForm.csproj b/TestForm/TestForm.csproj index bb399f4..2111a93 100644 --- a/TestForm/TestForm.csproj +++ b/TestForm/TestForm.csproj @@ -32,12 +32,11 @@ 4 - - ..\bin\IntentoSDK.dll + + ..\..\packages\IntentoSDK.1.5.4\lib\net45\IntentoSDK.dll - - False - ..\bin\Newtonsoft.Json.dll + + ..\..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll @@ -97,7 +96,10 @@ - + + {a4374128-dd01-4ce3-b62c-4cc3460620c0} + Intento.MT.Plugin.PropertiesForm + \ No newline at end of file diff --git a/TestForm/packages.config b/TestForm/packages.config index 1b95914..8252071 100644 --- a/TestForm/packages.config +++ b/TestForm/packages.config @@ -1,5 +1,5 @@ - - - - + + + + \ No newline at end of file