public static IValidator CreateValidator(ValidationRequest request) { IValidator validator; switch (Path.GetExtension(request.FileName).ToLower()) { case ".zip": validator = new ZipValidator(request); break; case ".pdf": validator = new PdfValidator(request); break; case ".xml": validator = new XmlValidator(request); break; case ".doc": case ".docx": validator = new WordValidator(request); break; case ".json": validator = new JsonValidator(request); break; case ".txt": validator = new TextValidator(request); break; case ".csv": validator = new CsvValidator(request); break; case ".html": case ".htm": validator = new HtmlValidator(request); break; default: validator = new UnknownValidator(request); break; } return(validator); }
public override EtlStepResult Invoke(EtlContext context, IEtlLogger logger) { if (context == null) { throw new ArgumentNullException("context"); } if (logger == null) { throw new ArgumentNullException("logger"); } if (this.Source == null) { throw new InvalidOperationException(string.Format(Properties.Resources.PropertyCannotBeNull, "Source")); } if (string.IsNullOrEmpty(this.Source.FieldDelimiter)) { throw new InvalidOperationException(string.Format(Properties.Resources.PropertyCannotBeNull, "Source.FieldDelimiter")); } if (string.IsNullOrEmpty(this.Source.FilePath)) { throw new InvalidOperationException(string.Format(Properties.Resources.PropertyCannotBeNull, "Source.FilePath")); } if (this.Source.FieldDelimiter.Length != 1) { throw new InvalidOperationException(string.Format(Properties.Resources.PropertyTooLong, "Source.FieldDelimiter", 1)); } if (this.Source.Quote != null && this.Source.Quote.Length != 1) { throw new InvalidOperationException(string.Format(Properties.Resources.PropertyTooLong, "Source.Quote", 1)); } if (this.Source.Escape != null && this.Source.Escape.Length != 1) { throw new InvalidOperationException(string.Format(Properties.Resources.PropertyTooLong, "Source.Escape", 1)); } var result = new EtlStepResult(EtlStatus.Succeeded, null); var sourceRowCount = 0L; var validRowCount = 0L; var errorRowCount = 0L; var csvSyntax = new CsvSyntaxInfo { HasHeaders = this.Source.HasHeaders, FieldDelimiter = this.Source.FieldDelimiter[0], Quote = this.Source.Quote != null ? this.Source.Quote[0] : DefaultQuote, Escape = this.Source.Escape != null ? this.Source.Escape[0] : DefaultEscape, LineDelimiter1 = this.Source.LineDelimiter != null ? this.Source.LineDelimiter[0] : DefaultLineDelimiter[0], LineDelimiter2 = this.Source.LineDelimiter != null ? this.Source.LineDelimiter[1] : DefaultLineDelimiter[1], }; using (var fileReader = new StreamReader(this.Source.FilePath, Encoding.GetEncoding(this.Source.CodePage))) { using (var csvReader = new CsvReader(fileReader, csvSyntax)) { var validator = new CsvValidator(this, csvReader, context, logger); result.Status = validator.Validate(); sourceRowCount = validator.ReadRowCount; validRowCount = validator.ValidRowCount; errorRowCount = validator.ErrorRowCount; } } //logger.LogEtlMessage(new EtlMessage //{ // EtlPackageId = context.EtlPackageId, // EtlSessionId = context.EtlSessionId, // EtlStepId = this.Id, // LogDateTime = endDateTime, // LogUtcDateTime = endDateTime.ToUniversalTime(), // MessageType = EtlMessageType.Statistics, // Text = "Found", // Flags = sourceRowCount, //}); //logger.LogEtlMessage(new EtlMessage //{ // EtlPackageId = context.EtlPackageId, // EtlSessionId = context.EtlSessionId, // EtlStepId = this.Id, // LogDateTime = endDateTime, // LogUtcDateTime = endDateTime.ToUniversalTime(), // MessageType = EtlMessageType.Statistics, // Text = "Validated", // Flags = validRowCount, //}); //logger.LogEtlMessage(new EtlMessage //{ // EtlPackageId = context.EtlPackageId, // EtlSessionId = context.EtlSessionId, // EtlStepId = this.Id, // LogDateTime = endDateTime, // LogUtcDateTime = endDateTime.ToUniversalTime(), // MessageType = EtlMessageType.Statistics, // Text = "Errors", // Flags = errorRowCount, //}); return result; }
public override EtlStepResult Invoke(EtlContext context, IEtlLogger logger) { if (context == null) { throw new ArgumentNullException("context"); } if (logger == null) { throw new ArgumentNullException("logger"); } if (this.Source == null) { throw new InvalidOperationException(string.Format(Properties.Resources.PropertyCannotBeNull, "Source")); } if (string.IsNullOrEmpty(this.Source.FieldDelimiter)) { throw new InvalidOperationException(string.Format(Properties.Resources.PropertyCannotBeNull, "Source.FieldDelimiter")); } if (string.IsNullOrEmpty(this.Source.FilePath)) { throw new InvalidOperationException(string.Format(Properties.Resources.PropertyCannotBeNull, "Source.FilePath")); } if (this.Source.FieldDelimiter.Length != 1) { throw new InvalidOperationException(string.Format(Properties.Resources.PropertyTooLong, "Source.FieldDelimiter", 1)); } if (this.Source.Quote != null && this.Source.Quote.Length != 1) { throw new InvalidOperationException(string.Format(Properties.Resources.PropertyTooLong, "Source.Quote", 1)); } if (this.Source.Escape != null && this.Source.Escape.Length != 1) { throw new InvalidOperationException(string.Format(Properties.Resources.PropertyTooLong, "Source.Escape", 1)); } var result = new EtlStepResult(EtlStatus.Succeeded, null); var sourceRowCount = 0L; var validRowCount = 0L; var errorRowCount = 0L; var csvSyntax = new CsvSyntaxInfo { HasHeaders = this.Source.HasHeaders, FieldDelimiter = this.Source.FieldDelimiter[0], Quote = this.Source.Quote != null ? this.Source.Quote[0] : DefaultQuote, Escape = this.Source.Escape != null ? this.Source.Escape[0] : DefaultEscape, LineDelimiter1 = this.Source.LineDelimiter != null ? this.Source.LineDelimiter[0] : DefaultLineDelimiter[0], LineDelimiter2 = this.Source.LineDelimiter != null ? this.Source.LineDelimiter[1] : DefaultLineDelimiter[1], }; using (var fileReader = new StreamReader(this.Source.FilePath, Encoding.GetEncoding(this.Source.CodePage))) { using (var csvReader = new CsvReader(fileReader, csvSyntax)) { var validator = new CsvValidator(this, csvReader, context, logger); result.Status = validator.Validate(); sourceRowCount = validator.ReadRowCount; validRowCount = validator.ValidRowCount; errorRowCount = validator.ErrorRowCount; } } //logger.LogEtlMessage(new EtlMessage //{ // EtlPackageId = context.EtlPackageId, // EtlSessionId = context.EtlSessionId, // EtlStepId = this.Id, // LogDateTime = endDateTime, // LogUtcDateTime = endDateTime.ToUniversalTime(), // MessageType = EtlMessageType.Statistics, // Text = "Found", // Flags = sourceRowCount, //}); //logger.LogEtlMessage(new EtlMessage //{ // EtlPackageId = context.EtlPackageId, // EtlSessionId = context.EtlSessionId, // EtlStepId = this.Id, // LogDateTime = endDateTime, // LogUtcDateTime = endDateTime.ToUniversalTime(), // MessageType = EtlMessageType.Statistics, // Text = "Validated", // Flags = validRowCount, //}); //logger.LogEtlMessage(new EtlMessage //{ // EtlPackageId = context.EtlPackageId, // EtlSessionId = context.EtlSessionId, // EtlStepId = this.Id, // LogDateTime = endDateTime, // LogUtcDateTime = endDateTime.ToUniversalTime(), // MessageType = EtlMessageType.Statistics, // Text = "Errors", // Flags = errorRowCount, //}); return(result); }