public void Revert() { var dialog = (IManagementUIService)this.GetService(typeof(IManagementUIService)); var result = dialog.ShowMessage( "Reverting to the parent configuration will result in the loss of all settings in the local configuration file for this feature. Are you sure you want to continue?", this.Name, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1); if (result != DialogResult.Yes) { return; } var service = (IConfigurationService)this.GetService(typeof(IConfigurationService)); var section = service.GetSection("system.webServer/rewrite/outboundRules"); ConfigurationElementCollection collection = section.GetCollection("preConditions"); collection.Clear(); collection.Delete(); collection = section.GetCollection(); this.SelectedItem = null; this.Items.Clear(); foreach (ConfigurationElement ruleElement in collection) { var node = new PreConditionItem(ruleElement); this.Items.Add(node); } service.ServerManager.CommitChanges(); this.OnRewriteSettingsSaved(); }
public PreConditionListViewItem(PreConditionItem item, PreConditionsPage page) : base(item.Name) { this.Item = item; _page = page; this.SubItems.Add(new ListViewSubItem(this, item.Conditions.Count.ToString())); this.SubItems.Add(new ListViewSubItem(this, item.Flag)); }
public void Load() { this.Items = new List <PreConditionItem>(); var service = (IConfigurationService)this.GetService(typeof(IConfigurationService)); var section = service.GetSection("system.webServer/rewrite/outboundRules"); ConfigurationElementCollection rulesCollection = section.GetCollection("preConditions"); foreach (ConfigurationElement ruleElement in rulesCollection) { var node = new PreConditionItem(ruleElement); this.Items.Add(node); } this.CanRevert = section.CanRevert(); this.OnRewriteSettingsSaved(); }
public void Load() { var service = (IConfigurationService)this.GetService(typeof(IConfigurationService)); var outSection = service.GetSection("system.webServer/rewrite/outboundRules"); var preConditions = outSection.ChildElements["preConditions"]; this.PreConditions = new List <PreConditionItem>(); this.Tags = new List <CustomTagsItem>(); foreach (ConfigurationElement condition in preConditions.GetCollection()) { var item = new PreConditionItem(condition); this.PreConditions.Add(item); } var tags = outSection.ChildElements["customTags"]; foreach (ConfigurationElement condition in tags.GetCollection()) { var item = new CustomTagsItem(condition); this.Tags.Add(item); } this.LoadItems(); }
public AddPreConditionDialog(IServiceProvider serviceProvider, PreConditionItem existing) : base(serviceProvider) { InitializeComponent(); Item = existing ?? new PreConditionItem(null); if (existing != null) { txtName.Text = Item.Name; cbUsing.SelectedIndex = (int)Item.PatternSyntax; cbGrouping.SelectedIndex = (int)Item.LogicalGrouping; foreach (var condition in Item.Conditions) { lvConditions.Items.Add(new ConditionListViewItem(condition)); } } var container = new CompositeDisposable(); FormClosed += (sender, args) => container.Dispose(); container.Add( Observable.FromEventPattern <EventArgs>(btnAdd, "Click") .ObserveOn(System.Threading.SynchronizationContext.Current) .Subscribe(evt => { var dialog = new AddConditionDialog(ServiceProvider, null); if (dialog.ShowDialog() != DialogResult.OK) { return; } var newItem = dialog.Item; Item.Conditions.Add(newItem); var listViewItem = new ConditionListViewItem(newItem); lvConditions.Items.Add(listViewItem); listViewItem.Selected = true; })); container.Add( Observable.FromEventPattern <EventArgs>(btnRemove, "Click") .ObserveOn(System.Threading.SynchronizationContext.Current) .Subscribe(evt => { var dialog = (IManagementUIService)GetService(typeof(IManagementUIService)); if ( dialog.ShowMessage("Are you sure that you want to remove the selected condition?", "Confirm Remove", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) != DialogResult.Yes) { return; } var listViewItem = ((ConditionListViewItem)lvConditions.SelectedItems[0]); listViewItem.Remove(); var item = listViewItem.Item; Item.Conditions.Remove(item); })); container.Add( Observable.FromEventPattern <EventArgs>(btnEdit, "Click") .ObserveOn(System.Threading.SynchronizationContext.Current) .Subscribe(evt => { var listViewItem = ((ConditionListViewItem)lvConditions.SelectedItems[0]); var dialog = new AddConditionDialog(ServiceProvider, listViewItem.Item); if (dialog.ShowDialog() != DialogResult.OK) { return; } listViewItem.Update(); })); container.Add( Observable.FromEventPattern <EventArgs>(btnMoveDown, "Click") .ObserveOn(System.Threading.SynchronizationContext.Current) .Subscribe(evt => { var listViewItem = ((ConditionListViewItem)lvConditions.SelectedItems[0]); var index = listViewItem.Index; var item = listViewItem.Item; Item.Conditions.RemoveAt(index); listViewItem.Remove(); Item.Conditions.Insert(index + 1, item); lvConditions.Items.Insert(index + 1, listViewItem); listViewItem.Selected = true; })); container.Add( Observable.FromEventPattern <EventArgs>(btnMoveUp, "Click") .ObserveOn(System.Threading.SynchronizationContext.Current) .Subscribe(evt => { var listViewItem = ((ConditionListViewItem)lvConditions.SelectedItems[0]); var index = listViewItem.Index; var item = listViewItem.Item; Item.Conditions.RemoveAt(index); listViewItem.Remove(); Item.Conditions.Insert(index - 1, item); lvConditions.Items.Insert(index - 1, listViewItem); listViewItem.Selected = true; })); container.Add( Observable.FromEventPattern <ListViewItemSelectionChangedEventArgs>(lvConditions, "ItemSelectionChanged") .ObserveOn(System.Threading.SynchronizationContext.Current) .Subscribe(evt => { var hasSelection = lvConditions.SelectedItems.Count > 0; btnRemove.Enabled = btnEdit.Enabled = hasSelection; btnMoveDown.Enabled = hasSelection && lvConditions.SelectedItems[0].Index < lvConditions.Items.Count - 1; btnMoveUp.Enabled = hasSelection && lvConditions.SelectedItems[0].Index > 0; })); container.Add( Observable.FromEventPattern <EventArgs>(txtName, "TextChanged") .Sample(TimeSpan.FromSeconds(1)) .ObserveOn(System.Threading.SynchronizationContext.Current) .Subscribe(evt => { btnOK.Enabled = !string.IsNullOrWhiteSpace(txtName.Text); })); container.Add( Observable.FromEventPattern <EventArgs>(btnOK, "Click") .ObserveOn(System.Threading.SynchronizationContext.Current) .Subscribe(evt => { Item.Name = txtName.Text; Item.PatternSyntax = cbUsing.SelectedIndex; Item.LogicalGrouping = cbGrouping.SelectedIndex; Item.Conditions.Clear(); foreach (ConditionListViewItem item in lvConditions.Items) { Item.Conditions.Add(item.Item); } DialogResult = DialogResult.OK; })); }