# HG changeset patch # User StephaneLenclud # Date 1471345172 -7200 # Node ID ba14a29944c49759b98b0b741a1f79fce932d04c # Parent 0c75dec19d39c35fc6b8579ad85da2d47390f25b Removing JSON type converter from ear manager. Using bindings for some application settings. diff -r 0c75dec19d39 -r ba14a29944c4 Server/ConsumerElectronicControl.cs --- a/Server/ConsumerElectronicControl.cs Tue Aug 16 12:25:20 2016 +0200 +++ b/Server/ConsumerElectronicControl.cs Tue Aug 16 12:59:32 2016 +0200 @@ -82,14 +82,14 @@ { MonitorPowerOn = true; //Trigger corresponding event thus executing associated actions - Manager.Current.TriggerEvent(); + Properties.Settings.Default.EarManager.TriggerEvent(); } private void OnMonitorPowerOff() { MonitorPowerOn = false; //Trigger corresponding event thus executing associated actions - Manager.Current.TriggerEvent(); + Properties.Settings.Default.EarManager.TriggerEvent(); } /// diff -r 0c75dec19d39 -r ba14a29944c4 Server/EarManager.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Server/EarManager.cs Tue Aug 16 12:59:32 2016 +0200 @@ -0,0 +1,22 @@ +using SharpLib.Utils; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Linq; +using System.Runtime.Serialization; +using System.Text; +using System.Threading.Tasks; +using Ear = SharpLib.Ear; + +namespace SharpDisplayManager +{ + /// + /// Allow saving our EAR manager as JSON within our application settings. + /// + [DataContract] + [TypeConverter(typeof(TypeConverterJson))] + public class EarManager: Ear.Manager + { + } +} diff -r 0c75dec19d39 -r ba14a29944c4 Server/FormMain.Designer.cs --- a/Server/FormMain.Designer.cs Tue Aug 16 12:25:20 2016 +0200 +++ b/Server/FormMain.Designer.cs Tue Aug 16 12:59:32 2016 +0200 @@ -297,13 +297,15 @@ // this.iCheckBoxStartIdleClient.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.iCheckBoxStartIdleClient.AutoSize = true; + this.iCheckBoxStartIdleClient.Checked = global::SharpDisplayManager.Properties.Settings.Default.StartIdleClient; + this.iCheckBoxStartIdleClient.CheckState = System.Windows.Forms.CheckState.Checked; + this.iCheckBoxStartIdleClient.DataBindings.Add(new System.Windows.Forms.Binding("Checked", global::SharpDisplayManager.Properties.Settings.Default, "StartIdleClient", true, System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged)); this.iCheckBoxStartIdleClient.Location = new System.Drawing.Point(108, 340); this.iCheckBoxStartIdleClient.Name = "iCheckBoxStartIdleClient"; this.iCheckBoxStartIdleClient.Size = new System.Drawing.Size(145, 17); this.iCheckBoxStartIdleClient.TabIndex = 22; this.iCheckBoxStartIdleClient.Text = "Start idle client on startup"; this.iCheckBoxStartIdleClient.UseVisualStyleBackColor = true; - this.iCheckBoxStartIdleClient.CheckedChanged += new System.EventHandler(this.checkBoxStartIdleClient_CheckedChanged); // // iButtonStartIdleClient // @@ -456,13 +458,14 @@ // this.checkBoxConnectOnStartup.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.checkBoxConnectOnStartup.AutoSize = true; + this.checkBoxConnectOnStartup.Checked = global::SharpDisplayManager.Properties.Settings.Default.DisplayConnectOnStartup; + this.checkBoxConnectOnStartup.DataBindings.Add(new System.Windows.Forms.Binding("Checked", global::SharpDisplayManager.Properties.Settings.Default, "DisplayConnectOnStartup", true, System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged)); this.checkBoxConnectOnStartup.Location = new System.Drawing.Point(113, 350); this.checkBoxConnectOnStartup.Name = "checkBoxConnectOnStartup"; this.checkBoxConnectOnStartup.Size = new System.Drawing.Size(119, 17); this.checkBoxConnectOnStartup.TabIndex = 13; this.checkBoxConnectOnStartup.Text = "Connect on stratup "; this.checkBoxConnectOnStartup.UseVisualStyleBackColor = true; - this.checkBoxConnectOnStartup.CheckedChanged += new System.EventHandler(this.checkBoxConnectOnStartup_CheckedChanged); // // trackBarBrightness // @@ -950,6 +953,8 @@ // checkBoxCecEnabled // this.checkBoxCecEnabled.AutoSize = true; + this.checkBoxCecEnabled.Checked = global::SharpDisplayManager.Properties.Settings.Default.CecEnabled; + this.checkBoxCecEnabled.DataBindings.Add(new System.Windows.Forms.Binding("Checked", global::SharpDisplayManager.Properties.Settings.Default, "CecEnabled", true, System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged)); this.checkBoxCecEnabled.Location = new System.Drawing.Point(6, 6); this.checkBoxCecEnabled.Name = "checkBoxCecEnabled"; this.checkBoxCecEnabled.Size = new System.Drawing.Size(83, 17); @@ -1009,13 +1014,14 @@ // iCheckBoxHarmonyEnabled // this.iCheckBoxHarmonyEnabled.AutoSize = true; + this.iCheckBoxHarmonyEnabled.Checked = global::SharpDisplayManager.Properties.Settings.Default.HarmonyEnabled; + this.iCheckBoxHarmonyEnabled.DataBindings.Add(new System.Windows.Forms.Binding("Checked", global::SharpDisplayManager.Properties.Settings.Default, "HarmonyEnabled", true, System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged)); this.iCheckBoxHarmonyEnabled.Location = new System.Drawing.Point(6, 6); this.iCheckBoxHarmonyEnabled.Name = "iCheckBoxHarmonyEnabled"; this.iCheckBoxHarmonyEnabled.Size = new System.Drawing.Size(104, 17); this.iCheckBoxHarmonyEnabled.TabIndex = 22; this.iCheckBoxHarmonyEnabled.Text = "Enable Harmony"; this.iCheckBoxHarmonyEnabled.UseVisualStyleBackColor = true; - this.iCheckBoxHarmonyEnabled.CheckedChanged += new System.EventHandler(this.iCheckBoxHarmonyEnabled_CheckedChanged); // // iTreeViewHarmony // @@ -1255,25 +1261,27 @@ // this.checkBoxStartMinimized.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.checkBoxStartMinimized.AutoSize = true; + this.checkBoxStartMinimized.Checked = global::SharpDisplayManager.Properties.Settings.Default.StartMinimized; + this.checkBoxStartMinimized.DataBindings.Add(new System.Windows.Forms.Binding("Checked", global::SharpDisplayManager.Properties.Settings.Default, "StartMinimized", true, System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged)); this.checkBoxStartMinimized.Location = new System.Drawing.Point(6, 285); this.checkBoxStartMinimized.Name = "checkBoxStartMinimized"; this.checkBoxStartMinimized.Size = new System.Drawing.Size(96, 17); this.checkBoxStartMinimized.TabIndex = 16; this.checkBoxStartMinimized.Text = "Start minimized"; this.checkBoxStartMinimized.UseVisualStyleBackColor = true; - this.checkBoxStartMinimized.CheckedChanged += new System.EventHandler(this.checkBoxStartMinimized_CheckedChanged); // // checkBoxMinimizeToTray // this.checkBoxMinimizeToTray.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.checkBoxMinimizeToTray.AutoSize = true; + this.checkBoxMinimizeToTray.Checked = global::SharpDisplayManager.Properties.Settings.Default.MinimizeToTray; + this.checkBoxMinimizeToTray.DataBindings.Add(new System.Windows.Forms.Binding("Checked", global::SharpDisplayManager.Properties.Settings.Default, "MinimizeToTray", true, System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged)); this.checkBoxMinimizeToTray.Location = new System.Drawing.Point(6, 308); this.checkBoxMinimizeToTray.Name = "checkBoxMinimizeToTray"; this.checkBoxMinimizeToTray.Size = new System.Drawing.Size(133, 17); this.checkBoxMinimizeToTray.TabIndex = 15; this.checkBoxMinimizeToTray.Text = "Minimize to system tray"; this.checkBoxMinimizeToTray.UseVisualStyleBackColor = true; - this.checkBoxMinimizeToTray.CheckedChanged += new System.EventHandler(this.checkBoxMinimizeToTray_CheckedChanged); // // checkBoxAutoStart // diff -r 0c75dec19d39 -r ba14a29944c4 Server/FormMain.cs --- a/Server/FormMain.cs Tue Aug 16 12:25:20 2016 +0200 +++ b/Server/FormMain.cs Tue Aug 16 12:59:32 2016 +0200 @@ -141,18 +141,17 @@ public FormMain() { - Ear.Manager.Current = Properties.Settings.Default.Events; - if (Ear.Manager.Current == null) + if (Properties.Settings.Default.EarManager == null) { //No actions in our settings yet - Ear.Manager.Current = new Ear.Manager(); - Properties.Settings.Default.Events = Ear.Manager.Current; + Properties.Settings.Default.EarManager = new EarManager(); } else { - //We loaded actions from our settings - //We need to hook them with corresponding events - Ear.Manager.Current.Init(); + // We loaded events and actions from our settings + // Internalizer apparently skips constructor so we need to initialize it here + // Though I reckon that should only be needed when loading an empty EAR manager I guess. + Properties.Settings.Default.EarManager.Init(); } iSkipFrameRendering = false; iClosing = false; @@ -329,7 +328,7 @@ //Reset our tree iTreeViewEvents.Nodes.Clear(); //Populate registered events - foreach (Ear.Event e in Ear.Manager.Current.Events) + foreach (Ear.Event e in Properties.Settings.Default.EarManager.Events) { //Create our event node TreeNode eventNode = iTreeViewEvents.Nodes.Add(e.Name); @@ -1238,11 +1237,7 @@ CheckFontHeight(); //Check if "run on Windows startup" is enabled checkBoxAutoStart.Checked = iStartupManager.Startup; - // - checkBoxConnectOnStartup.Checked = Properties.Settings.Default.DisplayConnectOnStartup; - checkBoxMinimizeToTray.Checked = Properties.Settings.Default.MinimizeToTray; - checkBoxStartMinimized.Checked = Properties.Settings.Default.StartMinimized; - iCheckBoxStartIdleClient.Checked = Properties.Settings.Default.StartIdleClient; + // labelStartFileName.Text = Properties.Settings.Default.StartFileName; @@ -1269,11 +1264,9 @@ } //Harmony settings - iCheckBoxHarmonyEnabled.Checked = Properties.Settings.Default.HarmonyEnabled; iTextBoxHarmonyHubAddress.Text = Properties.Settings.Default.HarmonyHubAddress; //CEC settings - checkBoxCecEnabled.Checked = Properties.Settings.Default.CecEnabled; comboBoxHdmiPort.SelectedIndex = Properties.Settings.Default.CecHdmiPort - 1; //Mini Display settings @@ -1418,34 +1411,6 @@ CheckFontHeight(); } - private void checkBoxConnectOnStartup_CheckedChanged(object sender, EventArgs e) - { - //Save our connect on startup setting - Properties.Settings.Default.DisplayConnectOnStartup = checkBoxConnectOnStartup.Checked; - Properties.Settings.Default.Save(); - } - - private void checkBoxMinimizeToTray_CheckedChanged(object sender, EventArgs e) - { - //Save our "Minimize to tray" setting - Properties.Settings.Default.MinimizeToTray = checkBoxMinimizeToTray.Checked; - Properties.Settings.Default.Save(); - - } - - private void checkBoxStartMinimized_CheckedChanged(object sender, EventArgs e) - { - //Save our "Start minimized" setting - Properties.Settings.Default.StartMinimized = checkBoxStartMinimized.Checked; - Properties.Settings.Default.Save(); - } - - private void checkBoxStartIdleClient_CheckedChanged(object sender, EventArgs e) - { - Properties.Settings.Default.StartIdleClient = iCheckBoxStartIdleClient.Checked; - Properties.Settings.Default.Save(); - } - private void checkBoxAutoStart_CheckedChanged(object sender, EventArgs e) { iStartupManager.Startup = checkBoxAutoStart.Checked; @@ -2658,9 +2623,6 @@ private void checkBoxCecEnabled_CheckedChanged(object sender, EventArgs e) { - //Save CEC enabled status - Properties.Settings.Default.CecEnabled = checkBoxCecEnabled.Checked; - Properties.Settings.Default.Save(); // ResetCec(); } @@ -2840,8 +2802,7 @@ DialogResult res = CodeProject.Dialog.DlgBox.ShowDialog(ea); if (res == DialogResult.OK) { - selectedEvent.Actions.Add(ea.Object); - Properties.Settings.Default.Events = Ear.Manager.Current; + selectedEvent.Actions.Add(ea.Object); Properties.Settings.Default.Save(); PopulateEventsTreeView(); } @@ -2872,7 +2833,6 @@ //Update our action selectedEvent.Actions[actionIndex]=ea.Object; //Save and rebuild our event tree view - Properties.Settings.Default.Events = Ear.Manager.Current; Properties.Settings.Default.Save(); PopulateEventsTreeView(); } @@ -2893,8 +2853,7 @@ return; } - Ear.Manager.Current.RemoveAction(action); - Properties.Settings.Default.Events = Ear.Manager.Current; + Properties.Settings.Default.EarManager.RemoveAction(action); Properties.Settings.Default.Save(); PopulateEventsTreeView(); } @@ -2938,7 +2897,6 @@ currentEvent.Actions[currentIndex-1] = movingUp; //Save and populate our tree again - Properties.Settings.Default.Events = Ear.Manager.Current; Properties.Settings.Default.Save(); PopulateEventsTreeView(); @@ -2968,7 +2926,6 @@ currentEvent.Actions[currentIndex + 1] = movingDown; //Save and populate our tree again - Properties.Settings.Default.Events = Ear.Manager.Current; Properties.Settings.Default.Save(); PopulateEventsTreeView(); } @@ -3038,8 +2995,7 @@ DialogResult res = CodeProject.Dialog.DlgBox.ShowDialog(ea); if (res == DialogResult.OK) { - Ear.Manager.Current.Events.Add(ea.Object); - Properties.Settings.Default.Events = Ear.Manager.Current; + Properties.Settings.Default.EarManager.Events.Add(ea.Object); Properties.Settings.Default.Save(); PopulateEventsTreeView(); SelectEvent(ea.Object); @@ -3055,8 +3011,7 @@ return; } - Ear.Manager.Current.Events.Remove(currentEvent); - Properties.Settings.Default.Events = Ear.Manager.Current; + Properties.Settings.Default.EarManager.Events.Remove(currentEvent); Properties.Settings.Default.Save(); PopulateEventsTreeView(); } @@ -3078,7 +3033,6 @@ if (res == DialogResult.OK) { //Save and rebuild our event tree view - Properties.Settings.Default.Events = Ear.Manager.Current; Properties.Settings.Default.Save(); PopulateEventsTreeView(); } @@ -3170,12 +3124,6 @@ //treeViewConfig.ExpandAll(); } - private void iCheckBoxHarmonyEnabled_CheckedChanged(object sender, EventArgs e) - { - Properties.Settings.Default.HarmonyEnabled = iCheckBoxHarmonyEnabled.Checked; - Properties.Settings.Default.Save(); - } - private async void iTreeViewHarmony_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e) { //Upon function node double click we execute it diff -r 0c75dec19d39 -r ba14a29944c4 Server/Properties/Settings.Designer.cs --- a/Server/Properties/Settings.Designer.cs Tue Aug 16 12:25:20 2016 +0200 +++ b/Server/Properties/Settings.Designer.cs Tue Aug 16 12:59:32 2016 +0200 @@ -156,12 +156,12 @@ [global::System.Configuration.UserScopedSettingAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - public global::SharpLib.Ear.Manager Events { + public global::SharpDisplayManager.EarManager EarManager { get { - return ((global::SharpLib.Ear.Manager)(this["Events"])); + return ((global::SharpDisplayManager.EarManager)(this["EarManager"])); } set { - this["Events"] = value; + this["EarManager"] = value; } } diff -r 0c75dec19d39 -r ba14a29944c4 Server/Properties/Settings.settings --- a/Server/Properties/Settings.settings Tue Aug 16 12:25:20 2016 +0200 +++ b/Server/Properties/Settings.settings Tue Aug 16 12:59:32 2016 +0200 @@ -35,7 +35,7 @@ True - + diff -r 0c75dec19d39 -r ba14a29944c4 Server/Settings.cs --- a/Server/Settings.cs Tue Aug 16 12:25:20 2016 +0200 +++ b/Server/Settings.cs Tue Aug 16 12:59:32 2016 +0200 @@ -17,6 +17,8 @@ // along with SharpDisplayManager. If not, see . // +using System; + namespace SharpDisplayManager.Properties { @@ -30,18 +32,34 @@ public Settings() : base("default") { // // To add event handlers for saving and changing settings, uncomment the lines below: // - // this.SettingChanging += this.SettingChangingEventHandler; + this.SettingChanging += this.SettingChangingEventHandler; // - // this.SettingsSaving += this.SettingsSavingEventHandler; + this.SettingsSaving += this.SettingsSavingEventHandler; // + this.SettingsLoaded += this.SettingsLoadedEventHandler; + // + this.PropertyChanged += this.PropertyChangedEventHandler; } - + + private void PropertyChangedEventHandler(object sender, System.ComponentModel.PropertyChangedEventArgs e) + { + Console.WriteLine($"Settings: property changed {e.PropertyName}"); + Default.Save(); + } + private void SettingChangingEventHandler(object sender, System.Configuration.SettingChangingEventArgs e) { // Add code to handle the SettingChangingEvent event here. + Console.WriteLine($"Settings: changing {e.SettingKey}.{e.SettingName}"); } - + + private void SettingsLoadedEventHandler(object sender, System.Configuration.SettingsLoadedEventArgs e) + { + Console.WriteLine($"Settings: loaded {e.Provider.ApplicationName}"); + } + private void SettingsSavingEventHandler(object sender, System.ComponentModel.CancelEventArgs e) { // Add code to handle the SettingsSaving event here. + Console.WriteLine("Settings: saving"); } } } diff -r 0c75dec19d39 -r ba14a29944c4 Server/SharpDisplayManager.csproj --- a/Server/SharpDisplayManager.csproj Tue Aug 16 12:25:20 2016 +0200 +++ b/Server/SharpDisplayManager.csproj Tue Aug 16 12:59:32 2016 +0200 @@ -177,6 +177,7 @@ + Form @@ -248,6 +249,7 @@ SettingsSingleFileGenerator Settings.Designer.cs + Designer True diff -r 0c75dec19d39 -r ba14a29944c4 SharpLibEar/Manager.cs --- a/SharpLibEar/Manager.cs Tue Aug 16 12:25:20 2016 +0200 +++ b/SharpLibEar/Manager.cs Tue Aug 16 12:59:32 2016 +0200 @@ -7,22 +7,18 @@ using System.Runtime.Serialization; using SharpLib.Utils; + namespace SharpLib.Ear { /// /// Event Action Router (Ear) is a generic and extensible framework allowing users to execute actions in response to events. /// Users can implement their own events and actions. /// - [TypeConverter(typeof(TypeConverterJson))] [DataContract] + [KnownType("DerivedTypes")] public class Manager { /// - /// Access the currently installed EAR manager. - /// - public static Manager Current = null; - - /// /// Our events instances. /// [DataMember] @@ -77,5 +73,15 @@ } } } + + /// + /// Allow extending our data contract. + /// See KnownType above. + /// + /// + private static IEnumerable DerivedTypes() + { + return SharpLib.Utils.Reflection.GetDerivedTypes(); + } } } \ No newline at end of file