12 changed files with 671 additions and 450 deletions
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,68 @@
@@ -0,0 +1,68 @@
|
||||
// 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(WebServer.None)] |
||||
public WebServer WebServer { get; set; } |
||||
} |
||||
} |
@ -0,0 +1,66 @@
@@ -0,0 +1,66 @@
|
||||
<?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" |
||||
Margin="0, 0, 0, 10"> |
||||
<StackPanel |
||||
Orientation="Vertical"> |
||||
<GroupBox |
||||
Header="{core:Localize ICSharpCode.WepProjectOptionsPanel.Server}"> |
||||
<widgets:StackPanelWithSpacing SpaceBetweenItems="5"> |
||||
<!--IIS Express--> |
||||
<widgets:StackPanelWithSpacing SpaceBetweenItems="5"> |
||||
<RadioButton |
||||
IsChecked="False" |
||||
GroupName="WebProject" |
||||
x:Name="UseIISExpress" |
||||
Click="UseIISExpress_Click" |
||||
Content="{core:Localize ICSharpCode.WepProjectOptionsPanel.UseIISExpress}" /> |
||||
</widgets:StackPanelWithSpacing> |
||||
<!--IIS Local Server--> |
||||
<widgets:StackPanelWithSpacing SpaceBetweenItems="5"> |
||||
<RadioButton |
||||
IsChecked="False" |
||||
GroupName="WebProject" |
||||
x:Name="UseLocalIIS" |
||||
Click="UseLocalIIS_Click" |
||||
Content="{core:Localize ICSharpCode.WepProjectOptionsPanel.UseLocalIIS}" /> |
||||
<Grid Margin="10, 10" |
||||
IsEnabled="False" |
||||
x:Name="LocalIISGroup" |
||||
VerticalAlignment="Top"> |
||||
<Grid.ColumnDefinitions> |
||||
<ColumnDefinition Width="Auto"/> |
||||
<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" /> |
||||
<Button |
||||
Grid.Row="1" |
||||
Grid.Column="2" |
||||
Style="{x:Static core:GlobalStyles.ButtonStyle}" |
||||
Name="CreateVirtualDirectoryButton" |
||||
Content="{core:Localize ICSharpCode.WepProjectOptionsPanel.CreateVirtualDir}" |
||||
Click="CreateVirtualDirectory_Click" /> |
||||
</Grid> |
||||
<TextBlock |
||||
Foreground="Red" |
||||
TextDecorations="Underline" |
||||
FontSize="12" |
||||
FontWeight="Bold" |
||||
TextWrapping="Wrap" |
||||
Name="StatusLabel" /> |
||||
</widgets:StackPanelWithSpacing> |
||||
</widgets:StackPanelWithSpacing> |
||||
</GroupBox> |
||||
</StackPanel> |
||||
</UserControl> |
@ -0,0 +1,131 @@
@@ -0,0 +1,131 @@
|
||||
// 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.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 += delegate(object sender, RoutedEventArgs e) { |
||||
switch (CurrentProjectDebugData.WebServer) |
||||
{ |
||||
case WebServer.IISExpress: |
||||
UseIISExpress.IsChecked = true; |
||||
UseIISExpress_Click(null, null); |
||||
break; |
||||
case WebServer.IIS: |
||||
UseLocalIIS.IsChecked = true; |
||||
ProjectUrl.Text = CurrentProjectDebugData.ProjectUrl ?? string.Empty; |
||||
UseLocalIIS_Click(null, null); |
||||
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) |
||||
{ |
||||
WebProjectDebugData data = new WebProjectDebugData(); |
||||
data.WebServer = WebServer.IISExpress; |
||||
|
||||
if (ProjectService.CurrentProject is CompilableProject) { |
||||
((CompilableProject)ProjectService.CurrentProject).StartAction = StartAction.Program; |
||||
parentPanel.SetStartAction(StartAction.Program); |
||||
} |
||||
|
||||
LocalIISGroup.IsEnabled = false; |
||||
CurrentProjectDebugData = data; |
||||
} |
||||
|
||||
void UseLocalIIS_Click(object sender, RoutedEventArgs e) |
||||
{ |
||||
WebProjectDebugData data = new WebProjectDebugData(); |
||||
data.WebServer = WebServer.IIS; |
||||
|
||||
if (!WebProjectService.IsIISInstalled) { |
||||
StatusLabel.Text = ResourceService.GetString("ICSharpCode.WepProjectOptionsPanel.IISNotFound"); |
||||
ProjectUrl.Text = string.Empty; |
||||
} |
||||
else { |
||||
StatusLabel.Text = string.Empty; |
||||
ProjectUrl.Text = @"http://localhost/" + ProjectService.CurrentProject.Name; |
||||
} |
||||
|
||||
data.ProjectUrl = ProjectUrl.Text; |
||||
CreateVirtualDirectoryButton.IsEnabled = WebProjectService.IsIISInstalled; |
||||
ProjectUrl.IsEnabled = WebProjectService.IsIISInstalled; |
||||
|
||||
if (ProjectService.CurrentProject is CompilableProject) { |
||||
((CompilableProject)ProjectService.CurrentProject).StartAction = StartAction.Project; |
||||
parentPanel.SetStartAction(StartAction.Project); |
||||
} |
||||
|
||||
LocalIISGroup.IsEnabled = true; |
||||
CurrentProjectDebugData = data; |
||||
} |
||||
|
||||
void ProjectUrl_TextChanged(object sender, TextChangedEventArgs e) |
||||
{ |
||||
WebProjectDebugData data = new WebProjectDebugData(); |
||||
data.WebServer = WebServer.IIS; |
||||
data.ProjectUrl = ProjectUrl.Text; |
||||
CurrentProjectDebugData = data; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,145 @@
@@ -0,0 +1,145 @@
|
||||
// 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 ICSharpCode.Core; |
||||
using Microsoft.Win32; |
||||
|
||||
namespace ICSharpCode.SharpDevelop.Project |
||||
{ |
||||
public enum IISVersion |
||||
{ |
||||
IIS5 = 5, |
||||
IIS6, |
||||
IIS7, |
||||
IIS_Future |
||||
} |
||||
|
||||
public enum WebServer |
||||
{ |
||||
None, |
||||
IISExpress, |
||||
IIS |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Exposes common operations used in Web Projects
|
||||
/// </summary>
|
||||
public static class WebProjectService |
||||
{ |
||||
const string IIS_REG_KEY_NAME = "Software\\Microsoft\\InetStp"; |
||||
const string IIS_REG_KEY_VALUE = "MajorVersion"; |
||||
const string DEFAULT_WEB_SITE = "Default Web Site"; |
||||
const string IIS_LOCATION = "IIS://localhost/W3SVC/1/Root"; |
||||
|
||||
/// <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 = "aspnet_wp"; |
||||
break; |
||||
|
||||
default: |
||||
name = "w3wp"; |
||||
break; |
||||
} |
||||
|
||||
return name; |
||||
} |
||||
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_REG_KEY_NAME, |
||||
IIS_REG_KEY_VALUE, |
||||
RegistryValueKind.DWord, |
||||
out regValue); |
||||
|
||||
return (IISVersion)regValue; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Creates a virtual directory in IIS.
|
||||
/// </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_LOCATION, |
||||
physicalDirectoryPath, |
||||
virtualDirectoryName, |
||||
out error); |
||||
break; |
||||
|
||||
default: |
||||
using (var manager = new Microsoft.Web.Administration.ServerManager()) |
||||
{ |
||||
string name = "/" + virtualDirectoryName; |
||||
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 |
||||
error = ResourceService.GetString("ICSharpCode.WepProjectOptionsPanel.MultipleIISServers"); |
||||
} |
||||
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