Exemplo n.º 1
0
        public void Generate(RawFileSchema rawFileSchema, DataSource dataSource)
        {
            var validationErrors = _schemaValidator.ValidateSchema(rawFileSchema);

            if (validationErrors.Any())
            {
                throw new Exception("Errors");
            }

            var fileFormat = rawFileSchema.FileFormat.ToEnum <FileSchemaType>();

            var rootDirectory = Path.Combine(_rootFolder, rawFileSchema.RootOutputDir);

            if (!Directory.Exists(rootDirectory))
            {
                Directory.CreateDirectory(rootDirectory);
            }

            var generatedFilePath = Path.Combine(rootDirectory, rawFileSchema.OutputFileName);

            if (!string.IsNullOrWhiteSpace(rawFileSchema.OutputFileExtension))
            {
                generatedFilePath += rawFileSchema.OutputFileExtension;
            }

            switch (fileFormat)
            {
            case FileSchemaType.Fixed:
                var fixedLengthFileSchemaBuilder = new FixedLengthSchemaBuilder();
                var fixedFileSchema = fixedLengthFileSchemaBuilder.BuildSchema(rawFileSchema);
                _fileWriter.Write(generatedFilePath, dataSource, fixedFileSchema);
                break;

            case FileSchemaType.Separated:
                var separatedFileSchemaBuilder = new SeparatedSchemaBuilder();
                var separatedFileSchema        = separatedFileSchemaBuilder.BuildSchema(rawFileSchema);
                _fileWriter.Write(generatedFilePath, dataSource, separatedFileSchema);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Exemplo n.º 2
0
        public void ParseFile(RawFileSchema rawFileSchema)
        {
            var validationErrors = _schemaValidator.ValidateSchema(rawFileSchema);

            if (validationErrors.Any())
            {
                throw new Exception("Errors");
            }

            var fileFormat = rawFileSchema.FileFormat.ToEnum <FileSchemaType>();

            var generatedFilePath = Path.Combine(rawFileSchema.RootOutputDir, rawFileSchema.OutputFileName);

            if (!string.IsNullOrWhiteSpace(rawFileSchema.OutputFileExtension))
            {
                generatedFilePath += rawFileSchema.OutputFileExtension;
            }

            switch (fileFormat)
            {
            case FileSchemaType.Fixed:
                var fixedLengthFileSchemaBuilder = new FixedLengthSchemaBuilder();
                var fixedFileSchema = fixedLengthFileSchemaBuilder.BuildSchema(rawFileSchema);

                using (var sr = new StreamReader(File.OpenRead(generatedFilePath)))
                {
                    //var fixedLengthSchemaReader = new FlatFiles.FixedLengthReader(sr, );
                }
                break;

            case FileSchemaType.Separated:
                var separatedFileSchemaBuilder = new SeparatedSchemaBuilder();
                var separatedFileSchema        = separatedFileSchemaBuilder.BuildSchema(rawFileSchema);
                //_fileWriter.Write(generatedFilePath, dataSource, separatedFileSchema);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Exemplo n.º 3
0
        private SchemaValidationResult ValidateSchema(XDocument documentToValidate, XmlSchemaSet schemaToValidateAgainst)
        {
            var result = _schemaValidator.ValidateSchema(documentToValidate, schemaToValidateAgainst);

            return(result);
        }