14 changed files with 1046 additions and 451 deletions
File diff suppressed because it is too large
Load Diff
@ -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; |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,71 @@
@@ -0,0 +1,71 @@
|
||||
// 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.Generic; |
||||
using System.ComponentModel; |
||||
|
||||
using ICSharpCode.Core; |
||||
using ICSharpCode.SharpDevelop.Project; |
||||
|
||||
namespace ICSharpCode.SharpDevelop.Gui.OptionPanels |
||||
{ |
||||
public sealed class WebProjectsOptions |
||||
{ |
||||
private WebProjectsOptions() { } |
||||
|
||||
private static readonly WebProjectsOptions _Instance = new WebProjectsOptions(); |
||||
|
||||
private List<WebProjectOptions> options = new List<WebProjectOptions>(); |
||||
|
||||
public WebProjectOptions GetWebProjectOptions(string projectName) { |
||||
return options.Find(o => o.ProjectName == projectName); |
||||
} |
||||
|
||||
public void SetWebProjectOptions(string projectName, WebProjectOptions data) |
||||
{ |
||||
var d = GetWebProjectOptions(projectName); |
||||
if (d == null) |
||||
{ |
||||
if (data == null) |
||||
data = new WebProjectOptions() { ProjectName = projectName }; |
||||
|
||||
options.Add(data); |
||||
} |
||||
else |
||||
{ |
||||
int index = options.IndexOf(d); |
||||
options[index] = data; |
||||
} |
||||
} |
||||
|
||||
public static WebProjectsOptions Instance { |
||||
get { |
||||
return _Instance; |
||||
} |
||||
} |
||||
} |
||||
|
||||
[Serializable] |
||||
public class WebProjectOptions |
||||
{ |
||||
[DefaultValue(null)] |
||||
public string ProjectName { get; set; } |
||||
|
||||
[DefaultValue(null)] |
||||
public WebProjectDebugData Data { get; set; } |
||||
} |
||||
|
||||
[Serializable] |
||||
public class WebProjectDebugData |
||||
{ |
||||
[DefaultValue(null)] |
||||
public string ProjectUrl { get; set; } |
||||
|
||||
[DefaultValue("8080")] |
||||
public string Port { get; set; } |
||||
|
||||
[DefaultValue(WebServer.None)] |
||||
public WebServer WebServer { get; set; } |
||||
} |
||||
} |
@ -0,0 +1,81 @@
@@ -0,0 +1,81 @@
|
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<UserControl |
||||
x:Class="ICSharpCode.SharpDevelop.Gui.OptionPanels.WebProjectOptionsPanel" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:core="http://icsharpcode.net/sharpdevelop/core" xmlns:widgets="http://icsharpcode.net/sharpdevelop/widgets" xmlns:gui="clr-namespace:ICSharpCode.SharpDevelop.Gui;assembly=ICSharpCode.SharpDevelop" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
||||
> |
||||
<GroupBox Margin="0, 0, 85, 0" |
||||
Header="{core:Localize ICSharpCode.WepProjectOptionsPanel.Server}"> |
||||
<widgets:StackPanelWithSpacing SpaceBetweenItems="3"> |
||||
<!--IIS Express--> |
||||
<widgets:StackPanelWithSpacing SpaceBetweenItems="3"> |
||||
<RadioButton |
||||
IsChecked="False" |
||||
GroupName="WebProject" |
||||
x:Name="UseIISExpress" |
||||
Click="UseIISExpress_Click" |
||||
Content="{core:Localize ICSharpCode.WepProjectOptionsPanel.UseIISExpress}" /> |
||||
<Grid Margin="10, 3" |
||||
IsEnabled="False" |
||||
x:Name="IISExpressGroup" |
||||
VerticalAlignment="Top"> |
||||
<Grid.ColumnDefinitions> |
||||
<ColumnDefinition Width="Auto"/> |
||||
<ColumnDefinition Width="Auto"/> |
||||
</Grid.ColumnDefinitions> |
||||
<TextBlock Text="{core:Localize ICSharpCode.WepProjectOptionsPanel.Port}"/> |
||||
<TextBox Grid.Column="1" x:Name="PortTextBox" |
||||
PreviewTextInput="PortTextBox_PreviewTextInput" Text="8080" |
||||
KeyUp="PortTextBox_KeyUp" /> |
||||
</Grid> |
||||
</widgets:StackPanelWithSpacing> |
||||
<!--IIS Local Server--> |
||||
<widgets:StackPanelWithSpacing SpaceBetweenItems="3"> |
||||
<RadioButton |
||||
IsChecked="False" |
||||
GroupName="WebProject" |
||||
x:Name="UseLocalIIS" |
||||
Click="UseLocalIIS_Click" |
||||
Content="{core:Localize ICSharpCode.WepProjectOptionsPanel.UseLocalIIS}" /> |
||||
<Grid Margin="10, 3" |
||||
IsEnabled="False" |
||||
x:Name="LocalIISGroup" |
||||
VerticalAlignment="Top"> |
||||
<Grid.ColumnDefinitions> |
||||
<ColumnDefinition Width="Auto"/> |
||||
<ColumnDefinition Width="Auto"/> |
||||
</Grid.ColumnDefinitions> |
||||
<TextBlock |
||||
VerticalAlignment="Center" |
||||
Grid.Row="1" |
||||
TextWrapping="Wrap" |
||||
Text="{core:Localize ICSharpCode.WepProjectOptionsPanel.ProjectUrl}" /> |
||||
<TextBox |
||||
Grid.Row="1" |
||||
Grid.Column="1" |
||||
x:Name="ProjectUrl" |
||||
TextChanged="ProjectUrl_TextChanged" |
||||
MinWidth="250" /> |
||||
</Grid> |
||||
</widgets:StackPanelWithSpacing> |
||||
<TextBlock |
||||
Foreground="Red" |
||||
TextDecorations="Underline" |
||||
FontSize="12" |
||||
FontWeight="Bold" |
||||
TextWrapping="Wrap" |
||||
Name="StatusLabel" /> |
||||
<widgets:UniformGridWithSpacing Columns="2" SpaceBetweenColumns="10"> |
||||
<Button |
||||
IsEnabled="False" |
||||
Style="{x:Static core:GlobalStyles.ButtonStyle}" |
||||
Name="CreateVirtualDirectoryButton" |
||||
Content="{core:Localize ICSharpCode.WepProjectOptionsPanel.CreateVirtualDir}" |
||||
Click="CreateVirtualDirectory_Click" /> |
||||
<Button |
||||
Style="{x:Static core:GlobalStyles.ButtonStyle}" |
||||
Name="ClearWebServerButton" |
||||
Content="{core:Localize ICSharpCode.WepProjectOptionsPanel.DisableWebServerButton}" |
||||
Click="ClearWebServerButton_Click" /> |
||||
</widgets:UniformGridWithSpacing> |
||||
</widgets:StackPanelWithSpacing> |
||||
</GroupBox> |
||||
</UserControl> |
@ -0,0 +1,207 @@
@@ -0,0 +1,207 @@
|
||||
// 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.IO; |
||||
using System.Web.Services.Description; |
||||
using System.Windows; |
||||
using System.Windows.Controls; |
||||
using ICSharpCode.Core; |
||||
using ICSharpCode.SharpDevelop.Project; |
||||
|
||||
namespace ICSharpCode.SharpDevelop.Gui.OptionPanels |
||||
{ |
||||
public partial class WebProjectOptionsPanel : UserControl |
||||
{ |
||||
private readonly DebugOptions parentPanel; |
||||
|
||||
public WebProjectOptionsPanel(DebugOptions parentPanel) |
||||
{ |
||||
InitializeComponent(); |
||||
|
||||
this.parentPanel = parentPanel; |
||||
|
||||
if (CurrentProjectDebugData == null) |
||||
CurrentProjectDebugData = new WebProjectDebugData(); |
||||
|
||||
Loaded += OnLoaded; |
||||
} |
||||
|
||||
void OnLoaded(object sender, RoutedEventArgs e) |
||||
{ |
||||
if (!WebProjectService.IsIISInstalled) { |
||||
StatusLabel.Text = ResourceService.GetString("ICSharpCode.WepProjectOptionsPanel.IISNotFound"); |
||||
return; |
||||
} |
||||
|
||||
switch (CurrentProjectDebugData.WebServer) |
||||
{ |
||||
case WebServer.IISExpress: |
||||
if (WebProjectService.IISVersion == IISVersion.IISExpress) { |
||||
UseIISExpress.IsChecked = true; |
||||
PortTextBox.Text = CurrentProjectDebugData.Port ?? "8080"; |
||||
|
||||
SelectIISExpress(); |
||||
} |
||||
break; |
||||
case WebServer.IIS: |
||||
if (WebProjectService.IISVersion == IISVersion.IIS5 || |
||||
WebProjectService.IISVersion == IISVersion.IIS6 || |
||||
WebProjectService.IISVersion == IISVersion.IIS7 || |
||||
WebProjectService.IISVersion == IISVersion.IIS_Future) { |
||||
UseLocalIIS.IsChecked = true; |
||||
ProjectUrl.Text = CurrentProjectDebugData.ProjectUrl ?? string.Empty; |
||||
|
||||
SelectLocalIIS(); |
||||
} |
||||
break; |
||||
default: |
||||
// do nothing
|
||||
break; |
||||
} |
||||
} |
||||
|
||||
WebProjectDebugData CurrentProjectDebugData { |
||||
get { |
||||
var data = WebProjectsOptions.Instance.GetWebProjectOptions(ProjectService.CurrentProject.Name); |
||||
if (data != null) |
||||
return data.Data; |
||||
|
||||
return null; |
||||
} |
||||
set { |
||||
WebProjectOptions data; |
||||
if (value != null) |
||||
{ |
||||
data = new WebProjectOptions() { |
||||
ProjectName = ProjectService.CurrentProject.Name, |
||||
Data = value |
||||
}; |
||||
} |
||||
else |
||||
data = new WebProjectOptions(); |
||||
|
||||
WebProjectsOptions.Instance.SetWebProjectOptions(ProjectService.CurrentProject.Name, data); |
||||
} |
||||
} |
||||
|
||||
void CreateVirtualDirectory_Click(object sender, RoutedEventArgs e) |
||||
{ |
||||
string error = WebProjectService.CreateVirtualDirectory(ProjectService.CurrentProject.Name, |
||||
Path.GetDirectoryName(ProjectService.CurrentProject.FileName)); |
||||
|
||||
if (!string.IsNullOrEmpty(error)) |
||||
MessageService.ShowError(error); |
||||
else { |
||||
MessageService.ShowMessage(ResourceService.GetString("ICSharpCode.WepProjectOptionsPanel.VirtualDirCreated")); |
||||
} |
||||
} |
||||
|
||||
void UseIISExpress_Click(object sender, RoutedEventArgs e) |
||||
{ |
||||
SelectIISExpress(); |
||||
} |
||||
|
||||
void SelectIISExpress() |
||||
{ |
||||
WebProjectDebugData data = new WebProjectDebugData(); |
||||
data.WebServer = WebServer.IISExpress; |
||||
data.Port = PortTextBox.Text; |
||||
data.ProjectUrl = string.Format(@"http://localhost:{0}/" + ProjectService.CurrentProject.Name, PortTextBox.Text); |
||||
bool isIISExpressInstalled = WebProjectService.IISVersion == IISVersion.IISExpress; |
||||
|
||||
if (!isIISExpressInstalled) { |
||||
UseIISExpress.IsChecked = false; |
||||
data.WebServer = WebServer.None; |
||||
StatusLabel.Text = ResourceService.GetString("ICSharpCode.WepProjectOptionsPanel.IISNotFound"); |
||||
data.ProjectUrl = string.Empty; |
||||
} |
||||
else |
||||
StatusLabel.Text = string.Empty; |
||||
|
||||
IISExpressGroup.IsEnabled = CreateVirtualDirectoryButton.IsEnabled = isIISExpressInstalled; |
||||
LocalIISGroup.IsEnabled = false; |
||||
CurrentProjectDebugData = data; |
||||
} |
||||
|
||||
void UseLocalIIS_Click(object sender, RoutedEventArgs e) |
||||
{ |
||||
SelectLocalIIS(); |
||||
} |
||||
|
||||
void SelectLocalIIS() |
||||
{ |
||||
WebProjectDebugData data = new WebProjectDebugData(); |
||||
data.WebServer = WebServer.IIS; |
||||
data.Port = string.Empty; |
||||
bool isIISInstalled = WebProjectService.IISVersion == IISVersion.IIS5 || |
||||
WebProjectService.IISVersion == IISVersion.IIS6 || |
||||
WebProjectService.IISVersion == IISVersion.IIS7; |
||||
|
||||
if (!isIISInstalled) { |
||||
StatusLabel.Text = ResourceService.GetString("ICSharpCode.WepProjectOptionsPanel.IISNotFound"); |
||||
ProjectUrl.Text = string.Empty; |
||||
data.WebServer = WebServer.None; |
||||
UseLocalIIS.IsChecked = false; |
||||
} |
||||
else { |
||||
StatusLabel.Text = string.Empty; |
||||
ProjectUrl.Text = @"http://localhost/" + ProjectService.CurrentProject.Name; |
||||
} |
||||
|
||||
data.ProjectUrl = ProjectUrl.Text; |
||||
LocalIISGroup.IsEnabled = CreateVirtualDirectoryButton.IsEnabled = isIISInstalled; |
||||
IISExpressGroup.IsEnabled = false; |
||||
CurrentProjectDebugData = data; |
||||
} |
||||
|
||||
void ProjectUrl_TextChanged(object sender, TextChangedEventArgs e) |
||||
{ |
||||
WebProjectDebugData data = new WebProjectDebugData(); |
||||
data.WebServer = WebServer.IIS; |
||||
data.ProjectUrl = ProjectUrl.Text; |
||||
CurrentProjectDebugData = data; |
||||
} |
||||
|
||||
void ClearWebServerButton_Click(object sender, RoutedEventArgs e) |
||||
{ |
||||
UseIISExpress.IsChecked = false; |
||||
UseLocalIIS.IsChecked = false; |
||||
CreateVirtualDirectoryButton.IsEnabled = false; |
||||
ProjectUrl.Text = string.Empty; |
||||
LocalIISGroup.IsEnabled = false; |
||||
IISExpressGroup.IsEnabled = false; |
||||
|
||||
WebProjectDebugData data = new WebProjectDebugData(); |
||||
data.WebServer = WebServer.None; |
||||
data.ProjectUrl = string.Empty; |
||||
|
||||
CurrentProjectDebugData = data; |
||||
} |
||||
|
||||
bool AreAllValidNumericChars(string str) |
||||
{ |
||||
foreach(char c in str) |
||||
{ |
||||
if(!Char.IsNumber(c)) return false; |
||||
} |
||||
|
||||
return true; |
||||
} |
||||
|
||||
void PortTextBox_PreviewTextInput(object sender, System.Windows.Input.TextCompositionEventArgs e) |
||||
{ |
||||
e.Handled = !AreAllValidNumericChars(e.Text); |
||||
base.OnPreviewTextInput(e); |
||||
} |
||||
|
||||
void PortTextBox_KeyUp(object sender, System.Windows.Input.KeyEventArgs e) |
||||
{ |
||||
WebProjectDebugData data = new WebProjectDebugData(); |
||||
data.WebServer = WebServer.IISExpress; |
||||
data.Port = PortTextBox.Text; |
||||
data.ProjectUrl = string.Format(@"http://localhost:{0}/" + ProjectService.CurrentProject.Name, PortTextBox.Text); |
||||
CurrentProjectDebugData = data; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,257 @@
@@ -0,0 +1,257 @@
|
||||
// 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.EnterpriseServices.Internal; |
||||
using System.IO; |
||||
using System.Reflection; |
||||
|
||||
using ICSharpCode.Core; |
||||
using Microsoft.Win32; |
||||
|
||||
namespace ICSharpCode.SharpDevelop.Project |
||||
{ |
||||
public enum IISVersion |
||||
{ |
||||
None = 0, |
||||
IIS5 = 5, |
||||
IIS6, |
||||
IIS7, |
||||
IISExpress, |
||||
IIS_Future |
||||
} |
||||
|
||||
public enum WebServer |
||||
{ |
||||
None, |
||||
IISExpress, |
||||
IIS |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Exposes common operations used in Web Projects
|
||||
/// </summary>
|
||||
public static class WebProjectService |
||||
{ |
||||
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_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\"; |
||||
|
||||
/// <summary>
|
||||
/// Gets "iisexpress" string.
|
||||
/// </summary>
|
||||
public const string IIS_EXPRESS_PROCESS_NAME = "iisexpress"; |
||||
|
||||
/// <summary>
|
||||
/// Gets "aspnet_wp" string.
|
||||
/// </summary>
|
||||
public const string IIS_5_PROCESS_NAME = "aspnet_wp"; |
||||
|
||||
/// <summary>
|
||||
/// Gets "w3wp" string.
|
||||
/// </summary>
|
||||
public const string IIS_NEW_PROCESS_NAME = "w3wp"; |
||||
|
||||
/// <summary>
|
||||
/// Gets IIS Express process location.
|
||||
/// </summary>
|
||||
public static string IIISExpressProcessLocation { |
||||
get { |
||||
return Environment.GetFolderPath(System.Environment.SpecialFolder.ProgramFiles) + |
||||
@"\IIS Express\iisexpress.exe"; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the IIS worker process name.
|
||||
/// </summary>
|
||||
public static string WorkerProcessName { |
||||
get { |
||||
if (!IsIISInstalled) |
||||
return ResourceService.GetString("ICSharpCode.WepProjectOptionsPanel.IISNotFound"); |
||||
|
||||
try { |
||||
string name; |
||||
|
||||
switch(IISVersion) |
||||
{ |
||||
case IISVersion.IIS5: |
||||
name = IIS_5_PROCESS_NAME; |
||||
break; |
||||
case IISVersion.IISExpress: |
||||
name = IIS_EXPRESS_PROCESS_NAME; |
||||
break; |
||||
default: |
||||
name = IIS_NEW_PROCESS_NAME; |
||||
break; |
||||
} |
||||
|
||||
return name; |
||||
} |
||||
catch (Exception ex) { |
||||
return ex.Message; |
||||
} |
||||
} |
||||
} |
||||
|
||||
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>
|
||||
public static bool IsIISInstalled { |
||||
get { |
||||
return (int)IISVersion > 4; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets a value representing IIS version.
|
||||
/// </summary>
|
||||
public static IISVersion IISVersion |
||||
{ |
||||
get { |
||||
int regValue = 0; |
||||
|
||||
RegistryService.GetRegistryValue<int>( |
||||
RegistryHive.LocalMachine, |
||||
IIS_LOCATION, |
||||
IIS_MAJOR_VERSION, |
||||
RegistryValueKind.DWord, |
||||
out regValue); |
||||
|
||||
if (regValue > 4) |
||||
return (IISVersion)regValue; |
||||
|
||||
if (File.Exists(IIISExpressProcessLocation)) |
||||
return IISVersion.IISExpress; |
||||
|
||||
return IISVersion.None; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Creates a virtual directory in local IIS or IIS Express.
|
||||
/// </summary>
|
||||
/// <param name="virtualDirectoryName">Virtual directory name.</param>
|
||||
/// <param name="virtualDirectoryPath">Physical path.</param>
|
||||
/// <returns></returns>
|
||||
public static string CreateVirtualDirectory(string virtualDirectoryName, string physicalDirectoryPath) |
||||
{ |
||||
try { |
||||
if (!IsIISInstalled) |
||||
return ResourceService.GetString("ICSharpCode.WepProjectOptionsPanel.IISNotFound"); |
||||
|
||||
string error; |
||||
|
||||
switch(IISVersion) |
||||
{ |
||||
case IISVersion.IIS5: |
||||
case IISVersion.IIS6: |
||||
var vr = new IISVirtualRoot(); |
||||
vr.Create(IIS_WEB_LOCATION, |
||||
physicalDirectoryPath, |
||||
virtualDirectoryName, |
||||
out error); |
||||
break; |
||||
|
||||
default: |
||||
// TODO: find a better way to create IIS 7 applications without Microsoft.Web.Administration.ServerManager
|
||||
string name = "/" + virtualDirectoryName; |
||||
// load from GAC - IIS7 is installed
|
||||
Assembly webAdministrationAssembly; |
||||
try { |
||||
// iis 7
|
||||
webAdministrationAssembly = Assembly.Load("Microsoft.Web.Administration, Version=7.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"); |
||||
} |
||||
catch { |
||||
// iis express
|
||||
webAdministrationAssembly = Assembly.Load("Microsoft.Web.Administration, Version=7.9.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"); |
||||
} |
||||
|
||||
// use dynamic because classic reflection is way TOO ugly
|
||||
dynamic manager = webAdministrationAssembly.CreateInstance("Microsoft.Web.Administration.ServerManager"); |
||||
|
||||
if (manager.Sites[DEFAULT_WEB_SITE] != null) { |
||||
if (manager.Sites[DEFAULT_WEB_SITE].Applications[name] == null) { |
||||
manager.Sites[DEFAULT_WEB_SITE].Applications.Add(name, physicalDirectoryPath); |
||||
manager.CommitChanges(); |
||||
error = string.Empty; |
||||
} else { |
||||
error = ResourceService.GetString("ICSharpCode.WepProjectOptionsPanel.ApplicationExists"); |
||||
} |
||||
} else { |
||||
if (manager.Sites[0].Applications[name] == null) { |
||||
manager.Sites[0].Applications.Add(name, physicalDirectoryPath); |
||||
manager.CommitChanges(); |
||||
error = string.Empty; |
||||
} else { |
||||
error = ResourceService.GetString("ICSharpCode.WepProjectOptionsPanel.ApplicationExists"); |
||||
} |
||||
} |
||||
manager.Dispose(); |
||||
break; |
||||
} |
||||
|
||||
return error; |
||||
} |
||||
catch (Exception ex) { |
||||
return ex.Message; |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,58 @@
@@ -0,0 +1,58 @@
|
||||
// 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.Globalization; |
||||
using Microsoft.Win32; |
||||
|
||||
namespace ICSharpCode.Core |
||||
{ |
||||
/// <summary>
|
||||
/// RegistryService.
|
||||
/// </summary>
|
||||
public static class RegistryService |
||||
{ |
||||
/// <summary>
|
||||
/// Gets the registry value.
|
||||
/// </summary>
|
||||
/// <param name="hive">Registry hive.</param>
|
||||
/// <param name="key">Registry key.</param>
|
||||
/// <param name="value">Registry value.</param>
|
||||
/// <param name="kind">Registry kind.</param>
|
||||
/// <param name="data">Data.</param>
|
||||
/// <returns>True, if the data was found, False otherwise.</returns>
|
||||
public static bool GetRegistryValue<T>(RegistryHive hive, string key, string value, RegistryValueKind kind, out T data) |
||||
{ |
||||
data = default(T); |
||||
|
||||
try { |
||||
using (RegistryKey baseKey = RegistryKey.OpenRemoteBaseKey(hive, String.Empty)) |
||||
{ |
||||
if (baseKey != null) |
||||
{ |
||||
using (RegistryKey registryKey = baseKey.OpenSubKey(key, RegistryKeyPermissionCheck.ReadSubTree)) |
||||
{ |
||||
if (registryKey != null) |
||||
{ |
||||
RegistryValueKind kindFound = registryKey.GetValueKind(value); |
||||
if (kindFound == kind) |
||||
{ |
||||
object regValue = registryKey.GetValue(value, null); |
||||
if (regValue != null) |
||||
{ |
||||
data = (T)Convert.ChangeType(regValue, typeof(T), CultureInfo.InvariantCulture); |
||||
return true; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
return false; |
||||
} catch { |
||||
return false; |
||||
} |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue