Esempio n. 1
0
 public static T Get <T>(string key, T def)
 {
     if (dict == null)
     {
         return(default(T));
     }
     if (!dict.Contains(key))
     {
         dict[key] = def;
         dict.Save();
     }
     return((T)dict[key]);
 }
Esempio n. 2
0
 private void SaveISS(string in_name, string in_val)
 {
     System.IO.IsolatedStorage.IsolatedStorageSettings iss = System.IO.IsolatedStorage.IsolatedStorageSettings.ApplicationSettings;
     if (iss.Contains(in_name))
     {
         iss.Remove(in_name);
     }
     iss.Add(in_name, in_val);
     iss.Save();
 }
Esempio n. 3
0
 private static void SaveUser(string userName, string password)
 {
     if (userSettings.Contains("user"))
     {
         userSettings["user"] = userName;
     }
     else
     {
         userSettings.Add("user", userName);
     }
     if (userSettings.Contains("pwd"))
     {
         userSettings["pwd"] = password;
     }
     else
     {
         userSettings.Add("pwd", password);
     }
     userSettings.Save();
 }
Esempio n. 4
0
        /// <summary>
        /// It is typically not necessary to call this method since it is automatically called when the value
        /// is changed or when T implements INotifyPropertyChanged or INotifyCollectionChanged. It is only
        /// necessary to call this method when using types that do not implement these interfaces, such as
        /// Dictionary&lt;TKey, TValue&gt;.
        /// </summary>
        public void Save()
        {
#if WINDOWS_PHONE
            if (DesignerProperties.IsInDesignTool)
            {
                return;
            }
#else
            if (Windows.ApplicationModel.DesignMode.DesignModeEnabled)
            {
                return;
            }
#endif

            // Update isolated storage
            object value;
            if (_shouldSerializeValue)
            {
                value = _xmlSerializer.SerializeToString(_value);
            }
            else
            {
                value = _value;
            }


#if WINDOWS_PHONE
            lock (_isolatedSettings)
            {
                _isolatedSettings[_keyName] = value;
                _isolatedSettings.Save();
            }
#else
            _localSettings.Values[_keyName] = value;
#endif

            // Run modified action
            if (_changeAction != null)
            {
                _changeAction(_value);
            }

            _log.Debug("Wrote value for key '{0}'", _keyName);
            _log.Trace("Updated value: '{0}' => {1}", _keyName, value);
        }
        /// <summary>
        /// Sets the value for a setting and saves the settings instance.
        /// </summary>
        /// <param name="sett"></param>
        /// <param name="key"></param>
        /// <param name="value"></param>
        public static void SetValueAndSave(this System.IO.IsolatedStorage.IsolatedStorageSettings sett, string key, object value)
        {
            sett[key] = value;

            sett.Save();
        }
