コード例 #1
0
        public void AddGlobal(GlobalModule item)
        {
            GlobalModules.Add(item);
            var service = (IConfigurationService)GetService(typeof(IConfigurationService));
            ConfigurationSection           globalSection    = service.GetSection("system.webServer/globalModules", null, false);
            ConfigurationElementCollection globalCollection = globalSection.GetCollection();

            item.AppendTo(globalCollection);
            service.ServerManager.CommitChanges();
        }
コード例 #2
0
        public void RemoveGlobal(GlobalModule item)
        {
            this.GlobalModules.Remove(item);
            var service = (IConfigurationService)this.GetService(typeof(IConfigurationService));
            ConfigurationSection           globalSection    = service.GetSection("system.webServer/globalModules", null, false);
            ConfigurationElementCollection globalCollection = globalSection.GetCollection();

            globalCollection.Remove(item.Element);
            service.ServerManager.CommitChanges();
        }
コード例 #3
0
        public NewNativeDialog(IServiceProvider serviceProvider, GlobalModule existing)
            : base(serviceProvider)
        {
            InitializeComponent();
            if (existing != null)
            {
                txtName.Text = existing.Name;
                txtPath.Text = existing.Image;
                Text         = "Edit Native Module Registration";
                txtName.SelectAll();
                Item = existing;
            }

            var container = new CompositeDisposable();

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

            container.Add(
                Observable.FromEventPattern <EventArgs>(btnBrowse, "Click")
                .ObserveOn(System.Threading.SynchronizationContext.Current)
                .Subscribe(evt =>
            {
                DialogHelper.ShowFileDialog(txtPath, "(*.dll)|*.dll|All Files (*.*)|*.*");
            }));

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

            container.Add(
                Observable.FromEventPattern <EventArgs>(btnOK, "Click")
                .ObserveOn(System.Threading.SynchronizationContext.Current)
                .Subscribe(evt =>
            {
                if (Item == null)
                {
                    Item = new GlobalModule(null);
                }

                Item.Name    = txtName.Text;
                Item.Image   = txtPath.Text;
                DialogResult = System.Windows.Forms.DialogResult.OK;
            }));
        }
コード例 #4
0
        public NativeModulesDialog(IServiceProvider serviceProvider, ModulesFeature feature)
            : base(serviceProvider)
        {
            InitializeComponent();
            if (feature.CanRevert)
            {
                btnRegister.Visible = btnEdit.Visible = btnRemove.Visible = false;
                lvModules.Width    += 130;
            }

            foreach (var global in feature.GlobalModules)
            {
                if (feature.Items.Any(module => module.Name == global.Name))
                {
                    continue;
                }

                var item = lvModules.Items.Add(global.Name);
                item.Tag = global;
            }

            var container = new CompositeDisposable();

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

            container.Add(
                Observable.FromEventPattern <EventArgs>(btnOK, "Click")
                .Subscribe(evt =>
            {
                Items = new List <ModulesItem>();
                foreach (ListViewItem item in lvModules.Items)
                {
                    if (!item.Checked)
                    {
                        continue;
                    }

                    var module    = (GlobalModule)item.Tag;
                    module.Loaded = true;
                    Items.Add(new ModulesItem(null)
                    {
                        Name = module.Name
                    }.Load(feature));
                }

                DialogResult = DialogResult.OK;
            }));

            container.Add(
                Observable.FromEventPattern <EventArgs>(lvModules, "SelectedIndexChanged")
                .Subscribe(evt =>
            {
                btnEdit.Enabled = btnRemove.Enabled = lvModules.SelectedItems.Count > 0;
            }));

            container.Add(
                Observable.FromEventPattern <EventArgs>(btnRegister, "Click")
                .Subscribe(evt =>
            {
                var dialog = new NewNativeDialog(ServiceProvider, null);
                if (dialog.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                var item = lvModules.Items.Add(dialog.Item.Name);
                item.Tag = dialog.Item;
                feature.AddGlobal(dialog.Item);
            }));

            container.Add(
                Observable.FromEventPattern <EventArgs>(btnEdit, "Click")
                .Subscribe(evt =>
            {
                GlobalModule item = (GlobalModule)lvModules.SelectedItems[0].Tag;
                var dialog        = new NewNativeDialog(ServiceProvider, item);
                if (dialog.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                dialog.Item.Apply();
                lvModules.SelectedItems[0].Text = dialog.Item.Name;
            }));

            container.Add(
                Observable.FromEventPattern <EventArgs>(btnRemove, "Click")
                .Subscribe(evt =>
            {
                var dialog = (IManagementUIService)GetService(typeof(IManagementUIService));
                if (
                    dialog.ShowMessage("Are you sure that you want to remove the selected native module registration?", "Confirm Remove",
                                       MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) !=
                    DialogResult.Yes)
                {
                    return;
                }

                GlobalModule item = (GlobalModule)lvModules.SelectedItems[0].Tag;
                feature.RemoveGlobal(item);
                lvModules.SelectedItems[0].Remove();
            }));
        }
コード例 #5
0
        public NewNativeDialog(IServiceProvider serviceProvider, GlobalModule existing)
            : base(serviceProvider)
        {
            InitializeComponent();
            if (existing != null)
            {
                txtName.Text = existing.Name;
                txtPath.Text = existing.Image;
                Text         = "Edit Native Module Registration";
                txtName.SelectAll();
                Item = existing;
            }

            var container = new CompositeDisposable();

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

            container.Add(
                Observable.FromEventPattern <EventArgs>(btnBrowse, "Click")
                .ObserveOn(System.Threading.SynchronizationContext.Current)
                .Subscribe(evt =>
            {
                DialogHelper.ShowOpenFileDialog(txtPath, "(*.dll)|*.dll|All Files (*.*)|*.*");
            }));

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

            container.Add(
                Observable.FromEventPattern <EventArgs>(btnOK, "Click")
                .ObserveOn(System.Threading.SynchronizationContext.Current)
                .Subscribe(evt =>
            {
                if (Item == null)
                {
                    Item = new GlobalModule(null);
                }

                Item.Name  = txtName.Text;
                Item.Image = txtPath.Text;

                try
                {
                    var bit32Condition = "bitness32";
                    var bit64Condition = "bitness64";
                    var bit32          = DialogHelper.GetImageArchitecture(txtPath.Text);
                    if (bit32 && !Item.PreConditions.Contains(bit32Condition))
                    {
                        Item.PreConditions.Add(bit32Condition);
                    }
                    else if (!bit32 && !Item.PreConditions.Contains(bit64Condition))
                    {
                        Item.PreConditions.Add(bit64Condition);
                    }
                }
                catch (Exception)
                {
                    ShowMessage(
                        "The specific module is invalid.",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Error,
                        MessageBoxDefaultButton.Button1);
                    return;
                }

                DialogResult = DialogResult.OK;
            }));
        }