Ejemplo n.º 1
0
        /// <inheritdoc />
        public void SetSettingsList(List <ISettingItemBase> settings)
        {
            if (settings?.Count == GetSettingsList().Count)
            {
                int index = 0;
                foreach (PropertyInfo item in this.GetType().GetProperties())
                {
                    ((ISettingItemBase)(item.GetValue(this, null))).StringValue = settings[index].StringValue;
                    index++;
                }
            }
            ;

            SettingsUpdated?.Invoke(this, null);
        }
Ejemplo n.º 2
0
 public static void SaveSettings(SettingsModel settings)
 {
     try
     {
         var serialzer = new XmlSerializer(typeof(SettingsModel));
         Directory.CreateDirectory(configFolder);
         using (var stream = File.Create(Path.Combine(configFolder, filename)))
             serialzer.Serialize(stream, settings);
         SettingsUpdated?.Invoke(CurrentSettings, settings);
         CurrentSettings = settings;
     }
     catch
     {
         //TODO:output
     }
 }
Ejemplo n.º 3
0
        public static void LoadSettings()
        {
            SettingsModel settings;

            try
            {
                var serialzer = new XmlSerializer(typeof(SettingsModel));
                using (var stream = File.OpenRead(Path.Combine(configFolder, filename)))
                    settings = (SettingsModel)serialzer.Deserialize(stream);
                SettingsUpdated?.Invoke(CurrentSettings, settings);
                CurrentSettings = settings;
            }
            catch
            {
                //TODO:output
            }
        }
Ejemplo n.º 4
0
        private void ApplySettings()
        {
            ledSettings.EnableKeyLockLEDs = cbEnable.Checked;
            ledSettings.AutoStartApp      = cbAutoStartApp.Checked;

            ledSettings.EnableCaps   = cbEnableCaps.Checked;
            ledSettings.EnableNum    = cbEnableNum.Checked;
            ledSettings.EnableScroll = cbEnableScroll.Checked;


            ledSettings.OsdEnabled        = cbOsdEnabled.Checked;
            ledSettings.OsdPosition       = (OSDPosition)cbOSDPosition.SelectedItem;
            ledSettings.OsdPadding        = (int)cbOsdPadding.Value;
            ledSettings.OsdMargin         = (int)cbOsdMargin.Value;
            ledSettings.OsdRoundedCorners = cbOsdRoundedCorners.Checked;
            ledSettings.OsdOpacity        = (int)cbOsdOpacity.Value;
            ledSettings.OsdDuration       = (int)cbOsdDurtation.Value;
            ledSettings.CapsOffColor      = btnCapsOffColour.BackColor;
            ledSettings.CapsOnColor       = btnCapsOnColour.BackColor;
            ledSettings.NumOffColor       = btnNumOffColour.BackColor;
            ledSettings.NumOnColor        = btnNumOnColour.BackColor;
            ledSettings.ScrollOffColor    = btnScrollOffColour.BackColor;
            ledSettings.ScrollOnColor     = btnScrollOnColour.BackColor;
            ledSettings.OsdTextColor      = btnOsdTxtColour.BackColor == Color.Black ? Color.FromArgb(3, 3, 3) : btnOsdTxtColour.BackColor;
            ledSettings.OsdBackColor      = btnOsdBkColour.BackColor == Color.Black ? Color.FromArgb(3, 3, 3) : btnOsdBkColour.BackColor;
            ledSettings.OsdShowNum        = cbOSDShowNum.Checked;
            ledSettings.OsdShowCaps       = cbOSDShowCaps.Checked;
            ledSettings.OsdShowScroll     = cbOSDShowScroll.Checked;

            ledSettings.TrayShowNum    = cbTrayShowNum.Checked;
            ledSettings.TrayShowCaps   = cbTrayShowCaps.Checked;
            ledSettings.TrayShowScroll = cbTrayShowScroll.Checked;

            ledSettings.TrayOnColor      = btnTrayOnColor.BackColor;
            ledSettings.TrayOnBackColor  = cbTrayOnTransparent.Checked ? Color.Transparent : btnTrayOnBgColor.BackColor;
            ledSettings.TrayOffColor     = btnTrayOffColor.BackColor;
            ledSettings.TrayOffBackColor = cbTrayOffTransparent.Checked ? Color.Transparent : btnTrayOffBgColor.BackColor;

            ledSettings.TrayOnBorder  = cbTrayOnBorder.Checked;
            ledSettings.TrayOffBorder = cbTrayOffBorder.Checked;

            ledSettings.SaveSettings();
            SettingsUpdated?.Invoke(this, new EventArgs());
        }
