예제 #1
0
        private void LoadFieldExprs(ChoIniFile iniFile1)
        {
            ChoIniFile iniFile = iniFile1.GetSection("EXPRESSION_FIELD");

            var    dict  = new Dictionary <string, string>();
            string value = null;
            Dictionary <string, string> iniKeyValuesDict = iniFile.KeyValuesDict;

            foreach (string fieldName in iniKeyValuesDict.Keys)
            {
                if (fieldName.IsNullOrWhiteSpace())
                {
                    continue;
                }
                if (!iniKeyValuesDict.ContainsKey(fieldName))
                {
                    continue;
                }

                try
                {
                    value = iniKeyValuesDict[fieldName].ExpandProperties();
                    dict.Add(fieldName, value);
                }
                catch (Exception ex)
                {
                    ChoETLFramework.WriteLog(ChoETLFramework.Switch.TraceError, "Error while loading field expression value '{0}' for '{1}' member. {2}".FormatString(value, fieldName, ex.Message));
                }
            }
            _fieldExprCache.Add(iniFile1.Key, dict);
        }
예제 #2
0
        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]);
            }
        }
예제 #3
0
        private void LoadSequences(ChoIniFile iniFile1)
        {
            ChoIniFile iniFile = iniFile1.GetSection("SEQUENCE_VALUE_GENERATOR");

            var                         dict             = new Dictionary <string, Tuple <IValueConverter, string> >();
            IValueConverter             value            = null;
            Dictionary <string, string> iniKeyValuesDict = iniFile.KeyValuesDict;

            foreach (string fieldName in iniKeyValuesDict.Keys)
            {
                if (fieldName.IsNullOrWhiteSpace())
                {
                    continue;
                }
                if (!iniKeyValuesDict.ContainsKey(fieldName))
                {
                    continue;
                }
                if (dict.ContainsKey(fieldName))
                {
                    continue;
                }

                if (!iniKeyValuesDict[fieldName].IsNullOrWhiteSpace())
                {
                    string val = iniKeyValuesDict[fieldName];

                    string vcType  = null;
                    string vcParam = null;
                    foreach (KeyValuePair <string, string> convParams in val.ToKeyValuePairs())
                    {
                        if (convParams.Key == "Type")
                        {
                            vcType = convParams.Value;
                        }
                        else if (convParams.Key == "Parameter")
                        {
                            vcParam = convParams.Value.Replace('&', ';');
                        }
                    }

                    if (!vcType.IsNullOrWhiteSpace())
                    {
                        try
                        {
                            value = Activator.CreateInstance(ChoType.GetType(vcType)) as IValueConverter;
                            if (value != null)
                            {
                                dict.Add(fieldName, new Tuple <IValueConverter, string>(value, vcParam));
                            }
                        }
                        catch (Exception ex)
                        {
                            ChoETLFramework.WriteLog(ChoETLFramework.Switch.TraceError, "Error while loading format value '{0}' for '{1}' member. {2}".FormatString(value, fieldName, ex.Message));
                        }
                    }
                }
            }
            _seqGeneratorCache.Add(iniFile1.Key, dict);
        }
예제 #4
0
        private void LoadDefaults(ChoIniFile iniFile1)
        {
            ChoIniFile iniFile = iniFile1.GetSection("DEFAULT_VALUE");

            var    dict         = new Dictionary <string, string>();
            string defaultValue = null;
            Dictionary <string, string> iniKeyValuesDict = iniFile.KeyValuesDict;

            foreach (string fieldName in iniKeyValuesDict.Keys)
            {
                if (fieldName.IsNullOrWhiteSpace())
                {
                    continue;
                }
                if (!iniKeyValuesDict.ContainsKey(fieldName))
                {
                    continue;
                }

                try
                {
                    defaultValue = iniKeyValuesDict[fieldName].ExpandProperties();
                    dict.Add(fieldName, defaultValue);
                }
                catch (Exception ex)
                {
                    ChoETLFramework.WriteLog(ChoETLFramework.Switch.TraceError, "Error while converting default value '{0}' for '{1}' member. {2}".FormatString(defaultValue, fieldName, ex.Message));
                }
            }
            _defaultsCache.Add(iniFile1.Key, dict);
        }
