Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,7 @@ public interface IWebSiteManager
void Update(WebSite webSite);

void ToggleStatus(WebSite webSite);

void Remove(long webSiteId);
}
}
24 changes: 17 additions & 7 deletions IISExpressGui/IISExpressGui.IISManagement/WebSiteManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class WebSiteManager : IWebSiteManager

string applicationHostConfigPath;
XmlDocument applicationHostConfig = new XmlDocument();
Dictionary<long, IISExpress> runningProcesses = new Dictionary<long, IISExpress>();
Dictionary<long, IISExpress> runningProcesses = new Dictionary<long, IISExpress>();

#endregion

Expand All @@ -40,13 +40,13 @@ public WebSiteManager(string applicationHostConfigPath)
public string IISPath
{
get { return IISExpress.IISDefaultPath; }
}
}

#endregion

#region Public Methods

public IList<WebSite> GetAllWebSites()
public IList<WebSite> GetAllWebSites()
{
if (!ApplicationHostConfigExists())
{
Expand Down Expand Up @@ -160,7 +160,8 @@ public void Update(WebSite webSite)
var virtualDirectoryNode = siteNode.SelectSingleNode("descendant::virtualDirectory");
virtualDirectoryNode.Attributes["physicalPath"].Value = webSite.PhysicalPath;
var bindingNode = siteNode.SelectSingleNode("descendant::binding");
bindingNode.Attributes["bindingInformation"].Value = string.Format(":{0}:localhost", webSite.Port);
var ip = webSite.Url.Replace("http://", "");
bindingNode.Attributes["bindingInformation"].Value = string.Format(":{0}:{1}", webSite.Port, ip);
this.applicationHostConfig.Save(this.applicationHostConfigPath);
}

Expand All @@ -181,6 +182,15 @@ public void ToggleStatus(WebSite webSite)
}
}

public void Remove(long webSiteId)
{
var siteByIdQuery = string.Format("descendant::site[@id='{0}']", webSiteId);
var siteNode = this.applicationHostConfig.SelectSingleNode(siteByIdQuery);
if (siteNode == null) return;
siteNode.ParentNode?.RemoveChild(siteNode);
this.applicationHostConfig.Save(this.applicationHostConfigPath);
}

public bool IsIISExpressInstalled()
{
return File.Exists(IISPath);
Expand All @@ -191,7 +201,7 @@ public bool ApplicationHostConfigExists()
return File.Exists(applicationHostConfigPath);
}

#endregion
#endregion

#region Private Methods

Expand All @@ -209,7 +219,7 @@ private void Stop(WebSite webSite)
this.runningProcesses.Remove(webSite.Id);
iisExpressInstance.Stop();
}
}
}

#endregion
}
Expand Down
3 changes: 2 additions & 1 deletion IISExpressGui/IISExpressGui.Presentation/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
<Window.Resources>
<ResourceDictionary Source="MainWindowResources.xaml" />
</Window.Resources>

<DockPanel>
<DockPanel DockPanel.Dock="Top" KeyboardNavigation.TabNavigation="None">
<Menu KeyboardNavigation.TabNavigation="Cycle">
<MenuItem Header="_File">
<MenuItem Header="_New WebSite" Command="{Binding Path=CreateWebSiteCommand}" />
<MenuItem Header="_Clear Invalided WebSite" Command="{Binding Path=ClearInvalidedWebSiteCommand}"></MenuItem>
<MenuItem Header="E_xit" Command="{Binding Path=CloseCommand}" />
</MenuItem>
<!--<MenuItem Header="_Edit" />-->
Expand Down
35 changes: 29 additions & 6 deletions IISExpressGui/IISExpressGui.Presentation/MainWindowResources.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@
HeaderTemplate="{StaticResource ContextMenuItemHeaderTemplate}"
Command="{Binding Path=ToggleStatusCommand}"
/>
<MenuItem Header="Delete"
Command="{Binding Path=DeleteWebSiteCommand}"></MenuItem>
</ContextMenu>
</StackPanel.ContextMenu>
</StackPanel>
Expand Down Expand Up @@ -165,6 +167,7 @@
<RowDefinition Height="30"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="30"/>
<RowDefinition Height="30"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="30"/>
<RowDefinition Height="*"/>
Expand All @@ -187,8 +190,8 @@
HorizontalAlignment="Right"
Target="portTextBox"/>
<StackPanel Orientation="Horizontal" Grid.Row="2" Grid.Column="1">
<TextBlock VerticalAlignment="Center"
Text="{Binding Path=Url}" />
<TextBox VerticalAlignment="Center" Width="200"
Text="{Binding Path=Url}" />
<TextBlock VerticalAlignment="Center"
Text=":" />
<TextBox x:Name="portTextBox"
Expand All @@ -201,11 +204,31 @@
<ContentPresenter Grid.Row="3" Grid.Column="1"
Content="{Binding ElementName=portTextBox, Path=(Validation.Errors).CurrentItem}"
/>
<Label Grid.Row="4" Grid.Column="0"
<Button Grid.Row="4" Grid.Column="1" Content="{Binding ViewUrl}" Command="{Binding Path=OpenBrowserCommand}">
<Button.Template>
<ControlTemplate TargetType="Button">
<TextBlock Cursor="Hand">
<TextBlock.Style>
<Style TargetType="TextBlock">
<Setter Property="Foreground" Value="Blue"></Setter>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Foreground" Value="DarkGreen"></Setter>
</Trigger>
</Style.Triggers>
</Style>
</TextBlock.Style>
<ContentPresenter Content="{TemplateBinding Content}"></ContentPresenter>
</TextBlock>
</ControlTemplate>
</Button.Template>
</Button>

