示例#1
0
文件: App.xaml.cs 项目: aelij/svcperf
 private void Application_Startup(object sender, StartupEventArgs e)
 {
     SplashScreen screen = new SplashScreen(@"\Assets\Images\SplashScreen.png");
     screen.Show(true, true);
     AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
     // The UI is never responsible for unpacking and is always
     // assumed to run from an unpacked from SvcPerf.exe into the app folder.
     SupportFiles.SupportFileDir = Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location);
     try
     {
         CommandLineArgs = new CommandProcessor();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message + "\n" + ex.StackTrace);
         Environment.Exit(1);
     }
 }
示例#2
0
        private static void ProcessArgs(string[] args)
        {
            CommandProcessor processor = null;
            try
            {
                processor = new CommandProcessor();
            }
            catch (Exception e)
            {
                CommandProcessor.CreateConsole();
                Console.WriteLine("Error: " + e.Message + "\r\n" + "Use -? for help.");
                Console.WriteLine("Press Enter to terminate...");
                Console.ReadLine();
                Environment.Exit(1);
            }

            if (processor.noGui)
            {
                processor.Process();
            }
            else
            {
                try
                {
                    const string SvcPerfExe = "SvcPerf.exe";
                    var info = new ProcessStartInfo();
                    string path = Path.Combine(SupportFiles.SupportFileDir, "SvcPerfUI.exe");
                    string exeName = Assembly.GetExecutingAssembly().Location;
                    string argsToUi = string.Empty;

                    try
                    {
                        //By default we pass in a space seperated argument list;
                        argsToUi = args.Length > 0 ? args.Aggregate((curr, next) => curr + " " + next) : string.Empty;
                        int commandArgStartIndex = Environment.CommandLine.IndexOf("SvcPerf.exe", StringComparison.OrdinalIgnoreCase);
                        string commandLine = Environment.CommandLine;

                        if (commandArgStartIndex > -1 && commandLine.Length > commandArgStartIndex + SvcPerfExe.Length)
                        {
                            commandLine = commandLine.Substring(commandArgStartIndex + SvcPerfExe.Length);
                            int spaceIndex = commandLine.IndexOf(' ');
                            if (spaceIndex >= 0)
                            {
                                argsToUi = commandLine.Substring(spaceIndex);
                            }
                        }
                    }
                    catch (Exception)
                    {
                    }

                    info.Arguments = argsToUi;
                    info.FileName = path;

                    if (processor.command == SvcPerfCommand.ShowUIRealtime)
                    {
                        //Realtime sessions require admin rights.
                        info.UseShellExecute = true;
                        info.Verb = "runas";
                    }

                    Process.Start(info);

                }
                catch (Win32Exception exception)
                {
                    if (exception.NativeErrorCode == 1223)
                    {
                        return;
                    }
                    throw;
                }
            }
        }