예제 #5
0
        private void LoadDataTypes(ChoIniFile iniFile1)
        {
            ChoIniFile iniFile = iniFile1.GetSection("DATATYPE");

            var  dict  = new Dictionary <string, Type>();
            Type value = null;
            Dictionary <string, string> iniKeyValuesDict = iniFile.KeyValuesDict;

            foreach (string fieldName in iniKeyValuesDict.Keys) //GetFieldNames(iniFile1))
            {
                if (fieldName.IsNullOrWhiteSpace())
                {
                    continue;
                }
                if (!iniKeyValuesDict.ContainsKey(fieldName))
                {
                    continue;
                }

                try
                {
                    value = Type.GetType(iniKeyValuesDict[fieldName]);
                    if (value != null)
                    {
                        dict.Add(fieldName, value);
                    }
                }
                catch (Exception ex)
                {
                    ChoETLFramework.WriteLog(ChoETLFramework.Switch.TraceError, "Error while loading format value '{0}' for '{1}' member. {2}".FormatString(value, fieldName, ex.Message));
                }
            }
            _dataTypeCache.Add(iniFile1.Key, dict);
        }
예제 #6
0
        private void LoadFallbacks(ChoIniFile iniFile1)
        {
            ChoIniFile iniFile = iniFile1.GetSection("FALLBACK_VALUE");

            var    dict          = new Dictionary <string, object>();
            object fallbackValue = null;
            Dictionary <string, string> iniKeyValuesDict = iniFile.KeyValuesDict;
            Type fieldType = null;

            foreach (string fieldName in iniKeyValuesDict.Keys)
            {
                if (fieldName.IsNullOrWhiteSpace())
                {
                    continue;
                }
                if (!iniKeyValuesDict.ContainsKey(fieldName))
                {
                    continue;
                }

                try
                {
                    fallbackValue = iniKeyValuesDict[fieldName].ExpandProperties();
                    fieldType     = typeof(string);
                    if (ChoDynamicObjectMemberMetaDataCache.Default.GetDataTypes(iniFile1).ContainsKey(fieldName))
                    {
                        fieldType = ChoDynamicObjectMemberMetaDataCache.Default.GetDataTypes(iniFile1)[fieldName];
                    }

                    //Look for converters and convert the value
                    if (ChoDynamicObjectMemberMetaDataCache.Default.GetValueConverters(iniFile1).ContainsKey(fieldName))
                    {
                        foreach (Tuple <IValueConverter, string> vcPair in ChoDynamicObjectMemberMetaDataCache.Default.GetValueConverters(iniFile1)[fieldName])
                        {
                            if (!vcPair.Item1.IsNull())
                            {
                                fallbackValue = vcPair.Item1.Convert(fallbackValue, fieldType, vcPair.Item2, null);
                            }
                        }
                    }

                    fallbackValue = Convert.ChangeType(fallbackValue, fieldType);

                    dict.Add(fieldName, fallbackValue);
                }
                catch (Exception ex)
                {
                    ChoETLFramework.WriteLog(ChoETLFramework.Switch.TraceError, "Error while converting fallback value '{0}' for '{1}' member. {2}".FormatString(fallbackValue, fieldName, ex.Message));
                }
            }
            _fallbackCache.Add(iniFile1.Key, dict);
        }
예제 #7
0
        private void LoadFixedLengthRecordFieldOptions(ChoIniFile iniFile1)
        {
            ChoIniFile iniFile = iniFile1.GetSection("FIXED_LENGTH_RECORD_FIELD");

            var dict = new OrderedDictionary();
            ChoFixedLengthRecordFieldAttribute value;
            Dictionary <string, string>        iniKeyValuesDict = iniFile.KeyValuesDict;

            if (iniKeyValuesDict.Count == 0)
            {
                throw new ApplicationException("Missing fixed length field names in the '{0}' ini file.".FormatString(iniFile1.FilePath));
            }
            foreach (string fieldName in iniKeyValuesDict.Keys) //GetFieldNames(iniFile1))
            {
                if (fieldName.IsNullOrWhiteSpace())
                {
                    continue;
                }
                if (!iniKeyValuesDict.ContainsKey(fieldName))
                {
                    continue;
                }

                try
                {
                    value = new ChoFixedLengthRecordFieldAttribute();
                    value.FieldValueTrimOption    = ChoFieldValueTrimOption.Trim;
                    value.FieldValueJustification = ChoFieldValueJustification.Left;
                    foreach (KeyValuePair <string, string> kvp in iniKeyValuesDict[fieldName].ToKeyValuePairs())
                    {
                        try
                        {
                            ChoType.ConvertNSetMemberValue(value, kvp.Key, kvp.Value);
                        }
                        catch (Exception ex)
                        {
                            ChoETLFramework.WriteLog(ChoETLFramework.Switch.TraceError, "Error while loading record field option '{0}' for '{1}' field. {2}".FormatString(iniKeyValuesDict[fieldName], fieldName, ex.Message));
                        }
                    }
                    value.Validate();
                    dict.Add(fieldName, value);
                }
                catch (Exception ex)
                {
                    throw new ApplicationException("[FieldName: {0}] - {1}".FormatString(fieldName, ex.Message));
                }
            }
            _flRecordFieldOptionCache.Add(iniFile1.Key, dict);
        }
