Esempio n. 1
0
 public void RaiseAfterRecordConfigurationConstruct(Type recordType, ChoRecordConfiguration config)
 {
     if (Reader is IChoManifoldReader)
     {
         ((IChoManifoldReader)Reader).RaiseAfterRecordConfigurationConstruct(recordType, config);
     }
 }
        protected override void Clone(ChoRecordConfiguration config)
        {
            base.Clone(config);

            if (!(config is ChoFileRecordConfiguration))
            {
                return;
            }

            ChoFileRecordConfiguration fconfig = config as ChoFileRecordConfiguration;

            fconfig.MaxScanRows             = MaxScanRows;
            fconfig.BufferSize              = BufferSize;
            fconfig.Comments                = Comments;
            fconfig.CultureName             = CultureName;
            fconfig.Culture                 = Culture;
            fconfig.EOLDelimiter            = EOLDelimiter;
            fconfig.MayContainEOLInData     = MayContainEOLInData;
            fconfig.IgnoreEmptyLine         = IgnoreEmptyLine;
            fconfig.ColumnCountStrict       = ColumnCountStrict;
            fconfig.ColumnOrderStrict       = ColumnOrderStrict;
            fconfig.EscapeQuoteAndDelimiter = EscapeQuoteAndDelimiter;
            fconfig.NestedColumnSeparator   = NestedColumnSeparator;
            fconfig.QuoteChar               = QuoteChar;
            fconfig.BackslashQuote          = BackslashQuote;
            fconfig.DoubleQuoteChar         = DoubleQuoteChar;
            fconfig.QuoteAllFields          = QuoteAllFields;
            fconfig.StringSplitOptions      = StringSplitOptions;
            fconfig.EncodingPage            = EncodingPage;
            fconfig.NullValue               = NullValue;
        }
Esempio n. 3
0
        public static void DoObjectLevelValidation(this object recObject, ChoRecordConfiguration configuration, IEnumerable <ChoRecordFieldConfiguration> fieldConfigurations)
        {
            if ((configuration.ObjectValidationMode & ChoObjectValidationMode.ObjectLevel) == ChoObjectValidationMode.ObjectLevel)
            {
                if (configuration.HasConfigValidators)
                {
                    IDictionary <string, Object> dict = null;
                    if (recObject is ExpandoObject)
                    {
                        dict = recObject as IDictionary <string, Object>;
                    }
                    else
                    {
                        dict = new Dictionary <string, object>();

                        foreach (var pd in configuration.PIDict.Values)
                        {
                            dict.Add(pd.Name, ChoType.GetPropertyValue(recObject, pd));
                        }
                    }

                    ChoValidator.Validate(dict, configuration.ValDict);
                }
                else
                {
                    if (!configuration.IsDynamicObject)
                    {
                        ChoValidator.Validate(recObject);
                    }
                }
            }
        }
Esempio n. 4
0
        public static void DoObjectLevelValidation(this object recObject, ChoRecordConfiguration configuration, ChoRecordFieldConfiguration[] fieldConfigurations)
        {
            if ((configuration.ObjectValidationMode & ChoObjectValidationMode.ObjectLevel) == ChoObjectValidationMode.ObjectLevel)
            {
                bool hasConfigValidators = (from fc in fieldConfigurations
                                            where !fc.Validators.IsNullOrEmpty()
                                            select fc).Any();

                if (hasConfigValidators)
                {
                    Dictionary <string, ValidationAttribute[]> valDict = (from fc in fieldConfigurations
                                                                          select new KeyValuePair <string, ValidationAttribute[]>(fc.Name, fc.Validators)).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
                    IDictionary <string, Object> dict = null;
                    if (recObject is ExpandoObject)
                    {
                        dict = recObject as IDictionary <string, Object>;
                    }
                    else
                    {
                        dict = recObject.ToDictionary();
                    }

                    ChoValidator.Validate(dict, valDict);
                }
                else
                {
                    if (!(recObject is ExpandoObject))
                    {
                        ChoValidator.Validate(recObject);
                    }
                }
            }
        }
