Esempio n. 1
0
        /// <summary>
        /// Called when the application is started.
        /// </summary>
        private void ApplicationStarted()
        {
            MainWindow = new MainWindow();
            var logFile = File.CreateText(App.LogFileName);

            StatusBar.AttachWriterToLogStream(logFile);
            App.CommandProcessor.LogFile = MainWindow.StatusBar.LogWriter;

            // Work around for Non-English/US locale (e.g. French) where among other things the decimal point is a comma.
            // WPF never uses the CurrentCulture when it formats numbers (it always uses US)
            // This sets the default to the current culture.
            // see http://serialseb.blogspot.com/2007/04/wpf-tips-1-have-all-your-dates-times.html
            FrameworkElement.LanguageProperty.OverrideMetadata(
                typeof(FrameworkElement),
                new FrameworkPropertyMetadata(XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag)));

            if (App.CommandLineArgs.HelpRequested)
            {
                MainWindow.Show();
                MainWindow.DoCommandLineHelp(null, null);
                return;
            }

            MainWindow.StatusBar.LogWriter.WriteLine("Started with command line: {0}", Environment.CommandLine);
            MainWindow.StatusBar.LogWriter.WriteLine("PerfView Version: {0}  BuildDate: {1}", AppLog.VersionNumber, AppLog.BuildDate);
            MainWindow.StatusBar.LogWriter.WriteLine("PerfView Start Time {0}", DateTime.Now);

            if (App.NeedsEulaConfirmation(App.CommandLineArgs))
            {
                var  eula     = new PerfView.Dialogs.EULADialog(MainWindow);
                bool?accepted = eula.ShowDialog();
                if (!(accepted ?? false))
                {
                    Environment.Exit(-10);
                }

                App.AcceptEula();       // Remember that we have accepted the EULA for next time.
            }

            MainWindow.Loaded += delegate(object sender, RoutedEventArgs ev)
            {
                string[] providers = App.CommandLineArgs.Providers;

                if (App.CommandLineArgs.CommandLineFailure != null)
                {
                    var message = App.CommandLineArgs.CommandLineFailure.Message;
                    if (message.Contains("\n"))
                    {
                        MainWindow.StatusBar.LogError("Command Line Error, see log file for details.");
                        MainWindow.StatusBar.Log(message);
                    }
                    else
                    {
                        MainWindow.StatusBar.LogError("Command Line Error: " + message);
                    }

                    return;
                }

                if (App.CommandLineArgs.DoCommand == null)
                {
                    App.CommandLineArgs.DoCommand = App.CommandProcessor.View;
                }

                string commandName  = "View";
                Action continuation = delegate
                {
                    if (App.CommandLineArgs.DataFile != null)
                    {
                        MainWindow.OpenPath(App.CommandLineArgs.DataFile);
                    }
                };
                if (App.CommandLineArgs.DoCommand != App.CommandProcessor.View)
                {
                    commandName  = App.CommandLineArgs.DoCommand.Method.Name;
                    continuation = null;
                }

                // Run commands in the PerfViewExtensions\PerfViewStartup file.
                PerfViewExtensibility.Extensions.RunUserStartupCommands(MainWindow.StatusBar);
                MainWindow.OpenPath(".");
                MainWindow.ExecuteCommand(commandName, App.CommandLineArgs.DoCommand, null, continuation);
            };
            MainWindow.Show();
        }