Adding user given name to EAR events and enabling User Events.
1.1 --- a/Server/Actions/ActionCecUserControlPressed.cs Tue Aug 30 11:04:40 2016 +0200
1.2 +++ b/Server/Actions/ActionCecUserControlPressed.cs Tue Aug 30 16:50:37 2016 +0200
1.3 @@ -46,7 +46,7 @@
1.4 /// <returns></returns>
1.5 public override string Brief()
1.6 {
1.7 - string brief = Name + ": " + Code.ToString() + " to " + DeviceName;
1.8 + string brief = AttributeName + ": " + Code.ToString() + " to " + DeviceName;
1.9 if (Wait)
1.10 {
1.11 brief += " (wait)";
2.1 --- a/Server/Actions/ActionCecUserControlReleased.cs Tue Aug 30 11:04:40 2016 +0200
2.2 +++ b/Server/Actions/ActionCecUserControlReleased.cs Tue Aug 30 16:50:37 2016 +0200
2.3 @@ -38,7 +38,7 @@
2.4 /// <returns></returns>
2.5 public override string Brief()
2.6 {
2.7 - string brief = Name + " to " + DeviceName;
2.8 + string brief = AttributeName + " to " + DeviceName;
2.9 if (Wait)
2.10 {
2.11 brief += " (wait)";
3.1 --- a/Server/Actions/ActionDisplayMessage.cs Tue Aug 30 11:04:40 2016 +0200
3.2 +++ b/Server/Actions/ActionDisplayMessage.cs Tue Aug 30 16:50:37 2016 +0200
3.3 @@ -52,7 +52,7 @@
3.4 /// <returns></returns>
3.5 public override string Brief()
3.6 {
3.7 - string brief = Name + ": " + PrimaryText;
3.8 + string brief = AttributeName + ": " + PrimaryText;
3.9 if (!string.IsNullOrEmpty(SecondaryText))
3.10 {
3.11 brief += " - " + SecondaryText;
4.1 --- a/Server/ConsumerElectronicControl.cs Tue Aug 30 11:04:40 2016 +0200
4.2 +++ b/Server/ConsumerElectronicControl.cs Tue Aug 30 16:50:37 2016 +0200
4.3 @@ -82,14 +82,14 @@
4.4 {
4.5 MonitorPowerOn = true;
4.6 //Trigger corresponding event thus executing associated actions
4.7 - Properties.Settings.Default.EarManager.TriggerEvent<EventMonitorPowerOn>();
4.8 + Properties.Settings.Default.EarManager.TriggerEvents<EventMonitorPowerOn>();
4.9 }
4.10
4.11 private void OnMonitorPowerOff()
4.12 {
4.13 MonitorPowerOn = false;
4.14 //Trigger corresponding event thus executing associated actions
4.15 - Properties.Settings.Default.EarManager.TriggerEvent<EventMonitorPowerOff>();
4.16 + Properties.Settings.Default.EarManager.TriggerEvents<EventMonitorPowerOff>();
4.17 }
4.18
4.19 /// <summary>
5.1 --- a/Server/Events/EventHid.cs Tue Aug 30 11:04:40 2016 +0200
5.2 +++ b/Server/Events/EventHid.cs Tue Aug 30 16:50:37 2016 +0200
5.3 @@ -83,7 +83,7 @@
5.4 /// <returns></returns>
5.5 public override string Brief()
5.6 {
5.7 - string brief = Name + ": ";
5.8 + string brief = AttributeName + ": ";
5.9
5.10 if (!IsValid())
5.11 {
6.1 --- a/Server/FormEditObject.Designer.cs Tue Aug 30 11:04:40 2016 +0200
6.2 +++ b/Server/FormEditObject.Designer.cs Tue Aug 30 16:50:37 2016 +0200
6.3 @@ -52,7 +52,9 @@
6.4 this.iComboBoxObjectType.Sorted = true;
6.5 this.iComboBoxObjectType.TabIndex = 18;
6.6 this.iComboBoxObjectType.SelectedIndexChanged += new System.EventHandler(this.comboBoxActionType_SelectedIndexChanged);
6.7 + this.iComboBoxObjectType.Enter += new System.EventHandler(this.iComboBoxObjectType_Enter);
6.8 this.iComboBoxObjectType.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.iComboBoxObjectType_KeyPress);
6.9 + this.iComboBoxObjectType.Leave += new System.EventHandler(this.iComboBoxObjectType_Leave);
6.10 //
6.11 // labelActionType
6.12 //
6.13 @@ -63,12 +65,12 @@
6.14 this.labelActionType.TabIndex = 20;
6.15 this.labelActionType.Text = "Type :";
6.16 //
6.17 - // buttonOk
6.18 + // iButtonOk
6.19 //
6.20 this.iButtonOk.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
6.21 this.iButtonOk.DialogResult = System.Windows.Forms.DialogResult.OK;
6.22 this.iButtonOk.Location = new System.Drawing.Point(12, 157);
6.23 - this.iButtonOk.Name = "buttonOk";
6.24 + this.iButtonOk.Name = "iButtonOk";
6.25 this.iButtonOk.Size = new System.Drawing.Size(75, 23);
6.26 this.iButtonOk.TabIndex = 21;
6.27 this.iButtonOk.Text = "Ok";
6.28 @@ -104,11 +106,11 @@
6.29 this.iTableLayoutPanel.Size = new System.Drawing.Size(312, 46);
6.30 this.iTableLayoutPanel.TabIndex = 23;
6.31 //
6.32 - // buttonTest
6.33 + // iButtonTest
6.34 //
6.35 this.iButtonTest.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
6.36 this.iButtonTest.Location = new System.Drawing.Point(252, 157);
6.37 - this.iButtonTest.Name = "buttonTest";
6.38 + this.iButtonTest.Name = "iButtonTest";
6.39 this.iButtonTest.Size = new System.Drawing.Size(75, 23);
6.40 this.iButtonTest.TabIndex = 24;
6.41 this.iButtonTest.Text = "Test";
6.42 @@ -160,7 +162,7 @@
6.43 this.MaximizeBox = false;
6.44 this.MinimizeBox = false;
6.45 this.Name = "FormEditObject";
6.46 - this.Text = "Edit action";
6.47 + this.Text = "Edit object";
6.48 this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.FormEditObject_FormClosing);
6.49 this.Load += new System.EventHandler(this.FormEditAction_Load);
6.50 this.ResumeLayout(false);
7.1 --- a/Server/FormEditObject.cs Tue Aug 30 11:04:40 2016 +0200
7.2 +++ b/Server/FormEditObject.cs Tue Aug 30 16:50:37 2016 +0200
7.3 @@ -107,11 +107,18 @@
7.4 private void comboBoxActionType_SelectedIndexChanged(object sender, EventArgs e)
7.5 {
7.6 //Instantiate an action corresponding to our type
7.7 - Type actionType = ((ItemObjectType) iComboBoxObjectType.SelectedItem).Type;
7.8 + Type objectType = ((ItemObjectType) iComboBoxObjectType.SelectedItem).Type;
7.9 //Create another type of action only if needed
7.10 - if (Object == null || Object.GetType() != actionType)
7.11 + if (Object == null || Object.GetType() != objectType)
7.12 {
7.13 - Object = (T)Activator.CreateInstance(actionType);
7.14 + if (Object != null)
7.15 + {
7.16 + // Make sure we exit edit mode and unhook from events
7.17 + Object.CurrentState = SharpLib.Ear.Object.State.Rest;
7.18 + Object.PropertyChanged -= PropertyChangedEventHandlerThreadSafe;
7.19 + Object = null;
7.20 + }
7.21 + Object = (T)Activator.CreateInstance(objectType);
7.22 }
7.23
7.24 //Create input fields
7.25 @@ -553,7 +560,7 @@
7.26 iLabelBrief.Text = Object.Brief();
7.27
7.28 // Update object description
7.29 - iLabelDescription.Text = Object.Description;
7.30 + iLabelDescription.Text = Object.AttributeDescription;
7.31 }
7.32
7.33 /// <summary>
7.34 @@ -570,5 +577,25 @@
7.35 e.Handled = true;
7.36 }
7.37 }
7.38 +
7.39 + private void iComboBoxObjectType_Enter(object sender, EventArgs e)
7.40 + {
7.41 + //Only edit HID event when our type combo box has the focus
7.42 + // TODO: That's an ugly workaround, fix that somehow. Maybe by only doing HID scan when a button property has the focus
7.43 + if (Object is EventHid)
7.44 + {
7.45 + Object.CurrentState = SharpLib.Ear.Object.State.Edit;
7.46 + }
7.47 + }
7.48 +
7.49 + private void iComboBoxObjectType_Leave(object sender, EventArgs e)
7.50 + {
7.51 + //Only edit HID event when our type combo box has the focus
7.52 + // TODO: That's an ugly workaround, fix that somehow. Maybe by only doing HID scan when a button property has the focus
7.53 + if (Object is EventHid)
7.54 + {
7.55 + Object.CurrentState = SharpLib.Ear.Object.State.Rest;
7.56 + }
7.57 + }
7.58 }
7.59 }
8.1 --- a/Server/FormMain.Hid.cs Tue Aug 30 11:04:40 2016 +0200
8.2 +++ b/Server/FormMain.Hid.cs Tue Aug 30 16:50:37 2016 +0200
8.3 @@ -119,7 +119,7 @@
8.4 //Trigger corresponding EAR event if any
8.5 EventHid e = new EventHid();
8.6 e.Copy(aHidEvent);
8.7 - Properties.Settings.Default.EarManager.TriggerEvent(e);
8.8 + Properties.Settings.Default.EarManager.TriggerEvents(e);
8.9 }
8.10 }
8.11
9.1 --- a/Server/FormMain.cs Tue Aug 30 11:04:40 2016 +0200
9.2 +++ b/Server/FormMain.cs Tue Aug 30 16:50:37 2016 +0200
9.3 @@ -233,7 +233,7 @@
9.4 ResetHarmonyAsync();
9.5
9.6 //Setup Events
9.7 - PopulateEventsTreeView();
9.8 + PopulateTreeViewEvents();
9.9
9.10 //Setup notification icon
9.11 SetupTrayIcon();
9.12 @@ -312,7 +312,7 @@
9.13 /// <summary>
9.14 /// Populate tree view with events and actions
9.15 /// </summary>
9.16 - private void PopulateEventsTreeView()
9.17 + private void PopulateTreeViewEvents()
9.18 {
9.19 //Disable action buttons
9.20 buttonActionAdd.Enabled = false;
9.21 @@ -328,7 +328,20 @@
9.22 foreach (Ear.Event e in Properties.Settings.Default.EarManager.Events)
9.23 {
9.24 //Create our event node
9.25 - TreeNode eventNode = iTreeViewEvents.Nodes.Add(e.Brief());
9.26 + //Work out the name of our node
9.27 + string eventNodeName = "";
9.28 + if (!string.IsNullOrEmpty(e.Name))
9.29 + {
9.30 + //That event has a proper name, use it then
9.31 + eventNodeName = $"{e.Name} - {e.Brief()}";
9.32 + }
9.33 + else
9.34 + {
9.35 + //Unnamed events just use brief
9.36 + eventNodeName = e.Brief();
9.37 + }
9.38 +
9.39 + TreeNode eventNode = iTreeViewEvents.Nodes.Add(eventNodeName);
9.40 eventNode.Tag = e; //For easy access to our event
9.41 if (!e.Enabled)
9.42 {
9.43 @@ -337,7 +350,7 @@
9.44 }
9.45
9.46 //Add event description as child node
9.47 - eventNode.Nodes.Add(e.Description).ForeColor = eventNode.ForeColor;
9.48 + eventNode.Nodes.Add(e.AttributeDescription).ForeColor = eventNode.ForeColor;
9.49 //Create child node for actions root
9.50 TreeNode actionsNodes = eventNode.Nodes.Add("Actions");
9.51 actionsNodes.ForeColor = eventNode.ForeColor;
9.52 @@ -2717,7 +2730,7 @@
9.53 {
9.54 selectedEvent.Actions.Add(ea.Object);
9.55 Properties.Settings.Default.Save();
9.56 - PopulateEventsTreeView();
9.57 + PopulateTreeViewEvents();
9.58 }
9.59 }
9.60
9.61 @@ -2747,7 +2760,7 @@
9.62 selectedEvent.Actions[actionIndex]=ea.Object;
9.63 //Save and rebuild our event tree view
9.64 Properties.Settings.Default.Save();
9.65 - PopulateEventsTreeView();
9.66 + PopulateTreeViewEvents();
9.67 }
9.68 }
9.69
9.70 @@ -2768,7 +2781,7 @@
9.71
9.72 Properties.Settings.Default.EarManager.RemoveAction(action);
9.73 Properties.Settings.Default.Save();
9.74 - PopulateEventsTreeView();
9.75 + PopulateTreeViewEvents();
9.76 }
9.77
9.78 /// <summary>
9.79 @@ -2811,7 +2824,7 @@
9.80
9.81 //Save and populate our tree again
9.82 Properties.Settings.Default.Save();
9.83 - PopulateEventsTreeView();
9.84 + PopulateTreeViewEvents();
9.85
9.86 }
9.87
9.88 @@ -2840,7 +2853,7 @@
9.89
9.90 //Save and populate our tree again
9.91 Properties.Settings.Default.Save();
9.92 - PopulateEventsTreeView();
9.93 + PopulateTreeViewEvents();
9.94 }
9.95
9.96
9.97 @@ -2915,7 +2928,7 @@
9.98 {
9.99 Properties.Settings.Default.EarManager.Events.Add(ea.Object);
9.100 Properties.Settings.Default.Save();
9.101 - PopulateEventsTreeView();
9.102 + PopulateTreeViewEvents();
9.103 SelectEvent(ea.Object);
9.104 }
9.105 }
9.106 @@ -2936,7 +2949,7 @@
9.107
9.108 Properties.Settings.Default.EarManager.Events.Remove(currentEvent);
9.109 Properties.Settings.Default.Save();
9.110 - PopulateEventsTreeView();
9.111 + PopulateTreeViewEvents();
9.112 }
9.113
9.114 /// <summary>
9.115 @@ -2966,7 +2979,7 @@
9.116 Properties.Settings.Default.EarManager.Events[index] = ea.Object;
9.117 //Save and rebuild our event tree view
9.118 Properties.Settings.Default.Save();
9.119 - PopulateEventsTreeView();
9.120 + PopulateTreeViewEvents();
9.121 }
9.122 }
9.123
9.124 @@ -3043,7 +3056,7 @@
9.125 Program.HarmonyConfig = await Program.HarmonyClient.GetConfigAsync();
9.126 PopulateTreeViewHarmony(Program.HarmonyConfig);
9.127 //Make sure harmony command actions are showing device name instead of device id
9.128 - PopulateEventsTreeView();
9.129 + PopulateTreeViewEvents();
9.130 }
9.131
9.132 /// <summary>
10.1 --- a/SharpLibEar/ActionLaunchApp.cs Tue Aug 30 11:04:40 2016 +0200
10.2 +++ b/SharpLibEar/ActionLaunchApp.cs Tue Aug 30 16:50:37 2016 +0200
10.3 @@ -46,7 +46,7 @@
10.4
10.5 public override string Brief()
10.6 {
10.7 - return Name + ": " + Path.GetFileName(File.FullPath);
10.8 + return AttributeName + ": " + Path.GetFileName(File.FullPath);
10.9 }
10.10
10.11 public override bool IsValid()
11.1 --- a/SharpLibEar/ActionOpticalDriveEject.cs Tue Aug 30 11:04:40 2016 +0200
11.2 +++ b/SharpLibEar/ActionOpticalDriveEject.cs Tue Aug 30 16:50:37 2016 +0200
11.3 @@ -38,7 +38,7 @@
11.4
11.5 public override string Brief()
11.6 {
11.7 - return Name + " " + Drive.CurrentItem ;
11.8 + return AttributeName + " " + Drive.CurrentItem ;
11.9 }
11.10
11.11 public override bool IsValid()
12.1 --- a/SharpLibEar/ActionSleep.cs Tue Aug 30 11:04:40 2016 +0200
12.2 +++ b/SharpLibEar/ActionSleep.cs Tue Aug 30 16:50:37 2016 +0200
12.3 @@ -39,7 +39,7 @@
12.4
12.5 public override string Brief()
12.6 {
12.7 - return Name + " for " + TimeoutInMilliseconds + " ms";
12.8 + return AttributeName + " for " + TimeoutInMilliseconds + " ms";
12.9 }
12.10
12.11
13.1 --- a/SharpLibEar/Event.cs Tue Aug 30 11:04:40 2016 +0200
13.2 +++ b/SharpLibEar/Event.cs Tue Aug 30 16:50:37 2016 +0200
13.3 @@ -10,7 +10,8 @@
13.4 namespace SharpLib.Ear
13.5 {
13.6 [DataContract]
13.7 - public abstract class Event : Object
13.8 + [AttributeObject(Id = "Event", Name = "User Event", Description = "An event that can be triggered by users.")]
13.9 + public class Event : Object
13.10 {
13.11 [DataMember]
13.12 [AttributeObjectProperty
13.13 @@ -23,6 +24,16 @@
13.14 public bool Enabled { get; set; } = true;
13.15
13.16 [DataMember]
13.17 + [AttributeObjectProperty
13.18 + (
13.19 + Id = "Event.Name",
13.20 + Name = "Name",
13.21 + Description = "Given event name. Can be used to trigger it."
13.22 + )
13.23 + ]
13.24 + public string Name { get; set; } = "";
13.25 +
13.26 + [DataMember]
13.27 public List<Action> Actions = new List<Action>();
13.28
13.29
13.30 @@ -42,16 +53,16 @@
13.31 /// <summary>
13.32 /// Allows testing from generic edit dialog.
13.33 /// </summary>
13.34 - public void Test()
13.35 + public async void Test()
13.36 {
13.37 Trace.WriteLine("Event test");
13.38 - Trigger();
13.39 + await Trigger();
13.40 }
13.41
13.42
13.43 public async Task Trigger()
13.44 {
13.45 - Trace.WriteLine("Event triggered: " + Name);
13.46 + Trace.WriteLine("Event triggered: " + AttributeName);
13.47 foreach (Action action in Actions)
13.48 {
13.49 await action.Execute();
14.1 --- a/SharpLibEar/Manager.cs Tue Aug 30 11:04:40 2016 +0200
14.2 +++ b/SharpLibEar/Manager.cs Tue Aug 30 16:50:37 2016 +0200
14.3 @@ -48,12 +48,12 @@
14.4 /// Trigger the given event.
14.5 /// </summary>
14.6 /// <param name="aEventType"></param>
14.7 - public void TriggerEvent<T>() where T: class
14.8 + public async void TriggerEvents<T>() where T: class
14.9 {
14.10 //Only trigger enabled events matching the desired type
14.11 foreach (Event e in Events.Where(e => e.GetType() == typeof(T) && e.Enabled))
14.12 {
14.13 - e.Trigger();
14.14 + await e.Trigger();
14.15 }
14.16 }
14.17
14.18 @@ -61,15 +61,36 @@
14.19 /// Trigger the given event.
14.20 /// </summary>
14.21 /// <param name="aEventType"></param>
14.22 - public void TriggerEvent<T>(T aEvent) where T : class
14.23 + public async void TriggerEvents<T>(T aEvent) where T : class
14.24 {
14.25 //Only trigger events matching the desired type
14.26 foreach (Event e in Events.Where(e => e.Equals(aEvent) && e.Enabled))
14.27 {
14.28 - e.Trigger();
14.29 + await e.Trigger();
14.30 }
14.31 }
14.32
14.33 + /// <summary>
14.34 + ///
14.35 + /// </summary>
14.36 + /// <typeparam name="T"></typeparam>
14.37 + /// <param name="aEvent"></param>
14.38 + public async void TriggerEventsByName(string aName)
14.39 + {
14.40 + if (string.IsNullOrEmpty(aName))
14.41 + {
14.42 + //Just don't do that that would be silly
14.43 + return;
14.44 + }
14.45 + //Only trigger events matching the desired type
14.46 + foreach (Event e in Events.Where(e => e.Name.Equals(aName)))
14.47 + {
14.48 + await e.Trigger();
14.49 + }
14.50 + }
14.51 +
14.52 +
14.53 +
14.54
14.55 /// <summary>
14.56 /// Remove the specified action from the event it belongs too.
15.1 --- a/SharpLibEar/Object.cs Tue Aug 30 11:04:40 2016 +0200
15.2 +++ b/SharpLibEar/Object.cs Tue Aug 30 16:50:37 2016 +0200
15.3 @@ -73,7 +73,7 @@
15.4 /// <summary>
15.5 /// Static object name.
15.6 /// </summary>
15.7 - public string Name
15.8 + public string AttributeName
15.9 {
15.10 //Get the name of this object attribute
15.11 get { return Utils.Reflection.GetAttribute<AttributeObject>(GetType()).Name; }
15.12 @@ -83,7 +83,7 @@
15.13 /// <summary>
15.14 /// Static object description.
15.15 /// </summary>
15.16 - public string Description
15.17 + public string AttributeDescription
15.18 {
15.19 //Get the description of this object attribute
15.20 get { return Utils.Reflection.GetAttribute<AttributeObject>(GetType()).Description; }
15.21 @@ -96,7 +96,7 @@
15.22 /// <returns></returns>
15.23 public virtual string Brief()
15.24 {
15.25 - return Name;
15.26 + return AttributeName;
15.27 }
15.28
15.29 /// <summary>
16.1 --- a/SharpLibUtils/Reflection.cs Tue Aug 30 11:04:40 2016 +0200
16.2 +++ b/SharpLibUtils/Reflection.cs Tue Aug 30 16:50:37 2016 +0200
16.3 @@ -12,6 +12,7 @@
16.4 {
16.5 /// <summary>
16.6 /// Get a list of all the concrete types derived from the given type in all loaded assembly.
16.7 + /// That includes the given type itself if it's intanciable.
16.8 /// </summary>
16.9 /// <typeparam name="T"></typeparam>
16.10 /// <returns></returns>
16.11 @@ -21,8 +22,8 @@
16.12
16.13 foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies())
16.14 {
16.15 - foreach (Type type in asm.GetTypes()
16.16 - .Where(myType => myType.IsClass && !myType.IsAbstract && myType.IsSubclassOf(typeof(T))))
16.17 + foreach (Type type in asm.GetTypes()
16.18 + .Where(myType => myType.IsClass && !myType.IsAbstract && (myType.IsSubclassOf(typeof(T)) || myType == typeof(T))))
16.19 {
16.20 objects.Add(type);
16.21 }