示例#1
0
        private void ImportCSVData(CsvImportData importData)
        {
            // Show open file dialog box.
            OpenFileDialog openFileDialog = new OpenFileDialog
            {
                AddExtension    = true,
                CheckFileExists = true,
                CheckPathExists = true,
                DefaultExt      = ".csv",
                Filter          = "Comma-separated values (.csv)|*.csv",
                ValidateNames   = true
            };

            var result = openFileDialog.ShowDialog();

            if (result != true)
            {
                return;
            }

            // Open CSV file.
            try
            {
                using (var stream = openFileDialog.OpenFile())
                {
                    var streamReader = new StreamReader(stream);
                    var csvReader    = new CsvReader(streamReader);
                    csvReader.Configuration.Delimiter = importData != null
                                                            ? importData.Delimiter
                                                            : CsvImportData.DefaultDelimiter;
                    var importCsvDataWindow = new ImportCsvDataWindow(this.Context, csvReader, importData)
                    {
                        Owner = this
                    };
                    importCsvDataWindow.ShowDialog();
                }
            }
            catch (IOException e)
            {
                EditorDialog.Error("Unable to open CSV file", e.Message);
            }
        }
示例#2
0
        /// <summary>
        ///   Creates and shows a new window that allows importing CSV data into the current project.
        /// </summary>
        /// <param name="context">Editor context holding the current model and project settings.</param>
        /// <param name="csvReader">CSV reader to use for the import.</param>
        /// <param name="importData">Custom CSV import settings for initializing the window.</param>
        /// <exception cref="ArgumentNullException">
        ///   <paramref name="context" /> or <paramref name="csvReader" /> is null.
        /// </exception>
        public ImportCsvDataWindow(EditorContext context, ICsvReader csvReader, CsvImportData importData)
        {
            this.InitializeComponent();

            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            if (csvReader == null)
            {
                throw new ArgumentNullException("csvReader");
            }

            this.context    = context;
            this.csvReader  = csvReader;
            this.importData = importData;

            this.InitializeWindow();
        }
示例#3
0
        /// <summary>
        ///   Saves the current import settings for future imports into the current project.
        /// </summary>
        private void SaveImportSettings()
        {
            if (this.importData == null)
            {
                this.importData = new CsvImportData();
                this.context.ProjectSettings.CustomImports.Add(this.importData);
            }

            this.importData.BlueprintIdColumn  = this.BlueprintIdColumn;
            this.importData.BlueprintParentId  = this.BlueprintParent.BlueprintId;
            this.importData.IgnoredBlueprintId = this.IgnoredBlueprintId;
            this.importData.Mappings           = new List <ValueMapping>();

            foreach (var mapping in this.ValueMappings)
            {
                this.importData.Mappings.Add(
                    new ValueMapping {
                    MappingSource = mapping.MappingSource, MappingTarget = mapping.MappingTarget
                });
            }
        }
示例#4
0
        internal static DataTable Create(CsvImportData importData)
        {
            ObservableCollection <string> lines = importData.Lines;

            string[] separators = importData.Separators;

            var dataTable = new DataTable();

            if (lines.Count == 0)
            {
                return(dataTable);
            }

            CreateHeader(dataTable, lines[0], separators);

            for (int i = 1; i < lines.Count; i++)
            {
                CreateRow(dataTable, lines[i], separators);
            }

            return(dataTable);
        }