public UserSettingsContainer Load() { var result = new UserSettingsContainer(); if (!_settingsStore.CollectionExists(SETTINGS_STORE_NAME)) { Save(result); } if (_settingsStore.CollectionExists(SETTINGS_STORE_NAME)) { try { var content = _settingsStore.GetString(SETTINGS_STORE_NAME, "Settings"); result = UserSettingsContainer.DeserializeFromJson(content); return(result); } catch (Exception ex) { _logger.Error(ex); } } return(result); }
private static void CheckConfigurationsFromFiles(UserSettingsContainer container, string appDirectoryPath) { if (container != null) { for (int i = 0; i < container.DeviceConnections.Count; i++) { var settings = container.DeviceConnections[i]; var filePath = Path.Combine(appDirectoryPath, settings.LoadConfigFromFileName); var loadedSettings = GetConfigFromFile(filePath); if (loadedSettings != null) { container.DeviceConnections[i] = loadedSettings; } } } if (!string.IsNullOrEmpty(container.CurrentUserSettings.LoadConfigFromFileName)) { var filePath = Path.Combine(appDirectoryPath, container.CurrentUserSettings.LoadConfigFromFileName); var loadedSettings = GetConfigFromFile(filePath); if (loadedSettings != null) { container._currentUserSettings = loadedSettings; } } }
public void Save(UserSettingsContainer settings) { string json = settings.SerializeToJson(); if (!store.CollectionExists(SETTINGS_STORE_NAME)) { store.CreateCollection(SETTINGS_STORE_NAME); } store.SetString(SETTINGS_STORE_NAME, "Settings", json); }
public UserSettingsContainer LoadFromPath(string path) { var result = new UserSettingsContainer(); try { var content = File.ReadAllText(path); result = UserSettingsContainer.DeserializeFromJson(content); return(result); } catch (Exception ex) { _logger.Error(ex); } return(result); }
private static void Validate(UserSettingsContainer instance) { instance.DeviceConnections = instance.DeviceConnections ?? new ObservableCollection <UserSettings>(); if (instance.DeviceConnections == null || instance.DeviceConnections.Count == 0) { instance.DeviceConnections.Add(new UserSettings()); } if (string.IsNullOrWhiteSpace(instance.SelectedId) || !instance.DeviceConnections.Any(x => x.Id == instance.SelectedId)) { instance.SelectedId = instance.DeviceConnections.First().Id; } foreach (var deviceConnection in instance.DeviceConnections) { UserSettings.Validate(deviceConnection); } }
public UserSettingsContainer Load(string appDirectoryPath) { var result = new UserSettingsContainer(); if (store.CollectionExists(SETTINGS_STORE_NAME)) { try { string content = store.GetString(SETTINGS_STORE_NAME, "Settings"); result = UserSettingsContainer.DeserializeFromJson(content, appDirectoryPath); return(result); } catch (Exception ex) { logger.Error(ex); } } return(result); }
private static void Validate(UserSettingsContainer instance) { instance.DeviceConnections = instance.DeviceConnections ?? new ObservableCollection <UserSettings>(); if (instance.DeviceConnections == null || instance.DeviceConnections.Count == 0) { instance.DeviceConnections.Add(new UserSettings()); } if (string.IsNullOrWhiteSpace(instance.SelectedId) || !instance.DeviceConnections.Any(x => x.Id == instance.SelectedId)) { instance.SelectedId = instance.DeviceConnections.First().Id; } foreach (var deviceConnection in instance.DeviceConnections) { if (deviceConnection.SSHMonoDebugPort <= 0) { deviceConnection.SSHMonoDebugPort = UserSettings.DEFAULT_DEBUGGER_AGENT_PORT; } } }
public void SaveAs(UserSettingsContainer settings, string path) { var json = settings.SerializeToJson(); File.WriteAllText(path, json); }