public bool Start(ProjectInfo pi, Run run, ProcessCompletedHandler pch) { _dtStart = DateTime.Now; _pi = pi; _pch = pch; _run = run; _run.State = Run.RunState.Initializing; _pss = new ProfilerSocketServer(pi.Options, run); _pss.Start(); _pss.Exited += new EventHandler(OnProcessExited); _pss.Error += new ProfilerSocketServer.ErrorHandler(OnError); _pss.Message += new ProfilerSocketServer.MessageHandler(OnMessage); switch (pi.ProjectType) { case ProjectType.File: { _p = new Process(); _p.StartInfo = new ProcessStartInfo(pi.ApplicationName, pi.Arguments); _p.StartInfo.EnvironmentVariables["COR_ENABLE_PROFILING"] = "0x1"; _p.StartInfo.EnvironmentVariables["COR_PROFILER"] = PROFILER_GUID; _p.StartInfo.EnvironmentVariables["NPROF_PROFILING_SOCKET"] = _pss.Port.ToString(); _p.StartInfo.UseShellExecute = false; _p.StartInfo.Arguments = pi.Arguments; _p.StartInfo.WorkingDirectory = pi.WorkingDirectory; _p.EnableRaisingEvents = true; //_p.Exited += new EventHandler( OnProcessExited ); return(_p.Start()); } case ProjectType.AspNet: { using (RegistryKey rk = Registry.LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\Services\W3SVC", true)) { if (rk != null) { SetRegistryKeys(rk, true); } } using (RegistryKey rk = Registry.LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\Services\IISADMIN", true)) { if (rk != null) { SetRegistryKeys(rk, true); } } Process p = Process.Start("iisreset.exe", ""); p.WaitForExit(); _run.Messages.AddMessage("Navigate to your project and ASP.NET will connect to the profiler"); _run.Messages.AddMessage("NOTE: ASP.NET must be set to run under the SYSTEM account in machine.config"); _run.Messages.AddMessage(@"If ASP.NET cannot be profiled, ensure that the userName=""SYSTEM"" in the <processModel> section of machine.config."); return(true); } case ProjectType.VSNet: { SetEnvironmentVariable("COR_ENABLE_PROFILING", "0x1"); SetEnvironmentVariable("COR_PROFILER", PROFILER_GUID); SetEnvironmentVariable("NPROF_PROFILING_SOCKET", _pss.Port.ToString()); return(true); } default: throw new InvalidOperationException("Unknown project type: " + pi.ProjectType); } }
public bool Start( ProjectInfo pi, Run run, ProcessCompletedHandler pch ) { _dtStart = DateTime.Now; _pi = pi; _pch = pch; _run = run; _run.State = Run.RunState.Initializing; _pss = new ProfilerSocketServer( pi.Options, run ); _pss.Start(); _pss.Exited += new EventHandler( OnProcessExited ); _pss.Error += new ProfilerSocketServer.ErrorHandler( OnError ); _pss.Message += new ProfilerSocketServer.MessageHandler( OnMessage ); switch ( pi.ProjectType ) { case ProjectType.File: { _p = new Process(); _p.StartInfo = new ProcessStartInfo( pi.ApplicationName, pi.Arguments ); _p.StartInfo.EnvironmentVariables[ "COR_ENABLE_PROFILING" ] = "0x1"; _p.StartInfo.EnvironmentVariables[ "COR_PROFILER" ] = PROFILER_GUID; _p.StartInfo.EnvironmentVariables[ "NPROF_PROFILING_SOCKET" ] = _pss.Port.ToString(); _p.StartInfo.UseShellExecute = false; _p.StartInfo.Arguments = pi.Arguments; _p.StartInfo.WorkingDirectory = pi.WorkingDirectory; _p.EnableRaisingEvents = true; _p.Exited += new EventHandler( OnProcessExited ); return _p.Start(); } case ProjectType.AspNet: { using ( RegistryKey rk = Registry.LocalMachine.OpenSubKey( @"SYSTEM\CurrentControlSet\Services\W3SVC", true ) ) { if ( rk != null ) SetRegistryKeys( rk, true ); } using ( RegistryKey rk = Registry.LocalMachine.OpenSubKey( @"SYSTEM\CurrentControlSet\Services\IISADMIN", true ) ) { if ( rk != null ) SetRegistryKeys( rk, true ); } Process p = Process.Start( "iisreset.exe", "" ); p.WaitForExit(); _run.Messages.AddMessage( "Navigate to your project and ASP.NET will connect to the profiler" ); _run.Messages.AddMessage( "NOTE: ASP.NET must be set to run under the SYSTEM account in machine.config" ); _run.Messages.AddMessage( @"If ASP.NET cannot be profiled, ensure that the userName=""SYSTEM"" in the <processModel> section of machine.config." ); return true; } case ProjectType.VSNet: { SetEnvironmentVariable( "COR_ENABLE_PROFILING", "0x1" ); SetEnvironmentVariable( "COR_PROFILER", PROFILER_GUID ); SetEnvironmentVariable( "NPROF_PROFILING_SOCKET", _pss.Port.ToString() ); return true; } default: throw new InvalidOperationException( "Unknown project type: " + pi.ProjectType ); } }