Skip to content

Commit

Permalink
Merge pull request #31 from intento/release/2.2.24
Browse files Browse the repository at this point in the history
CONTMS-117 Telemetry: 5XX on large project in Trados
CONTMS-120 Trados: fix bug with < > in Deepl
CONTMS-119 Add utm labels to the console link in the Trados app

Co-authored-by: Vladimir Abramov <mr.vovan@gmail.com>
  • Loading branch information
oerodger and vlabramov authored Apr 29, 2021
2 parents 061c8a4 + 0d4c138 commit 78243d6
Show file tree
Hide file tree
Showing 10 changed files with 91 additions and 126 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="IntentoSDK" Version="1.5.3" />
<PackageReference Include="IntentoSDK" Version="1.5.4" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="NUnit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.16.1" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
<AssemblyOriginatorKeyFile>intento_sn.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="IntentoSDK, Version=1.5.3.0, Culture=neutral, PublicKeyToken=7fbf26cf2c5f5508, processorArchitecture=MSIL">
<HintPath>..\..\packages\IntentoSDK.1.5.3\lib\net45\IntentoSDK.dll</HintPath>
<Reference Include="IntentoSDK, Version=1.5.4.0, Culture=neutral, PublicKeyToken=7fbf26cf2c5f5508, processorArchitecture=MSIL">
<HintPath>..\..\packages\IntentoSDK.1.5.4\lib\net45\IntentoSDK.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
Expand Down
84 changes: 67 additions & 17 deletions Intento.MT.Plugin.PropertiesForm/Logs.cs
Original file line number Diff line number Diff line change
@@ -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
{
/// <summary>
/// Limiting the request rate, ms
/// </summary>
const int sleepTime = 5000;
/// <summary>
/// Limit of entries from the queue in one request
/// </summary>
const int maxEntries = 300;

static string _consumer_id;
static string _session_id;
public static string ApiKey { get; set; }
public static string PluginName { get; set; }

/// <summary>
/// A stream instance that checks the data queue and sends it to the cloud
/// </summary>
static Timer sender;

/// <summary>
/// Data queue
/// </summary>
static ConcurrentQueue<KeyValuePair<char, string>> queue = new ConcurrentQueue<KeyValuePair<char, string>>();

const string url = "https://api.inten.to/telemetry/upload_json";

public static string ConsumerId
{
get
Expand Down Expand Up @@ -119,7 +140,7 @@ public static IEnumerable<string> 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;
Expand All @@ -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<char, string>(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<char, string> inprogress = new Dictionary<char, string>();
KeyValuePair<char, string> 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<char, string> 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 { }
}
}

}
87 changes: 1 addition & 86 deletions Intento.MT.Plugin.PropertiesForm/PluginHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,92 +8,7 @@ namespace Intento.MT.Plugin.PropertiesForm
{
public static class PluginHelper
{
private static IReadOnlyDictionary<string, string> specialCodesIn
= new Dictionary<string, string>
{
{ "&amp;gt;" , "<tph1/>" },
{ "&amp;lt;" , "<tph2/>" },
{ "&lt;" , "<tph3/>" },
{ "&gt;" , "<tph4/>" }
};

private static IReadOnlyDictionary<string, string> specialCodesOut
= new Dictionary<string, string>
{
{ "<tph1>" , "&amp;gt;" },
{ "<tph2>" , "&amp;lt;" },
{ "<tph3>" , "&lt;" },
{ "<tph4>" , "&gt;" },
{ "<tph1/>", "&amp;gt;" },
{ "<tph2/>", "&amp;lt;" },
{ "<tph3/>", "&lt;" },
{ "<tph4/>", "&gt;" },
{ "<tph1 />", "&amp;gt;" },
{ "<tph2 />", "&amp;lt;" },
{ "<tph3 />", "&lt;" },
{ "<tph4 />", "&gt;" },
{ "</tph1>", "" },
{ "</tph2>", "" },
{ "</tph3>", "" },
{ "</tph4>", "" }
};

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<string, string> pair in specialCodesIn)
{
data = data.Replace(pair.Key, pair.Value);
}
if (format == "xml")
return string.Format("<root>{0}</root>", data);
return data;
}

