/// <summary> /// Default constructor for settings configuration view model /// </summary> public SettingsConfigurationViewModel() { //set new collection this.AvailableApis = new ObservableCollection <string>(); //pull arr of strings out of properties xml string[] arr = new string[Properties.Settings.Default.Modules.Count]; Properties.Settings.Default.Modules.CopyTo(arr, 0); //add each item in the string array to list of available Apis for (int x = 0; x < arr.Length; x++) { AvailableApis.Add(arr[x]); } //See if it has default value or not if (!Properties.Settings.Default.ApiKeys.Equals("empty")) { //Get Api key value var keys = Properties.Settings.Default.ApiKeys; //if not default value deserialize the dictionary this.ApiKeys = JsonConvert.DeserializeObject <ObservableConcurrentDictionary <string, string> >(keys); } if (!Properties.Settings.Default.ConnectionStrings.Equals("empty")) { var constrs = Properties.Settings.Default.ConnectionStrings; this.ConnectionStrings = JsonConvert.DeserializeObject <ObservableConcurrentDictionary <string, string> >(constrs); } this.ToggleEncryptionCommand = new DelegateCommand(ToggleEncryption); this.EncryptSettingsFileCommand = new DelegateCommand(EncryptUserFile); this.DecryptSettingsFileCommand = new DelegateCommand(DecryptUserFile); this.UseEncryption = Properties.Settings.Default.Encryption; this.AddApiKeyCommand = new DelegateCommand(AddApiKey); this.AddConnectionStringCommand = new DelegateCommand(AddConnectionString); this.RemoveApiKeyCommand = new DelegateCommand(RemoveApiKey); this.RemoveConnectionStringCommand = new DelegateCommand(RemoveConnectionString); this.SelectedItemKey = null; // Open the configuration file and retrieve // the connectionStrings section. Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal); //Get section for user settings ConfigurationSection userSettings = config.GetSection("userSettings/prism7.Properties.Settings"); //Sets the start up value of the check boxes isChecked value based on the encryption status of the settings file if (userSettings.SectionInformation.IsProtected) { this.UseEncryption = true; } else { this.UseEncryption = false; } }
/// <summary> /// Gets a service /// </summary> /// <param name="api">The choice of API</param> protected void GetService(AvailableApis api) { string settingsFilePath = _config.GetSection("DatabaseSettings").Value; if (string.IsNullOrEmpty(settingsFilePath)) { throw new NullReferenceException("Couldn't read settings file"); } Factory factory = new Factory(settingsFilePath); Service = (T)factory.GetService(api); }
/// <summary> /// Given a type of APi returns the instanciated IApi /// </summary> /// <param name="api">The type of API to query</param> /// <returns>An IApi</returns> public IApi GetService(AvailableApis api) { try { switch (api) { case AvailableApis.UserAuthorization: return(new UserAuthorizationPublic(_fileSettingsPath)); case AvailableApis.UserAccounts: return(new UserAccountsPublic(_fileSettingsPath)); case AvailableApis.Toggler: return(new TogglerApiPublic(_fileSettingsPath)); case AvailableApis.TogglerInternal: return(new TogglerApiInternal()); case AvailableApis.Service: return(new ServiceApiPublic(_fileSettingsPath)); default: return(null); } } catch (System.Exception e) { return(null); } }