/// <summary> /// ctor /// </summary> /// <param name="configFile">The name of the file that contains the config data</param> /// <param name="exceptionReporter">The optional sink for exceptions</param> internal OverridableConfig(string configFile, IExceptionReporter exceptionReporter) { string fullPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), configFile); if (File.Exists(fullPath)) { try { string json = File.ReadAllText(fullPath); if (json.Length > 0) { _settings = Newtonsoft.Json.JsonConvert.DeserializeObject <Dictionary <string, string> >(json); return; } } #pragma warning disable CA1031 // Do not catch general exception types catch (Exception e) { if (exceptionReporter != null) { exceptionReporter.ReportException(e); } } #pragma warning restore CA1031 // Do not catch general exception types } // This is our typical path _settings = new Dictionary <string, string>(); }
/// <summary> /// Given a ReleaseChannel and a keyName, attempt to load the corresponding ChannelInfo objecvt /// </summary> /// <param name="releaseChannel">The ReleaseChannel being queried</param> /// <param name="channelInfo">Returns the ChannelInfo here</param> /// <param name="gitHubWrapper">An optional wrapper to the GitHub data</param> /// <param name="keyName">An optional override of the key to use when reading the ChannelInfo data</param> /// <param name="exceptionReporter">An optional IExceptionReporter if you want exception details</param> /// <returns>true if we found data</returns> public static bool TryGetChannelInfo(ReleaseChannel releaseChannel, out ChannelInfo channelInfo, IGitHubWrapper gitHubWrapper, string keyName = "default", IExceptionReporter exceptionReporter = null) { try { IGitHubWrapper wrapper = gitHubWrapper ?? new GitHubWrapper(exceptionReporter); using (Stream stream = new MemoryStream()) { wrapper.LoadChannelInfoIntoStream(releaseChannel, stream); channelInfo = GetChannelFromStream(stream, keyName); return(true); } } #pragma warning disable CA1031 // Do not catch general exception types catch (Exception e) { if (exceptionReporter != null) { exceptionReporter.ReportException(e); } } #pragma warning restore CA1031 // Do not catch general exception types // Default values channelInfo = null; return(false); }
/// <summary> /// The entry point for our code /// </summary> public MainWindow() { InitializeComponent(); Hide(); try { InstallationEngine engine = new InstallationEngine(ProductName, SafelyGetAppInstalledPath()); engine.PerformInstallation(); } catch (Exception e) { EventLogger.WriteErrorMessage(e.ToString()); ExceptionReporter.ReportException(e); MessageBox.Show(e.Message, "An error occurred during install"); } Close(); }
public void SwitchVersionAndInvokeCloseApplication() { string errorMessage = null; try { InstallationEngine engine = new InstallationEngine(ProductName, SafelyGetAppInstalledPath()); engine.PerformInstallation(DispatcherUpdateProgress); } #pragma warning disable CA1031 // Do not catch general exception types catch (Exception e) { EventLogger.WriteErrorMessage(e.ToString()); ExceptionReporter.ReportException(e); errorMessage = e.Message; } #pragma warning restore CA1031 // Do not catch general exception types Dispatcher.Invoke(() => CloseAppliction(errorMessage)); }
/// <summary> /// The entry point for our code /// </summary> public MainWindow() { InitializeComponent(); Hide(); try { InstallationEngine engine = new InstallationEngine(ProductName, SafelyGetAppInstalledPath()); engine.PerformInstallation(); } #pragma warning disable CA1031 // Do not catch general exception types catch (Exception e) { EventLogger.WriteErrorMessage(e.ToString()); ExceptionReporter.ReportException(e); MessageBox.Show(e.Message, "An error occurred during install"); } #pragma warning restore CA1031 // Do not catch general exception types Close(); }
/// <summary> /// Returns the product version of the currently installed /// Microsoft.AccessibilityInsights application /// Returns null if the version could not be found /// - could occur if the application has not been installed at all /// - could occur if Windows Installer's cached MSI file is corrupted or deleted /// </summary> /// <returns></returns> public static string GetInstalledProductVersion(IExceptionReporter exceptionReporter) { if (exceptionReporter == null) { throw new ArgumentNullException(nameof(exceptionReporter)); } string targetUpgradeCode = UpdateGuid.ToUpperInvariant(); // Check whether application with target upgrade code is installed on this machine IEnumerable <ProductInstallation> installations = ProductInstallation.GetRelatedProducts(targetUpgradeCode); bool existingApp; try { existingApp = installations.Any(); } catch (ArgumentException e) { exceptionReporter.ReportException(e); // occurs when the upgrade code is formatted incorrectly // exception text: "Parameter is incorrect" return(null); } if (!existingApp) { // occurs when the upgrade code does not match any existing application return(null); } ProductInstallation existingInstall = installations.FirstOrDefault <ProductInstallation>(i => i.ProductVersion != null); if (existingInstall == null) { return(null); } string msiFilePath = existingInstall.LocalPackage; if (msiFilePath != null) { return(GetMSIProductVersion(msiFilePath)); } // Should only get here if LocalPackage not set return(null); }