# HG changeset patch
# User StephaneLenclud
# Date 1472652407 -7200
# Node ID c4749a27966d75f3c0ecebaccdbf64c4b07a1720
# Parent e2729a990e8bf543363ed7f99be8899cc4476c6e
Fix crash when trying to select Harmony command without configuration.
Consolidate Named event Trigger.
diff -r e2729a990e8b -r c4749a27966d Server/Actions/ActionHarmonyCommand.cs
--- a/Server/Actions/ActionHarmonyCommand.cs Tue Aug 30 21:14:18 2016 +0200
+++ b/Server/Actions/ActionHarmonyCommand.cs Wed Aug 31 16:06:47 2016 +0200
@@ -8,6 +8,7 @@
using System.Threading.Tasks;
using System.Runtime.Serialization;
using System.Windows.Forms;
+using CodeProject.Dialog;
namespace SharpDisplayManager
{
@@ -120,6 +121,12 @@
///
void ClickEventHandler(object sender, EventArgs e)
{
+ if (Program.HarmonyConfig == null)
+ {
+ ErrBox.Show("No Harmony Hub configuration!");
+ return;
+ }
+
FormSelectHarmonyCommand dlg = new FormSelectHarmonyCommand();
DialogResult res = CodeProject.Dialog.DlgBox.ShowDialog(dlg);
if (res == DialogResult.OK)
diff -r e2729a990e8b -r c4749a27966d Server/FormSelectHarmonyCommand.cs
--- a/Server/FormSelectHarmonyCommand.cs Tue Aug 30 21:14:18 2016 +0200
+++ b/Server/FormSelectHarmonyCommand.cs Wed Aug 31 16:06:47 2016 +0200
@@ -8,6 +8,7 @@
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
+using CodeProject.Dialog;
namespace SharpDisplayManager
{
@@ -28,7 +29,15 @@
///
private void FormSelectHarmonyCommand_Load(object sender, EventArgs e)
{
- PopulateTreeViewHarmony(Program.HarmonyConfig);
+ if (Program.HarmonyConfig != null)
+ {
+ PopulateTreeViewHarmony(Program.HarmonyConfig);
+ }
+ else
+ {
+ ErrBox.Show("No Harmony Hub configuration!");
+ Close();
+ }
}
///
diff -r e2729a990e8b -r c4749a27966d SharpLibEar/Event.cs
--- a/SharpLibEar/Event.cs Tue Aug 30 21:14:18 2016 +0200
+++ b/SharpLibEar/Event.cs Wed Aug 31 16:06:47 2016 +0200
@@ -23,6 +23,10 @@
]
public bool Enabled { get; set; } = true;
+
+ ///
+ /// TODO: Should the name property be moved to our EAR Object?
+ ///
[DataMember]
[AttributeObjectProperty
(
@@ -33,6 +37,7 @@
]
public string Name { get; set; } = "";
+
[DataMember]
public List Actions = new List();
@@ -41,6 +46,12 @@
{
base.DoConstruct();
+ //Make sure our name is not null
+ if (Name == null)
+ {
+ Name = "";
+ }
+
// TODO: Construct properties too
foreach (Action a in Actions)
{
diff -r e2729a990e8b -r c4749a27966d SharpLibEar/Manager.cs
--- a/SharpLibEar/Manager.cs Tue Aug 30 21:14:18 2016 +0200
+++ b/SharpLibEar/Manager.cs Wed Aug 31 16:06:47 2016 +0200
@@ -79,11 +79,13 @@
{
if (string.IsNullOrEmpty(aName))
{
- //Just don't do that that would be silly
+ //Just don't do that, that would be silly
return;
}
- //Only trigger events matching the desired type
- foreach (Event e in Events.Where(e => e.Name.Equals(aName)))
+ // Only trigger events matching the desired type
+ // Doing some safety checks as well to prevent crashing if name was left null for some reason
+ // This was the case when loading existing settings after event Name was introduced
+ foreach (Event e in Events.Where(e => !string.IsNullOrEmpty(e.Name) && aName.Equals(e.Name)))
{
await e.Trigger();
}