示例#1
0
        //------------------------------------------------------------------------------
        public static object MakeDynamicSetting(SettingInfo inSettingInfo)
        {
            var simpleValue = SettingsSerializerHelper.SimplifyObject(inSettingInfo.SettingValue);
            var stringValue = SettingsSerializerHelper.ConvertUsingTypeConverter <String>(simpleValue);

            return(stringValue);
        }
示例#2
0
        public static NSObject ToNSObject(this Object obj)
        {
            var simpleObj = SettingsSerializerHelper.SimplifyObject(obj);

            Debug.Assert(simpleObj != null);

            return(NSObject.FromObject(simpleObj));
        }
        //------------------------------------------------------------------------------
        public void Save(string settingName, SettingBaseAttribute attr, object value)
        {
            var simpleValue = SettingsSerializerHelper.SimplifyObject(value);
            var stringValue = SettingsSerializerHelper.ConvertUsingTypeConverter <String>(simpleValue);

            SecStatusCode eCode = KeyChainUtils.SetPasswordForUsername(
                settingName,
                stringValue,
                m_serviceName,
                m_secAccessible,
                m_synchronizable);

            if (eCode == SecStatusCode.Success)
            {
                InternalConfiguration.PlatformHelper.Log(LogLevel.Info,
                                                         "KeyChainSerializer.Save - success",
                                                         settingName);
            }
            else
            {
                InternalConfiguration.PlatformHelper.Log(LogLevel.Error,
                                                         "KeyChainSerializer.Save - error",
                                                         String.Format("Setting name is {0}. Error code is {1}",
                                                                       settingName,
                                                                       eCode));
            }

            // keychain error handling from Xamarin.Auth
            // https://github.com/xamarin/Xamarin.Auth/blob/master/source/Core/Xamarin.Auth.XamarinIOS/AccountStore/KeyChainAccountStore.Aync.cs
            if (eCode != SecStatusCode.Success)
            {
                StringBuilder sb = new StringBuilder("error = ");
                sb.AppendLine("Could not save value to KeyChain: " + eCode);
                sb.AppendLine("Add Empty Entitlements.plist ");
                sb.AppendLine("File /+ New file /+ iOS /+ Entitlements.plist");

                /*
                 *  Error: Could not save account to KeyChain -- iOS 10 #128
                 *  https://github.com/xamarin/Xamarin.Auth/issues/128
                 *  https://bugzilla.xamarin.com/show_bug.cgi?id=43514
                 */
                if ((int)eCode == -34018)
                {
                    // http://stackoverflow.com/questions/38456471/secitemadd-always-returns-error-34018-in-xcode-8-in-ios-10-simulator
                    // NOTE: code was not copy/pasted! That was iOS sample

                    sb.AppendLine("SecKeyChain.Add returned : " + eCode);
                    sb.AppendLine("1. Add Keychain Access Groups to the Entitlements file.");
                    sb.AppendLine("2. Turn on the Keychain Sharing switch in the Capabilities section in the app.");
                }

                string msg = sb.ToString();

                throw new ExceptionForUser(new Exception(msg));
            }
        }
示例#4
0
        //------------------------------------------------------------------------------
        public void Save(string settingName, SettingBaseAttribute attr, object value)
        {
            var simpleObj = SettingsSerializerHelper.SimplifyObject(value);

            var prefs   = GetUserDefaults();
            var nsValue = simpleObj.ToNSObject();

            prefs[settingName] = nsValue;

            InternalConfiguration.PlatformHelper.Log(LogLevel.Info,
                                                     "UserDefaultsSerializer.Save - success",
                                                     String.Format("Setting name is {0}; Value is {1}",
                                                                   settingName,
                                                                   nsValue != null ? nsValue.ToString() : "null"));
        }
        //------------------------------------------------------------------------------
        public void Save(string settingName, SettingBaseAttribute attr, object value)
        {
            settingName = SettingNamePrefix + settingName;

            var simpleValue = SettingsSerializerHelper.SimplifyObject(value);
            var stringValue = SettingsSerializerHelper.ConvertUsingTypeConverter <String>(simpleValue);

            var binaryData = Encoding.ASCII.GetBytes(stringValue);

            var entropy       = SettingsConfiguration.SecureSettingsAdditionalEntropy;
            var encryptedData =
                ProtectedData.Protect(binaryData, entropy, SettingsConfiguration.SecureSettingsScope);

            string encryptedBase64StringData = Convert.ToBase64String(encryptedData);

            m_Store.Save(settingName, attr, encryptedBase64StringData);
        }
示例#6
0
        //------------------------------------------------------------------------------
        public void Save(string settingName, SettingBaseAttribute attr, object value)
        {
            var simpleValue = SettingsSerializerHelper.SimplifyObject(value);
            var stringValue = SettingsSerializerHelper.ConvertUsingTypeConverter <String>(simpleValue);

            using (var stream = m_Store.OpenFile(settingName, FileMode.Create, FileAccess.Write))
            {
                using (var sw = new StreamWriter(stream))
                {
                    sw.Write(stringValue);
                }
            }

            InternalConfiguration.PlatformHelper.Log(LogLevel.Info,
                                                     "IsolatedStorageSerializer.Save - success",
                                                     String.Format("setting is {0}, value is {1}",
                                                                   settingName,
                                                                   stringValue != null ? stringValue : "null"));
        }
        //------------------------------------------------------------------------------
        public void Save(string settingName, SettingBaseAttribute attr, object value)
        {
            if (m_editor == null)
            {
                var prefs = GetSharedPreferences();
                m_editor = prefs.Edit();
            }

            object saveValue = value;

            if (value is bool)
            {
                m_editor.PutBoolean(settingName, (bool)value);
            }
            else if (value is int)
            {
                m_editor.PutInt(settingName, (int)value);
            }
            else if (value is long)
            {
                m_editor.PutLong(settingName, (long)value);
            }
            else if (value is float)
            {
                m_editor.PutFloat(settingName, (float)value);
            }
            else
            {
                var simpleValue = SettingsSerializerHelper.SimplifyObject(value);
                var stringValue = SettingsSerializerHelper.ConvertUsingTypeConverter <String>(simpleValue);

                saveValue = stringValue;

                m_editor.PutString(settingName, stringValue);
            }

            InternalConfiguration.PlatformHelper.Log(LogLevel.Info,
                                                     "SharedPreferencesSerializer.Save - success",
                                                     String.Format("Setting is {0}. Value is {1}",
                                                                   settingName,
                                                                   saveValue != null ? saveValue.ToString() : "null"));
        }
        //------------------------------------------------------------------------------
        public void Save(string settingName, SettingBaseAttribute attr, object value)
        {
            var simpleValue = SettingsSerializerHelper.SimplifyObject(value);
            var stringValue = SettingsSerializerHelper.ConvertUsingTypeConverter <String>(simpleValue);

            bool status = m_keyChainUtils.SaveKey(settingName, stringValue);

            if (status)
            {
                InternalConfiguration.PlatformHelper.Log(LogLevel.Info,
                                                         "KeyChainSerializer.Save - success",
                                                         settingName);
            }
            else
            {
                InternalConfiguration.PlatformHelper.Log(LogLevel.Error,
                                                         "KeyChainSerializer.Save - error",
                                                         settingName);
            }
        }