Esempio n. 6
0
        public void StoreOAuthUserInfo()
        {
            //TODO: Change this to have ApplicationDataContainer that should have been passed in.

            //ApplicationData.Current.LocalSettings.DeleteContainer("TwitterAPIMash");

            #if NETFX_CORE
            ApplicationDataContainer appLocalData = ApplicationData.Current.LocalSettings.CreateContainer(CommonProperties.TwitterAPI_DataStorage, ApplicationDataCreateDisposition.Always);
            //Save or Update OAuth values in appLocalData if applicable, so won't have to Re-Authorize
            if (appLocalData.Values.ContainsKey("OAuthConsumerKey"))
            {
                appLocalData.Values["OAuthConsumerKey"] = OAuth.OAuthTypes.OAuthConsumerKey;
            }
            else
            {
                appLocalData.Values.Add("OAuthConsumerKey", OAuth.OAuthTypes.OAuthConsumerKey);
            }

            if (appLocalData.Values.ContainsKey("OAuthConsumerSecret"))
            {
                appLocalData.Values["OAuthConsumerSecret"] = OAuth.OAuthTypes.OAuthConsumerSecret;
            }
            else
            {
                appLocalData.Values.Add("OAuthConsumerSecret", OAuth.OAuthTypes.OAuthConsumerSecret);
            }

            if (appLocalData.Values.ContainsKey("OAuthAccessToken"))
            {
                appLocalData.Values["OAuthAccessToken"] = OAuth.OAuthTypes.OAuthAccessTokenKey;
            }
            else
            {
                appLocalData.Values.Add("OAuthAccessToken", OAuth.OAuthTypes.OAuthAccessTokenKey);
            }

            if (appLocalData.Values.ContainsKey("OAuthAccessSecret"))
            {
                appLocalData.Values["OAuthAccessSecret"] = OAuth.OAuthTypes.OAuthAccessTokenSecretKey;
            }
            else
            {
                appLocalData.Values.Add("OAuthAccessSecret", OAuth.OAuthTypes.OAuthAccessTokenSecretKey);
            }

            if (appLocalData.Values.ContainsKey("OAuthVerifier"))
            {
                appLocalData.Values["OAuthVerifier"] = OAuth.OAuthTypes.OAuthVerifierKey;
            }
            else
            {
                appLocalData.Values.Add("OAuthVerifier", OAuth.OAuthTypes.OAuthVerifierKey);
            }

            if (appLocalData.Values.ContainsKey("UserID"))
            {
                appLocalData.Values["UserID"] = TweetAuthConstants.OAuthUserID;
            }
            else
            {
                appLocalData.Values.Add("UserID", TweetAuthConstants.OAuthUserID);
            }

            if (appLocalData.Values.ContainsKey("UserScreenName"))
            {
                appLocalData.Values["UserScreenName"] = TweetAuthConstants.OAuthUserScreenName;
            }
            else
            {
                appLocalData.Values.Add("UserScreenName", TweetAuthConstants.OAuthUserScreenName);
            }
            #else
            System.IO.IsolatedStorage.IsolatedStorageSettings appData = System.IO.IsolatedStorage.IsolatedStorageSettings.ApplicationSettings;
            if (!appData.Contains(CommonProperties.TwitterAPI_DataStorage))
            {
                appData.Add(CommonProperties.TwitterAPI_DataStorage, new Dictionary <string, string>());
            }

            Dictionary <string, string> appLocalData = appData[CommonProperties.TwitterAPI_DataStorage] as Dictionary <string, string>;

            if (appLocalData.ContainsKey("OAuthConsumerKey"))
            {
                appLocalData["OAuthConsumerKey"] = OAuth.OAuthTypes.OAuthConsumerKey;
            }
            else
            {
                appLocalData.Add("OAuthConsumerKey", OAuth.OAuthTypes.OAuthConsumerKey);
            }

            if (appLocalData.ContainsKey("OAuthConsumerSecret"))
            {
                appLocalData["OAuthConsumerSecret"] = OAuth.OAuthTypes.OAuthConsumerSecret;
            }
            else
            {
                appLocalData.Add("OAuthConsumerSecret", OAuth.OAuthTypes.OAuthConsumerSecret);
            }

            if (appLocalData.ContainsKey("OAuthAccessToken"))
            {
                appLocalData["OAuthAccessToken"] = OAuth.OAuthTypes.OAuthAccessTokenKey;
            }
            else
            {
                appLocalData.Add("OAuthAccessToken", OAuth.OAuthTypes.OAuthAccessTokenKey);
            }

            if (appLocalData.ContainsKey("OAuthAccessSecret"))
            {
                appLocalData["OAuthAccessSecret"] = OAuth.OAuthTypes.OAuthAccessTokenSecretKey;
            }
            else
            {
                appLocalData.Add("OAuthAccessSecret", OAuth.OAuthTypes.OAuthAccessTokenSecretKey);
            }

            if (appLocalData.ContainsKey("OAuthVerifier"))
            {
                appLocalData["OAuthVerifier"] = OAuth.OAuthTypes.OAuthVerifierKey;
            }
            else
            {
                appLocalData.Add("OAuthVerifier", OAuth.OAuthTypes.OAuthVerifierKey);
            }

            if (appLocalData.ContainsKey("UserID"))
            {
                appLocalData["UserID"] = TweetAuthConstants.OAuthUserID;
            }
            else
            {
                appLocalData.Add("UserID", TweetAuthConstants.OAuthUserID);
            }

            if (appLocalData.ContainsKey("UserScreenName"))
            {
                appLocalData["UserScreenName"] = TweetAuthConstants.OAuthUserScreenName;
            }
            else
            {
                appLocalData.Add("UserScreenName", TweetAuthConstants.OAuthUserScreenName);
            }

            appData.Save();
            #endif
        }