private void DoImport()
        {
            if (String.IsNullOrEmpty(txtFilename.Text)) {
                ErrorMessage.Show("You must select a file before proceeding!");
                return;
            }

            int rowCount = 0;

            var service = new SupportService(User);

            using (var parser = new GenericParserAdapter(txtFilename.Text)) {
                parser.ColumnDelimiter = ',';
                parser.FirstRowHasHeader = chkFirstRowHeaders.IsChecked.GetValueOrDefault(false);
                parser.TextQualifier = '\"';
                parser.FirstRowSetsExpectedColumnCount = true;

                var columnNames = new List<String>();
                var values = new List<string>();
                while (parser.Read()) {
                    if (rowCount == 0) {
                        for (int i = 0; i < parser.ColumnCount; ++i) {
                            if (parser.FirstRowHasHeader) {
                                columnNames.Add(parser.GetColumnName(i));
                            } else {
                                columnNames.Add("Column" + i);
                            }
                        }
                    }
                    values.Clear();
                    for (int i = 0; i < parser.ColumnCount; ++i) {
                        values.Add(parser[i]);
                    }

                    String strFullPath = null;
                    if (values.Count == 0) {
                        strFullPath = values[0];
                    } else {
                        strFullPath = values.Join("\\");
                    }

                    if (!String.IsNullOrWhiteSpace(strFullPath)) {
                        service.GetDistributionIdFromPath(strFullPath);
                        lblProgress.InvokeIfRequired(() => {
                            lblProgress.Content = strFullPath;
                            lblProgress.UpdateLayout();
                        });
                        rowCount++;
                    }
                }
            }

            lblProgress.InvokeIfRequired(() => {
                lblProgress.Content = String.Format("{0} rows processed.", rowCount);
            });
            btnCancel.Content = "_Close";
        }
Пример #2
0
 protected void IterateOverCSVZipEntry(ZipEntry entry, Func<GenericParserAdapter, bool> func)
 {
     using (var reader = new StreamReader(entry.OpenReader())) {
         using (var parser = new GenericParserAdapter(reader)) {
             parser.ColumnDelimiter = ',';
             parser.FirstRowHasHeader = true;
             parser.TextQualifier = '\"';
             parser.FirstRowSetsExpectedColumnCount = true;
             while (parser.Read()) {
                 if (func != null) {
                     if (!func(parser)) {
                         return;
                     }
                 }
             }
         }
     }
 }
        private void btnBrowseForDataFile_Click(object sender, EventArgs e)
        {
            diagOpenFile.ShowDialog();
            if (!String.IsNullOrEmpty(diagOpenFile.FileName))
            {
                txtDataFile.Text = diagOpenFile.FileName;

                using (GenericParserAdapter parser = new GenericParserAdapter(diagOpenFile.FileName))
                {
                    parser.FirstRowHasHeader = true;
                    parser.Read();
                    sourceData = parser.GetDataTable();
                }

                foreach (DataColumn column in sourceData.Columns)
                {
                    cboColumnNames.Items.Add(column.ColumnName);
                }
            }
        }
Пример #4
0
        private bool Validate()
        {
            if (string.IsNullOrWhiteSpace(txtFilename.Text)) {
                ErrorMessage.Show("You must specify an input file!");
                return false;
            }

            if (!File.Exists(txtFilename.Text)) {
                ErrorMessage.Show("File does not exist!");
                return false;
            }

            // Extract Column Headers...
            ColumnNames = new List<String>();

            GenericParser parser = null;
            try {
                using (parser = new GenericParserAdapter(Filename)) {
                    parser.ColumnDelimiter = Delimiter.ToCharArray()[0];
                    parser.FirstRowHasHeader = IsFirstRowContainNames;
                    parser.MaxRows = 2;
                    parser.TextQualifier = _textQualifier;

                    if (parser.Read()) {
                        for (int i = 0; i < parser.ColumnCount; ++i) {
                            if (IsFirstRowContainNames) {
                                ColumnNames.Add(parser.GetColumnName(i));
                            } else {
                                ColumnNames.Add("Column" + i);
                            }
                        }
                    } else {
                        ErrorMessage.Show("Failed to extract column names from data source!");
                        return false;
                    }
                }
            } finally {
                if (parser != null) {
                    System.GC.SuppressFinalize(parser);
                }
            }

            return true;
        }
Пример #5
0
        public override ImportRowSource CreateRowSource(IProgressObserver progress)
        {
            if (_options == null) {
                throw new Exception("Null or incorrect options type received!");
            }

            ImportRowSource rowsource = null;

            using (var parser = new GenericParserAdapter(_options.Filename)) {
                parser.ColumnDelimiter = _options.Delimiter[0];
                parser.FirstRowHasHeader = _options.FirstRowContainsNames;
                parser.TextQualifier = '\"';
                parser.FirstRowSetsExpectedColumnCount = true;

                var service = new ImportStagingService();
                var columnNames = new List<String>();

                int rowCount = 0;
                service.BeginTransaction();
                var values = new List<string>();
                while (parser.Read()) {
                    if (rowCount == 0) {
                        for (int i = 0; i < parser.ColumnCount; ++i) {
                            if (_options.FirstRowContainsNames) {
                                columnNames.Add(parser.GetColumnName(i));
                            } else {
                                columnNames.Add("Column" + i);
                            }
                        }
                        service.CreateImportTable(columnNames);
                    }

                    values.Clear();
                    for (int i = 0; i < parser.ColumnCount; ++i) {
                        values.Add(parser[i]);
                    }

                    service.InsertImportRow(values);

                    rowCount++;
                }

                service.CommitTransaction();

                rowsource = new ImportRowSource(service, rowCount);
            }

            return rowsource;
        }