コード例 #1
0
ファイル: ChoActivator.cs プロジェクト: neuli1980/ChoETL
        private static Dictionary <string, ChoRandomGenerator> GetRandomGenerators(ChoIniFile iniFile)
        {
            if (_randomGeneratorsCache.ContainsKey(iniFile.Key))
            {
                return(_randomGeneratorsCache[iniFile.Key]);
            }

            lock (_rgLock)
            {
                if (_randomGeneratorsCache.ContainsKey(iniFile.Key))
                {
                    return(_randomGeneratorsCache[iniFile.Key]);
                }

                Dictionary <string, ChoRandomGenerator> dict = new Dictionary <string, ChoRandomGenerator>();
                ChoIniFile                  randomIniFile    = iniFile.GetSection("RANDOM");
                ChoRandomGenerator          ra = null;
                Dictionary <string, string> iniKeyValuesDict = randomIniFile.KeyValuesDict;
                foreach (string fieldName in iniKeyValuesDict.Keys)
                {
                    ra = GetRandomObject(fieldName, randomIniFile.GetValue <string>(fieldName));
                    dict.Add(fieldName, ra);
                }

                _randomGeneratorsCache.Add(iniFile.Key, dict);
                return(_randomGeneratorsCache[iniFile.Key]);
            }
        }
コード例 #2
0
        public ChoFileHeaderAttribute GetFileHeaderAttribute(ChoIniFile iniFile)
        {
            if (_headerAttr != null)
            {
                return(_headerAttr);
            }

            lock (_padlock)
            {
                if (_headerAttr != null)
                {
                    return(_headerAttr);
                }

                _headerAttr = ChoFileHeaderAttribute.Default;
                ChoIniFile iniFile1 = iniFile.GetSection("FILE_HEADER");
                _headerAttr.FieldValueJustification = iniFile1.GetValue <ChoFieldValueJustification>("FieldValueJustification", _headerAttr.FieldValueJustification, true);
                _headerAttr.FieldValueTrimOption    = iniFile1.GetValue <ChoFieldValueTrimOption>("FieldValueTrimOption", _headerAttr.FieldValueTrimOption, true);
                _headerAttr.FillChar = iniFile1.GetValue <char>("FillChar", _headerAttr.FillChar, true);
                _headerAttr.Truncate = iniFile1.GetValue <bool>("Truncate", _headerAttr.Truncate, true);
            }

            return(_headerAttr);
        }
コード例 #3
0
        private void InitIsLockedCache(Type declaringType)
        {
            if (!_turnOnMetaDataCache)
            {
                return;
            }

            ChoIniFile iniFile = ChoIniFile.New(declaringType.FullName);

            if (!_isLockedCache.ContainsKey(declaringType))
            {
                lock (_padlock)
                {
                    if (!_isLockedCache.ContainsKey(declaringType))
                    {
                        _isLockedCache.Add(declaringType, iniFile.GetValue <bool>("IsLocked"));
                    }
                }
            }
        }
コード例 #4
0
        private void LoadConverterParams(Type declaringType)
        {
            ChoIniFile iniFile = GetIniSection(declaringType, "FORMATTER");

            var                dict            = new Dictionary <string, object[]>();
            string             parameters      = null;
            ChoMemberAttribute memberAttribute = null;

            foreach (MemberInfo memberInfo in ChoType.GetMembers(declaringType))
            {
                memberAttribute = ChoType.GetAttribute <ChoMemberAttribute>(memberInfo);
                if (memberAttribute == null)
                {
                    continue;
                }

                try
                {
                    if (_turnOnMetaDataCache)
                    {
                        parameters = iniFile.GetValue(memberInfo.Name);
                    }

                    List <object> p = new List <object>();
                    if (!parameters.IsNullOrWhiteSpace())
                    {
                        foreach (string kv in parameters.SplitNTrim(';'))
                        {
                            p.Add(kv.SplitNTrim(','));
                        }
                    }

                    dict.Add(memberInfo.Name, parameters.IsNullOrWhiteSpace() ? null : p.ToArray());
                }
                catch (Exception ex)
                {
                    ChoETLFramework.WriteLog(ChoETLFramework.Switch.TraceError, "Failed to retrieve converter params for '{0}' member type from INI file. {1}".FormatString(ChoType.GetMemberName(memberInfo), ex.Message));
                }
            }
            _converterParams.Add(declaringType, dict);
        }
