private void ProcessFile(ExcelLayer excelLayer, string inputFilePath) { switch (SelectedDirectionConvert.Direction) { case DirectionConvert.FromGtmsToCarrier: IEnumerable<GtmsFormatTarrifModel> gtmsTariffs = excelLayer.GetTariffFromGtms(inputFilePath); var carrierTariffs = SelectedTariffType.Map(gtmsTariffs); var carrierTariffFilePath = string.Format("{0}{1}", Path.Combine(_rootPath, PrefixCarrierOutputFileName + ' ' + Path.GetFileNameWithoutExtension(inputFilePath)), Path.GetExtension(GtmsFromatTariffPath)); var targetFilePath = string.Empty; switch (SelectedTariffType.Type) { case TarrifType.Ltl: targetFilePath = CarrierLtlFromatTariffPath; break; case TarrifType.Vor: targetFilePath = CarrierVorFromatTariffPath; break; } File.Copy(targetFilePath, carrierTariffFilePath, true); excelLayer.WriteTariff(carrierTariffs, carrierTariffFilePath); break; case DirectionConvert.FromCarrierToGtms: IEnumerable<CarrierFormatTariffModel> carrierTarrifs = null; switch (SelectedTariffType.Type) { case TarrifType.Ltl: carrierTarrifs = excelLayer.GetLtlTariff(inputFilePath); break; case TarrifType.Vor: carrierTarrifs = excelLayer.GetVorTariff(inputFilePath); break; default: break; } var outputCarrierTarrifs = SelectedTariffType.Map(carrierTarrifs); var outputFilePath = string.Format("{0}{1}", Path.Combine(_rootPath, PrefixGtmsOutputFileName + ' ' + Path.GetFileNameWithoutExtension(inputFilePath)), Path.GetExtension(GtmsFromatTariffPath)); File.Copy(GtmsFromatTariffPath, outputFilePath, true); excelLayer.WriteTariff(outputCarrierTarrifs, outputFilePath); break; } }
private async void StartProcessingFiles(object sender, RoutedEventArgs e) { StartConvertButton.IsEnabled = false; ClearFileListButton.IsEnabled = false; SelectFileButton.IsEnabled = false; await Task.Run(() => { foreach (var logModel in _logModels) { try { Dispatcher.Invoke(() => logModel.Status = ProcessStatus.Processing); using (var excelLayer = new ExcelLayer()) { ProcessFile(excelLayer, Path.Combine(_rootPath, logModel.InputFileName)); } Dispatcher.Invoke(() => logModel.Status = ProcessStatus.Success); } catch (AuthenticationException exception) { MessageBox.Show("Error", exception.Message, MessageBoxButton.OK, MessageBoxImage.Error); Dispatcher.Invoke(() => logModel.Status = ProcessStatus.Error); LogManager.Logger.Error(exception); } catch (Exception exception) { Dispatcher.Invoke(() => logModel.Status = ProcessStatus.Error); LogManager.Logger.Error(exception); } finally { Dispatcher.Invoke(() => logModel.OutputFileName = string.Format("{0} {1}", PrefixGtmsOutputFileName, logModel.InputFileName)); } } }); ClearFileListButton.IsEnabled = true; SelectFileButton.IsEnabled = true; }