public static string PrepareResult(string format, string text)
{
// Return HTML codes instead of special tags
foreach (KeyValuePair<string, string> pair in specialCodesOut)
{
text = text.Replace(pair.Key, pair.Value);
}
if (format == "xml")
{
// Remove <? > tag
int n1 = text.IndexOf("<?");
string text2 = text;
if (n1 != -1)
{
int n2 = text.IndexOf(">");
text2 = text.Substring(n2 + 1);
}

// Remove <root> and </root> tags
string text3 = text2.Replace("<root>", "").Replace("</root>", "");
return text3;
}

if (format == "html")
{
// Remove <meta> and </meta> tags
int n1 = text.IndexOf("<meta");
string text2 = text;
if (n1 != -1)
{
int n2 = text.IndexOf(">");
text2 = text.Substring(n2 + 1);
}

return text2;
}

return text;
}

public class ErrorInfo
public class ErrorInfo
{
public bool isError;
public string visibleErrorText;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
<package>
<metadata>
<id>Intento.MT.Plugin.PropertiesForm</id>
<version>2.2.23.0</version>
<version>2.2.24.0</version>
<authors>Intento</authors>
<owners>Intento</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>A library with a settings form used in Intento momoQ plugin and Intento Trados plugin.</description>
<copyright>Copyright © Intento 2018-2021</copyright>
<dependencies>
<dependency id="IntentoSDK" version="1.5.3.0" />
<dependency id="IntentoSDK" version="1.5.4.0" />
</dependencies>
</metadata>
<files>
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 4 additions & 6 deletions Intento.MT.Plugin.PropertiesForm/packages.config
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="AWSSDK.Core" version="3.3.107.14" targetFramework="net45" />
<package id="AWSSDK.S3" version="3.3.111.14" targetFramework="net45" />
<package id="IntentoSDK" version="1.5.3" targetFramework="net45" />
<package id="Newtonsoft.Json" version="13.0.1" targetFramework="net45" />
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="IntentoSDK" version="1.5.4" targetFramework="net45" />
<package id="Newtonsoft.Json" version="13.0.1" targetFramework="net45" />
</packages>
2 changes: 1 addition & 1 deletion TestForm/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
<bindingRedirect oldVersion="0.0.0.0-4.5.0.0" newVersion="4.5.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
Expand Down
14 changes: 8 additions & 6 deletions TestForm/TestForm.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,11 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="IntentoSDK">
<HintPath>..\bin\IntentoSDK.dll</HintPath>
<Reference Include="IntentoSDK, Version=1.5.4.0, Culture=neutral, PublicKeyToken=7fbf26cf2c5f5508, processorArchitecture=MSIL">
<HintPath>..\..\packages\IntentoSDK.1.5.4\lib\net45\IntentoSDK.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\bin\Newtonsoft.Json.dll</HintPath>
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand Down Expand Up @@ -97,7 +96,10 @@
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<Analyzer Include="..\..\Plugins\packages\AWSSDK.S3.3.5.0-beta\analyzers\dotnet\cs\AWSSDK.S3.CodeAnalysis.dll" />
<ProjectReference Include="..\Intento.MT.Plugin.PropertiesForm\Intento.MT.Plugin.PropertiesForm.csproj">
<Project>{a4374128-dd01-4ce3-b62c-4cc3460620c0}</Project>
<Name>Intento.MT.Plugin.PropertiesForm</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
8 changes: 4 additions & 4 deletions TestForm/packages.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="AWSSDK.Core" version="3.5.0-beta" targetFramework="net47" />
<package id="AWSSDK.S3" version="3.5.0-beta" targetFramework="net47" />
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="IntentoSDK" version="1.5.4" targetFramework="net47" />
<package id="Newtonsoft.Json" version="13.0.1" targetFramework="net47" />
</packages>

0 comments on commit 78243d6

Please sign in to comment.