public void IsConfigurationException() { var configurationException = new ConfigurationException ("configurationException"); var outputTrue = _remotionReflector.IsConfigurationException (configurationException); var outputFalse = _remotionReflector.IsConfigurationException (new Exception ()); Assert.That (outputTrue, Is.True); Assert.That (outputFalse, Is.False); }
/// <summary> /// Used in the rare event that the configuration file for the application is corrupted /// </summary> private static void HandleConfigurationException(ConfigurationException ce) { bool exceptionHandled = false; try { // perhaps this should be checked for if it is null var in3 = ce.InnerException.InnerException; // saves having to have a reference to System.Xml just to check that we have an XmlException if (in3.GetType().Name == "XmlException") { var localSettingsPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "GitExtensions"); // assume that if we are having this error and the installation is not a portable one then the folder will exist. if (Directory.Exists(localSettingsPath)) { string messageContent = string.Format("There is a problem with the user.xml configuration file.{0}{0}The error message was: {1}{0}{0}The configuration file is usually found in: {2}{0}{0}Problems with configuration can usually be solved by deleting the configuration file. Would you like to delete the file?", Environment.NewLine, in3.Message, localSettingsPath); if (DialogResult.Yes.Equals(MessageBox.Show(messageContent, "Configuration Error", MessageBoxButtons.YesNo, MessageBoxIcon.Error, MessageBoxDefaultButton.Button2))) { try { Directory.Delete(localSettingsPath, true); // deletes all application settings not just for this instance - but should work // Restart Git Extensions with the same arguments after old config is deleted? if (DialogResult.OK.Equals(MessageBox.Show(string.Format("Files have been deleted.{0}{0}Would you like to attempt to restart Git Extensions?", Environment.NewLine), "Configuration Error", MessageBoxButtons.OKCancel, MessageBoxIcon.Information))) { var args = Environment.GetCommandLineArgs(); var p = new System.Diagnostics.Process { StartInfo = { FileName = args[0] } }; if (args.Length > 1) { args[0] = ""; p.StartInfo.Arguments = string.Join(" ", args); } p.Start(); } } catch (IOException) { MessageBox.Show(string.Format("Could not delete all files and folders in {0}!", localSettingsPath), "Configuration Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } // assuming that there is no localSettingsPath directory in existence we probably have a portable installation. else { string messageContent = string.Format("There is a problem with the application settings XML configuration file.{0}{0}The error message was: {1}{0}{0}Problems with configuration can usually be solved by deleting the configuration file.", Environment.NewLine, in3.Message); MessageBox.Show(messageContent, "Configuration Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } exceptionHandled = true; } } finally { // if we fail in this somehow at least this message might get somewhere if (!exceptionHandled) { MessageBox.Show(ce.ToString(), "Configuration Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } Environment.Exit(1); } }