<Label Grid.Row="5" Grid.Column="0"
Content="_Path:"
HorizontalAlignment="Right"
Target="pathTextBox"/>
<StackPanel Orientation="Horizontal" Grid.Row="4" Grid.Column="1">
<StackPanel Orientation="Horizontal" Grid.Row="5" Grid.Column="1">
<TextBox x:Name="pathTextBox"
Text="{Binding Path=PhysicalPath, ValidatesOnDataErrors=True}"
HorizontalAlignment="Left"
Expand All @@ -218,11 +241,11 @@
Margin="4,2"
MinWidth="60" />
</StackPanel>
<ContentPresenter Grid.Row="5" Grid.Column="1"
<ContentPresenter Grid.Row="6" Grid.Column="1"
Content="{Binding ElementName=pathTextBox, Path=(Validation.Errors).CurrentItem}"
/>
<Button
Grid.Row="6" Grid.Column="2"
Grid.Row="7" Grid.Column="2"
Command="{Binding Path=SaveCommand}"
Content="_Save"
HorizontalAlignment="Right"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Data;
using System.Windows.Input;

Expand All @@ -22,6 +23,7 @@ public class MainWindowViewModel : WorkspaceViewModel
readonly IMediator mediator;
readonly IWebSiteManager webSiteManager;
RelayCommand createWebSiteCommand;
RelayCommand clearInvalidedWebSiteCommand;

#endregion

Expand All @@ -36,7 +38,7 @@ public MainWindowViewModel(IWebSiteManager webSiteManager)
this.mediator = new Mediator();
this.webSiteManager = webSiteManager;
base.DisplayName = "IIS Express GUI";
}
}

#endregion

Expand All @@ -52,12 +54,16 @@ public ObservableCollection<WebSiteViewModel> WebSites
if (this.webSites == null)
{
List<WebSiteViewModel> webSiteList = LoadAvailableWebSites();
foreach (var model in webSiteList)
{
model.WhenDeleted = site => this.webSites.Remove(site);
}
this.webSites = new ObservableCollection<WebSiteViewModel>(webSiteList);
}
return this.webSites;
}
}

#endregion

#region Commands
Expand All @@ -78,7 +84,19 @@ public ICommand CreateWebSiteCommand
return this.createWebSiteCommand;
}
}


public ICommand ClearInvalidedWebSiteCommand
{
get
{
if (this.clearInvalidedWebSiteCommand == null)
{
this.clearInvalidedWebSiteCommand = new RelayCommand(param => ClearInvalidedWebSite());
}
return this.clearInvalidedWebSiteCommand;
}
}

#endregion

#region Methods
Expand All @@ -92,7 +110,7 @@ List<WebSiteViewModel> LoadAvailableWebSites()
).ToList();
return allWebSites;
}

void CreateWebSite()
{
var newWebSite = WebSiteViewModel.CreateNew(this.webSiteManager, this.mediator);
Expand All @@ -111,6 +129,27 @@ void SetActiveWebSite(WebSiteViewModel webSite)
}
}

void ClearInvalidedWebSite()
{
var tobeRemoved = new List<WebSiteViewModel>();
foreach (var webSite in WebSites)
{
if (!webSite.IsValid) tobeRemoved.Add(webSite);
}
if (tobeRemoved.Count <= 0) return;
if (MessageBox.Show($"Are you sure to clear the invalided websites? total:{tobeRemoved.Count}"
, "confirm"
, MessageBoxButton.YesNo
, MessageBoxImage.Question) == MessageBoxResult.Yes)
{
foreach (var viewModel in tobeRemoved)
{
webSiteManager.Remove(viewModel.WebSiteId);
WebSites.Remove(viewModel);
}
}
}

#endregion
}
}
}
Loading