Added back the plugin call home

This commit is contained in:
Brett Hewitson 2021-12-20 11:37:04 +10:00
parent decf281598
commit cc95409722
8 changed files with 44 additions and 144 deletions

View file

@ -25,7 +25,7 @@ namespace ServerManagerTool.Plugin.Discord {
[global::System.Configuration.ApplicationScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("http://servermanager.azurewebsites.net/api/plugin/call/{0}/{1}/")]
[global::System.Configuration.DefaultSettingValueAttribute("http://servermanagers.azurewebsites.net/api/plugin/call/{0}/{1}/")]
public string PluginCallUrlFormat {
get {
return ((string)(this["PluginCallUrlFormat"]));
@ -35,9 +35,9 @@ namespace ServerManagerTool.Plugin.Discord {
[global::System.Configuration.ApplicationScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("12")]
public int CallHomeDelay {
public int PluginCallUrlDelay {
get {
return ((int)(this["CallHomeDelay"]));
return ((int)(this["PluginCallUrlDelay"]));
}
}

View file

@ -3,9 +3,9 @@
<Profiles />
<Settings>
<Setting Name="PluginCallUrlFormat" Type="System.String" Scope="Application">
<Value Profile="(Default)">http://servermanager.azurewebsites.net/api/plugin/call/{0}/{1}/</Value>
<Value Profile="(Default)">http://servermanagers.azurewebsites.net/api/plugin/call/{0}/{1}/</Value>
</Setting>
<Setting Name="CallHomeDelay" Type="System.Int32" Scope="Application">
<Setting Name="PluginCallUrlDelay" Type="System.Int32" Scope="Application">
<Value Profile="(Default)">12</Value>
</Setting>
<Setting Name="RequestTimeout" Type="System.Int32" Scope="Application">

View file

@ -89,18 +89,10 @@ namespace ServerManagerTool.Plugin.Discord
{
var publicIP = await NetworkUtils.DiscoverPublicIPAsync();
await NetworkUtils.PerformCallToAPIAsync(PluginCode, publicIP);
#if DEBUG
var logFile = Path.Combine(PluginHelper.PluginFolder, "DiscordApiCalls.log");
File.AppendAllLines(logFile, new[] { "CallHomeAsync successful" }, Encoding.Unicode);
#endif
}
catch (Exception ex)
{
Debug.WriteLine($"Failed calling home {ex.Message}");
#if DEBUG
var logFile = Path.Combine(PluginHelper.PluginFolder, "DiscordErrors.log");
File.AppendAllLines(logFile, new[] { $"Failed calling home {ex.Message}" }, Encoding.Unicode);
#endif
Debug.WriteLine($"Failed calling home to API.\r\n{ex.Message}");
}
}
@ -117,10 +109,6 @@ namespace ServerManagerTool.Plugin.Discord
&& !string.IsNullOrWhiteSpace(cp.DiscordWebhookUrl));
if (configProfiles == null || configProfiles.IsEmpty())
{
#if DEBUG
var logFile = Path.Combine(PluginHelper.PluginFolder, "DiscordErrors.log");
File.AppendAllLines(logFile, new[] { $"{alertType}; {profileName} - {alertMessage.Replace(Environment.NewLine, " ")} (No config profiles found)" }, Encoding.Unicode);
#endif
return;
}
@ -192,27 +180,15 @@ namespace ServerManagerTool.Plugin.Discord
if (httpResponse.StatusCode == HttpStatusCode.OK)
{
Debug.WriteLine($"{nameof(HandleAlert)}\r\nResponse: {responseString}");
#if DEBUG
var logFile = Path.Combine(PluginHelper.PluginFolder, "DiscordSuccess.log");
File.AppendAllLines(logFile, new[] { $"{alertType}; {profileName} - {alertMessage.Replace(Environment.NewLine, " ")} ({responseString})" }, Encoding.Unicode);
#endif
}
else
{
Debug.WriteLine($"{nameof(HandleAlert)}\r\n{httpResponse.StatusCode}: {responseString}");
#if DEBUG
var logFile = Path.Combine(PluginHelper.PluginFolder, "DiscordErrors.log");
File.AppendAllLines(logFile, new[] { $"{alertType}; {profileName} - {alertMessage.Replace(Environment.NewLine, " ")} ({responseString})" }, Encoding.Unicode);
#endif
}
}
catch (Exception ex)
{
Debug.WriteLine($"ERROR: {nameof(HandleAlert)}\r\n{ex.Message}");
#if DEBUG
var logFile = Path.Combine(PluginHelper.PluginFolder, "DiscordExceptions.log");
File.AppendAllLines(logFile, new[] { $"{alertType}; {profileName} - {alertMessage.Replace(Environment.NewLine, " ")} ({ex.Message})" }, Encoding.Unicode);
#endif
}
}
@ -220,11 +196,11 @@ namespace ServerManagerTool.Plugin.Discord
{
LoadConfig();
if (PluginConfig.LastCallHome.AddHours(Config.Default.CallHomeDelay) < DateTime.Now)
if (PluginConfig.PluginCallUrlLast.AddHours(Config.Default.PluginCallUrlDelay) < DateTime.Now)
{
//CallHomeAsync().DoNotWait();
CallHomeAsync().DoNotWait();
PluginConfig.LastCallHome = DateTime.Now;
PluginConfig.PluginCallUrlLast = DateTime.Now;
SaveConfig();
}
}

View file

@ -9,12 +9,12 @@ namespace ServerManagerTool.Plugin.Discord
public DiscordPluginConfig()
: base()
{
LastCallHome = DateTime.MinValue;
PluginCallUrlLast = DateTime.MinValue;
ConfigProfiles = new ObservableList<ConfigProfile>();
}
[DataMember]
public DateTime LastCallHome
public DateTime PluginCallUrlLast
{
get;
set;

View file

@ -90,7 +90,7 @@ namespace ServerManagerTool.Plugin.Discord
}
catch (Exception ex)
{
Debug.WriteLine($"ERROR: {nameof(PerformCallToAPIAsync)} - {pluginCode}; {ipAddress}\r\n{ex.Message}");
Debug.WriteLine($"{nameof(PerformCallToAPIAsync)} - Failed calling API.\r\n{ex.Message}");
}
}
}

