# HG changeset patch
# User StephaneLenclud
# Date 1469204389 -7200
# Node ID fef4ca058087bf83177cd9980eb20768eb079ab4
# Parent 6cd9ffdd638641b0a0894c08dd1527c80ec1552c
Prototype for event and action framework.
diff -r 6cd9ffdd6386 -r fef4ca058087 Server/MainForm.cs
--- a/Server/MainForm.cs Fri Jul 22 13:47:44 2016 +0200
+++ b/Server/MainForm.cs Fri Jul 22 18:19:49 2016 +0200
@@ -46,6 +46,7 @@
using SharpDisplay;
using MiniDisplayInterop;
using SharpLib.Display;
+using Slions.Ear;
namespace SharpDisplayManager
{
@@ -69,6 +70,7 @@
[System.ComponentModel.DesignerCategory("Form")]
public partial class MainForm : MainFormHid, IMMNotificationClient
{
+ private Manager iManager = new Manager();
DateTime LastTickTime;
Display iDisplay;
System.Drawing.Bitmap iBmp;
diff -r 6cd9ffdd6386 -r fef4ca058087 Server/SharpDisplayManager.csproj
--- a/Server/SharpDisplayManager.csproj Fri Jul 22 13:47:44 2016 +0200
+++ b/Server/SharpDisplayManager.csproj Fri Jul 22 18:19:49 2016 +0200
@@ -188,6 +188,14 @@
+
+
+
+
+
+
+
+
@@ -300,6 +308,7 @@
+
diff -r 6cd9ffdd6386 -r fef4ca058087 Server/Slions/Ear/Action.cs
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Server/Slions/Ear/Action.cs Fri Jul 22 18:19:49 2016 +0200
@@ -0,0 +1,16 @@
+//
+
+
+using System.Runtime.Serialization;
+using System.Threading;
+
+namespace Slions.Ear
+{
+ [DataContract]
+ abstract class Action
+ {
+ public abstract void Execute();
+ }
+
+
+}
\ No newline at end of file
diff -r 6cd9ffdd6386 -r fef4ca058087 Server/Slions/Ear/ActionCallback.cs
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Server/Slions/Ear/ActionCallback.cs Fri Jul 22 18:19:49 2016 +0200
@@ -0,0 +1,29 @@
+//
+
+using System.Runtime.Serialization;
+
+
+namespace Slions.Ear
+{
+ [DataContract]
+ abstract class ActionCallback : Action
+ {
+ public delegate void Delegate();
+
+ private readonly Delegate iCallback;
+
+ public ActionCallback(Delegate aCallback = null)
+ {
+ iCallback = aCallback;
+ }
+
+ public override void Execute()
+ {
+ if (iCallback != null)
+ {
+ iCallback.Invoke();
+ }
+ }
+ }
+
+}
\ No newline at end of file
diff -r 6cd9ffdd6386 -r fef4ca058087 Server/Slions/Ear/ActionSleep.cs
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Server/Slions/Ear/ActionSleep.cs Fri Jul 22 18:19:49 2016 +0200
@@ -0,0 +1,38 @@
+//
+
+
+using System.Runtime.Serialization;
+using System.Threading;
+
+namespace Slions.Ear
+{
+
+
+ [DataContract]
+ class ActionSleep : Action
+ {
+ static readonly string Name = "Sleep";
+ static readonly string Description = "Have the current thread sleep for the specified amount of milliseconds.";
+
+ private readonly int iMillisecondsTimeout;
+
+ public ActionSleep()
+ {
+ iMillisecondsTimeout = 1000;
+ }
+
+
+ public ActionSleep(int aMillisecondsTimeout)
+ {
+ iMillisecondsTimeout = aMillisecondsTimeout;
+ }
+
+ public override void Execute()
+ {
+ Thread.Sleep(iMillisecondsTimeout);
+ }
+ }
+
+
+
+}
\ No newline at end of file
diff -r 6cd9ffdd6386 -r fef4ca058087 Server/Slions/Ear/ActionType.cs
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Server/Slions/Ear/ActionType.cs Fri Jul 22 18:19:49 2016 +0200
@@ -0,0 +1,19 @@
+//
+
+
+using System.Runtime.Serialization;
+using System.Threading;
+
+namespace Slions.Ear
+{
+ [DataContract]
+ abstract class ActionType
+ {
+ [DataMember]
+ public string Name { get; protected set; }
+ [DataMember]
+ public string Description { get; protected set; }
+ }
+
+
+}
\ No newline at end of file
diff -r 6cd9ffdd6386 -r fef4ca058087 Server/Slions/Ear/Event.cs
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Server/Slions/Ear/Event.cs Fri Jul 22 18:19:49 2016 +0200
@@ -0,0 +1,42 @@
+//
+
+
+using System;
+using System.Collections.Generic;
+using System.Runtime.Serialization;
+
+namespace Slions.Ear
+{
+ [DataContract]
+ abstract class MEvent
+ {
+ [DataMember]
+ public string Name { get; protected set; }
+
+ [DataMember]
+ public string Description { get; protected set; }
+
+ public abstract void Trigger();
+ };
+
+ [DataContract]
+ abstract class Event : MEvent
+ {
+ List iActions;
+
+ protected Event()
+ {
+ iActions = new List();
+ }
+
+ public override void Trigger()
+ {
+ Console.WriteLine("Event '" + Name + "' triggered.");
+ foreach (Action action in iActions)
+ {
+ action.Execute();
+ }
+ }
+ }
+
+}
\ No newline at end of file
diff -r 6cd9ffdd6386 -r fef4ca058087 Server/Slions/Ear/EventMonitorPowerOff.cs
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Server/Slions/Ear/EventMonitorPowerOff.cs Fri Jul 22 18:19:49 2016 +0200
@@ -0,0 +1,18 @@
+//
+
+
+using System.Runtime.Serialization;
+
+namespace Slions.Ear
+{
+ [DataContract]
+ class EventMonitorPowerOff : Event
+ {
+ public EventMonitorPowerOff()
+ {
+ Name = "Monitor Power Off";
+ Description = "";
+ }
+ }
+
+}
\ No newline at end of file
diff -r 6cd9ffdd6386 -r fef4ca058087 Server/Slions/Ear/EventMonitorPowerOn.cs
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Server/Slions/Ear/EventMonitorPowerOn.cs Fri Jul 22 18:19:49 2016 +0200
@@ -0,0 +1,19 @@
+//
+
+
+using System.Runtime.Serialization;
+
+namespace Slions.Ear
+{
+ [DataContract]
+ class EventMonitorPowerOn : Event
+ {
+ public EventMonitorPowerOn()
+ {
+ Name = "Monitor Power On";
+ Description = "";
+ }
+
+ }
+
+}
\ No newline at end of file
diff -r 6cd9ffdd6386 -r fef4ca058087 Server/Slions/Ear/Manager.cs
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Server/Slions/Ear/Manager.cs Fri Jul 22 18:19:49 2016 +0200
@@ -0,0 +1,49 @@
+//
+
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using System.Runtime.Serialization;
+
+namespace Slions.Ear
+{
+ public static class ReflectiveEnumerator
+ {
+ static ReflectiveEnumerator() { }
+
+ public static IEnumerable GetEnumerableOfType() where T : class
+ {
+ List objects = new List();
+ foreach (Type type in
+ Assembly.GetAssembly(typeof(T)).GetTypes()
+ .Where(myType => myType.IsClass && !myType.IsAbstract && myType.IsSubclassOf(typeof(T))))
+ {
+ objects.Add((T)Activator.CreateInstance(type));
+ }
+ //objects.Sort();
+ return objects;
+ }
+ }
+
+
+ [DataContract]
+ class Manager
+ {
+ private IEnumerable Actions;
+ private IEnumerable Events;
+
+ public Manager()
+ {
+ Actions = ReflectiveEnumerator.GetEnumerableOfType();
+ Events = ReflectiveEnumerator.GetEnumerableOfType();
+
+ //CollectActions();
+ //CollectEvents();
+ }
+
+
+
+ }
+}
\ No newline at end of file