예제 #8
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);
        }
예제 #9
0
        private void LoadDbRecordFieldOptions(ChoIniFile iniFile1)
        {
            ChoIniFile iniFile = iniFile1.GetSection("Db_RECORD_FIELD");

            var dict = new Dictionary <string, ChoDbRecordFieldAttribute>();
            ChoDbRecordFieldAttribute   value;
            Dictionary <string, string> iniKeyValuesDict = iniFile.KeyValuesDict;

            foreach (string fieldName in iniKeyValuesDict.Keys)
            {
                if (fieldName.IsNullOrWhiteSpace())
                {
                    continue;
                }
                if (!iniKeyValuesDict.ContainsKey(fieldName))
                {
                    continue;
                }

                value = new ChoDbRecordFieldAttribute();
                foreach (KeyValuePair <string, string> kvp in iniKeyValuesDict[fieldName].ToKeyValuePairs())
                {
                    try
                    {
                        ChoType.ConvertNSetMemberValue(value, kvp.Key, kvp.Value);
                    }
                    catch (Exception ex)
                    {
                        ChoETLFramework.WriteLog(ChoETLFramework.Switch.TraceError, "Error while loading record field '{0}' for '{1}' field. {2}".FormatString(iniKeyValuesDict[fieldName], fieldName, ex.Message));
                    }
                }
                value.Validate();
                dict.Add(fieldName, value);
            }
            _dbRecordFieldOptionCache.Add(iniFile1.Key, dict);
        }
예제 #10
0
        private void LoadValueConverters(ChoIniFile iniFile1)
        {
            ChoIniFile iniFile = iniFile1.GetSection("CONVERTER");

            var                         dict             = new Dictionary <string, List <Tuple <IValueConverter, string> > >();
            IValueConverter             value            = null;
            Dictionary <string, string> iniKeyValuesDict = iniFile.KeyValuesDict;

            foreach (string fieldName in iniKeyValuesDict.Keys) //GetFieldNames(iniFile1))
            {
                if (fieldName.IsNullOrWhiteSpace())
                {
                    continue;
                }
                if (!iniKeyValuesDict.ContainsKey(fieldName))
                {
                    continue;
                }
                if (dict.ContainsKey(fieldName))
                {
                    continue;
                }

                dict.Add(fieldName, new List <Tuple <IValueConverter, string> >());

                if (!iniKeyValuesDict[fieldName].IsNullOrWhiteSpace())
                {
                    foreach (string val in iniKeyValuesDict[fieldName].SplitNTrim(";"))
                    {
                        if (val.IsNullOrWhiteSpace())
                        {
                            continue;
                        }

                        string vcType  = null;
                        string vcParam = null;
                        foreach (KeyValuePair <string, string> convParams in val.ToKeyValuePairs('&'))
                        {
                            if (convParams.Key == "Type")
                            {
                                vcType = convParams.Value;
                            }
                            else if (convParams.Key == "Parameter")
                            {
                                vcParam = convParams.Value;
                            }
                        }

                        if (!vcType.IsNullOrWhiteSpace())
                        {
                            try
                            {
                                value = Activator.CreateInstance(ChoType.GetType(vcType)) as IValueConverter;
                                if (value != null)
                                {
                                    dict[fieldName].Add(new Tuple <IValueConverter, string>(value, vcParam));
                                }
                            }
                            catch (Exception ex)
                            {
                                ChoETLFramework.WriteLog(ChoETLFramework.Switch.TraceError, "Error while loading format value '{0}' for '{1}' member. {2}".FormatString(value, fieldName, ex.Message));
                            }
                        }
                    }
                }
            }
            _valueConverterCache.AddOrUpdate(iniFile1.Key, dict);
        }
예제 #11
0
 public static ChoIniFile OpenFixedLengthRecordFieldSection(this ChoIniFile @this)
 {
     ChoGuard.ArgumentNotNull(@this, "IniFile");
     return(@this.GetSection("FIXED_LENGTH_RECORD_FIELD"));
 }
예제 #12
0
 public static ChoIniFile OpenMapReduceParamsSection(this ChoIniFile @this)
 {
     ChoGuard.ArgumentNotNull(@this, "IniFile");
     return(@this.GetSection("MAP_REDUCE_PARAMS"));
 }
예제 #13
0
 public static ChoIniFile OpenTextRecordParamsSection(this ChoIniFile @this)
 {
     ChoGuard.ArgumentNotNull(@this, "IniFile");
     return(@this.GetSection("TEXT_RECORD_PARAMS"));
 }