//-------------------------------------------------------------------------------------------------- public static bool Execute <T>(out string fileName, out T exporter) where T : class, IExchanger { fileName = null; exporter = null; var exchangers = ExchangeRegistry.EnumerateExchanger <T>()?.ToArray(); if (exchangers == null || exchangers.Length == 0) { return(false); } // Create Filter var filter = string.Join("|", exchangers.Select(exchanger => { var extensions = string.Join(";", exchanger.Extensions.Select(s => "*." + s)); return(string.Format("{0} ({1})|{1}", exchanger.Description, extensions)); })); // Execute dialog var dlg = new SaveFileDialog() { Title = "Export...", CheckPathExists = true, OverwritePrompt = true, Filter = filter, FilterIndex = _LastFilterIndex }; if (!dlg.ShowDialog(Application.Current.MainWindow) ?? false) { return(false); } // Do export fileName = dlg.FileName; var fileExt = PathUtils.GetExtensionWithoutPoint(fileName); if (!fileExt.IsNullOrEmpty()) { exporter = ExchangeRegistry.FindExchanger <T>(fileExt); } exporter ??= exchangers[dlg.FilterIndex - 1]; _LastFilterIndex = dlg.FilterIndex; return(true); }
void ExecuteExport() { InteractiveContext.Current.SaveLocalSettings("ExportViewportHlr", Settings); var exchangers = ExchangeRegistry.EnumerateExchanger <IDrawingExporter>()?.ToArray(); if (exchangers == null || exchangers.Length == 0) { return; } // Create Filter var filter = string.Join("|", exchangers.Select(exchanger => { var extensions = string.Join(";", exchanger.Extensions.Select(s => "*." + s)); return(string.Format("{0} ({1})|{1}", exchanger.Description, extensions)); })); // Execute Dialog var dlg = new SaveFileDialog() { CheckPathExists = true, OverwritePrompt = true, Filter = filter, FilterIndex = _LastFilterIndex }; var result = dlg.ShowDialog(Application.Current.MainWindow) ?? false; DialogResult = true; if (result) { var exporter = exchangers[dlg.FilterIndex - 1]; _LastFilterIndex = dlg.FilterIndex; if (!ExchangerSettings.Execute <IDrawingExporter>(exporter)) { return; } using (new ProcessingScope(null, "Exporting Line Drawing")) { if (!DoExport(dlg.FileName, exporter)) { MessageBox.Show(Application.Current.MainWindow, "The export was not successfull. Please see message log for further information about the error.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } } } }
public static bool Execute <T>(out string fileName, out T importer) where T : class, IExchanger { fileName = null; importer = null; var exchangers = ExchangeRegistry.EnumerateExchanger <T>()?.ToArray(); if (exchangers == null || exchangers.Length == 0) { return(false); } // Create Filter var filter = String.Format("All supported files|{0}|", string.Join(";", exchangers.SelectMany(exchanger => exchanger.Extensions.Select(s => "*." + s)))) + string.Join("|", exchangers.Select(exchanger => { var extensions = string.Join(";", exchanger.Extensions.Select(s => "*." + s)); return(string.Format("{0} ({1})|{1}", exchanger.Description, extensions)); })); // Execute dialog var dlg = new OpenFileDialog() { Title = "Import...", CheckFileExists = true, Filter = filter, FilterIndex = 1 }; var result = dlg.ShowDialog(Application.Current.MainWindow) ?? false; if (result) { importer = dlg.FilterIndex == 1 ? ExchangeRegistry.FindExchanger <T>(PathUtils.GetExtensionWithoutPoint(dlg.FileName)) : exchangers[dlg.FilterIndex - 2]; fileName = dlg.FileName; } return(result); }
public static bool Execute <T>(out string fileName, out T exporter) where T : class, IExchanger { fileName = null; exporter = null; var exchangers = ExchangeRegistry.EnumerateExchanger <T>()?.ToArray(); if (exchangers == null || exchangers.Length == 0) { return(false); } // Create Filter var filter = string.Join("|", exchangers.Select(exchanger => { var extensions = string.Join(";", exchanger.Extensions.Select(s => "*." + s)); return(string.Format("{0} ({1})|{1}", exchanger.Description, extensions)); })); // Execute dialog var dlg = new SaveFileDialog() { Title = "Export...", CheckPathExists = true, OverwritePrompt = true, Filter = filter, FilterIndex = 1 }; var result = dlg.ShowDialog(Application.Current.MainWindow) ?? false; // Do export if (result) { fileName = dlg.FileName; exporter = exchangers[dlg.FilterIndex - 1]; } return(result); }