Skip to content

Commit

Permalink
v2022.3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
LAB02 Research committed Mar 1, 2022
1 parent 020ee57 commit d917584
Show file tree
Hide file tree
Showing 11 changed files with 410 additions and 112 deletions.
52 changes: 47 additions & 5 deletions src/HASS.Agent/HASSAgent/Controls/Configuration/MQTT.Designer.cs

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

1 change: 1 addition & 0 deletions src/HASS.Agent/HASSAgent/Controls/Configuration/MQTT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ private void BtnMqttClearConfig_Click(object sender, EventArgs e)
TbMqttUsername.Text = string.Empty;
TbMqttPassword.Text = string.Empty;
TbMqttDiscoveryPrefix.Text = "homeassistant";
TbMqttClientId.Text = string.Empty;
TbMqttRootCertificate.Text = string.Empty;
TbMqttClientCertificate.Text = string.Empty;
CbAllowUntrustedCertificates.CheckState = CheckState.Checked;
Expand Down
2 changes: 2 additions & 0 deletions src/HASS.Agent/HASSAgent/Forms/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ private void LoadSettings()
_mqtt.TbMqttUsername.Text = Variables.AppSettings.MqttUsername;
_mqtt.TbMqttPassword.Text = Variables.AppSettings.MqttPassword;
_mqtt.TbMqttDiscoveryPrefix.Text = Variables.AppSettings.MqttDiscoveryPrefix;
_mqtt.TbMqttClientId.Text = Variables.AppSettings.MqttClientId;
_mqtt.TbMqttRootCertificate.Text = Variables.AppSettings.MqttRootCertificate;
_mqtt.TbMqttClientCertificate.Text = Variables.AppSettings.MqttClientCertificate;
_mqtt.CbAllowUntrustedCertificates.CheckState = Variables.AppSettings.MqttAllowUntrustedCertificates ? CheckState.Checked : CheckState.Unchecked;
Expand Down Expand Up @@ -324,6 +325,7 @@ private void StoreSettings()
Variables.AppSettings.MqttUsername = _mqtt.TbMqttUsername.Text;
Variables.AppSettings.MqttPassword = _mqtt.TbMqttPassword.Text;
Variables.AppSettings.MqttDiscoveryPrefix = _mqtt.TbMqttDiscoveryPrefix.Text;
Variables.AppSettings.MqttClientId = _mqtt.TbMqttClientId.Text;
Variables.AppSettings.MqttRootCertificate = _mqtt.TbMqttRootCertificate.Text;
Variables.AppSettings.MqttClientCertificate = _mqtt.TbMqttClientCertificate.Text;
Variables.AppSettings.MqttAllowUntrustedCertificates = _mqtt.CbAllowUntrustedCertificates.CheckState == CheckState.Checked;
Expand Down
66 changes: 5 additions & 61 deletions src/HASS.Agent/HASSAgent/Functions/HelperFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Sockets;
using System.Reflection;
using System.Runtime.ExceptionServices;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
Expand All @@ -25,6 +29,7 @@
using HASSAgent.Mqtt;
using HASSAgent.Notifications;
using HASSAgent.Sensors;
using MQTTnet.Exceptions;
using Serilog;
using Syncfusion.Windows.Forms;
using Task = System.Threading.Tasks.Task;
Expand Down Expand Up @@ -95,67 +100,6 @@ internal static void SetMsgBoxStyle(Font font)
MessageBoxAdv.MessageFont = font;
}

/// <summary>
/// Initializes Serilog logger, optionally with exception logging through Coderr
/// </summary>
internal static void PrepareLogging()
{
if (Variables.ExceptionLogging)
{
PrepareCoderrEnabledLogging();
return;
}

// prepare a serilog logger without coderr
Log.Logger = new LoggerConfiguration()
.WriteTo.Async(a =>
a.File(Path.Combine(Variables.LogPath, $"[{DateTime.Now:yyyy-MM-dd}] {Variables.ApplicationName}_.log"),
rollingInterval: RollingInterval.Day,
fileSizeLimitBytes: 10000000,
retainedFileCountLimit: 10,
rollOnFileSizeLimit: true,
buffered: true,
flushToDiskInterval: TimeSpan.FromMilliseconds(150)))
.CreateLogger();

Log.Information("[LOG] Coderr exception reporting disabled");
}

/// <summary>
/// Prepare Serilog logger and bind Coderr reporting
/// </summary>
private static void PrepareCoderrEnabledLogging()
{
// initialize coderr
Err.Configuration.ThrowExceptions = false;

var url = new Uri("https://report.coderr.io/");
Err.Configuration.Credentials(url,
"b8f26633ad354e91ab570f840080816a",
"87163340045849d993879be4407d952b");

Err.Configuration.CatchWinFormsExceptions();

Err.Configuration.UserInteraction.AskUserForDetails = false;
Err.Configuration.UserInteraction.AskUserForPermission = false;
Err.Configuration.UserInteraction.AskForEmailAddress = false;

// prepare a serilog logger including coderr
Log.Logger = new LoggerConfiguration()
.WriteTo.Coderr()
.WriteTo.Async(a =>
a.File(Path.Combine(Variables.LogPath, $"[{DateTime.Now:yyyy-MM-dd}] {Variables.ApplicationName}_.log"),
rollingInterval: RollingInterval.Day,
fileSizeLimitBytes: 10000000,
retainedFileCountLimit: 10,
rollOnFileSizeLimit: true,
buffered: true,
flushToDiskInterval: TimeSpan.FromMilliseconds(150)))
.CreateLogger();

Log.Information("[LOG] Coderr exception reporting enabled");
}

/// <summary>
/// Restarts HASS.Agent through a temporary bat file
/// </summary>
Expand Down
Loading

0 comments on commit d917584

Please sign in to comment.