Exemplo n.º 1
0
        private void CoreService_SettingsUpdatedEvent(object sender, TotpWifiSettings e)
        {
            try
            {
                //var x = System.Reflection.Assembly.GetExecutingAssembly().CodeBase;
                if (e.IsValid())
                {
                    var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

                    config.AppSettings.Settings.AddOrUpdate(nameof(TotpWifiSettings.AutoConnect), e.AutoConnect.ToString());
                    config.AppSettings.Settings.AddOrUpdate(nameof(TotpWifiSettings.ESSID), e.ESSID);
                    config.AppSettings.Settings.AddOrUpdate(nameof(TotpWifiSettings.PSHK), e.PSHK);
                    config.AppSettings.Settings.AddOrUpdate(nameof(TotpWifiSettings.SecretKeyBase32), e.SecretKeyBase32);
                    config.AppSettings.Settings.AddOrUpdate(nameof(TotpWifiSettings.StepSeconds), e.StepSeconds.ToString());
                    config.AppSettings.Settings.AddOrUpdate(nameof(TotpWifiSettings.TotpDigitCount), e.TotpDigitCount.ToString());
                    config.AppSettings.Settings.AddOrUpdate(nameof(TotpWifiSettings.WlanInterfaceId), e.WlanInterfaceId.ToString());

                    config.Save(ConfigurationSaveMode.Full);


                    this.settings = e;
                    this.currentConfigCancelSource.Cancel(false);
                }
            }
            catch (Exception ex)
            {
                Trace.TraceError(ex.ToString());
            }
        }
Exemplo n.º 2
0
        private void LoadConfig()
        {
            var              config        = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            string           wlanId        = config.AppSettings.Settings.ReadOrDefault <string>(nameof(TotpWifiSettings.WlanInterfaceId));
            TotpWifiSettings savedSettings = new TotpWifiSettings(
                config.AppSettings.Settings.ReadOrDefault <string>(nameof(TotpWifiSettings.SecretKeyBase32)),
                config.AppSettings.Settings.ReadOrDefault <string>(nameof(TotpWifiSettings.PSHK)),
                config.AppSettings.Settings.ReadOrDefault <int>(nameof(TotpWifiSettings.StepSeconds)),
                config.AppSettings.Settings.ReadOrDefault <string>(nameof(TotpWifiSettings.ESSID)),
                String.IsNullOrWhiteSpace(wlanId) ? Guid.Empty : Guid.Parse(wlanId),
                config.AppSettings.Settings.ReadOrDefault <bool>(nameof(TotpWifiSettings.AutoConnect)));

            if (savedSettings.IsValid())
            {
                this.settings = savedSettings;
            }
        }