# HG changeset patch # User StephaneLenclud # Date 1469282404 -7200 # Node ID 83dd86e7344875b8509f76862ed48290014ba4e7 # Parent fef4ca058087bf83177cd9980eb20768eb079ab4 Most basic event action manager. diff -r fef4ca058087 -r 83dd86e73448 Server/ConsumerElectronicControl.cs --- a/Server/ConsumerElectronicControl.cs Fri Jul 22 18:19:49 2016 +0200 +++ b/Server/ConsumerElectronicControl.cs Sat Jul 23 16:00:04 2016 +0200 @@ -6,6 +6,7 @@ using System.Diagnostics; using System.Windows.Forms; using CecSharp; +using SharpLib.Ear; namespace SharpDisplayManager { @@ -92,12 +93,14 @@ private void OnMonitorPowerOn() { + EventActionManager.Current.GetEvent().Trigger(); + Console.WriteLine("OnMonitorPowerOn"); if (iReconnectToPowerTv) { ConnectCecClient(); - } + } //Turn on the TV //iCecClient.Lib.PowerOnDevices(CecLogicalAddress.Tv); @@ -109,6 +112,8 @@ private void OnMonitorPowerOff() { + EventActionManager.Current.GetEvent().Trigger(); + Console.WriteLine("OnMonitorPowerOff"); if (iReconnectToPowerTv) diff -r fef4ca058087 -r 83dd86e73448 Server/MainForm.cs --- a/Server/MainForm.cs Fri Jul 22 18:19:49 2016 +0200 +++ b/Server/MainForm.cs Sat Jul 23 16:00:04 2016 +0200 @@ -46,7 +46,7 @@ using SharpDisplay; using MiniDisplayInterop; using SharpLib.Display; -using Slions.Ear; +using SharpLib.Ear; namespace SharpDisplayManager { @@ -70,7 +70,7 @@ [System.ComponentModel.DesignerCategory("Form")] public partial class MainForm : MainFormHid, IMMNotificationClient { - private Manager iManager = new Manager(); + public EventActionManager iManager = new EventActionManager(); DateTime LastTickTime; Display iDisplay; System.Drawing.Bitmap iBmp; @@ -131,7 +131,8 @@ public MainForm() { - iSkipFrameRendering = false; + EventActionManager.Current = iManager; + iSkipFrameRendering = false; iClosing = false; iCurrentClientSessionId = ""; iCurrentClientData = null; diff -r fef4ca058087 -r 83dd86e73448 Server/SharpDisplayManager.csproj --- a/Server/SharpDisplayManager.csproj Fri Jul 22 18:19:49 2016 +0200 +++ b/Server/SharpDisplayManager.csproj Sat Jul 23 16:00:04 2016 +0200 @@ -188,14 +188,6 @@ - - - - - - - - @@ -248,6 +240,14 @@ {c174f23d-3055-49bc-b6b0-563011af624d} PowerManager + + {84a9ed37-e6ea-4cbd-b995-b713f46eaab0} + SharpLibEar + + + {ae897704-461d-4018-8336-2517988bf7ad} + SharpLibUtils + diff -r fef4ca058087 -r 83dd86e73448 Server/Slions/Ear/Action.cs --- a/Server/Slions/Ear/Action.cs Fri Jul 22 18:19:49 2016 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,16 +0,0 @@ -// - - -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 fef4ca058087 -r 83dd86e73448 Server/Slions/Ear/ActionCallback.cs --- a/Server/Slions/Ear/ActionCallback.cs Fri Jul 22 18:19:49 2016 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,29 +0,0 @@ -// - -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 fef4ca058087 -r 83dd86e73448 Server/Slions/Ear/ActionSleep.cs --- a/Server/Slions/Ear/ActionSleep.cs Fri Jul 22 18:19:49 2016 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,38 +0,0 @@ -// - - -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 fef4ca058087 -r 83dd86e73448 Server/Slions/Ear/ActionType.cs --- a/Server/Slions/Ear/ActionType.cs Fri Jul 22 18:19:49 2016 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,19 +0,0 @@ -// - - -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 fef4ca058087 -r 83dd86e73448 Server/Slions/Ear/Event.cs --- a/Server/Slions/Ear/Event.cs Fri Jul 22 18:19:49 2016 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,42 +0,0 @@ -// - - -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 fef4ca058087 -r 83dd86e73448 Server/Slions/Ear/EventMonitorPowerOff.cs --- a/Server/Slions/Ear/EventMonitorPowerOff.cs Fri Jul 22 18:19:49 2016 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,18 +0,0 @@ -// - - -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 fef4ca058087 -r 83dd86e73448 Server/Slions/Ear/EventMonitorPowerOn.cs --- a/Server/Slions/Ear/EventMonitorPowerOn.cs Fri Jul 22 18:19:49 2016 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,19 +0,0 @@ -// - - -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 fef4ca058087 -r 83dd86e73448 Server/Slions/Ear/Manager.cs --- a/Server/Slions/Ear/Manager.cs Fri Jul 22 18:19:49 2016 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,49 +0,0 @@ -// - - -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 diff -r fef4ca058087 -r 83dd86e73448 SharpDisplayManager.sln --- a/SharpDisplayManager.sln Fri Jul 22 18:19:49 2016 +0200 +++ b/SharpDisplayManager.sln Sat Jul 23 16:00:04 2016 +0200 @@ -13,6 +13,10 @@ EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharpDisplayClientTest", "Clients\Test\SharpDisplayClientTest.csproj", "{7EE64074-8CDB-4448-B40C-81B75D6B31CD}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharpLibUtils", "SharpLibUtils\SharpLibUtils.csproj", "{AE897704-461D-4018-8336-2517988BF7AD}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharpLibEar", "SharpLibEar\SharpLibEar.csproj", "{84A9ED37-E6EA-4CBD-B995-B713F46EAAB0}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -75,6 +79,30 @@ {7EE64074-8CDB-4448-B40C-81B75D6B31CD}.Release|x64.Build.0 = Release|Any CPU {7EE64074-8CDB-4448-B40C-81B75D6B31CD}.Release|x86.ActiveCfg = Release|x86 {7EE64074-8CDB-4448-B40C-81B75D6B31CD}.Release|x86.Build.0 = Release|x86 + {AE897704-461D-4018-8336-2517988BF7AD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {AE897704-461D-4018-8336-2517988BF7AD}.Debug|Any CPU.Build.0 = Debug|Any CPU + {AE897704-461D-4018-8336-2517988BF7AD}.Debug|x64.ActiveCfg = Debug|Any CPU + {AE897704-461D-4018-8336-2517988BF7AD}.Debug|x64.Build.0 = Debug|Any CPU + {AE897704-461D-4018-8336-2517988BF7AD}.Debug|x86.ActiveCfg = Debug|Any CPU + {AE897704-461D-4018-8336-2517988BF7AD}.Debug|x86.Build.0 = Debug|Any CPU + {AE897704-461D-4018-8336-2517988BF7AD}.Release|Any CPU.ActiveCfg = Release|Any CPU + {AE897704-461D-4018-8336-2517988BF7AD}.Release|Any CPU.Build.0 = Release|Any CPU + {AE897704-461D-4018-8336-2517988BF7AD}.Release|x64.ActiveCfg = Release|Any CPU + {AE897704-461D-4018-8336-2517988BF7AD}.Release|x64.Build.0 = Release|Any CPU + {AE897704-461D-4018-8336-2517988BF7AD}.Release|x86.ActiveCfg = Release|Any CPU + {AE897704-461D-4018-8336-2517988BF7AD}.Release|x86.Build.0 = Release|Any CPU + {84A9ED37-E6EA-4CBD-B995-B713F46EAAB0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {84A9ED37-E6EA-4CBD-B995-B713F46EAAB0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {84A9ED37-E6EA-4CBD-B995-B713F46EAAB0}.Debug|x64.ActiveCfg = Debug|Any CPU + {84A9ED37-E6EA-4CBD-B995-B713F46EAAB0}.Debug|x64.Build.0 = Debug|Any CPU + {84A9ED37-E6EA-4CBD-B995-B713F46EAAB0}.Debug|x86.ActiveCfg = Debug|Any CPU + {84A9ED37-E6EA-4CBD-B995-B713F46EAAB0}.Debug|x86.Build.0 = Debug|Any CPU + {84A9ED37-E6EA-4CBD-B995-B713F46EAAB0}.Release|Any CPU.ActiveCfg = Release|Any CPU + {84A9ED37-E6EA-4CBD-B995-B713F46EAAB0}.Release|Any CPU.Build.0 = Release|Any CPU + {84A9ED37-E6EA-4CBD-B995-B713F46EAAB0}.Release|x64.ActiveCfg = Release|Any CPU + {84A9ED37-E6EA-4CBD-B995-B713F46EAAB0}.Release|x64.Build.0 = Release|Any CPU + {84A9ED37-E6EA-4CBD-B995-B713F46EAAB0}.Release|x86.ActiveCfg = Release|Any CPU + {84A9ED37-E6EA-4CBD-B995-B713F46EAAB0}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff -r fef4ca058087 -r 83dd86e73448 SharpLibEar/Action.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SharpLibEar/Action.cs Sat Jul 23 16:00:04 2016 +0200 @@ -0,0 +1,23 @@ +// + + +using System; +using System.Runtime.Serialization; +using System.Threading; + +namespace SharpLib.Ear +{ + [DataContract] + public abstract class Action: IComparable + { + public abstract void Execute(); + + public int CompareTo(object obj) + { + //Sort by action name + return Utils.Reflection.GetAttribute(GetType()).Name.CompareTo(obj.GetType()); + } + } + + +} \ No newline at end of file diff -r fef4ca058087 -r 83dd86e73448 SharpLibEar/ActionCallback.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SharpLibEar/ActionCallback.cs Sat Jul 23 16:00:04 2016 +0200 @@ -0,0 +1,29 @@ +// + +using System.Runtime.Serialization; + + +namespace SharpLib.Ear +{ + [DataContract] + public 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 fef4ca058087 -r 83dd86e73448 SharpLibEar/ActionSleep.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SharpLibEar/ActionSleep.cs Sat Jul 23 16:00:04 2016 +0200 @@ -0,0 +1,38 @@ +// + + +using System.Runtime.Serialization; +using System.Threading; + + +namespace SharpLib.Ear +{ + + + [DataContract] + [AttributeAction(Id = "Thread.Sleep", Name = "Sleep", Description = "Have the current thread sleep for the specified amount of milliseconds.")] + public class ActionSleep : Action + { + 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 fef4ca058087 -r 83dd86e73448 SharpLibEar/ActionType.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SharpLibEar/ActionType.cs Sat Jul 23 16:00:04 2016 +0200 @@ -0,0 +1,19 @@ +// + + +using System.Runtime.Serialization; +using System.Threading; + +namespace SharpLib.Ear +{ + [DataContract] + public 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 fef4ca058087 -r 83dd86e73448 SharpLibEar/AttributeAction.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SharpLibEar/AttributeAction.cs Sat Jul 23 16:00:04 2016 +0200 @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SharpLib.Ear +{ + + // Multiuse attribute. + [System.AttributeUsage(System.AttributeTargets.Class)] + public class AttributeAction : System.Attribute + { + public string Id; + public string Name; + public string Description; + } + +} diff -r fef4ca058087 -r 83dd86e73448 SharpLibEar/Event.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SharpLibEar/Event.cs Sat Jul 23 16:00:04 2016 +0200 @@ -0,0 +1,42 @@ +// + + +using System; +using System.Collections.Generic; +using System.Runtime.Serialization; + +namespace SharpLib.Ear +{ + [DataContract] + public abstract class MEvent + { + [DataMember] + public string Name { get; protected set; } + + [DataMember] + public string Description { get; protected set; } + + public abstract void Trigger(); + }; + + [DataContract] + public abstract class Event : MEvent + { + public List Actions; + + protected Event() + { + Actions = new List(); + } + + public override void Trigger() + { + Console.WriteLine("Event '" + Name + "' triggered."); + foreach (Action action in Actions) + { + action.Execute(); + } + } + } + +} \ No newline at end of file diff -r fef4ca058087 -r 83dd86e73448 SharpLibEar/EventActionManager.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SharpLibEar/EventActionManager.cs Sat Jul 23 16:00:04 2016 +0200 @@ -0,0 +1,31 @@ +// + + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Runtime.Serialization; + +namespace SharpLib.Ear +{ + [DataContract] + public class EventActionManager + { + public static EventActionManager Current = null; + public IDictionary ActionTypes; + private IDictionary Events; + + public EventActionManager() + { + ActionTypes = Utils.Reflection.GetConcreteClassesDerivedFromByName(); + Events = Utils.Reflection.GetConcreteClassesInstanceDerivedFromByName(); + } + + public Event GetEvent() where T : class + { + return Events[typeof(T).Name]; + } + + } +} \ No newline at end of file diff -r fef4ca058087 -r 83dd86e73448 SharpLibEar/EventMonitorPowerOff.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SharpLibEar/EventMonitorPowerOff.cs Sat Jul 23 16:00:04 2016 +0200 @@ -0,0 +1,18 @@ +// + + +using System.Runtime.Serialization; + +namespace SharpLib.Ear +{ + [DataContract] + public class EventMonitorPowerOff : Event + { + public EventMonitorPowerOff() + { + Name = "Monitor Power Off"; + Description = ""; + } + } + +} \ No newline at end of file diff -r fef4ca058087 -r 83dd86e73448 SharpLibEar/EventMonitorPowerOn.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SharpLibEar/EventMonitorPowerOn.cs Sat Jul 23 16:00:04 2016 +0200 @@ -0,0 +1,19 @@ +// + + +using System.Runtime.Serialization; + +namespace SharpLib.Ear +{ + [DataContract] + public class EventMonitorPowerOn : Event + { + public EventMonitorPowerOn() + { + Name = "Monitor Power On"; + Description = ""; + } + + } + +} \ No newline at end of file diff -r fef4ca058087 -r 83dd86e73448 SharpLibEar/Properties/AssemblyInfo.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SharpLibEar/Properties/AssemblyInfo.cs Sat Jul 23 16:00:04 2016 +0200 @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("SharpLibEar")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("SharpLibEar")] +[assembly: AssemblyCopyright("Copyright © 2016")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("84a9ed37-e6ea-4cbd-b995-b713f46eaab0")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff -r fef4ca058087 -r 83dd86e73448 SharpLibEar/SharpLibEar.csproj --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SharpLibEar/SharpLibEar.csproj Sat Jul 23 16:00:04 2016 +0200 @@ -0,0 +1,69 @@ + + + + + Debug + AnyCPU + {84A9ED37-E6EA-4CBD-B995-B713F46EAAB0} + Library + Properties + SharpLibEar + SharpLibEar + v4.6 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + + + + + + + + {ae897704-461d-4018-8336-2517988bf7ad} + SharpLibUtils + + + + + \ No newline at end of file diff -r fef4ca058087 -r 83dd86e73448 SharpLibUtils/Properties/AssemblyInfo.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SharpLibUtils/Properties/AssemblyInfo.cs Sat Jul 23 16:00:04 2016 +0200 @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("SharpLibUtils")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("SharpLibUtils")] +[assembly: AssemblyCopyright("Copyright © 2016")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("ae897704-461d-4018-8336-2517988bf7ad")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff -r fef4ca058087 -r 83dd86e73448 SharpLibUtils/Reflection.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SharpLibUtils/Reflection.cs Sat Jul 23 16:00:04 2016 +0200 @@ -0,0 +1,118 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Linq; +using System.Reflection; + + +namespace SharpLib.Utils +{ + public class Reflection + { + /// + /// + /// + /// + /// + public static IEnumerable GetConcreteClassesDerivedFrom() 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(type); + } + + return objects; + } + + /// + /// + /// + /// + /// + public static IDictionary GetConcreteClassesDerivedFromByName() where T : class + { + Dictionary objects = new Dictionary(); + foreach (Type type in + Assembly.GetAssembly(typeof(T)).GetTypes() + .Where(myType => myType.IsClass && !myType.IsAbstract && myType.IsSubclassOf(typeof(T)))) + { + objects.Add(type.Name,type); + } + + return objects; + } + + /// + /// + /// + /// + /// + public static IEnumerable GetConcreteClassesInstanceDerivedFrom() 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)); + } + + if (objects.Count>0 + && objects[0] is IComparable) + { + objects.Sort(); + } + + return objects; + } + + /// + /// + /// + /// + /// + public static IDictionary GetConcreteClassesInstanceDerivedFromByName() where T : class + { + Dictionary objects = new Dictionary(); + foreach (Type type in + Assembly.GetAssembly(typeof(T)).GetTypes() + .Where(myType => myType.IsClass && !myType.IsAbstract && myType.IsSubclassOf(typeof(T)))) + { + objects.Add(type.Name,(T)Activator.CreateInstance(type)); + } + + + return objects; + } + + + + /// + /// + /// + /// + /// + /// + public static T GetAttribute(Type aType) where T : class + { + object[] attrs = aType.GetCustomAttributes(true); + foreach (object attr in attrs) + { + T attribute = attr as T; + if (attribute != null) + { + return attribute; + } + } + + return null; + } + + } + +} diff -r fef4ca058087 -r 83dd86e73448 SharpLibUtils/SharpLibUtils.csproj --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SharpLibUtils/SharpLibUtils.csproj Sat Jul 23 16:00:04 2016 +0200 @@ -0,0 +1,54 @@ + + + + + Debug + AnyCPU + {AE897704-461D-4018-8336-2517988BF7AD} + Library + Properties + SharpLibUtils + SharpLibUtils + v4.6 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + \ No newline at end of file