Esempio n. 5
0
        internal void Validate(ChoRecordConfiguration config)
        {
            StringComparer = StringComparer.Create(_culture == null ? CultureInfo.CurrentCulture : _culture, IgnoreCase);

            if (FillChar == ChoCharEx.NUL)
            {
                throw new ChoRecordConfigurationException("Invalid '{0}' FillChar specified.".FormatString(FillChar));
            }

            if (config is ChoCSVRecordConfiguration)
            {
                ChoCSVRecordConfiguration csvConfig = config as ChoCSVRecordConfiguration;

                if (csvConfig.Delimiter.Contains(FillChar))
                {
                    throw new ChoRecordConfigurationException("FillChar [{0}] can't be one of Delimiter characters [{1}]".FormatString(FillChar, csvConfig.Delimiter));
                }
                if (csvConfig.EOLDelimiter.Contains(FillChar))
                {
                    throw new ChoRecordConfigurationException("FillChar [{0}] can't be one EOLDelimiter characters [{1}]".FormatString(FillChar, csvConfig.EOLDelimiter));
                }
                if ((from comm in csvConfig.Comments
                     where comm.Contains(FillChar.ToString())
                     select comm).Any())
                {
                    throw new ChoRecordConfigurationException("One of the Comments contains FillChar. Not allowed.");
                }
            }
        }
Esempio n. 6
0
        public void RaiseAfterRecordConfigurationConstruct(Type recordType, ChoRecordConfiguration config)
        {
            EventHandler <ChoRecordConfigurationConstructArgs> afterRecordConfigurationConstruct = AfterRecordConfigurationConstruct;

            if (afterRecordConfigurationConstruct == null)
            {
                return;
            }

            var ea = new ChoRecordConfigurationConstructArgs(recordType, config);

            afterRecordConfigurationConstruct(this, ea);
        }
Esempio n. 7
0
        protected virtual void Clone(ChoRecordConfiguration config)
        {
            if (config == null)
            {
                return;
            }

            config.ErrorMode                  = ErrorMode;
            config.IgnoreFieldValueMode       = IgnoreFieldValueMode;
            config.AutoDiscoverColumns        = AutoDiscoverColumns;
            config.ThrowAndStopOnMissingField = ThrowAndStopOnMissingField;
            config.ObjectValidationMode       = ObjectValidationMode;
            config.NotifyAfter                = NotifyAfter;
        }
Esempio n. 8
0
        public static void DoObjectLevelValidation(this object recObject, ChoRecordConfiguration configuration, IEnumerable <ChoRecordFieldConfiguration> fieldConfigurations)
        {
            if (recObject == null)
            {
                return;
            }

            if ((configuration.ObjectValidationMode & ChoObjectValidationMode.ObjectLevel) == ChoObjectValidationMode.ObjectLevel)
            {
                if (configuration.Validator == null)
                {
                    if (configuration.HasConfigValidators)
                    {
                        IDictionary <string, Object> dict = null;
                        if (recObject is IDictionary <string, object> )
                        {
                            dict = recObject as IDictionary <string, Object>;
                        }
                        else
                        {
                            dict = new Dictionary <string, object>();

                            foreach (var pd in configuration.PIDict.Values)
                            {
                                dict.Add(pd.Name, ChoType.GetPropertyValue(recObject, pd));
                            }
                        }

                        ChoValidator.Validate(dict, configuration.ValDict);
                    }
                    else
                    {
                        if (!configuration.IsDynamicObject)
                        {
                            ChoValidator.Validate(recObject);
                        }
                    }
                }
                else
                {
                    if (recObject != null && configuration.Validator(recObject))
                    {
                        throw new ValidationException("Failed to validate '{0}' object. {1}".FormatString(recObject.GetType().FullName, Environment.NewLine));
                    }
                }
            }
        }
        protected override void Clone(ChoRecordConfiguration config)
        {
            base.Clone(config);
            if (!(config is ChoXmlRecordConfiguration))
            {
                return;
            }

            ChoXmlRecordConfiguration xconfig = config as ChoXmlRecordConfiguration;

            xconfig.Indent            = Indent;
            xconfig.IndentChar        = IndentChar;
            xconfig.NamespaceManager  = NamespaceManager;
            xconfig.XmlSerializer     = XmlSerializer;
            xconfig.NullValueHandling = NullValueHandling;
            xconfig.IgnoreCase        = IgnoreCase;
        }
Esempio n. 10
0
        protected void InitializeRecordConfiguration(ChoRecordConfiguration configuration)
        {
            if (configuration == null || configuration.IsDynamicObject || configuration.RecordType == null)
            {
                return;
            }

            if (!typeof(IChoNotifyRecordConfigurable).IsAssignableFrom(configuration.RecordMapType))
            {
                return;
            }

            var obj = ChoActivator.CreateInstance(configuration.RecordMapType) as IChoNotifyRecordConfigurable;

            if (obj != null)
            {
                obj.RecondConfigure(configuration);
            }
        }
Esempio n. 11
0
 public ChoRecordConfigurationConstructArgs(Type recordType, ChoRecordConfiguration config)
 {
     recordType    = recordType;
     Configuration = config;
 }