} // RecorderLauncherPath #region HandleException methods public static void HandleException(Form owner, Exception ex) { BasicGoogleTelemetry.SendExtendedExceptionHit(ex); AddExceptionAdvancedInformation(ex); var box = new Microsoft.SqlServer.MessageBox.ExceptionMessageBox() { Caption = Properties.Texts.MyAppHandleExceptionDefaultCaption, Message = ex, Beep = true, Symbol = ExceptionMessageBoxSymbol.Error, }; box.Show(owner); } // HandleException
} // HandleException public static void HandleException(Form owner, string caption, string message, MessageBoxIcon icon, Exception ex) { BasicGoogleTelemetry.SendExtendedExceptionHit(ex, true, message, null); AddExceptionAdvancedInformation(ex); var box = new ExceptionMessageBox() { Caption = caption ?? Properties.Texts.MyAppHandleExceptionDefaultCaption, Text = message ?? Properties.Texts.MyAppHandleExceptionDefaultMessage, InnerException = ex, Beep = true, Symbol = TranslateIconToSymbol(icon), }; box.Show(owner); } // HandleException
private void HandleException(IWin32Window owner, Exception ex) { string message; BasicGoogleTelemetry.SendExtendedExceptionHit(ex, false, TelemetryScreenName, TelemetryScreenName); var isSocket = ex as SocketException; var isTimeout = ex as TimeoutException; message = TextDownloadException ?? Properties.Texts.HelperExceptionText; if (isSocket != null) { message = string.Format(Properties.Texts.SocketException, message, isSocket.SocketErrorCode); } else if (isTimeout != null) { message = string.Format(Properties.Texts.TimeoutException, message); } var box = new ExceptionMessageBox() { Buttons = ExceptionMessageBoxButtons.Custom, InnerException = ex, Text = message, DefaultButton = ExceptionMessageBoxDefaultButton.Button2, CustomSymbol = Properties.Resources.DvbStpDownload_Error_48x48 }; box.SetButtonText(ExceptionMessageBox.OKButtonText, Properties.Texts.HandleExceptionHelpButton); box.Show(owner); if (box.CustomDialogResult == ExceptionMessageBoxDialogResult.Button2) { BasicGoogleTelemetry.SendEventHit("ShowDialog", "UiServices.DvbStpClient.HelpDialog", TelemetryScreenName, TelemetryScreenName); HelpDialog.ShowRtfHelp(owner, Properties.Texts.RtfTroubleshootingGuide, null); } // if } // HandleException
} // HandleOwnedFormException /// <summary> /// Exception handler. /// By default displays an ExceptionMessageBox. Descendants are encouraged to provide their own implementation. /// </summary> /// <param name="ex">The data about the exception, including additional information for the user, such a caption or a text</param> /// <remarks>Descendants who override this method MUST NOT call base.ExceptionHandler. /// This method MUST NOT be called directly. To handle and exception, HandleException MUST be used instead. /// </remarks> protected virtual void ExceptionHandler(ExceptionEventData ex) { BasicGoogleTelemetry.SendExtendedExceptionHit(ex.Exception, true, ex.Message, this.GetType().Name); var box = new ExceptionMessageBox() { Caption = Properties.CommonForm.UncaughtExceptionCaption, Buttons = ExceptionMessageBoxButtons.OK, Symbol = ExceptionMessageBoxSymbol.Stop, }; if (ex.Message == null) { box.Text = ex.Exception.Message; box.Message = ex.Exception; } else { box.Text = ex.Message; box.InnerException = ex.Exception; } // if-else box.Show(ParentForm); } // ExceptionHandler
} // GetRedistFileFullPath #endregion #region Firewall installation public static InitializationResult RunSelfForFirewall(string binPath, string vlcPath) { int exitCode; try { BasicGoogleTelemetry.SendScreenHit("FirewallForm"); var arguments = new StringBuilder(); arguments.AppendFormat("/ForceUiCulture:{0}", CultureInfo.CurrentUICulture.Name); arguments.Append(" /firewall"); if (!string.IsNullOrEmpty(binPath)) { arguments.Append(" \""); arguments.AppendFormat("/decoder:{0}", binPath); // this trick is to avoid a nasty 'feature' of .NET (or even Windows) when parsing arguments // The bin path ends with '\' and if followed by '"', then it will be interpreted as '"' // ["/decoder:foo\bar\" "/vlc:C:\Program Files\foo\bar.exe"] is incorrectly interpreted as [/decoder:foo\bar" /vlc:C:\Program] and [Files\foo\bar.exe] // WARNING: be sure to call Path.GetDirectoryName() before using the path to remove '*.exe' arguments.Append("*.exe"); arguments.Append("\""); } // if if (!string.IsNullOrEmpty(vlcPath)) { arguments.Append(" \""); arguments.AppendFormat("/vlc:{0}", vlcPath); arguments.Append("\""); } // if using (var process = new Process()) { process.StartInfo = new ProcessStartInfo() { FileName = Application.ExecutablePath, Arguments = arguments.ToString(), UseShellExecute = true, Verb = "runas", }; process.Start(); process.WaitForExit(); exitCode = process.ExitCode; } // using process } catch (Win32Exception win32) { if (win32.NativeErrorCode == 1223) // operation cancelled by user { BasicGoogleTelemetry.SendScreenHit("FirewallForm: UACancel"); return(new InitializationResult(Texts.FirewallUserCancel)); } else { BasicGoogleTelemetry.SendScreenHit("FirewallForm: Exception"); return(new InitializationResult(win32)); } // if-else } catch (Exception ex) { BasicGoogleTelemetry.SendScreenHit("FirewallForm: Exception"); BasicGoogleTelemetry.SendExtendedExceptionHit(ex, true, "FirewallForm: Execute", "FirewallForm"); return(new InitializationResult(ex)); } // try-catch if (exitCode == 0) { BasicGoogleTelemetry.SendScreenHit("FirewallForm: Ok"); return(new InitializationResult(Texts.FirewallOk) { IsOk = true }); } else if (exitCode > 0) { BasicGoogleTelemetry.SendScreenHit("FirewallForm: Cancel"); return(new InitializationResult(Texts.FirewallUserCancel)); } else { BasicGoogleTelemetry.SendScreenHit("FirewallForm: " + exitCode.ToString()); return(new InitializationResult((string)null)); } // if-else } // RunSelfForFirewall