Beispiel #1
0
        protected override object NativeGet(Type type, string key)
        {
            //type = type.Unwrap();
            if (type == typeof(string))
            {
                return(Preference.Get <string>(key));
            }

            if (type == typeof(long))
            {
                return(Preference.Get <long>(key));
            }

            if (type == typeof(int))
            {
                return(Preference.Get <int>(key));
            }

            if (type == typeof(bool))
            {
                return(Preference.Get <bool>(key));
            }

            throw new ArgumentException("Invalid Type - " + type.FullName);
        }
Beispiel #2
0
        public T Get <T>(string key, T defaultValue, string sharedName)
        {
            lock (locker)
            {
                var value   = defaultValue;
                var fullKey = GetFullKey(key, sharedName);
                if (Preference.Contains(fullKey))
                {
                    switch (defaultValue)
                    {
                    case int i:
                    case bool b:
                    case long l:
                    case double d:
                    case float f:
                    case string s:
                        value = Preference.Get <T>(fullKey);
                        break;

                    default:
                        // the case when the string is null
                        if (typeof(T) == typeof(string))
                        {
                            value = (T)(object)Preference.Get <string>(fullKey);
                        }
                        break;
                    }
                }
                return(value);
            }
        }
Beispiel #3
0
 public bool GetRecordOnResume()
 {
     if (Preference.Contains("record_on_resume"))
     {
         return(Preference.Get <bool>("record_on_resume"));
     }
     return(false);
 }
Beispiel #4
0
 public bool GetRecordOnStart()
 {
     if (Preference.Contains("record_on_start"))
     {
         return(Preference.Get <bool>("record_on_start"));
     }
     return(false);
 }
Beispiel #5
0
 public bool GetVibrateFeedback()
 {
     if (Preference.Contains("vibrate_feedback"))
     {
         return(Preference.Get <bool>("vibrate_feedback"));
     }
     return(true);
 }
Beispiel #6
0
 public bool GetLargerFont()
 {
     if (Preference.Contains("larger_font"))
     {
         return(Preference.Get <bool>("larger_font"));
     }
     return(false);
 }
Beispiel #7
0
 public bool GetHtmlResponse()
 {
     if (Preference.Contains("html_response"))
     {
         return(Preference.Get <bool>("html_response"));
     }
     return(false);
 }
Beispiel #8
0
 public bool GetSoundFeedback()
 {
     if (Preference.Contains("sound_feedback"))
     {
         return(Preference.Get <bool>("sound_feedback"));
     }
     return(true);
 }
Beispiel #9
0
 public bool GetRawVoiceRecognitionText()
 {
     if (Preference.Contains("raw_voice_recognition"))
     {
         return(Preference.Get <bool>("raw_voice_recognition"));
     }
     return(true);
 }
Beispiel #10
0
        public override T Get <T>(string key, T defaultValue = default)
        {
            if (!Preference.Contains(key))
            {
                return(defaultValue);
            }

            return(Preference.Get <T>(key));
        }
Beispiel #11
0
        protected override IDictionary <string, string> NativeValues()
        {
            var dict = new Dictionary <string, string>(Preference.Keys.Count());

            foreach (var key in Preference.Keys)
            {
                var value = Preference.Get <object>(key);
                dict.Add(key, value.ToString());
            }
            return(dict);
        }
Beispiel #12
0
 /// <summary>
 /// Get value for the specific key
 /// </summary>
 /// <param name="key">key string</param>
 /// <returns>value string</returns>
 public string GetValue(string key)
 {
     lock (_locker)
     {
         try
         {
             return(Preference.Get <string>(key));
         }
         catch (Exception ex)
         {
             Console.WriteLine("[Preference.GetValue] key : " + key + ", exception:" + ex.Message);
             return(null);
         }
     }
 }
Beispiel #13
0
        public static void Save(Preference P, string FileName)
        {
            var X = new XmlSave(FileName);

            X.StartXML("preferences");

            foreach (var ID in P.ID)
            {
                X.StartTag("pref");
                X.Attribute("id", ID);
                X.Attribute("value", P.Get(ID));
                X.EndTag();
            }
            X.EndXML();
            X.Close();
        }
Beispiel #14
0
        public void LoadInfo()
        {
            tokenData = new GoogleTokenData();

            if (!Preference.Contains("access_token") || !Preference.Contains("refresh_token") ||
                !Preference.Contains("issued_date") || !Preference.Contains("expires"))
            {
                isLoggedIn = false;
                return;
            }

            tokenData.access_token  = Preference.Get <string>("access_token");
            tokenData.refresh_token = Preference.Get <string>("refresh_token");
            tokenData.issued_date   = DateTime.ParseExact(Preference.Get <string>("issued_date"), "yyyy-MM-dd HH:mm:ss", null);
            tokenData.expires_in    = Preference.Get <int>("expires");

            isLoggedIn = true;
        }
        public static Task <List <Dialog>?> GetDialogs()
        {
            if (Preference.Contains(DialogsCacheKey))
            {
                try
                {
                    var json   = Preference.Get <string>(DialogsCacheKey);
                    var result = JsonConvert.DeserializeObject <List <Dialog> >(json);
                    return(Task.FromResult <List <Dialog>?>(result));
                }
                catch (Exception e)
                {
                    Logger.Error(e);
                }
            }

            return(Task.FromResult <List <Dialog>?>(null));
        }
