internal ConnectionViewModel(INavigationService navigationService, SettingsHost settingsHost, Connection connection, Action changed) : this (navigationService, settingsHost) { this.connection = connection; this.changed = changed; this.SetConnectionParameters(); }
public void RemoveConnection(Connection connection) { this.Settings.Connections.Remove(connection); var newConnection = this.Settings.Connections.FirstOrDefault(); this.SetActiveConnection(newConnection); if (this.isSaved) { this.SaveSettings(); } }
protected override void OnActivate() { base.OnActivate(); if (this.MachineAddress != null) { var active = this.settingsHost.Settings.Connections.Where( c => c.Url == new Uri(string.Format("http://{0}:{1}", this.MachineAddress, this.Port))).FirstOrDefault(); if (active != null) { this.connection = active; this.SetConnectionParameters(); } } }
public void SetActiveConnection(Connection connection) { if (connection == null) { this.Settings.Active = null; this.SaveSettings(); } else if (this.Settings.Active == null) { this.Settings.Active = connection; this.SaveSettings(); } else if (this.Settings.Active.Url != connection.Url || this.Settings.Active.Username != connection.Username || this.Settings.Active.Password != connection.Password) { this.Settings.Active = connection; this.SaveSettings(); } }
public void AddConnection(Connection connection) { Connection existing = this.Settings.Connections.Where(c => c.Url == connection.Url).FirstOrDefault(); if (existing != null) { SetActiveConnection(existing); return; } this.isSaved = false; this.appSettings.Connections.Add(connection); this.SetActiveConnection(connection); if (!this.isSaved) { this.SaveSettings(); } }
private void LoadSettings() { using (IsolatedStorageFile storageFile = IsolatedStorageFile.GetUserStoreForApplication()) { if (!storageFile.FileExists(SettingsFileName)) { var demo = new Connection() { Url = new Uri("http://demo:1234") }; this.appSettings = new Settings() {Active = demo, Connections = { demo }}; return; } using (IsolatedStorageFileStream fileStream = storageFile.OpenFile(SettingsFileName, FileMode.Open)) { using (var sr = new StreamReader(fileStream)) { var text = sr.ReadToEnd(); this.appSettings = JsonConvert.DeserializeObject<Settings>(text); } } if (this.appSettings == null) { return; } } }