Skip to content

Commit

Permalink
Fixed inbound rule page.
Browse files Browse the repository at this point in the history
  • Loading branch information
lextm committed Apr 14, 2018
1 parent 0a0c6ce commit 788f337
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 19 deletions.
22 changes: 12 additions & 10 deletions JexusManager.Features.Rewrite/ConditionItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,23 @@ public class ConditionItem

public ConditionItem(ConfigurationElement element)
{
this.Element = element;
Element = element;
if (element == null)
{
this.Input = "{QUERY_STRING}";
this.MatchType = 4;
this.IgnoreCase = true;
Input = "{QUERY_STRING}";
MatchType = 4;
IgnoreCase = true;
return;
}

this.Input = (string)element["input"];
this.Pattern = (string)element["pattern"];
this.IgnoreCase = (bool)element["ignoreCase"];
Input = (string)element["input"];
Pattern = (string)element["pattern"];
IgnoreCase = (bool)element["ignoreCase"];

var root = (long)element["matchType"];
var negate = (bool)element["negate"];
this.MatchType = (int)root * 2 + (negate ? 1 : 0);
var value = root == 0 ? 2 : root - 1;
MatchType = (int)value * 2 + (negate ? 1 : 0);
}

public bool IgnoreCase { get; set; }
Expand All @@ -44,7 +45,8 @@ public void Apply()
Element["pattern"] = Pattern;
Element["ignoreCase"] = IgnoreCase;
Element["negate"] = MatchType % 2 == 1;
Element["matchType"] = MatchType / 2;
var value = MatchType / 2;
Element["matchType"] = value == 2 ? 0 : value + 1;
}

public void AppendTo(ConfigurationElementCollection conditionsCollection)
Expand All @@ -54,4 +56,4 @@ public void AppendTo(ConfigurationElementCollection conditionsCollection)
conditionsCollection.Add(Element);
}
}
}
}
4 changes: 2 additions & 2 deletions JexusManager.Features.Rewrite/ConditionListViewItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public ConditionListViewItem(ConditionItem condition)
{
_matchType = new ListViewSubItem(this, GetText(condition.MatchType));
this.SubItems.Add(_matchType);
_pattern = new ListViewSubItem(this, condition.Pattern);
_pattern = new ListViewSubItem(this, condition.MatchType > 3 ? condition.Pattern : "N/A");
this.SubItems.Add(_pattern);
this.Item = condition;
}
Expand Down Expand Up @@ -52,4 +52,4 @@ private static string GetText(int matchType)
return string.Empty;
}
}
}
}
5 changes: 3 additions & 2 deletions JexusManager.Features.Rewrite/Inbound/AddConditionDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ namespace JexusManager.Features.Rewrite.Inbound
{
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Reactive.Disposables;
using System.Reactive.Linq;
using System.Windows.Forms;
Expand All @@ -36,9 +35,10 @@ public AddConditionDialog(IServiceProvider serviceProvider, ConditionItem existi
var check = Observable.FromEventPattern<EventArgs>(cbCheck, "SelectedIndexChanged");
container.Add(
check.ObserveOn(System.Threading.SynchronizationContext.Current)
.Merge(Observable.FromEventPattern<EventArgs>(this, "Load"))
.Subscribe(evt =>
{
txtPattern.Enabled = btnTest.Enabled = cbCheck.SelectedIndex > 3;
txtPattern.Enabled = btnTest.Enabled = cbIgnore.Enabled = cbCheck.SelectedIndex > 3;
if (!txtPattern.Enabled)
{
txtPattern.Text = string.Empty;
Expand All @@ -48,6 +48,7 @@ public AddConditionDialog(IServiceProvider serviceProvider, ConditionItem existi
container.Add(
Observable.FromEventPattern<EventArgs>(txtPattern, "TextChanged")
.Merge(check)
.Merge(Observable.FromEventPattern<EventArgs>(txtInput, "TextChanged"))
.Sample(TimeSpan.FromSeconds(1))
.ObserveOn(System.Threading.SynchronizationContext.Current)
.Subscribe(evt =>
Expand Down
2 changes: 2 additions & 0 deletions JexusManager.Features.Rewrite/Inbound/InboundRule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,14 @@ public void CancelChanges()
TrackAllCaptures = (bool)conditions["trackAllCaptures"];
LogicalGrouping = (long)conditions["logicalGrouping"];

Conditions.Clear();
foreach (ConfigurationElement condition in conditions.GetCollection())
{
var item = new ConditionItem(condition);
Conditions.Add(item);
}

ServerVariables.Clear();
var variables = Element.ChildElements["serverVariables"];
foreach (ConfigurationElement variable in variables.GetCollection())
{
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 19 additions & 5 deletions JexusManager.Features.Rewrite/Inbound/InboundRulePage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ namespace JexusManager.Features.Rewrite.Inbound
{
using System;
using System.Collections;
using System.Diagnostics;
using System.Reflection;
using System.Windows.Forms;

using JexusManager.Services;
using Microsoft.Web.Management.Client;
using Microsoft.Web.Management.Client.Win32;

Expand Down Expand Up @@ -94,7 +93,9 @@ public InboundRulePage()
protected override void Initialize(object navigationData)
{
base.Initialize(navigationData);
// TODO: pictureBox1.Image
var service = (IConfigurationService)ServiceProvider.GetService(typeof(IConfigurationService));
pictureBox1.Image = service.Scope.GetImage();

var info = (Tuple<InboundFeature, InboundRule>)navigationData;
_feature = info.Item1;
Rule = info.Item2;
Expand Down Expand Up @@ -260,8 +261,11 @@ protected override bool CanApplyChanges
{
get
{
return !string.IsNullOrWhiteSpace(txtName.Text) && !string.IsNullOrWhiteSpace(txtPattern.Text)
&& !string.IsNullOrWhiteSpace(txtUrl.Text);
return !string.IsNullOrWhiteSpace(txtName.Text) && !string.IsNullOrWhiteSpace(txtPattern.Text) &&
(
(cbAction.SelectedIndex == 1 && !string.IsNullOrWhiteSpace(txtUrl.Text)) ||
(cbAction.SelectedIndex == 2 && !string.IsNullOrWhiteSpace(txtRedirect.Text)) ||
(cbAction.SelectedIndex == 3 && !string.IsNullOrWhiteSpace(txtReason.Text) && !string.IsNullOrWhiteSpace(txtError.Text) && !string.IsNullOrWhiteSpace(txtStatus.Text) && !string.IsNullOrWhiteSpace(txtSubstatus.Text)));
}
}

Expand Down Expand Up @@ -547,5 +551,15 @@ private void UpdateVariablesButtons()
&& lvVariables.SelectedItems[0].Index < lvVariables.Items.Count - 1;
btnVarUp.Enabled = hasSelection && lvVariables.SelectedItems[0].Index > 0;
}

private void lvConditions_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
{
UpdateConditionsButtons();
}

private void lvVariables_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
{
UpdateVariablesButtons();
}
}
}

0 comments on commit 788f337

Please sign in to comment.