static GlobalSettingsManager() { localSettings = ApplicationData.Current.LocalSettings; var containers = localSettings.Containers; if (!containers.ContainsKey(NotificationsContainer)) { localSettings.CreateContainer(NotificationsContainer, ApplicationDataCreateDisposition.Always); } if (!containers.ContainsKey(PrivacyContainer)) { localSettings.CreateContainer(PrivacyContainer, ApplicationDataCreateDisposition.Always); } if (!containers.ContainsKey(AppearanceContainer)) { localSettings.CreateContainer(AppearanceContainer, ApplicationDataCreateDisposition.Always); } if (!containers.ContainsKey(ChatsAndMediaContainer)) { localSettings.CreateContainer(ChatsAndMediaContainer, ApplicationDataCreateDisposition.Always); } if (!containers.ContainsKey(AdvancedContainer)) { localSettings.CreateContainer(AdvancedContainer, ApplicationDataCreateDisposition.Always); } }
private void createGame() { //Local Settings ApplicationDataContainer container = localSettings.CreateContainer("Names", ApplicationDataCreateDisposition.Always); object p1obj; object p2obj; string p1Default; string p2Default; p1obj = localSettings.Containers["Names"].Values["P1"]; p2obj = localSettings.Containers["Names"].Values["P2"]; p1Default = (string)p1obj; p2Default = (string)p2obj; if (p2Default == null) { P2.Text = "Player 2"; } else { P2.Text = p2Default; } if (p1Default == null) { P1.Text = "Player 1"; } else { P1.Text = p1Default; } }//end createGame
public SettingsManager(ref MapControl MapMain) { // Check is the instance doesnt already exist. if (Current != null) { //if there is an instance in the app already present then simply throw an error. throw new Exception("Only one settings manager can exist in a App."); } // Setting the instance to the static instance field. Current = this; this.MapMain = MapMain; ApplicationData.Current.DataChanged += new TypedEventHandler <ApplicationData, object>(DataChangeHandler); // Roaming Settings RoamingSettings = ApplicationData.Current.RoamingSettings; RoamingSettings.CreateContainer("Map", ApplicationDataCreateDisposition.Always); RoamingSettings.CreateContainer("Appearance", ApplicationDataCreateDisposition.Always); // Local Settings LocalSettings = ApplicationData.Current.LocalSettings; LocalSettings.CreateContainer("Location", ApplicationDataCreateDisposition.Always); }
/// <summary> /// /// </summary> /// <param name="key"></param> /// <param name="value"></param> /// <param name="container"></param> public static void SetValue(string key, object value, string container = null) { ApplicationDataContainer applicationDataContainer; if (container != null) { if (localSettings.Containers.ContainsKey(container)) { applicationDataContainer = localSettings.Containers[container]; } else { applicationDataContainer = localSettings.CreateContainer(container, ApplicationDataCreateDisposition.Always); } } else { applicationDataContainer = localSettings; } if (applicationDataContainer.Values.ContainsKey(key)) { applicationDataContainer.Values[key] = value; } else { applicationDataContainer.Values.Add(key, value); } }
private void Save() { ApplicationDataContainer root = ApplicationData.Current.LocalSettings; root.DeleteContainer("Remote"); ApplicationDataContainer remote = root .CreateContainer("Remote", ApplicationDataCreateDisposition.Always); foreach (RemoteClient client in remoteClients.Values) { ApplicationDataContainer item = remote .CreateContainer(client.Key.ToString(), ApplicationDataCreateDisposition.Always); item.Values["Name"] = client.Name; item.Values["Url"] = client.Url; item.Values["AuthenticationToken"] = client.AuthenticationToken; } root.DeleteContainer("Local"); if (localClient != null) { ApplicationDataContainer localContainer = root.CreateContainer("Local", ApplicationDataCreateDisposition.Always); localContainer.Values["Key"] = localClient.Key; localContainer.Values["Port"] = localClient.Port; localContainer.Values["AuthenticationToken"] = localClient.AuthenticationToken; localContainer.Values["Interval"] = localClient.Interval; localContainer.Values["Delay"] = localClient.Delay; } }
public MainPage() { bool opened = true; this.InitializeComponent(); // TEMP: delete settings - for debugging only //localSettings.DeleteContainer("startup"); // Try to read composite value "startup" from settings to either load or create data try { startupSettings = localSettings.CreateContainer("startup", ApplicationDataCreateDisposition.Existing); } catch (Exception e) { // Startup settings have never been created! Create a new Schedule data structure System.Diagnostics.Debug.WriteLine("Creating ApplicationData in localSettings for new schedule"); opened = false; startupSettings = localSettings.CreateContainer("startup", ApplicationDataCreateDisposition.Always); // Create new scjedule object nextEventID = 1; // TODO: read from global configuration file (permanent storage) uint calID = (uint)rng.Next(int.MinValue, int.MaxValue); schedule = new SmartSchedule(startupSettings, calID, "Default", new SolidColorBrush(Color.FromArgb(0xFF, 0x10, 0xEE, 0xEE))); scheduleStorageID = schedule.StorageID(); // Store these values into the startup settings // startupSettings = new ApplicationDataCompositeValue(); startupSettings.Values["nextEventID"] = nextEventID; // Events always start at 1 startupSettings.Values["scheduleStorageID"] = scheduleStorageID; scheduleData = startupSettings.CreateContainer(scheduleStorageID, ApplicationDataCreateDisposition.Always); //startupSettings.Values[scheduleStorageID] = scheduleData; //localSettings.Values["startup"] = startupSettings; } if (opened) { // Startup settings already exist! Load previous values into usable data structure System.Diagnostics.Debug.WriteLine("Loading schedule data from application storage"); nextEventID = (uint)startupSettings.Values["nextEventID"]; scheduleStorageID = (string)startupSettings.Values["scheduleStorageID"]; scheduleData = startupSettings.CreateContainer(scheduleStorageID, ApplicationDataCreateDisposition.Existing); schedule = new SmartSchedule(startupSettings, scheduleStorageID); } // Initialize XAML components CB_TypePicker.ItemsSource = schedule.taskTypeList; CB_RequiredPicker.ItemsSource = schedule.ynList; CB_RepeatPicker.ItemsSource = schedule.repeatTypeList; CB_DurHoursPicker.ItemsSource = SmartTask.hours; CB_DurMinsPicker.ItemsSource = SmartTask.mins; LV_Schedule.ItemsSource = schedule.GetTastsAt(selectedDate.Date); selectedDate = DateTime.Now; }
public static void MarkContainer <T>(SettingContainer container, string containerValue, T value) { #if !NETFX_CORE var json = Newtonsoft.Json.JsonConvert.SerializeObject(value); LocalSettings.Values[containerValue] = json; #else _ = LocalSettings.CreateContainer(container.ToString(), ApplicationDataCreateDisposition.Always); LocalSettings.Containers[container.ToString()].Values[containerValue] = value != null?JsonConvert.SerializeObject(value) : null; #endif }
private bool TryGetContainer(string containerPath, bool isCreatedWhenNotExists, out ApplicationDataContainer container) { Ensure.NotNullOrEmpty(containerPath, "containerPath"); ApplicationDataContainer result = storageContainerFactory.Create(); string[] paths = containerPath.Split('.'); foreach (string path in paths) { if (!result.Containers.TryGetValue(path, out ApplicationDataContainer current)) { if (isCreatedWhenNotExists) { current = result.CreateContainer(path, ApplicationDataCreateDisposition.Always); } else { container = null; return(false); } } result = current; } container = result; return(true); }
private static ApplicationDataContainer ContainerFromName(string settingName, out string key, SettingsScope scope, bool create = false) { string[] pieces = settingName.Split('.'); key = pieces[pieces.Length - 1]; ApplicationDataContainer container = scope == SettingsScope.Local ? ApplicationData.Current.LocalSettings : ApplicationData.Current.RoamingSettings; for (int i = 0; i < pieces.Length - 1; i++) { if (container.Containers.ContainsKey(pieces[i])) { container = container.Containers[pieces[i]]; } else if (create) { container = container.CreateContainer(pieces[i], ApplicationDataCreateDisposition.Always); } else { container = null; break; } } return(container); }
public SettingsServiceBase(SettingsStrategies strategy, string folderName, bool createFolderIfNotExists) { _strategy = strategy; Helper = new SettingsHelper(); switch (strategy) { case SettingsStrategies.Local: _container = ApplicationData.Current.LocalSettings; break; case SettingsStrategies.Roam: _container = ApplicationData.Current.RoamingSettings; break; default: throw new ArgumentException($"Unsupported Settings Strategy: {strategy}", nameof(strategy)); } if (!string.IsNullOrWhiteSpace(folderName)) { try { _container = _container.CreateContainer(folderName, createFolderIfNotExists ? ApplicationDataCreateDisposition.Always : ApplicationDataCreateDisposition.Existing); } catch (Exception) { throw new KeyNotFoundException($"No folder exists named '{folderName}'"); } } }
/// <summary> /// Создает новый контейнер указанного типа или возвращает существующий /// </summary> /// <typeparam name="TContainer">Тип контейнера</typeparam> /// <param name="name"></param> /// <returns></returns> public TContainer GetContainer <TContainer>(string name) where TContainer : SettingsStorageContainer, new() { if (_containers.ContainsKey(name)) { return((TContainer)_containers[name]); } TContainer container = new TContainer { _container = _container.CreateContainer(name, ApplicationDataCreateDisposition.Always) }; _containers.Add(name, container); return(container); }
/// <summary> /// Initializes AppData model, should be called only once for the app-running-session. /// </summary> public static void AppDataInitialize() { if (!_isInitDone) { try { _dataContainer = ApplicationData.Current.LocalSettings; // Creating container for 'Configuration' data _dataContainer.CreateContainer(SettingsCommands.AppConfiguration, ApplicationDataCreateDisposition.Always); // Setting app specific data if (String.IsNullOrEmpty(GetAppData(ConfigurationNames.DontAskAgainEnergySavingSetting))) { SetAppData(ConfigurationNames.DontAskAgainEnergySavingSetting, false.ToString()); // Configuring default value in case of null value } if (String.IsNullOrEmpty(GetAppData(ConfigurationNames.DisplayEndpointID))) { SetAppData(ConfigurationNames.DisplayEndpointID, string.Empty); // Configuring default value in case of null value } _isInitDone = true; } catch (Exception ex) { throw new Exception("Error in AppData initialization. " + ex.Message); } } }
public DataLocalSettings() { if (!currentLocalSettings.Containers.ContainsKey(containerName)) { currentLocalSettings.CreateContainer(containerName, ApplicationDataCreateDisposition.Always); } }
//Save feedSubscriptionsCollection to Roaming Settings private void SaveFeedSubscriptionsSettings() { try { if (feedSubscriptionsCollection.Count > 0) { ApplicationDataContainer roamingSettings = ApplicationData.Current.RoamingSettings; ApplicationDataContainer container = roamingSettings.CreateContainer("feedSubscriptions", ApplicationDataCreateDisposition.Always); foreach (ApplicationDataCompositeValue myApplicationDataCompositeValue in feedSubscriptionsCollection) { string myKey = myApplicationDataCompositeValue["FeedUri"].ToString(); //If feed not already defined then add it to the container if (!roamingSettings.Containers["feedSubscriptions"].Values.ContainsKey(myKey)) { roamingSettings.Containers["feedSubscriptions"].Values.Add(myKey.ToString(), myApplicationDataCompositeValue); } } } } catch (Exception ex) { Debug.WriteLine(ex.Message); } }
public void SaveShowData(Show show) { ApplicationDataContainer showContainer = settings.CreateContainer(show.Id, ApplicationDataCreateDisposition.Always); showContainer.Values["name"] = show.Name; showContainer.Values["showPath"] = show.ShowPath; foreach (Season season in show.Seasons) { if (season.Number == 0) { continue; } ApplicationDataContainer seasonContainer = showContainer.CreateContainer(season.Name, ApplicationDataCreateDisposition.Always); seasonContainer.Values["number"] = season.Number; foreach (Episode episode in season.Episodes) { ApplicationDataContainer episodeContainer = seasonContainer.CreateContainer(episode.Filename, ApplicationDataCreateDisposition.Always); episodeContainer.Values["number"] = episode.Number; episodeContainer.Values["manuallySet"] = episode.ManuallySet; episodeContainer.Values["episodePath"] = episode.EpisodePath; episodeContainer.Values["originalFilename"] = episode.OriginalFilename; } } }
/// <summary> /// Update a setting value for our application. If the setting does not /// exist, then add the setting. /// </summary> /// <param name="Key"> Key to access the container to the values </param> /// <param name="value"> Value to update to </param> /// <returns></returns> public bool AddOrUpdateValue(string Key, Object value) { bool valueChanged = false; // If the key exists if (settings.Containers.ContainsKey(Key)) { // If the value has changed if (settings.Containers[Key] != value) { // Store the new value settings.Containers[Key].Values[Key] = value; valueChanged = true; } } // Otherwise create the key. else { //settings.Add(Key, value); settings.CreateContainer(Key, Windows.Storage.ApplicationDataCreateDisposition.Always); settings.Containers[Key].Values[Key] = value; valueChanged = true; } return(valueChanged); }
/// <summary> /// 设置设置用新的容器 /// </summary> /// <param name="con">根容器</param> /// <param name="key">键</param> /// <param name="value">值</param> /// <param name="newname">容器名</param> /// <returns>创建后的容器</returns> public ApplicationDataContainer SetSettingValueByNewContainer(ApplicationDataContainer con, string key, string value, string newname) { var ncon = con.CreateContainer(newname, ApplicationDataCreateDisposition.Always); SetSettingValue(ncon, key, value); return(ncon); }
private void _RestoreLayout() { string deviceIdentifier = this.currentDevice.ProductId.ToString() + "_" + this.currentDevice.VendorId; string key = string.Format(HID_SAVE_ID, deviceIdentifier); var settings = ApplicationData.Current.LocalSettings; ApplicationDataContainer settingsContainer = null; ApplicationDataContainer channelContainer = null; try { settingsContainer = settings.CreateContainer(HIDManager.HID_CONTAINER_ID, ApplicationDataCreateDisposition.Existing); channelContainer = settingsContainer.CreateContainer(key, ApplicationDataCreateDisposition.Existing); } catch (Exception e) { #if DEBUG System.Diagnostics.Debug.WriteLine(e.Message); #endif return; } try { ApplicationDataContainer primaryContainer = channelContainer.CreateContainer(PRIM_MAPPING_ID, ApplicationDataCreateDisposition.Existing); this.restoreButtonMap(primaryContainer, this.mapping); } catch (Exception e) { #if DEBUG System.Diagnostics.Debug.WriteLine(e.Message); #endif } try { ApplicationDataContainer secondaryContainer = channelContainer.CreateContainer(SEC_MAPPING_ID, ApplicationDataCreateDisposition.Existing); this.restoreButtonMap(secondaryContainer, this.mappingAlternative); } catch (Exception e) { #if DEBUG System.Diagnostics.Debug.WriteLine(e.Message); #endif } }
// Constructor public PlatformStorage() { // Key-value storage objects ApplicationDataContainer localSettings = ApplicationData.Current.LocalSettings; localSettings.CreateContainer(STORAGE_NAME, ApplicationDataCreateDisposition.Always); appData = localSettings.Containers[STORAGE_NAME]; }
//创建存储容器,需要传入容器的名称 //不考虑嵌套Container public SettingLib CreateContainer(string containerName) { ApplicationDataContainer container = dataSettings.CreateContainer(containerName, ApplicationDataCreateDisposition.Always); tempContainer = container; tempContainerName = containerName; return(this); }
public AppSettings() { _localSettings = ApplicationData.Current.LocalSettings; if (!_localSettings.Containers.ContainsKey(ContainerName)) { _localSettings.CreateContainer(ContainerName, ApplicationDataCreateDisposition.Always); } }
/// <summary> /// 新建一个容器不管键,把全部值tostring放入 /// </summary> /// <typeparam name="TVALUE">值类型</typeparam> /// <param name="con">目标容器</param> /// <param name="values">值列表</param> /// <param name="newname">容器名字</param> /// <returns>返回新建立的容器</returns> public ApplicationDataContainer SetSettingValuesByNewContainer <TVALUE>(ApplicationDataContainer con, IList <TVALUE> values, string newname) where TVALUE : class { var ncon = con.CreateContainer(newname, ApplicationDataCreateDisposition.Always); SetSettingValues(ncon, values); return(ncon); }
//------------------------------------------------------------------------------------- // Class constructor /// <summary> /// Class constructor. Scope is internal so external code cannot create instances. /// </summary> static SettingsManager() { #if !WINDOWS_PHONE // Initialise the _settings object _settings = ApplicationData.Current.LocalSettings; _settings.CreateContainer("main", ApplicationDataCreateDisposition.Always); #endif }
public void Save() { var container = _rootContainer.CreateContainer(SettingsContainerName, ApplicationDataCreateDisposition.Always); container.Values["SID"] = SID; container.Values["LSID"] = LSID; container.Values["Auth"] = Auth; }
internal ParquetUwpFunctions() { ApplicationDataContainer localSettings = ApplicationData.Current.LocalSettings; ParquetContainer = !localSettings.Containers.ContainsKey("ParquetContainer") ? localSettings.CreateContainer("ParquetContainer", ApplicationDataCreateDisposition.Always) : localSettings.Containers["ParquetContainer"]; }
public Settings() { roamingSettings = Windows.Storage.ApplicationData.Current.RoamingSettings; settingsContainer = roamingSettings.CreateContainer("AppSettings", ApplicationDataCreateDisposition.Always); localSettings = Windows.Storage.ApplicationData.Current.LocalSettings; localSettingsContainer = localSettings.CreateContainer("AppSettings", ApplicationDataCreateDisposition.Always); }
public void SaveUserData() { if (!_appSettings.Containers.ContainsKey("AppSettings")) { _appSettings.CreateContainer("AppSettings", Windows.Storage.ApplicationDataCreateDisposition.Always); } if (_appSettings.Containers.ContainsKey("AppSettings")) { if (_appSettings.Containers["AppSettings"].Values.ContainsKey("fb_userid")) { _appSettings.Containers["AppSettings"].Values["fb_userid"] = UserId; } else { _appSettings.Containers["AppSettings"].Values.Add("fb_userid", UserId); } if (_appSettings.Containers["AppSettings"].Values.ContainsKey("fb_username")) { _appSettings.Containers["AppSettings"].Values["fb_username"] = UserName; } else { _appSettings.Containers["AppSettings"].Values.Add("fb_username", UserName); } if (_appSettings.Containers["AppSettings"].Values.ContainsKey("fb_token")) { _appSettings.Containers["AppSettings"].Values["fb_token"] = Token; } else { _appSettings.Containers["AppSettings"].Values.Add("fb_token", Token); } if (_appSettings.Containers["AppSettings"].Values.ContainsKey("fb_token_ex")) { _appSettings.Containers["AppSettings"].Values["fb_token_ex"] = TokenExprite; } else { _appSettings.Containers["AppSettings"].Values.Add("fb_token_ex", TokenExprite); } if (_appSettings.Containers["AppSettings"].Values.ContainsKey("fb_cancel_num")) { _appSettings.Containers["AppSettings"].Values["fb_cancel_num"] = CancelNum; } else { _appSettings.Containers["AppSettings"].Values.Add("fb_cancel_num", CancelNum); } if (_appSettings.Containers["AppSettings"].Values.ContainsKey("fb_request_login")) { _appSettings.Containers["AppSettings"].Values["fb_request_login"] = RequestLogin; } else { _appSettings.Containers["AppSettings"].Values.Add("fb_request_login", RequestLogin); } } }
private SettingPivotViewModel() { ApplicationDataContainer container; if (!localSettings.Containers.TryGetValue("nRFToolboxSetting", out container)) { localSettings.CreateContainer(nRFToolboxSetting, ApplicationDataCreateDisposition.Always); } }
/// <summary> /// Permet de créer un nouveau paramètre qui sera sauvegardé et récupéré /// à la réouverture de l'application /// </summary> /// <param name="key">Clé</param> /// <param name="value"></param> public void creerParametre(string key, object value) { localSettings.CreateContainer(key, ApplicationDataCreateDisposition.Always); if (localSettings.Values[key] == null) { localSettings.Values[key] = value; } }
private void OnStatChanged(object sender, PropertyChangedEventArgs e) { Stat stat = sender as Stat; string container = stat.StatName.ToString(); ApplicationDataContainer storage = ApplicationData.Current.LocalSettings; storage.CreateContainer(container, ApplicationDataCreateDisposition.Always); storage.Containers[container].Values["ComputerAll"] = stat.ComputerAllCount.ToString(); storage.Containers[container].Values["PlayerAll"] = stat.PlayerAllCount.ToString(); }