public ServerVariableListViewItem(ServerVariableItem variable)
     : base(variable.Name)
 {
     _value = new ListViewSubItem(this, variable.Value);
     SubItems.Add(_value);
     _replace = new ListViewSubItem(this, variable.Replace.ToString());
     SubItems.Add(_replace);
     Item = variable;
 }
        public AddServerVariableDialog(IServiceProvider serviceProvider, ServerVariableItem existing)
            : base(serviceProvider)
        {
            InitializeComponent();
            Item              = existing ?? new ServerVariableItem(null);
            cbName.Text       = Item.Name;
            txtValue.Text     = Item.Value;
            cbReplace.Checked = Item.Replace;
            var service      = (IConfigurationService)serviceProvider.GetService(typeof(IConfigurationService));
            var rulesSection = service.GetSection("system.webServer/rewrite/allowedServerVariables");
            ConfigurationElementCollection rulesCollection = rulesSection.GetCollection();

            foreach (ConfigurationElement ruleElement in rulesCollection)
            {
                cbName.Items.Add(ruleElement["name"]);
            }

            var container = new CompositeDisposable();

            FormClosed += (sender, args) => container.Dispose();

            container.Add(
                Observable.FromEventPattern <EventArgs>(txtValue, "TextChanged")
                .Merge(Observable.FromEventPattern <EventArgs>(cbName, "TextChanged"))
                .Sample(TimeSpan.FromSeconds(0.5))
                .ObserveOn(System.Threading.SynchronizationContext.Current)
                .Subscribe(evt =>
            {
                btnOK.Enabled = !string.IsNullOrWhiteSpace(cbName.Text) && !string.IsNullOrWhiteSpace(txtValue.Text);
            }));

            container.Add(
                Observable.FromEventPattern <EventArgs>(btnOK, "Click")
                .ObserveOn(System.Threading.SynchronizationContext.Current)
                .Subscribe(evt =>
            {
                Item.Name    = cbName.Text;
                Item.Value   = txtValue.Text;
                Item.Replace = cbReplace.Checked;
                DialogResult = DialogResult.OK;
            }));
        }
Example #3
0
        public void CancelChanges()
        {
            if (Element == null)
            {
                return;
            }

            this.Name           = (string)this.Element["name"];
            this.Enabled        = (bool)this.Element["enabled"];
            this.PatternSyntax  = (long)this.Element["patternSyntax"];
            this.StopProcessing = (bool)this.Element["stopProcessing"];
            ConfigurationElement matchElement = this.Element.ChildElements["match"];

            this.PatternUrl = (string)matchElement["url"];
            this.Negate     = (bool)matchElement["negate"];
            ConfigurationElement actionElement = this.Element.ChildElements["action"];

            this.Type              = (long)actionElement["type"];
            this.ActionUrl         = (string)actionElement["url"];
            this.AppendQueryString = (bool)actionElement["appendQueryString"];
            this.LogRewrittenUrl   = (bool)actionElement["logRewrittenUrl"];
            var redirect = (long)actionElement["redirectType"];

            switch (redirect)
            {
            case 301:
                this.RedirectType = 0;
                break;

            case 302:
                this.RedirectType = 1;
                break;

            case 303:
                this.RedirectType = 2;
                break;

            case 307:
                this.RedirectType = 3;
                break;
            }

            this.StatusCode        = (uint)actionElement["statusCode"];
            this.SubStatusCode     = (uint)actionElement["subStatusCode"];
            this.StatusReason      = (string)actionElement["statusReason"];
            this.StatusDescription = (string)actionElement["statusDescription"];

            var conditions = this.Element.ChildElements["conditions"];

            this.TrackAllCaptures = (bool)conditions["trackAllCaptures"];
            this.LogicalGrouping  = (long)conditions["logicalGrouping"];

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

            var variables = this.Element.ChildElements["serverVariables"];

            foreach (ConfigurationElement variable in variables.GetCollection())
            {
                var item = new ServerVariableItem(variable);
                this.ServerVariables.Add(item);
            }
        }