/// <summary>
        /// Saves a group of items by its key in a composite.
        /// This method should be considered for objects that do not exceed 8k bytes during the lifetime of the application
        /// (refers to <see cref="SaveFileAsync{T}(string, T)"/> for complex/large objects) and for groups of settings which
        /// need to be treated in an atomic way.
        /// </summary>
        /// <typeparam name="T">Type of object saved</typeparam>
        /// <param name="compositeKey">Key of the composite (that contains settings)</param>
        /// <param name="values">Objects to save</param>
        public void Save <T>(string compositeKey, IDictionary <string, T> values)
        {
            if (KeyExists(compositeKey))
            {
                ApplicationDataCompositeValue composite = (ApplicationDataCompositeValue)Settings.Values[compositeKey];

                foreach (KeyValuePair <string, T> setting in values)
                {
                    if (composite.ContainsKey(setting.Key))
                    {
                        composite[setting.Key] = JsonConvert.SerializeObject(setting.Value);
                    }
                    else
                    {
                        composite.Add(setting.Key, JsonConvert.SerializeObject(setting.Value));
                    }
                }
            }
            else
            {
                ApplicationDataCompositeValue composite = new ApplicationDataCompositeValue();
                foreach (KeyValuePair <string, T> setting in values)
                {
                    composite.Add(setting.Key, JsonConvert.SerializeObject(setting.Value));
                }

                Settings.Values[compositeKey] = composite;
            }
        }
 private void setTextBoxValue(ApplicationDataCompositeValue Composite, TextBox tbObject)
 {
     if (Composite.ContainsKey(tbObject.Name))
     {
         tbObject.Text = Composite[tbObject.Name].ToString();
     }
 }
Exemplo n.º 3
0
        /// <inheritdoc />
        public void Save<T>(string compositeKey, IDictionary<string, T> values)
        {
            if (KeyExists(compositeKey))
            {
                ApplicationDataCompositeValue composite = (ApplicationDataCompositeValue)Settings[compositeKey];

                foreach (KeyValuePair<string, T> setting in values)
                {
                    if (composite.ContainsKey(setting.Key))
                    {
                        composite[setting.Key] = _serializer.Serialize(setting.Value);
                    }
                    else
                    {
                        composite.Add(setting.Key, _serializer.Serialize(setting.Value));
                    }
                }

                Settings[compositeKey] = composite;
                Task.Run(() => Set(_extensionId, UserId, compositeKey, composite));
            }
            else
            {
                ApplicationDataCompositeValue composite = new ApplicationDataCompositeValue();
                foreach (KeyValuePair<string, T> setting in values)
                {
                    composite.Add(setting.Key, _serializer.Serialize(setting.Value));
                }

                Settings[compositeKey] = composite;
                Task.Run(() => Set(_extensionId, UserId, compositeKey, composite));
            }
        }
 private void setComboBoxValue(ApplicationDataCompositeValue Composite, ComboBox tbObject)
 {
     if (Composite.ContainsKey(tbObject.Name))
     {
         tbObject.SelectedIndex = (int)Composite[tbObject.Name];
     }
 }
 private void setRadioBoxValue(ApplicationDataCompositeValue Composite, RadioButton rbObject)
 {
     if (Composite.ContainsKey(rbObject.Name) && Composite[rbObject.Name].ToString().Equals("true"))
     {
         rbObject.IsChecked = true;
     }
 }
 private void setCheckBoxValue(ApplicationDataCompositeValue Composite, CheckBox cbObject)
 {
     if (Composite.ContainsKey(cbObject.Name) && Composite[cbObject.Name].ToString().Equals("true"))
     {
         cbObject.IsChecked = true;
     }
 }
Exemplo n.º 7
0
        internal static byte[] GetCacheValue(ApplicationDataCompositeValue composite)
        {
            if (!composite.ContainsKey(CacheValueLength))
            {
                return(null);
            }

            int encyptedValueLength = (int)composite[CacheValueLength];
            int segmentCount        = (int)composite[CacheValueSegmentCount];

            byte[] encryptedValue = new byte[encyptedValueLength];
            if (segmentCount == 1)
            {
                encryptedValue = (byte[])composite[CacheValue + 0];
            }
            else
            {
                for (int i = 0; i < segmentCount - 1; i++)
                {
                    Array.Copy((byte[])composite[CacheValue + i], 0, encryptedValue, i * MaxCompositeValueLength,
                               MaxCompositeValueLength);
                }
            }

            Array.Copy((byte[])composite[CacheValue + (segmentCount - 1)], 0, encryptedValue,
                       (segmentCount - 1) * MaxCompositeValueLength,
                       encyptedValueLength - (segmentCount - 1) * MaxCompositeValueLength);

            return(CryptographyHelper.Decrypt(encryptedValue));
        }
