コード例 #1
0
        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();
        }
コード例 #2
0
        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();
        }
コード例 #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;
                }
            }
        }
コード例 #4
0
        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;
        }
コード例 #5
0
        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);
        }