private void WriteMetaXml(Stream stream, DarwinCoreExporterOptions options, List <String> columnNames)
        {
            // new XAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"), new XAttribute("xsi:schemaLocation", "http://rs.tdwg.org/dwc/text/   http://rs.tdwg.org/dwc/text/tdwg_dwc_text.xsd")

            XNamespace ns = @"http://rs.tdwg.org/dwc/text/";

            var core = new XElement(ns + "core", new XAttribute("encoding", "UTF-8"), new XAttribute("fieldsTerminatedBy", ","), new XAttribute("linesTerminatedBy", "\r\n"), new XAttribute("fieldsEnclosedBy", "\""), new XAttribute("ignoreHeaderLines", "1"), new XAttribute("rowType", "http://rs.tdwg.org/dwc/terms/Occurrence"));

            var xml = new XDocument(new XDeclaration("1.0", "utf-8", "yes"),
                                    new XElement(ns + "archive", new XAttribute("xmlns", ns), core)
                                    );

            var idIndex = columnNames.IndexOf("catalogNumber");

            core.Add(
                new XElement(ns + "files", new XElement(ns + "location", new XText("occurrence.txt"))),
                new XElement(ns + "id", new XAttribute("index", String.Format("{0}", idIndex)))
                );

            for (int i = 0; i < columnNames.Count; ++i)
            {
                var columnName = columnNames[i];
                core.Add(new XElement(ns + "field", new XAttribute("index", i.ToString()), new XAttribute("term", String.Format("http://rs.tdwg.org/dwc/terms/{0}", columnName))));
            }

            using (var writer = new StreamWriter(stream)) {
                writer.Write(xml.ToString());
            }
        }
        protected override object GetOptions(System.Windows.Window parentWindow, Data.DataMatrix matrix, string datasetName)
        {
            var filename = PromptForFilename(".zip", "DwC-A Files (.zip)|*.zip", datasetName);

            if (!String.IsNullOrEmpty(filename))
            {
                if (FileExistsAndNotOverwrite(filename))
                {
                    return(null);
                }

                DarwinCoreExporterOptions options = new DarwinCoreExporterOptions();
                options.Filename = filename;
                return(options);
            }

            return(null);
        }
        private void ExportToCSV(DataMatrix matrix, Stream stream, DarwinCoreExporterOptions options, bool writeColumnHeaders)
        {
            // Now emit each row...
            int numCols    = matrix.Columns.Count;
            var numRows    = matrix.Rows.Count;
            var currentRow = 0;
            var _quote     = '"';

            using (var writer = new StreamWriter(stream)) {
                if (writeColumnHeaders)
                {
                    for (int colIndex = 0; colIndex < numCols; ++colIndex)
                    {
                        MatrixColumn col = matrix.Columns[colIndex];
                        if (!col.IsHidden)
                        {
                            if (options.QuoteValues)
                            {
                                writer.Write(_quote);
                            }
                            writer.Write(col.Name);
                            if (options.QuoteValues)
                            {
                                writer.Write(_quote);
                            }
                            if (colIndex < numCols - 1)
                            {
                                writer.Write(options.Delimiter);
                            }
                        }
                    }
                    writer.WriteLine();
                }

                for (int rowIndex = 0; rowIndex < matrix.Rows.Count; ++rowIndex)
                {
                    var row = matrix.Rows[rowIndex];
                    for (int colIndex = 0; colIndex < numCols; ++colIndex)
                    {
                        if (!matrix.Columns[colIndex].IsHidden)
                        {
                            var objValue = row[colIndex];
                            var value    = objValue == null ? "" : objValue.ToString();

                            if (options.EscapeSpecial)
                            {
                                value = value.Replace("\"", "\\\"");
                                value = value.Replace(options.Delimiter, "\\" + options.Delimiter);
                            }

                            var quoteValue = options.QuoteValues || value.Contains(options.Delimiter);

                            if (quoteValue)
                            {
                                writer.Write(_quote);
                            }

                            writer.Write(value);

                            if (quoteValue)
                            {
                                writer.Write(_quote);
                            }
                            if (colIndex < numCols - 1)
                            {
                                writer.Write(options.Delimiter);
                            }
                        }
                    }
                    writer.WriteLine();
                    currentRow++;
                    if ((currentRow % 1000) == 0)
                    {
                        double percent = (currentRow / ((double)numRows)) * 100.0;
                        ProgressMessage(String.Format("{0} rows exported to {1}", currentRow, options.Filename), percent);
                    }
                }
            }
        }