Exemplo n.º 8
0
        private void Initialize(ApplicationDataContainer container, ApplicationDataCompositeValue data, string name = "")
        {
            this.container = container;

            this.PropertyChanged += ROMDatabaseEntry_PropertyChanged;

            this.data = data;

            int  version   = -1;
            bool restoring = data.ContainsKey("version");

            if (restoring)
            {
                version = (int)data["version"];
            }

            if (version < 0)
            {
                data["version"] = version = 0;

                // load version 0 defaults;
                this.data["Name"]       = name;
                this.data["LastPlayed"] = "1337";
            }

            if (version < 1)
            {
                // load version 1 defaults
                data["version"] = 1;

                data["saveSlot"] = 0;
            }

            this.storeData();
        }
        /// <summary>
        /// Determines whether a setting already exists in composite.
        /// </summary>
        /// <param name="compositeKey">Key of the composite (that contains settings)</param>
        /// <param name="key">Key of the setting (that contains object)</param>
        /// <returns><c>true</c> if the setting exists; otherwise, <c>false</c>.</returns>
        public bool KeyExists(string compositeKey, string key)
        {
            if (KeyExists(compositeKey))
            {
                ApplicationDataCompositeValue composite = (ApplicationDataCompositeValue)Settings.Values[compositeKey];
                if (composite != null)
                {
                    return(composite.ContainsKey(key));
                }
            }

            return(false);
        }
        public static InkToolbarPreferences FromCompositeValue(this ApplicationDataCompositeValue preferences)
        {
            var result = new InkToolbarPreferences();

            foreach (var property in GetProperties(result))
            {
                if (preferences.ContainsKey(property.Name))
                {
                    property.SetValue(result, preferences[property.Name]);
                }
            }

            return(result);
        }
Exemplo n.º 11
0
 public void RestoreSettings(ApplicationDataCompositeValue settings)
 {
     if (settings.ContainsKey("MenuButton"))
     {
         if (settings["MenuButton"] != null)
         {
             switch (settings["MenuButton"] as string)
             {
                 case "Search": _lastButton = _searchButton; _lastPanel = _searchPanel; break;
                 case "Bibles": _lastButton = _biblesButton; _lastPanel = _bibleListPanel; break;
                 case "BibleBooks": _lastButton = _biblesBookButton; _lastPanel = _bibleBookListPanel; break;
             }
             _lastButton.IsChecked = true;
             _lastPanel.Visibility = Visibility.Visible;
         }
     }
 }
Exemplo n.º 12
0
        /// <summary>
        /// LoadData from LocalSetting
        /// </summary>
        public string LoadData(string key)
        {
            string value = string.Empty;
            ApplicationDataCompositeValue dict       = null;
            ApplicationDataContainer      appsetting = ApplicationData.Current.RoamingSettings;

            if (appsetting.Values.ContainsKey(conCacheKey))
            {
                dict = (ApplicationDataCompositeValue)appsetting.Values[conCacheKey];
            }
            if (dict != null)
            {
                if (dict.ContainsKey(key))
                {
                    value = dict[key].ToString();
                }
            }
            return(value);
        }
Exemplo n.º 13
0
        /// <summary>
        /// LoadData from LocalSetting
        /// </summary>
        public object LoadData(string key)
        {
            object value = null;
            ApplicationDataCompositeValue dict       = null;
            ApplicationDataContainer      appsetting = ApplicationData.Current.LocalSettings;

            if (appsetting.Values.ContainsKey(conCacheKey))
            {
                dict = (ApplicationDataCompositeValue)appsetting.Values[conCacheKey];
            }
            if (dict != null)
            {
                if (dict.ContainsKey(key))
                {
                    value = dict[key].ToString();
                }
            }
            return(value);
        }
        private async void validateStep1(ApplicationDataCompositeValue result)
        {
            if (result.Count != 1)
            {
                await new MessageDialog("ERROR: Expected 1 user input value, but there were " + result.Count).ShowAsync();
            }

            else if (!result.ContainsKey("message"))
            {
                await new MessageDialog("ERROR: Expected a user input value for 'message', but there was none.").ShowAsync();
            }

            else if (!(result["message"] as string).Equals("Windows 10"))
            {
                await new MessageDialog("ERROR: User input value for 'message' was not 'Windows 10'").ShowAsync();
            }

            else
            {
                stepsControl.Step = int.MaxValue;
                UnregisterBackgroundTask();
            }
        }
        private async void validateStep1(ApplicationDataCompositeValue result)
        {
            if (result.Count != 1)
                await new MessageDialog("ERROR: Expected 1 user input value, but there were " + result.Count).ShowAsync();

            else if (!result.ContainsKey("message"))
                await new MessageDialog("ERROR: Expected a user input value for 'message', but there was none.").ShowAsync();

            else if (!(result["message"] as string).Equals("Windows 10"))
                await new MessageDialog("ERROR: User input value for 'message' was not 'Windows 10'").ShowAsync();

            else
            {
                stepsControl.Step = int.MaxValue;
                UnregisterBackgroundTask();
            }
        }