private async void ConfigureMappingsExecute(object obj)
        {
            CsvPath = (CsvPath ?? "").Replace("\"", "");
            RootDir = (RootDir ?? "").Replace("\"", "");
            if (System.IO.File.Exists(CsvPath))
            {
                Dictionary <int, string>         headers = null;
                List <Dictionary <int, string> > rows    = null;
                Encoding.GetEncodings();
                try
                {
                    using (var csvReader = new CsvReader(CsvPath, ";", SelectedEncoding))
                    {
                        headers = await csvReader.ReadHeaders();

                        rows = await csvReader.ReadRows();
                    }
                }
                catch (Exception ex)
                {
                    Logger.LogE($"Error in ConfigureMappingsExecute: {ex.ToString()}");
                    ProgressText = $"Error: {ex.Message}";
                    return;
                }

                if (_mappingsViewModel != null)
                {
                    if (_mappingsViewModel.SelectedCsvPath != CsvPath || _mappingsViewModel.SelectedEncoding != SelectedEncodingInfo)
                    {
                        _mappingsViewModel = null;
                    }
                }

                if (_mappingsViewModel == null)
                {
                    if (rows.Count == 0)
                    {
                        ProgressText = $"CSV file could not be read";
                        return;
                    }
                    _mappingsViewModel = new MappingsViewModel(headers, rows, RootDir);
                    _mappingsViewModel.SelectedCsvPath  = CsvPath;
                    _mappingsViewModel.SelectedEncoding = SelectedEncodingInfo;
                }
                MappingsWindow2 mappingsWindow = new MappingsWindow2(_mappingsViewModel);
                _mappingsViewModel.SetParentWindow(mappingsWindow);
                _mappingsViewModel.CloseAction = () => { mappingsWindow.Close(); };
                await mappingsWindow.ShowDialog(_parentWindow);

                MappingsConfigured = true;
            }
            else
            {
                ProgressText = $"CSV file could not be found";
            }
        }
示例#2
0
 public MappingsWindow2(MappingsViewModel viewModel) : this()
 {
     this.DataContext = _viewModel = viewModel;
 }