/// <summary> /// Runs the given <seealso cref="Action"/> and handles all non-critical exceptions by showing an /// error dialog to the user. If the exception is critical, as determiend by <seealso cref="ErrorHandler.IsCriticalException(Exception)"/> /// then it is re-thrown as this could be that the process is not in a good state to continue executing. /// </summary> /// <param name="action"></param> public static void HandleExceptions(Action action) { try { action(); } catch (AggregateException ex) { Debug.WriteLine($"Uncaught aggregate exception: {ex.Message}"); if (ErrorHandler.ContainsCriticalException(ex)) { throw; } EventsReporterWrapper.ReportEvent(UnhandledExceptionEvent.Create(ex)); UserPromptUtils.ExceptionPrompt(ex); } catch (Exception ex) { Debug.WriteLine($"Uncaught exception: {ex.Message}"); if (ErrorHandler.IsCriticalException(ex)) { throw; } EventsReporterWrapper.ReportEvent(UnhandledExceptionEvent.Create(ex)); UserPromptUtils.ExceptionPrompt(ex); } }
/// <summary> /// Verify that the Cloud SDK is installed and at the right version. Optionally also verify that the given /// component is installed. /// </summary> /// <param name="component">The component to check, optional.</param> /// <returns>True if the Cloud SDK installation is valid.</returns> public static async Task <bool> VerifyGCloudDependencies(GCloudComponent component = GCloudComponent.None) { var result = await GCloudWrapper.ValidateGCloudAsync(component); if (result.IsValid) { return(true); } if (!result.IsCloudSdkInstalled) { LinkPromptDialogWindow.PromptUser( Resources.GcloudMissingGcloudErrorTitle, Resources.GcloudMissingCloudSdkErrorMessage, new LinkInfo(link: "https://cloud.google.com/sdk/", caption: Resources.GcloudInstallLinkCaption)); } else if (!result.IsCloudSdkUpdated) { UserPromptUtils.ErrorPrompt( message: String.Format( Resources.GCloudWrapperUtilsOldCloudSdkMessage, result.CloudSdkVersion, GCloudWrapper.GCloudSdkMinimumVersion), title: Resources.GCloudWrapperUtilsOldCloudSdkTitle); } else { UserPromptUtils.ErrorPrompt( message: String.Format(Resources.GcloudMissingComponentErrorMessage, component), title: Resources.GcloudMissingComponentTitle); } return(false); }
/// <summary> /// Sets the app engine to the given project Id. /// </summary> public static async Task <bool> SetAppRegionAsync(string projectId, IGaeDataSource dataSource) { string selectedLocation = AppEngineManagementWindow.PromptUser(projectId); if (selectedLocation == null) { Debug.WriteLine("The user cancelled creating a new app."); return(false); } try { await ProgressDialogWindow.PromptUser( dataSource.CreateApplicationAsync(selectedLocation), new ProgressDialogWindow.Options { Title = Resources.GaeUtilsSetAppEngineRegionProgressTitle, Message = Resources.GaeUtilsSetAppEngineRegionProgressMessage, IsCancellable = false }); return(true); } catch (DataSourceException ex) { UserPromptUtils.ExceptionPrompt(ex); return(false); } }
/// <summary> /// Runs the given <seealso cref="Task"/> and handles all non-critical exceptions by showing an /// error dialog to the user. If the exception is critical, as determiend by <seealso cref="ErrorHandler.IsCriticalException(Exception)"/> /// then it is re-thrown as this could be that the process is not in a good state to continue executing. /// </summary> public static async void HandleAsyncExceptions(Func <Task> task) { try { await task(); } catch (Exception ex) when(!IsCriticalException(ex)) { Debug.WriteLine($"Uncaught exception: {ex.Message}"); EventsReporterWrapper.ReportEvent(UnhandledExceptionEvent.Create(ex)); UserPromptUtils.ExceptionPrompt(ex); } }
/// <summary> /// Runs the given <seealso cref="Action"/> and handles all non-critical exceptions by showing an /// error dialog to the user. If the exception is critical, as determiend by <seealso cref="ErrorHandler.IsCriticalException(Exception)"/> /// then it is re-thrown as this could be that the process is not in a good state to continue executing. /// </summary> /// <param name="action"></param> public static void HandleExceptions(Action action) { try { action(); } catch (Exception ex) when(!IsCriticalException(ex)) { Debug.WriteLine($"Uncaught exception: {ex.Message}"); EventsReporterWrapper.ReportEvent(UnhandledExceptionEvent.Create(ex)); UserPromptUtils.ExceptionPrompt(ex); } }