コード例 #1
0
        /// <summary>
        /// Create a new reader.
        /// </summary>
        /// <param name="filename">The xml file to read.</param>
        /// <param name="translation">The translation scheme between the import file and the record, if any.</param>
        /// <param name="schema">The xsd schema for the import.</param>
        /// <param name="schemaVersion">The version of the xsd schema to look for.</param>
        /// <param name="recordType">The type of the records to create.</param>
        /// <param name="parameters">Additional parameters for the record.</param>
        /// <param name="writeFailedRecord">The function to report failed records with.</param>
        public XmlImportReader(String filename, Dictionary <String, String> translation, Stream schema, Int32 schemaVersion, Type recordType, Dictionary <String, object> parameters, WriteFailedRecordDelegate writeFailedRecord)
            : base(translation, schema, schemaVersion, recordType, parameters, writeFailedRecord)
        {
            XmlReaderSettings settings = new XmlReaderSettings();

            settings.ValidationFlags         = XmlSchemaValidationFlags.ReportValidationWarnings;
            settings.ValidationType          = ValidationType.None;
            settings.ValidationEventHandler += this.OnValidationError;
            settings.IgnoreWhitespace        = true;

            this.file = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read);
            this.xml  = XmlReader.Create(this.file, settings);

            this.ReadStart();
        }
コード例 #2
0
        /// <summary>
        /// Create an appropriate reader.
        /// </summary>
        /// <param name="filename">The filename of the import file.</param>
        /// <param name="translation">The translation scheme between the import file and the record, if any.</param>
        /// <param name="schema">The xsd schema for the import.</param>
        /// <param name="schemaVersion">The version of the xsd schema to look for.</param>
        /// <param name="recordType">The type of the records to create.</param>
        /// <param name="parameters">Additional parameters for the record.</param>
        /// <param name="writeFailedRecord">The function to report failed records with.</param>
        /// <returns>The reader for the file.</returns>
        public static ImportReader Create(String filename, Dictionary <String, String> translation, Stream schema, Int32 schemaVersion, Type recordType, Dictionary <String, object> parameters, WriteFailedRecordDelegate writeFailedRecord)
        {
            String       extension = Path.GetExtension(filename);
            ImportReader reader    = null;

            if (extension.Equals(".xml"))
            {
                reader = new XmlImportReader(filename, translation, schema, schemaVersion, recordType, parameters, writeFailedRecord);
            }
            else if (extension.Equals(".xlsx"))
            {
                reader = new ExcelImportReader(filename, translation, schema, schemaVersion, recordType, parameters, writeFailedRecord);
            }

            return(reader);
        }
コード例 #3
0
        /// <summary>
        /// Create a new reader.
        /// </summary>
        /// <param name="translation">The translation scheme between the import file and the record, if any.</param>
        /// <param name="schema">The xsd schema for the import.</param>
        /// <param name="schemaVersion">The version of the xsd schema to look for.</param>
        /// <param name="recordType">The type of the records to create.</param>
        /// <param name="parameters">Additional parameters for the record.</param>
        /// <param name="writeFailedRecord">The function to report failed records with.</param>
        public ImportReader(Dictionary <String, String> translation, Stream schema, Int32 schemaVersion, Type recordType, Dictionary <String, object> parameters, WriteFailedRecordDelegate writeFailedRecord)
        {
            DataTable table;
            String    rootElementName;

            this.Translation       = translation;
            this.SchemaVersion     = schemaVersion;
            this.Parameters        = parameters;
            this.Properties        = new Dictionary <String, PropertyInfo>();
            this.RecordIndex       = 0;
            this.RecordType        = recordType;
            this.WriteFailedRecord = writeFailedRecord;

            this.LoadSchema(schema, out table, out rootElementName);

            this.Table           = table;
            this.RootElementName = rootElementName;
        }
コード例 #4
0
        /// <summary>
        /// Create a new reader.
        /// </summary>
        /// <param name="filename">The excel file to read.</param>
        /// <param name="translation">The translation scheme between the import file and the record, if any.</param>
        /// <param name="schema">The xsd schema for the import.</param>
        /// <param name="schemaVersion">The version of the xsd schema to look for.</param>
        /// <param name="recordType">The type of the records to create.</param>
        /// <param name="parameters">Additional parameters for the record.</param>
        /// <param name="writeFailedRecord">The function to report failed records with.</param>
        public ExcelImportReader(String filename, Dictionary <String, String> translation, Stream schema, Int32 schemaVersion, Type recordType, Dictionary <String, object> parameters, WriteFailedRecordDelegate writeFailedRecord)
            : base(translation, schema, schemaVersion, recordType, parameters, writeFailedRecord)
        {
            WorkbookPart          workbook;
            SharedStringTablePart shareStringPart;

            this.filename    = filename;
            this.translation = translation;

            this.spreadsheet = SpreadsheetDocument.Open(filename, false);
            workbook         = spreadsheet.WorkbookPart;
            shareStringPart  = workbook.GetPartsOfType <SharedStringTablePart>().First();

            this.sharedItemsTable = shareStringPart.SharedStringTable.Elements <SharedStringItem>().ToArray();
            this.worksheetParts   = workbook.WorksheetParts.GetEnumerator();

            foreach (WorksheetPart worksheet in workbook.WorksheetParts)
            {
                this.size += worksheet.Worksheet.Descendants <Row>().Count();
            }

            this.ReadStart();
        }