Ejemplo n.º 5
0
        public void SetSetting(string setting, string value)
        {
            if (_settings != null)
            {
                _settings[setting] = new Setting
                {
                    Key       = setting,
                    Value     = value,
                    Inherited = false
                };

                SaveSettings();

                SettingsUpdated?.Invoke(this, new SettingsEventArgs
                {
                    Settings = _settings.Values.ToArray()
                });
            }
        }
Ejemplo n.º 6
0
        void DoSave()
        {
            Settings.CanUserClose          = CanUserClose.IsChecked ?? false;
            Settings.CloseOnRightClick     = CloseOnRightClick.IsChecked ?? false;
            Settings.CloseAfterClickAction = CloseAfterClickAction.IsChecked ?? false;

            Settings.Lifetime = int.Parse(Lifetime.Text);
            Settings.RefreshLifetimeOnMouseOver = RefreshLifetimeOnMouseOver.IsChecked ?? false;

            Settings.DynamicLifetime     = DynamicLifetime.IsChecked ?? false;
            Settings.DynamicLifetimeBase = int.Parse(DynamicLifetimeBase.Text);
            Settings.DynamicLifetimeMillisecondsPerCharacter = int.Parse(DynamicLifetimeMillisecondsPerCharacter.Text);
            Settings.DynamicLifetimeMinimum = int.Parse(DynamicLifetimeMinimum.Text);
            Settings.DynamicLifetimeMaximum = int.Parse(DynamicLifetimeMaximum.Text);

            Settings.LeaveTime = int.Parse(FadeTime.Text);

            if (Settings.Name.ToLower() != "default")
            {
                _savedSettings.Save();
            }

            SettingsUpdated?.Invoke(this, new EventArgs());
        }
Ejemplo n.º 7
0
 private static void OnSettingsUpdated(object sender, EventArgs ea) => SettingsUpdated?.Invoke(sender, ea);
Ejemplo n.º 8
0
 public void RaiseSettingsUpdated(IEnumerable <string> updatedKeys)
 => SettingsUpdated?.Invoke(this, updatedKeys);
Ejemplo n.º 9
0
 private void UpdateConnection()
 {
     SettingsUpdated?.Invoke(this, EventArgs.Empty);
 }
Ejemplo n.º 10
0
 private void wordWrapToolStripMenuItem_Click(object sender, EventArgs e)
 {
     CurrentFileSettings.WordWrap = wordWrapToolStripMenuItem.Checked;
     SettingsUpdated?.Invoke();
 }
Ejemplo n.º 11
0
 private void enableHighlightingToolStripMenuItem_Click(object sender, EventArgs e)
 {
     CurrentFileSettings.EnableHighlight = enableHighlightingToolStripMenuItem.Checked;
     SettingsUpdated?.Invoke();
 }
Ejemplo n.º 12
0
 private void comboBoxLoadLast_SelectedIndexChanged(object sender, EventArgs e)
 {
     CurrentFileSettings.LoadLastLines = LoadLastNLines;
     SettingsUpdated?.Invoke();
 }
Ejemplo n.º 13
0
 private void showLineNumbersToolStripMenuItem_Click(object sender, EventArgs e)
 {
     CurrentFileSettings.ShowLineNumbers = showLineNumbersToolStripMenuItem.Checked;
     SettingsUpdated?.Invoke();
 }
Ejemplo n.º 14
0
 private void autoScrollToolStripMenuItem_Click(object sender, EventArgs e)
 {
     CurrentFileSettings.AutoScroll = autoScrollToolStripMenuItem.Checked;
     SettingsUpdated?.Invoke();
 }
Ejemplo n.º 15
0
 private void OnSettingsUpdated()
 {
     SettingsUpdated?.Invoke(this);
 }