コード例 #5
0
        private void LoadIsRequireds(Type declaringType)
        {
            ChoIniFile iniFile = GetIniSection(declaringType, "REQUIRED");

            var  dict       = new Dictionary <string, bool>();
            bool isRequired = false;
            ChoMemberAttribute memberAttribute = null;

            foreach (MemberInfo memberInfo in ChoType.GetMembers(declaringType))
            {
                memberAttribute = ChoType.GetAttribute <ChoMemberAttribute>(memberInfo);
                if (memberAttribute == null)
                {
                    continue;
                }

                try
                {
                    if (_turnOnMetaDataCache)
                    {
                        isRequired = iniFile.GetValue(memberInfo.Name, memberAttribute.IsRequired, _isLockedCache[declaringType]);
                    }
                    else
                    {
                        isRequired = memberAttribute.IsRequired;
                    }

                    dict.Add(memberInfo.Name, isRequired);
                }
                catch (Exception ex)
                {
                    ChoETLFramework.WriteLog(ChoETLFramework.Switch.TraceError, "Incorrect IsRequired value specified for '{0}' member type in INI file. Defaulted to false. {1}".FormatString(ChoType.GetMemberName(memberInfo), ex.Message));
                }
            }

            _isReqCache.Add(declaringType, dict);
        }
コード例 #6
0
        private void LoadDefaults(Type declaringType)
        {
            ChoIniFile iniFile = GetIniSection(declaringType, "DEFAULT_VALUE");

            var    dict         = new Dictionary <string, object>();
            object defaultValue = null;
            string memberName   = null;

            foreach (PropertyDescriptor pd in TypeDescriptor.GetProperties(declaringType).AsTypedEnumerable <PropertyDescriptor>().Where(pd => !pd.Attributes.OfType <ChoIgnoreMemberAttribute>().Any()))
            {
                try
                {
                    memberName = pd.Name;
                    if (_turnOnMetaDataCache)
                    {
                        defaultValue = iniFile.GetValue(pd.Name, ChoType.GetDefaultValue(pd), _isLockedCache[declaringType]);
                    }
                    else
                    {
                        defaultValue = ChoType.GetDefaultValue(pd);
                    }

                    if (defaultValue is string)
                    {
                        defaultValue = ((string)defaultValue).ExpandProperties();
                    }

                    defaultValue = ChoConvert.ConvertFrom(defaultValue, pd.PropertyType);

                    dict.Add(pd.Name, defaultValue);
                }
                catch (Exception ex)
                {
                    ChoETLFramework.WriteLog(ChoETLFramework.Switch.TraceError, "Error while converting default value '{0}' to '{1}' member type. {2}".FormatString(defaultValue, ChoType.GetMemberName(pd), ex.Message));
                }
            }

            foreach (FieldInfo memberInfo in ChoType.GetFields(declaringType))
            {
                try
                {
                    memberName = memberInfo.Name;
                    if (_turnOnMetaDataCache)
                    {
                        defaultValue = iniFile.GetValue(memberInfo.Name, ChoType.GetDefaultValue(memberInfo), _isLockedCache[declaringType]);
                    }
                    else
                    {
                        defaultValue = ChoType.GetDefaultValue(memberInfo);
                    }

                    if (defaultValue is string)
                    {
                        defaultValue = ((string)defaultValue).ExpandProperties();
                    }

                    defaultValue = ChoConvert.ConvertFrom(defaultValue, memberInfo.FieldType);

                    dict.Add(memberInfo.Name, defaultValue);
                }
                catch (Exception ex)
                {
                    ChoETLFramework.WriteLog(ChoETLFramework.Switch.TraceError, "Error while converting default value '{0}' to '{1}' member type. {2}".FormatString(defaultValue, ChoType.GetMemberName(memberInfo), ex.Message));
                }
            }

            _defaultsCache.Add(declaringType, dict);
        }