Пример #1
0
        private void LoadCSVRecordFieldOptions(ChoIniFile iniFile1)
        {
            ChoIniFile iniFile = iniFile1.GetSection("CSV_RECORD_FIELD");

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

            if (iniKeyValuesDict.Count == 0)
            {
                throw new ApplicationException("Missing CSV 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;
                }

                value = new ChoCSVRecordFieldAttribute(0);
                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 '{0}' for '{1}' field. {2}".FormatString(iniKeyValuesDict[fieldName], fieldName, ex.Message));
                    }
                }
                value.Validate();
                dict.Add(fieldName, value);
            }
            _csvRecordFieldOptionCache.Add(iniFile1.Key, dict);
        }