Browse Source

Add ProcessMonitor to monitor the creation of worker process

pull/15/head
Eusebiu Marcu 16 years ago
parent
commit
e8e1ca322c
  1. 2
      src/AddIns/Debugger/Debugger.AddIn/Debugger.AddIn.csproj
  2. 60
      src/AddIns/Debugger/Debugger.AddIn/Service/ProcessMonitor.cs
  3. 82
      src/AddIns/Debugger/Debugger.AddIn/Service/WindowsDebugger.cs
  4. 1
      src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/WebProjectOptions/WebProjectOptionsPanel.xaml.cs
  5. 80
      src/Main/Base/Project/Src/Services/WebProjectService/WebProjectService.cs

2
src/AddIns/Debugger/Debugger.AddIn/Debugger.AddIn.csproj

@ -86,6 +86,7 @@ @@ -86,6 +86,7 @@
</Reference>
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
<Reference Include="System.Management" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
<Reference Include="System.Xaml" />
@ -181,6 +182,7 @@ @@ -181,6 +182,7 @@
<DependentUpon>EditBreakpointScriptWindow.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="Service\ProcessMonitor.cs" />
<Compile Include="Tooltips\DebuggerPopup.cs" />
<Compile Include="Tooltips\DebuggerTooltipControl.xaml.cs">
<DependentUpon>DebuggerTooltipControl.xaml</DependentUpon>

60
src/AddIns/Debugger/Debugger.AddIn/Service/ProcessMonitor.cs

@ -0,0 +1,60 @@ @@ -0,0 +1,60 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Collections;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.Management;
namespace ICSharpCode.SharpDevelop.Services
{
public class ProcessMonitor : ManagementEventWatcher, IDisposable
{
// Process Events
public event EventHandler ProcessCreated;
public event EventHandler ProcessDeleted;
public event EventHandler ProcessModified;
// WMI WQL process query strings
static readonly string WMI_OPER_EVENT_QUERY = @"SELECT * FROM __InstanceOperationEvent WITHIN 1 WHERE TargetInstance ISA 'Win32_Process'";
static readonly string WMI_OPER_EVENT_QUERY_WITH_PROC = WMI_OPER_EVENT_QUERY + " and TargetInstance.Name LIKE '%{0}%'";
public ProcessMonitor(string processName)
{
this.Query.QueryLanguage = "WQL";
if (string.IsNullOrEmpty(processName))
{
this.Query.QueryString = WMI_OPER_EVENT_QUERY;
}
else
{
this.Query.QueryString =
string.Format(WMI_OPER_EVENT_QUERY_WITH_PROC, processName);
}
this.EventArrived += new EventArrivedEventHandler(OnEventArrived);
}
private void OnEventArrived(object sender, EventArrivedEventArgs e)
{
string eventType = e.NewEvent.ClassPath.ClassName;
switch (eventType)
{
case "__InstanceCreationEvent":
if (ProcessCreated != null)
ProcessCreated(this, EventArgs.Empty);
break;
case "__InstanceDeletionEvent":
if (ProcessDeleted != null)
ProcessDeleted(this, EventArgs.Empty);
break;
case "__InstanceModificationEvent":
if (ProcessModified != null)
ProcessModified(this, EventArgs.Empty);
break;
}
}
}
}

82
src/AddIns/Debugger/Debugger.AddIn/Service/WindowsDebugger.cs

