-
-
Notifications
You must be signed in to change notification settings - Fork 59
/
NewRestrictionDialog.cs
83 lines (73 loc) · 3.17 KB
/
NewRestrictionDialog.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// Copyright (c) Lex Li. All rights reserved.
//
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
namespace JexusManager.Features.IsapiCgiRestriction
{
using System;
using System.ComponentModel;
using System.Linq;
using System.Reactive.Disposables;
using System.Reactive.Linq;
using System.Windows.Forms;
using Microsoft.Web.Management.Client.Win32;
internal sealed partial class NewRestrictionDialog : DialogForm
{
public NewRestrictionDialog(IServiceProvider serviceProvider, IsapiCgiRestrictionItem existing, IsapiCgiRestrictionFeature feature)
: base(serviceProvider)
{
InitializeComponent();
Text = existing == null ? "Add ISAPI or CGI Restriction" : "Edit ISAPI or CGI Restriction";
Item = existing ?? new IsapiCgiRestrictionItem(null);
if (existing != null)
{
txtPath.Text = Item.Path;
txtName.Text = Item.Description;
cbAllowed.Checked = Item.Allowed;
}
var container = new CompositeDisposable();
FormClosed += (sender, args) => container.Dispose();
container.Add(
Observable.FromEventPattern<EventArgs>(btnOK, "Click")
.ObserveOn(System.Threading.SynchronizationContext.Current)
.Subscribe(evt =>
{
Item.Path = txtPath.Text;
Item.Description = txtName.Text;
Item.Allowed = cbAllowed.Checked;
if (feature.Items.Any(item => item.Match(Item)))
{
ShowMessage(
"This restriction already exists.",
MessageBoxButtons.OK,
MessageBoxIcon.Error,
MessageBoxDefaultButton.Button1);
return;
}
DialogResult = DialogResult.OK;
}));
container.Add(
Observable.FromEventPattern<EventArgs>(txtPath, "TextChanged")
.Sample(TimeSpan.FromSeconds(0.5))
.ObserveOn(System.Threading.SynchronizationContext.Current)
.Subscribe(evt =>
{
btnOK.Enabled = !string.IsNullOrWhiteSpace(txtPath.Text);
}));
container.Add(
Observable.FromEventPattern<EventArgs>(btnBrowse, "Click")
.ObserveOn(System.Threading.SynchronizationContext.Current)
.Subscribe(evt =>
{
DialogHelper.ShowOpenFileDialog(txtPath, "(*.dll)|*.dll|(*.exe)|*.exe|All files (*.*)|*.*", null);
}));
container.Add(
Observable.FromEventPattern<CancelEventArgs>(this, "HelpButtonClicked")
.ObserveOn(System.Threading.SynchronizationContext.Current)
.Subscribe(EnvironmentVariableTarget =>
{
feature.ShowHelp();
}));
}
public IsapiCgiRestrictionItem Item { get; set; }
}
}