Пример #1
0
        internal ConnectionViewModel(INavigationService navigationService, SettingsHost settingsHost, Connection connection, Action changed)
            : this (navigationService, settingsHost)
        {
            this.connection = connection;
            this.changed = changed;

            this.SetConnectionParameters();
        }
Пример #2
0
        public void RemoveConnection(Connection connection)
        {
            this.Settings.Connections.Remove(connection);
            var newConnection = this.Settings.Connections.FirstOrDefault();
            this.SetActiveConnection(newConnection);

            if (this.isSaved)
            {
                this.SaveSettings();
            }
        }
Пример #3
0
        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();
                }
            }
        }
Пример #4
0
 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();
     }
 }
Пример #5
0
        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();
            }
        }
Пример #6
0
        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;
                }
                
            }
        }