@ -45,6 +45,7 @@ namespace ICSharpCode.SharpDevelop.Services @@ -45,6 +45,7 @@ namespace ICSharpCode.SharpDevelop.Services
ICorPublish corPublish;
Process debuggedProcess;
ProcessMonitor monitor;
//DynamicTreeDebuggerRow currentTooltipRow;
//Expression currentTooltipExpression;
@ -148,41 +149,58 @@ namespace ICSharpCode.SharpDevelop.Services @@ -148,41 +149,58 @@ namespace ICSharpCode.SharpDevelop.Services
}
var debugData = WebProjectsOptions.Instance.GetWebProjectOptions(project.Name);
if (debugData == null) {
if (debugData == null || debugData.Data == null) {
MessageService.ShowError("${res:ICSharpCode.WepProjectOptionsPanel.NoProjectUrlOrProgramAction}");
return;
}
System.Diagnostics.Process localProcess = null;
// start default application(e.g. browser)
if (project.StartAction == StartAction.StartURL)
localProcess = System.Diagnostics.Process.Start(processStartInfo.FileName);
else
if (!string.IsNullOrEmpty(debugData.Data.ProjectUrl) && debugData.Data.WebServer == WebServer.IIS)
localProcess = System.Diagnostics.Process.Start(debugData.Data.ProjectUrl);
// try attach to IIS WP
var processes = System.Diagnostics.Process.GetProcesses();
string processName = WebProjectService.WorkerProcessName;
if (debugData.Data.WebServer == WebServer.IISExpress)
processName = "iisexpress";
foreach(var process in processes) {
if (process.ProcessName.ToLower().IndexOf(processName) == 0) {
Attach(process);
break;
}
}
if (!attached) {
if(debugData.Data.WebServer == WebServer.IIS) {
string format = ResourceService.GetString("ICSharpCode.WepProjectOptionsPanel.NoIISWP");
MessageService.ShowMessage(string.Format(format, processName));
if (debugData.Data.WebServer != WebServer.None) {
// try attach to IIS WP
var processes = System.Diagnostics.Process.GetProcesses();
string processName = WebProjectService.WorkerProcessName;
if (debugData.Data.WebServer == WebServer.IISExpress)
processName = WebProjectService.IIS_EXPRESS_PROCESS_NAME;
System.Diagnostics.Process localProcess = null;
// try find the worker process
int index = processes.FindIndex<System.Diagnostics.Process>(
p => p.ProcessName.IndexOf(processName, StringComparison.OrdinalIgnoreCase) == 0);
if (index > -1){
Attach(processes[index]);
} else {
this.monitor = new ProcessMonitor(processName);
this.monitor.ProcessCreated += delegate {
processes = System.Diagnostics.Process.GetProcesses();
index = processes.FindIndex<System.Diagnostics.Process>(
p => p.ProcessName.IndexOf(processName, StringComparison.OrdinalIgnoreCase) == 0);
Attach(processes[index]);
if (!attached) {
if(debugData.Data.WebServer == WebServer.IIS) {
string format = ResourceService.GetString("ICSharpCode.WepProjectOptionsPanel.NoIISWP");
MessageService.ShowMessage(string.Format(format, processName));
} else {
Attach(localProcess);
if (!attached) {
MessageService.ShowMessage(ResourceService.GetString("ICSharpCode.WepProjectOptionsPanel.UnableToAttach"));
}
}
}
};
this.monitor.Start();
}
// start default application(e.g. browser)
if (project.StartAction == StartAction.StartURL)
localProcess = System.Diagnostics.Process.Start(processStartInfo.FileName);
else {
Attach(localProcess);
if (!attached) {
MessageService.ShowMessage(ResourceService.GetString("ICSharpCode.WepProjectOptionsPanel.UnableToAttach"));
if (!string.IsNullOrEmpty(debugData.Data.ProjectUrl) && debugData.Data.WebServer == WebServer.IIS)
localProcess = System.Diagnostics.Process.Start(debugData.Data.ProjectUrl);
else {
if (debugData.Data.WebServer == WebServer.IISExpress)
localProcess = System.Diagnostics.Process.Start(debugData.Data.ProjectUrl);
}
}
}
@ -315,6 +333,12 @@ namespace ICSharpCode.SharpDevelop.Services @@ -315,6 +333,12 @@ namespace ICSharpCode.SharpDevelop.Services
} else {
debuggedProcess.Terminate();
}
if (monitor != null) {
monitor.Stop();
monitor.Dispose();
monitor = null;
}
}
// ExecutionControl:

1
src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/WebProjectOptions/WebProjectOptionsPanel.xaml.cs

@ -101,6 +101,7 @@ namespace ICSharpCode.SharpDevelop.Gui.OptionPanels @@ -101,6 +101,7 @@ namespace ICSharpCode.SharpDevelop.Gui.OptionPanels
if (!WebProjectService.IsIISInstalled) {
StatusLabel.Text = ResourceService.GetString("ICSharpCode.WepProjectOptionsPanel.IISNotFound");
ProjectUrl.Text = string.Empty;
data.WebServer = WebServer.None;
}
else {
StatusLabel.Text = string.Empty;

80
src/Main/Base/Project/Src/Services/WebProjectService/WebProjectService.cs

@ -13,6 +13,7 @@ namespace ICSharpCode.SharpDevelop.Project @@ -13,6 +13,7 @@ namespace ICSharpCode.SharpDevelop.Project
IIS5 = 5,
IIS6,
IIS7,
IISExpress,
IIS_Future
}
@ -28,10 +29,22 @@ namespace ICSharpCode.SharpDevelop.Project @@ -28,10 +29,22 @@ namespace ICSharpCode.SharpDevelop.Project
/// </summary>
public static class WebProjectService
{
const string IIS_REG_KEY_NAME = "Software\\Microsoft\\InetStp";
const string IIS_REG_KEY_VALUE = "MajorVersion";
const string IIS_LOCATION = "Software\\Microsoft\\InetStp";
const string IIS_MAJOR_VERSION = "MajorVersion";
const string IIS_INSTALL_PATH = "InstallPath";
const string DEFAULT_WEB_SITE = "Default Web Site";
const string IIS_LOCATION = "IIS://localhost/W3SVC/1/Root";
const string IIS_WEB_LOCATION = "IIS://localhost/W3SVC/1/Root";
const string ASPNET_REG_PATH = @"SOFTWARE\MICROSOFT\ASP.NET";
const string ASPNET_ROOT_VER = @"RootVer";
const string FRAMEWORK_LOCATION = @"%systemroot%\Microsoft.NET\";
const string FRAMEWORK32 = @"Framework\";
const string FRAMEWORK64 = @"Framework64\";
public const string IIS_EXPRESS_PROCESS_NAME = "iisexpress";
public const string IIS_5_PROCESS_NAME = "aspnet_wp";
public const string IIS_NEW_PROCESS_NAME = "w3wp";
/// <summary>
/// Gets the IIS worker process name.
@ -47,11 +60,13 @@ namespace ICSharpCode.SharpDevelop.Project @@ -47,11 +60,13 @@ namespace ICSharpCode.SharpDevelop.Project
switch(IISVersion)
{
case IISVersion.IIS5:
name = "aspnet_wp";
name = IIS_5_PROCESS_NAME;
break;
case IISVersion.IISExpress:
name = IIS_EXPRESS_PROCESS_NAME;
break;
default:
name = "w3wp";
name = IIS_NEW_PROCESS_NAME;
break;
}
@ -63,6 +78,53 @@ namespace ICSharpCode.SharpDevelop.Project @@ -63,6 +78,53 @@ namespace ICSharpCode.SharpDevelop.Project
}
}
public static string WorkerProcessLocation {
get {
if (!IsIISInstalled)
return ResourceService.GetString("ICSharpCode.WepProjectOptionsPanel.IISNotFound");
try {
string location;
switch(IISVersion)
{
case IISVersion.IIS5:
location = FRAMEWORK_LOCATION + (Environment.Is64BitOperatingSystem ? FRAMEWORK64 : FRAMEWORK32);
string frameworkString = "";
RegistryService.GetRegistryValue<string>(
RegistryHive.LocalMachine,
ASPNET_REG_PATH,
ASPNET_ROOT_VER,
RegistryValueKind.String,
out frameworkString);
int ind = frameworkString.LastIndexOf('.');
location += "v" + frameworkString.Substring(0, ind) + "\\";
break;
default:
string regValue = "";
RegistryService.GetRegistryValue<string>(
RegistryHive.LocalMachine,
IIS_LOCATION,
IIS_INSTALL_PATH,
RegistryValueKind.String,
out regValue);
location = regValue + "\\";
break;
}
return location;
}
catch (Exception ex) {
return ex.Message;
}
}
}
/// <summary>
/// Gets a value representing whether IIS is installed.
/// </summary>
@ -82,8 +144,8 @@ namespace ICSharpCode.SharpDevelop.Project @@ -82,8 +144,8 @@ namespace ICSharpCode.SharpDevelop.Project
RegistryService.GetRegistryValue<int>(
RegistryHive.LocalMachine,
IIS_REG_KEY_NAME,
IIS_REG_KEY_VALUE,
IIS_LOCATION,
IIS_MAJOR_VERSION,
RegistryValueKind.DWord,
out regValue);
@ -110,7 +172,7 @@ namespace ICSharpCode.SharpDevelop.Project @@ -110,7 +172,7 @@ namespace ICSharpCode.SharpDevelop.Project
case IISVersion.IIS5:
case IISVersion.IIS6:
var vr = new IISVirtualRoot();
vr.Create(IIS_LOCATION,
vr.Create(IIS_WEB_LOCATION,
physicalDirectoryPath,
virtualDirectoryName,
out error);

Loading…
Cancel
Save