private void ConfigureControls() { imgGspLogo.ImageUrl = Util.GetUrl("/images/gsp_logo_313x75.png"); hlHome.NavigateUrl = Util.GetCurrentPageUrl(); // The global error handler in Gallery.cs should have, just prior to transferring to this page, the original // InvalidLicenseException instance. Grab this instance and display its message. InvalidLicenseException ex = System.Web.HttpContext.Current.Items["CurrentException"] as InvalidLicenseException; if (ex != null) { litErrorInfo.Text = Util.HtmlEncode(ex.Message); } else { litErrorInfo.Text = Util.HtmlEncode(new InvalidLicenseException().Message); } }
/// <summary> /// Handle all unhandled exceptions. /// </summary> /// <param name="sender">The object that generated the event.</param> /// <param name="dispatcherUnhandledExceptionEventArgs">Information about the exception event.</param> void OnDispatcherUnhandledException(Object sender, DispatcherUnhandledExceptionEventArgs dispatcherUnhandledExceptionEventArgs) { // A certain class of errors should kill the application, others will just mortally wound it. This is used to euthanize the application when the right // conditions arise. Boolean isFatal = false; // This string will collect the error message that is eventually displayed to the user after the exceptions are examined in order of importance to the // user. The more generic exceptions are examined first and then, if more specific information is available, it will overwrite the generic message. String errorMessage = null; // This handler will try to extract the most specific error message and work its way up to the least specific. As a general rule, if a specific error // message can be made more friendly for the user, the effort is made to provide a less technical description and a more action-oriented message. if (dispatcherUnhandledExceptionEventArgs.Exception.InnerException != null) { // The inner exception has the real reason for this exception. Exception innerException = dispatcherUnhandledExceptionEventArgs.Exception.InnerException; // This will determine if the invalid period for a license has expired and provide detailed instructions about how to correct the error // including the product name and manufacturer. InvalidLicenseException invalidlicenseException = innerException as InvalidLicenseException; if (invalidlicenseException != null) { IProductId iProductId = invalidlicenseException.Instance as IProductId; errorMessage = ExceptionMessage.Format( Teraque.ExplorerChromeExample.Properties.Resources.InvalidLicense, App.productNames[iProductId.ProductId]); isFatal = true; } // This will determine if the evaluation period for a license has expired and provide detailed instructions about how to correct the error // including the product name and manufacturer. EvaluationLicenseException evaluationlicenseException = innerException as EvaluationLicenseException; if (evaluationlicenseException != null) { IProductId iProductId = evaluationlicenseException.Instance as IProductId; errorMessage = ExceptionMessage.Format( Teraque.ExplorerChromeExample.Properties.Resources.EvaluationLicense, App.productNames[iProductId.ProductId]); isFatal = true; } // This will determine if the a valid license has expired and provide detailed instructions about how to correct the error including the product // name and manufacturer. ExpiredLicenseException expiredlicenseException = innerException as ExpiredLicenseException; if (expiredlicenseException != null) { IProductId iProductId = expiredlicenseException.Instance as IProductId; errorMessage = ExceptionMessage.Format( Teraque.ExplorerChromeExample.Properties.Resources.ExpiredLicense, App.productNames[iProductId.ProductId]); isFatal = true; } // If a message wasn't extracted for a specific purpose above then use the general message associated with the inner exception as the text that the // user will see. if (errorMessage == null) { errorMessage = dispatcherUnhandledExceptionEventArgs.Exception.InnerException.Message; } } // The handling of this event works from the most specific error message to the least specific. If no error message has been extracted by this point // the message associated with the exception that generated this event is used as the most general message. if (errorMessage == null) { errorMessage = dispatcherUnhandledExceptionEventArgs.Exception.Message; } // Display the message associated with the exception to the user. MessageBox.Show(errorMessage, Teraque.ExplorerChromeExample.Properties.Resources.Title, MessageBoxButton.OK, MessageBoxImage.Error); // If the error was fatal then shut down the application. if (isFatal) { Application.Current.Shutdown(); } // The exceptions will not kill the program. dispatcherUnhandledExceptionEventArgs.Handled = true; }