public void Protect(Action action) { tryagain: try { action(); } catch (Exception ex) { RemoteLogger.ReportIssueAsync(ex); if (HandleException(this, ex)) { goto tryagain; } } }
private void ClipboardToExcel() { datagrid.SelectionMode = DataGridSelectionMode.Extended; try { datagrid.SelectAllCells(); try { ApplicationCommands.Copy.Execute(null, datagrid); } catch (Exception ex) { RemoteLogger.ReportIssueAsync(ex); MessageBox.Show(App.Current.MainWindow, ex.Message, ex.GetType().ToString(), MessageBoxButton.OK, MessageBoxImage.Error); return; } finally { datagrid.UnselectAllCells(); } var dlg = new System.Windows.Forms.FolderBrowserDialog(); var ww = new WindowWrapper(new WindowInteropHelper(App.Current.MainWindow).Handle); if (dlg.ShowDialog(ww) == System.Windows.Forms.DialogResult.OK) { string fileName = System.IO.Path.Combine(dlg.SelectedPath, string.Format("VisLab_{0}.csv", tbkHeader.Text)); string data = (string)Clipboard.GetData(DataFormats.Text); Clipboard.Clear(); if (data != null) { data = data.Replace('\t', ';').Replace('?', '.'); } File.WriteAllText(fileName, data); Process.Start(fileName); } } finally { datagrid.SelectionMode = DataGridSelectionMode.Single; } }