コード例 #1
0
 public bool GetRecordOnStart()
 {
     if (Preference.Contains("record_on_start"))
     {
         return(Preference.Get <bool>("record_on_start"));
     }
     return(false);
 }
コード例 #2
0
 public bool GetRecordOnResume()
 {
     if (Preference.Contains("record_on_resume"))
     {
         return(Preference.Get <bool>("record_on_resume"));
     }
     return(false);
 }
コード例 #3
0
 public bool GetVibrateFeedback()
 {
     if (Preference.Contains("vibrate_feedback"))
     {
         return(Preference.Get <bool>("vibrate_feedback"));
     }
     return(true);
 }
コード例 #4
0
ファイル: SettingsImpl.cs プロジェクト: tomarcd/shiny
        public override T Get <T>(string key, T defaultValue = default)
        {
            if (!Preference.Contains(key))
            {
                return(defaultValue);
            }

            return(Preference.Get <T>(key));
        }
コード例 #5
0
ファイル: SettingsImpl.cs プロジェクト: tomarcd/shiny
 protected override void NativeRemove(string[] keys)
 {
     foreach (var key in keys)
     {
         if (Preference.Contains(key))
         {
             Preference.Remove(key);
         }
     }
 }
コード例 #6
0
 /// <summary>
 /// Removes a desired key from the settings
 /// </summary>
 /// <param name="key">Key for setting</param>
 /// <param name="fileName">Prefix for the key</param>
 public void Remove(string key, string fileName = null)
 {
     lock (locker)
     {
         var prefkey = GetFullPrefKey(key, fileName);
         if (Preference.Contains(prefkey))
         {
             Preference.Remove(prefkey);
         }
     }
 }
コード例 #7
0
ファイル: Preferences.tizen.cs プロジェクト: sung-su/maui
 public void Remove(string key, string sharedName)
 {
     lock (locker)
     {
         var fullKey = GetFullKey(key, sharedName);
         if (Preference.Contains(fullKey))
         {
             Preference.Remove(fullKey);
         }
     }
 }
コード例 #8
0
 public static void Default()
 {
     Preference.RemoveAll();
     if (!Preference.Contains(SettingsNames.TemperatureTypeSetting))
     {
         SettingsVariables.TemperatureType = TemperatureType.C;
     }
     if (!Preference.Contains(SettingsNames.already_started))
     {
         SettingsVariables.already_started = false;
     }
 }
コード例 #9
0
        /// <summary>
        /// Returns a value that indicates whether a specified key exists in the <see cref="ApplicationDataContainerSettings"/>.
        /// </summary>
        /// <param name="key">The key to check for 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 ContainsKey(string key)
        {
#if WINDOWS_UWP || WINDOWS_APP || WINDOWS_PHONE_APP || WINDOWS_PHONE_81
            return(_settings.ContainsKey(key));
#elif __ANDROID__ || WINDOWS_PHONE || __UNIFIED__
            return(DoContainsKey(key));
#elif TIZEN
            return(Preference.Contains(key));
#else
            throw new PlatformNotSupportedException();
#endif
        }
コード例 #10
0
        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));
        }
コード例 #11
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;
        }
コード例 #12
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;
            }
        }
コード例 #13
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)));
     }
 }
コード例 #14
0
        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);
            }
        }
コード例 #15
0
 /// <summary>
 /// Check if the specified key exists or not
 /// </summary>
 /// <param name="key">key string</param>
 /// <returns>true if it exists</returns>
 public bool Contain(string key)
 {
     return(Preference.Contains(key));
 }
コード例 #16
0
ファイル: SettingsImpl.cs プロジェクト: tomarcd/shiny
 public override bool Contains(string key)
 => Preference.Contains(key);