View file

@ -5,7 +5,30 @@
<title>Discord Plugin Version Feed</title>
<subtitle>This is the Discord Plugin release version feed.</subtitle>
<link href="" />
<updated>2021-12-12T00:00:00Z</updated>
<updated>2021-12-20T00:00:00Z</updated>
<entry>
<id>urn:uuid:F8987FDF-7A69-4E03-99D8-E04ADFFFF0BB</id>
<title>1.0.20 (1.0.20.1)</title>
<summary>1.0.20.1</summary>
<link href="" />
<updated>2021-12-20T00:00:00Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml" style="font-family: Arial, Verdana, Helvetica, Sans-Serif;font-size: .8em;">
<p>
<u style="font-size: .9em;">CHANGE</u>
<br/>
<ul>
<li>Additional changes to config loading to prevent blanking the config file.</li>
</ul>
</p>
</div>
</content>
<author>
<name>bletch</name>
<email>bletch1971@hotmail.com</email>
</author>
</entry>
<entry>
<id>urn:uuid:A9EC2F32-E026-485F-BD7B-C657DBA95B54</id>

View file

@ -5,120 +5,21 @@
<title>Discord Plugin Version Feed</title>
<subtitle>This is the Discord Plugin beta version feed.</subtitle>
<link href="" />
<updated>2021-12-12T00:00:00Z</updated>
<updated>2021-12-20T00:00:00Z</updated>
<entry>
<id>urn:uuid:A0D7BFD2-F2F0-481A-A22D-3C193BFB4C99</id>
<title>1.0.19 (1.0.19.5)</title>
<summary>1.0.19.5</summary>
<id>urn:uuid:F8987FDF-7A69-4E03-99D8-E04ADFFFF0BB</id>
<title>1.0.20 (1.0.20.1)</title>
<summary>1.0.20.1</summary>
<link href="" />
<updated>2021-12-12T00:00:00Z</updated>
<updated>2021-12-20T00:00:00Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml" style="font-family: Arial, Verdana, Helvetica, Sans-Serif;font-size: .8em;">
<p>
<u style="font-size: .9em;">CHANGE</u>
<br/>
<ul>
<li>ru-RU Translation file updated.</li>
</ul>
</p>
</div>
</content>
<author>
<name>bletch</name>
<email>bletch1971@hotmail.com</email>
</author>
</entry>
<entry>
<id>urn:uuid:38A61493-CA4E-479E-A3FD-266565E83D90</id>
<title>1.0.19 (1.0.19.4)</title>
<summary>1.0.19.4</summary>
<link href="" />
<updated>2021-12-12T00:00:00Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml" style="font-family: Arial, Verdana, Helvetica, Sans-Serif;font-size: .8em;">
<p>
<u style="font-size: .9em;">CHANGE</u>
<br/>
<ul>
<li>ru-RU Translation file added.</li>
</ul>
</p>
</div>
</content>
<author>
<name>bletch</name>
<email>bletch1971@hotmail.com</email>
</author>
</entry>
<entry>
<id>urn:uuid:DDB25735-1D20-4580-B5FE-1AD4BD107376</id>
<title>1.0.19 (1.0.19.3)</title>
<summary>1.0.19.3</summary>
<link href="" />
<updated>2021-12-12T00:00:00Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml" style="font-family: Arial, Verdana, Helvetica, Sans-Serif;font-size: .8em;">
<p>
<u style="font-size: .9em;">CHANGE</u>
<br/>
<ul>
<li>fr-FR Translation file added.</li>
<li>pt-BR Translation file updated.</li>
</ul>
</p>
</div>
</content>
<author>
<name>bletch</name>
<email>bletch1971@hotmail.com</email>
</author>
</entry>
<entry>
<id>urn:uuid:FD4F56C3-9E44-4422-A761-87E7F957454F</id>
<title>1.0.19 (1.0.19.2)</title>
<summary>1.0.19.2</summary>
<link href="" />
<updated>2021-12-09T00:00:00Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml" style="font-family: Arial, Verdana, Helvetica, Sans-Serif;font-size: .8em;">
<p>
<u style="font-size: .9em;">CHANGE</u>
<br/>
<ul>
<li>Changed the plugin initialization so it throws an exception if unable to load config file, rather than creating a new config file.</li>
</ul>
</p>
</div>
</content>
<author>
<name>bletch</name>
<email>bletch1971@hotmail.com</email>
</author>
</entry>
<entry>
<id>urn:uuid:A9EC2F32-E026-485F-BD7B-C657DBA95B54</id>
<title>1.0.19 (1.0.19.1)</title>
<summary>1.0.19.1</summary>
<link href="" />
<updated>2021-12-09T00:00:00Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml" style="font-family: Arial, Verdana, Helvetica, Sans-Serif;font-size: .8em;">
<p>
<u style="font-size: .9em;">BUGFIX</u>
<br/>
<ul>
<li>Fixed alert test message to support globalization.</li>
</ul>
<u style="font-size: .9em;">CHANGE</u>
<br/>
<ul>
<li>de-DE Translation file updated.</li>
<li>pt-BR Translation file updated.</li>
<li>Additional changes to config loading to prevent blanking the config file.</li>
</ul>
</p>
</div>

View file

@ -8,9 +8,9 @@
<applicationSettings>
<ServerManagerTool.Plugin.Discord.Config>
<setting name="PluginCallUrlFormat" serializeAs="String">
<value>http://servermanager.azurewebsites.net/api/plugin/call/{0}/{1}/</value>
<value>http://servermanagers.azurewebsites.net/api/plugin/call/{0}/{1}/</value>
</setting>
<setting name="CallHomeDelay" serializeAs="String">
<setting name="PluginCallUrlDelay" serializeAs="String">
<value>12</value>
</setting>
<setting name="RequestTimeout" serializeAs="String">