Ejemplo n.º 1
0
 public DataCleanerBase(ImportSettings settings)
 {
     if (settings == null)
         throw new ArgumentNullException("settings");
     _connString = ConfigurationManager.
         ConnectionStrings[settings.ConnectionStringName].ConnectionString;
     _batchParams = settings.BatchParams;
     _targetTable = settings.TargetTable;
 }
Ejemplo n.º 2
0
 public PricesImporter(ImportSettings settings, ImportMode mode)
     : base(settings, mode)
 {
     _priceCleaner = new PricesCleaner(settings);
 }
Ejemplo n.º 3
0
 public StandardImporter(ImportSettings settings, ImportMode mode)
     : base(settings, mode)
 {
 }
Ejemplo n.º 4
0
 public PricesCleaner(ImportSettings settings)
     : base(settings)
 {
 }
Ejemplo n.º 5
0
        public ImporterBase( ImportSettings settings, ImportMode mode )
        {
            if( settings == null )
                throw new ArgumentNullException( "settings" );
            _Connection = new SqlConnection( ConfigurationManager.ConnectionStrings[ settings.ConnectionStringName ].ConnectionString );
            _Connection.Open();
            _Activity = new ImportActivity(
                        mode,
                        _Connection,
                        settings.BatchParams,
                        settings.TargetTable,
                        settings.CsvDelimiterChar,
                        settings.NumberFormatInfo,
                        settings.CsvMetadata );

            _Activity.ValidateRecord += OnValidateRecord;

            _Activity.Complete += ( s, e ) => _CurrentReport.Counters = e.Counters;

            _Activity.DbError += ( s, e ) => _CurrentReport.AddError( e.ErrorInfo );
        }
        public object Create(object parent, object configContext, XmlNode section)
        {
            var settings = new ImportSettings();

            var csnAttr = section.Attributes["connectionStringName"];
            if (csnAttr == null || string.IsNullOrEmpty(csnAttr.Value))
                throw new ConfigurationErrorsException("ConnectionString name not specified");
            settings.ConnectionStringName = csnAttr.Value;

            BatchParams batchParams;
            var batchSizeAttr = section.Attributes["batchSize"];
            var batchTimeoutAttr = section.Attributes["batchTimeout"];
            var batchDelayAttr = section.Attributes["batchDelay"];
            if (batchSizeAttr == null || string.IsNullOrEmpty(batchSizeAttr.Value))
                throw new ConfigurationErrorsException("Batch size is not specified");
            if (batchTimeoutAttr == null || string.IsNullOrEmpty(batchTimeoutAttr.Value))
                throw new ConfigurationErrorsException("Batch timeout is not specified");
            if (batchDelayAttr == null || string.IsNullOrEmpty(batchDelayAttr.Value))
                throw new ConfigurationErrorsException("Batch delay is not specified");
            if (!int.TryParse(batchSizeAttr.Value, out batchParams.Size) || batchParams.Size < 0)
                throw new ConfigurationErrorsException("Batch size is not valid");
            if (!int.TryParse(batchTimeoutAttr.Value, out batchParams.Timeout) || batchParams.Timeout < 0)
                throw new ConfigurationErrorsException("Batch timeout is not valid");
            batchParams.DelayMode = batchDelayAttr.Value.EndsWith("%")
                ? DelayMode.Percentage : DelayMode.Мilliseconds;
            if (batchParams.DelayMode == DelayMode.Percentage)
                batchDelayAttr.Value = batchDelayAttr.Value.Substring(0, batchDelayAttr.Value.Length - 1);
            if (!int.TryParse(batchDelayAttr.Value, out batchParams.Delay) || batchParams.Delay < 0)
                throw new ConfigurationErrorsException("Batch delay is not valid");
            settings.BatchParams = batchParams;

            var tableAttr = section.Attributes["targetTable"];
            if (tableAttr == null || string.IsNullOrEmpty(tableAttr.Value))
                throw new ConfigurationErrorsException("Target table is not specified");
            settings.TargetTable = tableAttr.Value;

            var delimAttr = section.Attributes["csvDelimiterChar"];
            settings.CsvDelimiterChar = (delimAttr != null && !string.IsNullOrEmpty(delimAttr.Value)) ?
                Convert.ToChar(System.Text.RegularExpressions.Regex.Unescape(delimAttr.Value)) :
                _DefaultCsvDelimiterChar;

            var formatAttr = section.Attributes["numberFormatInfo"];
            if (formatAttr != null)
                settings.NumberFormatInfo = formatAttr.Value;

            foreach (XmlNode column in section["csvMetadata"])
            {
                if (column.NodeType == XmlNodeType.Element)
                {
                    bool exclude = false;
                    var exclAttr = column.Attributes["excludeFromMapping"];
                    if (exclAttr != null && !string.IsNullOrEmpty(exclAttr.Value))
                        exclude = bool.Parse(exclAttr.Value);

                    bool isNullable = false;
                    var nullAttr = column.Attributes["isNullable"];
                    if (nullAttr != null && !string.IsNullOrEmpty(nullAttr.Value))
                        isNullable = bool.Parse(nullAttr.Value);

                    int maxLength = -1;
                    var lenAttr = column.Attributes["maxLength"];
                    if (lenAttr != null && !string.IsNullOrEmpty(lenAttr.Value))
                        maxLength = int.Parse(lenAttr.Value);

                    bool deletionKey = false;
                    var keyAttr = column.Attributes["deletionKey"];
                    if (keyAttr != null && !string.IsNullOrEmpty(keyAttr.Value))
                        deletionKey = bool.Parse(keyAttr.Value);

                    settings.AssCsvColumnInfo(new CsvColumnInfo(
                        column.Attributes["name"].Value,
                        column.Attributes["type"].Value,
                        exclude,
                        isNullable,
                        maxLength,
                        deletionKey));
                }
            }
            return settings;
        }