Esempio n. 4
0
        protected override object GetOptions(System.Windows.Window parentWindow, Data.DataMatrix matrix, string datasetName)
        {
            var filename = PromptForFilename(".zip", "DwC-A Files (.zip)|*.zip", datasetName);
            if (!String.IsNullOrEmpty(filename)) {

                if (FileExistsAndNotOverwrite(filename)) {
                    return null;
                }

                DarwinCoreExporterOptions options = new DarwinCoreExporterOptions();
                options.Filename = filename;
                return options;
            }

            return null;
        }
Esempio n. 5
0
        private void WriteMetaXml(Stream stream, DarwinCoreExporterOptions options, List<String> columnNames)
        {
            // new XAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"), new XAttribute("xsi:schemaLocation", "http://rs.tdwg.org/dwc/text/   http://rs.tdwg.org/dwc/text/tdwg_dwc_text.xsd")

            XNamespace ns = @"http://rs.tdwg.org/dwc/text/";

            var core = new XElement(ns + "core", new XAttribute("encoding", "UTF-8"), new XAttribute("fieldsTerminatedBy", ","), new XAttribute("linesTerminatedBy", "\r\n"), new XAttribute("fieldsEnclosedBy", "\""), new XAttribute("ignoreHeaderLines", "1"), new XAttribute("rowType", "http://rs.tdwg.org/dwc/terms/Occurrence"));

            var xml = new XDocument(new XDeclaration("1.0", "utf-8", "yes"),
                new XElement(ns + "archive", new XAttribute("xmlns", ns), core)
            );

            var idIndex = columnNames.IndexOf("catalogNumber");

            core.Add(
                new XElement(ns + "files", new XElement(ns + "location", new XText("occurrence.txt"))),
                new XElement(ns + "id", new XAttribute("index", String.Format("{0}", idIndex)))
            );

            for (int i = 0; i < columnNames.Count; ++i) {
                var columnName = columnNames[i];
                core.Add(new XElement( ns + "field", new XAttribute("index", i.ToString()), new XAttribute("term", String.Format("http://rs.tdwg.org/dwc/terms/{0}", columnName))));
            }

            using (var writer = new StreamWriter(stream)) {
                writer.Write(xml.ToString());
            }
        }
Esempio n. 6
0
        private void ExportToCSV(DataMatrix matrix, Stream stream, DarwinCoreExporterOptions options, bool writeColumnHeaders)
        {
            // Now emit each row...
            int numCols = matrix.Columns.Count;
            var numRows = matrix.Rows.Count;
            var currentRow = 0;
            var _quote = '"';

            using (var writer = new StreamWriter(stream)) {
                if (writeColumnHeaders) {
                    for (int colIndex = 0; colIndex < numCols; ++colIndex) {
                        MatrixColumn col = matrix.Columns[colIndex];
                        if (!col.IsHidden) {
                            if (options.QuoteValues) {
                                writer.Write(_quote);
                            }
                            writer.Write(col.Name);
                            if (options.QuoteValues) {
                                writer.Write(_quote);
                            }
                            if (colIndex < numCols - 1) {
                                writer.Write(options.Delimiter);
                            }
                        }
                    }
                    writer.WriteLine();
                }

                for (int rowIndex = 0; rowIndex < matrix.Rows.Count; ++rowIndex) {
                    var row = matrix.Rows[rowIndex];
                    for (int colIndex = 0; colIndex < numCols; ++colIndex) {
                        if (!matrix.Columns[colIndex].IsHidden) {
                            var objValue = row[colIndex];
                            var value = objValue == null ? "" : objValue.ToString();

                            if (options.EscapeSpecial) {
                                value = value.Replace("\"", "\\\"");
                                value = value.Replace(options.Delimiter, "\\" + options.Delimiter);
                            }

                            var quoteValue = options.QuoteValues || value.Contains(options.Delimiter);

                            if (quoteValue) {
                                writer.Write(_quote);
                            }

                            writer.Write(value);

                            if (quoteValue) {
                                writer.Write(_quote);
                            }
                            if (colIndex < numCols - 1) {
                                writer.Write(options.Delimiter);
                            }
                        }
                    }
                    writer.WriteLine();
                    currentRow++;
                    if ((currentRow % 1000) == 0) {
                        double percent = (currentRow / ((double)numRows)) * 100.0;
                        ProgressMessage(String.Format("{0} rows exported to {1}", currentRow, options.Filename), percent);
                    }
                }
            }
        }