//------------------------------------------------------------------------------ IEnumerable <string> GetSimpleSettingsNamesImpl(IEnumerable <string> fullSettingsNames) { if (fullSettingsNames == null) { return(null); } var settingsNames = new List <string>(); var serializer = SettingsHelper.GetSerializerDependFromSettingAttributeType(this.Context, typeof(ATTRIBUTE)); var delimeter = SettingNameFormatInfo.GetSettingNameDelimeter(serializer as ISettingsSerializerWishes); foreach (var fullSettingName in fullSettingsNames) { string formatVersionPrefix; string typeInfo; string settingName; var parseResult = SettingNameFormatInfo.Parse(fullSettingName, delimeter, out formatVersionPrefix, out typeInfo, out settingName, SettingNameMode.Dynamic); if (parseResult) { settingsNames.Add(settingName); } } return(settingsNames); }
//------------------------------------------------------------------------------ static bool ContainsObjectSettingImpl <T>(object settings, Expression <Func <ST, T> > value) { SettingBaseAttribute settingBaseAttribute = GetSettingBaseAttribute(value); MemberExpression me = (MemberExpression)value.Body; MemberInfo mi = me.Member; var serializersCache = new Dictionary <Type, KeyValuePair <ISettingsSerializer, bool> >(); var serializer = SettingsHelper.GetSerializerForMemberInfo(settings, GetForegroundSerializer(), mi, ref serializersCache); var serializerSettingName = SettingNameFormatInfo.GetFullSettingName( settings.GetType(), mi, settingBaseAttribute, serializer as ISettingsSerializerWishes, SettingNameMode.Static); bool secure = false; var settingAttribute = settingBaseAttribute as SettingAttribute; if (settingAttribute != null) { secure = settingAttribute.Secure; } var contains = serializer.Contains(serializerSettingName, secure, settingBaseAttribute); return(contains); }
//------------------------------------------------------------------------------ public virtual void DeleteSettings() { lock (m_lockObject) { var serializersCache = new Dictionary <Type, KeyValuePair <ISettingsSerializer, bool> >(); var settingsHelperData = new SettingsHelperData() { SerializersCache = serializersCache }; ProcessDynamicSettings(SettingsEnumerationMode.Delete, ref settingsHelperData); var serializer = SettingsHelper.GetSerializerDependFromSettingAttributeType(this.Context, typeof(ATTRIBUTE)); var wishes = serializer as ISettingsSerializerWishes; var settingsDefaultOrderFullName = SettingNameFormatInfo.GetFullDynamicSettingsDefaultOrderSettingName(wishes, this.Context.GetType()); var settingsCustomOrderFullName = SettingNameFormatInfo.GetFullDynamicSettingsCustomOrderSettingName(wishes, this.Context.GetType()); var inSettingInfo = new SettingInfo(); inSettingInfo.SettingName = settingsDefaultOrderFullName; ProcessArbitraryDynamicSetting(inSettingInfo, SettingsEnumerationMode.Delete, ref settingsHelperData); inSettingInfo.SettingName = settingsCustomOrderFullName; ProcessArbitraryDynamicSetting(inSettingInfo, SettingsEnumerationMode.Delete, ref settingsHelperData); m_dynamicSettings.Clear(); } }
//------------------------------------------------------------------------------ void SaveDynamicSettingsCustomOrder(ISettingsSerializer serializer, Type settingsType, ref SettingsHelperData settingsHelperData) { var settingsCustomOrderSettingName = SettingNameFormatInfo.GetFullDynamicSettingsCustomOrderSettingName(serializer as ISettingsSerializerWishes, settingsType); var simpleSettingsNames = GetSimpleSettingsNamesWithCustomOrder(); SaveDynamicSettingsOrderImpl(settingsCustomOrderSettingName, simpleSettingsNames, serializer, settingsType, ref settingsHelperData); }
//------------------------------------------------------------------------------ public IEnumerable <string> GetDynamicSettingsNames() { var delimeter = SettingNameFormatInfo.GetSettingNameDelimeter(this as ISettingsSerializerWishes); var dynamicSettingsNames = m_Store.GetFileNames(SettingNameFormatInfo.DynamicSettingNamePrefix + delimeter + "*"); return(dynamicSettingsNames); }
//------------------------------------------------------------------------------ IEnumerable <string> GetDynamicSettingsNamesForType(ISettingsSerializer serializer, Type settingsType, bool respectOrder) { IEnumerable <string> result = null; var dynamicSettingsInfo = (IDynamicSettingsInfo)serializer; var delimeter = SettingNameFormatInfo.GetSettingNameDelimeter(serializer as ISettingsSerializerWishes); var settingsTypeInfo = SettingNameFormatInfo.GetSettingsTypeInfo(settingsType, serializer as ISettingsSerializerWishes); var settingsNames = dynamicSettingsInfo.GetDynamicSettingsNames(); var filteredSettingsNames = new List <string>(); foreach (var rawSettingName in settingsNames) { string formatVersion; string typeInfo; string name; bool parseResult = SettingNameFormatInfo.Parse(rawSettingName, delimeter, out formatVersion, out typeInfo, out name, SettingNameMode.Dynamic); if (parseResult) { if (settingsTypeInfo == typeInfo) { filteredSettingsNames.Add(rawSettingName); } } } result = filteredSettingsNames; if (respectOrder) { var settingsOrder = LoadDynamicSettingsDefaultOrder(serializer, settingsType); if (settingsOrder != null) { var fullSettingsNamesCustomOrder = new List <string>(); foreach (var simpleSettingName in settingsOrder) { var fullSettingName = SettingNameFormatInfo.GetFullSettingName(simpleSettingName, serializer as ISettingsSerializerWishes, settingsType, SettingNameMode.Dynamic); fullSettingsNamesCustomOrder.Add(fullSettingName); } // берём только то, что есть в каждой коллекции result = fullSettingsNamesCustomOrder.Intersect(result); } } return(result); }
//------------------------------------------------------------------------------ string CorrectDynamicSettingName(string settingName) { var serializer = SettingsHelper.GetSerializerDependFromSettingAttributeType(this.Context, typeof(ATTRIBUTE)); settingName = SettingNameFormatInfo.GetFullSettingName(settingName, serializer as ISettingsSerializerWishes, this.Context.GetType(), SettingNameMode.Dynamic); return(settingName); }
//------------------------------------------------------------------------------ static string GetFullSettingNameByPatternAndAddPrefix(string settingName, ISettingsSerializerWishes wishes, Type settingsType, SettingNameMode nameMode) { if (settingsType != null) { var settingNamePattern = SettingsBaseConfiguration.SettingsNamePattern; string updatedSettingName; string updatedClassName; string updatedNamespaceName; if (wishes != null) { updatedSettingName = wishes.RemoveInappropriateSymbols(settingName); updatedClassName = wishes.RemoveInappropriateSymbols(settingsType.Name); updatedNamespaceName = wishes.RemoveInappropriateSymbols(settingsType.Namespace); } else { updatedSettingName = settingName; updatedClassName = settingsType.Name; updatedNamespaceName = settingsType.Namespace; } settingNamePattern = settingNamePattern.Replace(SettingsBaseConfiguration.FieldNamePatternName, updatedSettingName); var delimeter = GetSettingNameDelimeter(wishes); settingNamePattern = settingNamePattern.Replace(SettingsBaseConfiguration.DelimeterPatternName, delimeter.ToString()); if (String.IsNullOrEmpty(settingsType.Namespace)) { // remove empty namespace if it doesn't exist settingNamePattern = settingNamePattern.Replace(SettingsBaseConfiguration.NamespacePatternName, ""); } else { settingNamePattern = settingNamePattern.Replace(SettingsBaseConfiguration.NamespacePatternName, updatedNamespaceName); } settingNamePattern = settingNamePattern.Replace(SettingsBaseConfiguration.ClassNamePatternName, updatedClassName); settingName = settingNamePattern; } var fullSettingName = SettingNameFormatInfo.AddSettingNameModeAndVersion(settingName, wishes, nameMode); return(fullSettingName); }
//------------------------------------------------------------------------------ public IEnumerable <string> GetDynamicSettingsNames() { var prefs = GetSharedPreferences(); List <string> dynamicSettingsNames = new List <string>(); foreach (var key in prefs.All.Keys) { if (SettingNameFormatInfo.GetSettingNameMode(key) == SettingNameMode.Dynamic) { dynamicSettingsNames.Add(key); } } return(dynamicSettingsNames); }
//------------------------------------------------------------------------------ public IEnumerable <string> GetDynamicSettingsNames() { var prefs = GetUserDefaults(); List <string> dynamicSettingsNames = new List <string>(); foreach (var key in prefs.ToDictionary().Keys) { var strKey = key.ToString(); if (SettingNameFormatInfo.GetSettingNameMode(strKey) == SettingNameMode.Dynamic) { dynamicSettingsNames.Add(strKey); } } return(dynamicSettingsNames); }
//------------------------------------------------------------------------------ public IEnumerable <string> GetDynamicSettingsNames() { var dynamicSettingsNames = new List <string>(); var settings = GetAppSettings(); foreach (var item in settings.Values) { var settingName = item.Key; if (SettingNameFormatInfo.GetSettingNameMode(settingName) == SettingNameMode.Dynamic) { dynamicSettingsNames.Add(settingName); } } return(dynamicSettingsNames); }
//------------------------------------------------------------------------------ public static string GetSettingsTypeInfo(Type settingsType, ISettingsSerializerWishes wishes) { var delimeter = SettingNameFormatInfo.GetSettingNameDelimeter(wishes); string settingsTypeInfo; if (wishes != null) { var updatedNamespaceName = wishes.RemoveInappropriateSymbols(settingsType.Namespace); var updatedClassName = wishes.RemoveInappropriateSymbols(settingsType.Name); settingsTypeInfo = updatedNamespaceName + delimeter + updatedClassName; } else { settingsTypeInfo = settingsType.Namespace + delimeter + settingsType.Name; } return(settingsTypeInfo); }
//------------------------------------------------------------------------------ IEnumerable <string> LoadDynamicSettingsCustomOrder(ISettingsSerializer serializer, Type settingsClassType) { var settingsCustomOrderFullName = SettingNameFormatInfo.GetFullDynamicSettingsCustomOrderSettingName(serializer as ISettingsSerializerWishes, settingsClassType); return(LoadDynamicSettingsOrderImpl(settingsCustomOrderFullName, serializer, settingsClassType)); }
//------------------------------------------------------------------------------ public static bool ProcessSetting(SettingsObjectInfo settingsObjectInfo, SettingInfo inSettingInfo, SettingsEnumerationMode mode, SettingsHelperData settingsHelperData, out SettingInfo outSettingInfo, FunctionalityHook functionalityHook) { bool processStatus = false; outSettingInfo = new SettingInfo(); SettingBaseAttribute settingBaseAttribute = null; if (settingsObjectInfo.MemberInfo != null) { settingBaseAttribute = settingsObjectInfo.MemberInfo.GetCustomAttribute <SettingBaseAttribute>(); if (settingBaseAttribute == null) { return(false); } } ISettingsSerializer serializer = null; if (settingsObjectInfo.MemberInfo != null) { serializer = GetSerializerForMemberInfo(settingsObjectInfo.Settings, settingsObjectInfo.ForegroundSerializer, settingsObjectInfo.MemberInfo, ref settingsHelperData.SerializersCache); } else { serializer = GetSerializerForSettingAttributeType(settingsObjectInfo.Settings, settingsObjectInfo.ForegroundSerializer, settingsObjectInfo.SettingAttributeType, ref settingsHelperData.SerializersCache); } Debug.Assert(serializer != null); if (settingsObjectInfo.MemberInfo != null) { inSettingInfo.SettingName = SettingNameFormatInfo.GetFullSettingName(settingsObjectInfo.Settings.GetType(), settingsObjectInfo.MemberInfo, settingBaseAttribute, serializer as ISettingsSerializerWishes, SettingNameMode.Static); } if (settingsObjectInfo.MemberInfo != null) { var settingValueType = SettingsSerializer.GetSettingType(settingsObjectInfo.MemberInfo); inSettingInfo.SettingValueType = settingValueType; inSettingInfo.SettingValue = SettingsSerializer.GetSettingValue(settingsObjectInfo.MemberInfo, settingsObjectInfo.Settings); } bool secure = false; var settingSecureAttr = settingBaseAttribute as SettingAttribute; if (settingSecureAttr != null) { secure = settingSecureAttr.Secure; } switch (mode) { case SettingsEnumerationMode.Load: { Wrapper defaultValueWrapper = null; if (settingBaseAttribute != null && settingBaseAttribute.DefaultValueInUse) { var defaultValue = SettingsSerializer.GetDefaultValue(settingBaseAttribute, inSettingInfo.SettingValueType); defaultValueWrapper = new Wrapper() { Value = defaultValue }; } processStatus = SettingsSerializer.Load(serializer, settingBaseAttribute, inSettingInfo.SettingName, secure, defaultValueWrapper, inSettingInfo.SettingValueType, ref outSettingInfo, functionalityHook); // outSettingInfo.SettingValue type was corrected // in the SettingsSerializer.Load method if (processStatus && settingsObjectInfo.MemberInfo != null) { SettingsSerializer.SetSettingValue(settingsObjectInfo.MemberInfo, settingsObjectInfo.Settings, outSettingInfo.SettingValue); } #if __TDD__ SettingsBaseConfiguration.TDDData.SerializerAction(serializer.GetType(), TDDData.SerializerActions.Load, inSettingInfo.SettingName, secure); #endif // __TDD__ break; } case SettingsEnumerationMode.Save: { if (settingsObjectInfo.MemberInfo != null) { inSettingInfo.SettingValue = SettingsSerializer.GetSettingValue(settingsObjectInfo.MemberInfo, settingsObjectInfo.Settings); } processStatus = SettingsSerializer.Save(serializer, settingBaseAttribute, inSettingInfo.SettingName, secure, inSettingInfo.SettingValue, functionalityHook); settingsHelperData.SerializersToSync.Add(serializer); outSettingInfo = inSettingInfo; #if __TDD__ SettingsBaseConfiguration.TDDData.SerializerAction(serializer.GetType(), TDDData.SerializerActions.Save, inSettingInfo.SettingName, secure); #endif // __TDD__ break; } case SettingsEnumerationMode.Delete: { processStatus = SettingsSerializer.Delete(serializer, settingBaseAttribute, inSettingInfo.SettingName, secure, functionalityHook); settingsHelperData.SerializersToSync.Add(serializer); object defaultValue = SettingsSerializer.GetDefaultValue(settingBaseAttribute, inSettingInfo.SettingValueType); outSettingInfo.SettingName = inSettingInfo.SettingName; outSettingInfo.SettingValue = defaultValue; outSettingInfo.SettingDefaultValue = defaultValue; outSettingInfo.SettingValueType = inSettingInfo.SettingValueType; if (processStatus && settingsObjectInfo.MemberInfo != null) { SettingsSerializer.SetSettingValue(settingsObjectInfo.MemberInfo, settingsObjectInfo.Settings, defaultValue); } #if __TDD__ SettingsBaseConfiguration.TDDData.SerializerAction(serializer.GetType(), TDDData.SerializerActions.Delete, inSettingInfo.SettingName, secure); #endif // __TDD__ break; } case SettingsEnumerationMode.LoadDefaults: { Debug.Assert(inSettingInfo.SettingValueType != null); var defaultValue = SettingsSerializer.GetDefaultValue(settingBaseAttribute, inSettingInfo.SettingValueType); if (settingsObjectInfo.MemberInfo != null) { SettingsSerializer.SetSettingValue(settingsObjectInfo.MemberInfo, settingsObjectInfo.Settings, defaultValue); } outSettingInfo.SettingName = inSettingInfo.SettingName; outSettingInfo.SettingValue = defaultValue; outSettingInfo.SettingDefaultValue = defaultValue; outSettingInfo.SettingValueType = inSettingInfo.SettingValueType; processStatus = true; #if __TDD__ SettingsBaseConfiguration.TDDData.SerializerAction(serializer.GetType(), TDDData.SerializerActions.LoadDefaults, inSettingInfo.SettingName, secure); #endif // __TDD__ break; } default: Debug.Assert(false); throw new NotImplementedException(String.Format("Not implemented for '{0}' mode", mode)); } return(processStatus); }