public void Save(PreferencesV2 preferences)
        {
            var isoStore = IsolatedStorageFile.GetStore(IsolatedStorageScope.User | IsolatedStorageScope.Assembly, null, null);
            IsolatedStorageFileStream configStream;

            if (!isoStore.DirectoryExists(this.preferencesPath))
            {
                isoStore.CreateDirectory(this.preferencesPath);
            }

            var fullPath = this.preferencesPath + "/" + PreferencesFileName;

            if (!isoStore.FileExists(fullPath))
            {
                configStream = isoStore.CreateFile(fullPath);
            }
            else
            {
                configStream = isoStore.OpenFile(fullPath, FileMode.Open);
            }
            var formatter = new BinaryFormatter();

            formatter.Serialize(configStream, preferences);
            configStream.Flush();
            configStream.Close();
        }
        public void Save(PreferencesV2 preferences)
        {
            var isoStore = IsolatedStorageFile.GetStore(IsolatedStorageScope.User | IsolatedStorageScope.Assembly, null, null);
            IsolatedStorageFileStream configStream;

            if (!isoStore.DirectoryExists(this.preferencesPath))
                isoStore.CreateDirectory(this.preferencesPath);

            var fullPath = this.preferencesPath + "/" + PreferencesFileName;
            if (!isoStore.FileExists(fullPath))
                configStream = isoStore.CreateFile(fullPath);
            else
                configStream = isoStore.OpenFile(fullPath, FileMode.Open);
            var formatter = new BinaryFormatter();
            formatter.Serialize(configStream, preferences);
            configStream.Flush();
            configStream.Close();
        }
Example #3
0
        private void LoadCloudsFromPreferences()
        {
            PreferencesV2 preferences = preferencesProvider.Load();

            if (false == preferences.Clouds.IsNullOrEmpty())
            {
                foreach (Cloud cloud in preferences.Clouds)
                {
                    cloud.PropertyChanged -= Cloud_PropertyChanged;
                }

                clouds.Clear();

                foreach (Cloud cloud in preferences.Clouds)
                {
                    var kvp = new KeyValuePair <Guid, Cloud>(cloud.ID, cloud);
                    clouds.Add(kvp);
                    cloud.PropertyChanged += Cloud_PropertyChanged;
                }
            }
        }
        public PreferencesV2 Load()
        {
            var preferences = new PreferencesV2();

            try
            {
                var fullPath = this.preferencesPath + "/" + PreferencesFileName;
                IsolatedStorageFile isoStore = IsolatedStorageFile.GetStore(IsolatedStorageScope.User | IsolatedStorageScope.Assembly, null, null);
                if (isoStore.DirectoryExists(this.preferencesPath) && isoStore.FileExists(fullPath))
                {
                    using (IsolatedStorageFileStream configStream = isoStore.OpenFile(fullPath, FileMode.Open))
                    {
                        var formatter = new BinaryFormatter();
                        object tmp = formatter.Deserialize(configStream); // as PreferencesV2;
                        PreferencesV2 v2prefs = tmp as PreferencesV2;
                        if (null != v2prefs)
                        {
                            preferences = v2prefs;
                        }
                        else
                        {
                            Preferences v1prefs = tmp as Preferences;
                            if (null != v1prefs)
                            {
                                preferences = convertPreferences(v1prefs);
                            }
                        }
                    }
                }
            }
            catch (Exception)
            {
                // If preferences fail to load, swallow the exception.
            }

            return preferences;
        }
        public PreferencesV2 Load()
        {
            var preferences = new PreferencesV2();

            try
            {
                var fullPath = this.preferencesPath + "/" + PreferencesFileName;
                IsolatedStorageFile isoStore = IsolatedStorageFile.GetStore(IsolatedStorageScope.User | IsolatedStorageScope.Assembly, null, null);
                if (isoStore.DirectoryExists(this.preferencesPath) && isoStore.FileExists(fullPath))
                {
                    using (IsolatedStorageFileStream configStream = isoStore.OpenFile(fullPath, FileMode.Open))
                    {
                        var           formatter = new BinaryFormatter();
                        object        tmp       = formatter.Deserialize(configStream); // as PreferencesV2;
                        PreferencesV2 v2prefs   = tmp as PreferencesV2;
                        if (null != v2prefs)
                        {
                            preferences = v2prefs;
                        }
                        else
                        {
                            Preferences v1prefs = tmp as Preferences;
                            if (null != v1prefs)
                            {
                                preferences = convertPreferences(v1prefs);
                            }
                        }
                    }
                }
            }
            catch (Exception)
            {
                // If preferences fail to load, swallow the exception.
            }

            return(preferences);
        }