//------------------------------------------------------------------------------
        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);
        }
Esempio n. 2
0
        //------------------------------------------------------------------------------
        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);
        }
Esempio n. 3
0
        //------------------------------------------------------------------------------
        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);
        }
        //------------------------------------------------------------------------------
        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);
        }