Ejemplo n.º 16
0
        public SensiConnection()
        {
            Trace.WriteLine("SensiConnection ctor");

            this._cookieJar     = new CookieContainer();
            this._hubConnection = new HubConnection(_urlBase + "realtime", false);
            this._hubConnection.CookieContainer = this._cookieJar;
            this._hubProxy      = this._hubConnection.CreateHubProxy("thermostat-v1");
            this._subscriptions = new List <string>();

            this._hubConnection.StateChanged += (state) =>
            {
                Debug.WriteLine($"State Changed from {state.OldState} to {state.NewState}");
            };

            this._hubConnection.ConnectionSlow += () => { Debug.WriteLine("Connection Slow"); };
            this._hubConnection.Reconnected    += () => { Debug.WriteLine("Reconnected"); };
            this._hubConnection.Reconnecting   += () => { Debug.WriteLine("Reconnecting"); };
            this._hubConnection.Error          += async(ex) =>
            {
                Trace.WriteLine(ex, "HubConnection Error");

                if (ex is System.Net.WebException)
                {
                    if (((System.Net.WebException)ex).Status == WebExceptionStatus.ProtocolError)
                    {
                        var response = ((System.Net.WebException)ex).Response as HttpWebResponse;

                        if (response != null && (
                                response.StatusCode == HttpStatusCode.Unauthorized ||
                                response.StatusCode == HttpStatusCode.InternalServerError)
                            )
                        {
                            Trace.WriteLine("Restarting Realtime due to WebExpection");

                            while (await this.BeginRealtime() == false)
                            {
                                Trace.WriteLine("Not Connected, Delaying...");
                                this.StopRealtime();
                                await Task.Delay(5000);
                            }

                            foreach (var sub in _subscriptions)
                            {
                                Trace.WriteLine("Attempt Re-Subscription for " + sub);
                                this.Subscribe(sub).Wait();
                            }
                            return;
                        }
                    }
                }
                else if (ex is System.Net.Sockets.SocketException)
                {
                    Trace.WriteLine("Restarting Realtime due to SocketException");

                    while (await this.BeginRealtime() == false)
                    {
                        Trace.WriteLine("Not Connected, Delaying...");
                        this.StopRealtime();
                        await Task.Delay(5000);
                    }

                    foreach (var sub in _subscriptions)
                    {
                        Trace.WriteLine("Attempt Re-Subscription for " + sub);
                        this.Subscribe(sub).Wait();
                    }
                    return;
                }
            };

            this._hubConnection.Received += (data) => { Debug.WriteLine("Data Received"); };

            this._hubProxy.On <object>("initalized", (data) =>
            {
                Trace.WriteLine(data, "Initalized");
            });

            this._hubProxy.On <object, object>("online", (icd, data) =>
            {
                //Trace.WriteLine(Environment.NewLine + data, $"Received Online Message for ICD [{icd}]");
                Trace.WriteLine($"Received Online Message for ICD [{icd}]");
                this.LastUpdateReceived = DateTime.Now;

                try
                {
                    var msg  = JsonConvert.DeserializeObject <OnlineResponse>(data.ToString());
                    var args = (ThermostatOnlineEventArgs)msg;
                    args.Icd = icd.ToString();

                    ThermostatOnline?.Invoke(this, args);
                }
                catch (Exception ex)
                {
                    Trace.WriteLine(ex);
                }
            });

            this._hubProxy.On <object, object>("update", (icd, data) =>
            {
                //Trace.WriteLine(Environment.NewLine + data, $"Received Update Message for ICD [{icd}]");
                Trace.WriteLine($"Received Update Message for ICD [{icd}]");
                this.LastUpdateReceived = DateTime.Now;

                OnlineResponse msg = null;

                try
                {
                    msg = JsonConvert.DeserializeObject <OnlineResponse>(data.ToString());
                }
                catch (Exception ex) { Trace.WriteLine(ex); }

                if (msg != null)
                {
                    if (msg != null && msg.OperationalStatus != null)
                    {
                        OperationalStatusUpdated?.Invoke(this, new OperationalStatusUpdatedEventArgs {
                            Icd = icd.ToString(), OperationalStatus = msg.OperationalStatus
                        });
                    }

                    if (msg != null && msg.EnvironmentControls != null)
                    {
                        EnvironmentalControlsUpdated?.Invoke(this, new EnvironmentalControlsUpdatedEventArgs {
                            Icd = icd.ToString(), EnvironmentControls = msg.EnvironmentControls
                        });
                    }

                    if (msg != null && msg.Capabilities != null)
                    {
                        CapabilitiesUpdated?.Invoke(this, new CapabilitiesUpdatedEventArgs {
                            Icd = icd.ToString(), Capabilities = msg.Capabilities
                        });
                    }

                    if (msg != null && msg.Settings != null)
                    {
                        SettingsUpdated?.Invoke(this, new SettingsUpdatedEventArgs {
                            Icd = icd.ToString(), Settings = msg.Settings
                        });
                    }

                    if (msg != null && msg.Product != null)
                    {
                        ProductUpdated?.Invoke(this, new ProductUpdatedEventArgs {
                            Icd = icd.ToString(), Product = msg.Product
                        });
                    }
                }
            });

            this._hubProxy.On <object, object>("offline", (icd, data) =>
            {
                //Trace.WriteLine(Environment.NewLine + data, $"Received Offline Message for ICD [{icd}]");
                Trace.WriteLine($"Received Offline Message for ICD [{icd}]");
                this.LastUpdateReceived = DateTime.Now;
            });
        }