Esempio n. 1
0
        private void UnhandledceptionHandler(object sender, UnhandledExceptionEventArgs e)
        {
            MessageBox.Show(e.ExceptionObject.ToString());

            // Send the exception telemetry:
            AppTelemetry.ReportError("Unhandled", (Exception)e.ExceptionObject);

            // Close application
            if (e.IsTerminating)
            {
                Environment.Exit(0);
            }
        }
Esempio n. 2
0
        private void Window_Unloaded(object sender, RoutedEventArgs e)
        {
            try
            {
                TimeSpan runtime = DateTime.UtcNow - System.Diagnostics.Process.GetCurrentProcess().StartTime.ToUniversalTime();
                AppTelemetry.ReportUsage((int)runtime.TotalMinutes, PluginFactory.ParserFactories.Count, PluginFactory.PanelFactories.Count, PluginFactory.Analyzers.Count);
            }
            catch (Exception)
            {
                // Catch all since we are closing
            }

            ViewModel.ViewModelLocator.Cleanup();
            this.Close();
            App.Current.Shutdown();
        }
Esempio n. 3
0
        private async void Window_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                var pluginManager = SimpleIoc.Default.GetInstance <ViewModel.PluginManagerViewModel>();

                // Create plugin directory
                if (!Directory.Exists(pluginManager.PluginPath))
                {
                    Directory.CreateDirectory(pluginManager.PluginPath);
                }

                //  Move standard panels dll to plugin directory
                string standardPanelsTargetPath = Path.Combine(pluginManager.PluginPath, "StandardPanels.dll");
                if (!File.Exists(standardPanelsTargetPath))
                {
                    string standardPanelsSourcePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "StandardPanels.dll");
                    File.Copy(standardPanelsSourcePath, standardPanelsTargetPath, true);
                }

                // Load plugins from plugin directory
                List <Exception> errors = PluginFactory.LoadPlugins(pluginManager.PluginPath);

                foreach (var ex in errors)
                {
                    await MainViewModel.DialogService.ShowError(ex.InnerException, ex.Message, "Continue", null);
                }
            }
            catch (Exception ex)
            {
                await MainViewModel.DialogService.ShowError(ex.Message, "Could not load plugins", "Continue", null);

                AppTelemetry.ReportError("Loading", ex);
            }

            // Add local factories which will not be found because they are not in dll's.
            PluginFactory.PanelFactories.Add(PluginFactory.CreatePanelFactory(typeof(Factory.MarkerPanelFactory)));
            PluginFactory.PanelFactories.Add(PluginFactory.CreatePanelFactory(typeof(Factory.ProjectPanelFactory)));

            MainViewModel.PropertyChanged += Main_PropertyChanged;

            foreach (var item in PluginFactory.PanelFactories)
            {
                // Add if it has no attribute set or if the attribute is set check the visible flag
                PanelPluginAttribute attr = item.GetType().GetCustomAttribute <PanelPluginAttribute>(false);
                if (attr == null || attr.Visible)
                {
                    MainViewModel.Windows.Add(item);
                }
            }

            MainViewModel.NewProjectCommand.Execute(null);

            if (AppDomain.CurrentDomain.SetupInformation.ActivationArguments != null && AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData != null && AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData.Length > 0)
            {
                string filename = AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData[0].ToString();
                try
                {
                    MainViewModel.Project.AddLogFile(filename);
                }
                catch (FileLoadException)
                {
                    MessageBox.Show("There is no available log file reader that can read that file.");
                    return;
                }
            }

            // If this is first run show news
            try
            {
                bool firstrun = Properties.Settings.Default.FirstRun;
                if (firstrun)
                {
                    MainViewModel.ShowWebPageCommand.Execute(@"https://wolkesson.github.io/SampleCrunch/getting-started");
                    Properties.Settings.Default.AppTelemetry = (MessageBox.Show(
                                                                    "Sample Crunch uses volentary telemetry to track usage and find bugs. Do you approve to send annonumous data?",
                                                                    "Allow telemetry?", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.Yes) == MessageBoxResult.Yes);
                    Properties.Settings.Default.FirstRun = false;
                    Properties.Settings.Default.Save();
                }
            }
            catch (System.Deployment.Application.InvalidDeploymentException)
            {
                // We will end up here if application is not installed, but run locally.
            }

            try
            {
                // Block App telemetry if user has disapproved it
                AppTelemetry.DoNotSend = !Properties.Settings.Default.AppTelemetry;
                if (string.IsNullOrEmpty(Properties.Settings.Default.AppTelemetryUID))
                {
                    AppTelemetry.RegisterUser(CultureInfo.InstalledUICulture.EnglishName, MainViewModel.Version);
                }
            }
            catch
            { }
        }