Beispiel #16
0
        public DeviceInformation()
        {
            // Check whether STT feature is supported or not
            Information.TryGetValue(Features.STT, out isSpeechRecognitionSupported);
            // Check whether mic is available or not
            Information.TryGetValue(Features.Microphone, out isMicrophoneSupported);
            isFeatureSupported = isSpeechRecognitionSupported && isMicrophoneSupported;

            bool existing = Preference.Contains(LastUsedID);

            if (existing)
            {
                _numbering = Preference.Get <int>(LastUsedID);
            }
            else
            {
                _numbering = 0;
            }
        }
        /// <summary>
        /// Returns a value that indicates whether a specified key exists in the <see cref="ApplicationDataContainerSettings"/>.
        /// If an item with that key exists, the item is retrieved as an out parameter.
        /// </summary>
        /// <param name="key">The key to check for in the <see cref="ApplicationDataContainerSettings"/>.</param>
        /// <param name="value">The item, if it exists.
        /// Contains null if the item does not exist in the <see cref="ApplicationDataContainerSettings"/>.</param>
        /// <returns>true if an item with that key exists in the <see cref="ApplicationDataContainerSettings"/>; otherwise, false.</returns>
        public bool TryGetValue(string key, out object value)
        {
#if WINDOWS_UWP || WINDOWS_APP || WINDOWS_PHONE_APP || WINDOWS_PHONE_81
            return(_settings.TryGetValue(key, out value));
#elif __ANDROID__ || WINDOWS_PHONE || __UNIFIED__
            return(DoTryGetValue(key, out value));
#elif TIZEN
            try
            {
                value = Preference.Get <object>(key);
                return(value != null);
            }
            catch
            {
                value = null;
                return(false);
            }
#else
            throw new PlatformNotSupportedException();
#endif
        }
Beispiel #18
0
 public Task <T> GetDataAsync <T>(string key)
 {
     try
     {
         if (Preference.Contains(key))
         {
             var json = Preference.Get <string>(key);
             var data = JsonConvert.DeserializeObject <T>(json);
             LogUtil.Debug($"Found cached data for {key}");
             return(Task.FromResult(data));
         }
         else
         {
             LogUtil.Debug($"Missed cached data for {key}");
             return(Task.FromResult(default(T)));
         }
     }
     catch (Exception)
     {
         return(Task.FromResult(default(T)));
     }
 }
        T GetValueOrDefaultInternal <T>(string key, T defaultValue = default(T), string fileName = null)
        {
            lock (locker)
            {
                var prefkey = GetFullPrefKey(key, fileName);
                if (!Preference.Contains(prefkey))
                {
                    return(defaultValue);
                }

                Type typeOf = typeof(T);
                if (typeOf.GetTypeInfo().IsGenericType&& typeOf.GetGenericTypeDefinition() == typeof(Nullable <>))
                {
                    typeOf = Nullable.GetUnderlyingType(typeOf);
                }
                object value    = null;
                var    typeCode = Type.GetTypeCode(typeOf);
                switch (typeCode)
                {
                case TypeCode.Decimal:
                    var savedDecimal = Preference.Get <string>(prefkey);
                    value = Convert.ToDecimal(savedDecimal, System.Globalization.CultureInfo.InvariantCulture);
                    break;

                case TypeCode.Boolean:
                    value = Preference.Get <bool>(prefkey);
                    break;

                case TypeCode.Int64:
                    var savedInt64 = Preference.Get <string>(prefkey);
                    value = Convert.ToInt64(savedInt64, System.Globalization.CultureInfo.InvariantCulture);
                    break;

                case TypeCode.Double:
                    value = Preference.Get <double>(prefkey);
                    break;

                case TypeCode.String:
                    value = Preference.Get <string>(prefkey);
                    break;

                case TypeCode.Int32:
                    value = Preference.Get <int>(prefkey);
                    break;

                case TypeCode.Single:
                    var savedSingle = Preference.Get <string>(prefkey);
                    value = Convert.ToSingle(savedSingle, System.Globalization.CultureInfo.InvariantCulture);
                    break;

                case TypeCode.DateTime:
                    var savedTime = Preference.Get <string>(prefkey);
                    if (string.IsNullOrWhiteSpace(savedTime))
                    {
                        value = defaultValue;
                    }
                    else
                    {
                        var ticks = Convert.ToInt64(savedTime, System.Globalization.CultureInfo.InvariantCulture);
                        if (ticks >= 0)
                        {
                            //Old value, stored before update to UTC values
                            value = new DateTime(ticks);
                        }
                        else
                        {
                            //New value, UTC
                            value = new DateTime(-ticks, DateTimeKind.Utc);
                        }
                    }
                    break;

                default:

                    if (defaultValue is Guid)
                    {
                        var outGuid   = Guid.Empty;
                        var savedGuid = Preference.Get <string>(prefkey);
                        if (string.IsNullOrWhiteSpace(savedGuid))
                        {
                            value = outGuid;
                        }
                        else
                        {
                            Guid.TryParse(savedGuid, out outGuid);
                            value = outGuid;
                        }
                    }
                    else
                    {
                        throw new ArgumentException($"Value of type {typeCode} is not supported.");
                    }

                    break;
                }


                return(null != value ? (T)value : defaultValue);
            }
        }