public static void WriteConfig(Configuration config)
        {
            if (config.GetSection("metabuilders/polling") != null)
            {
                return;
            }

            ConfigurationSectionGroup group = new ConfigurationSectionGroup();

            config.SectionGroups.Add("metabuilders", group);

            PollingConfig pollingConfig = new PollingConfig();

            group.Sections.Add("polling", pollingConfig);

            pollingConfig.DefaultProvider = "AccessPollingProvider";
            pollingConfig.SectionInformation.RequirePermission        = false;
            pollingConfig.SectionInformation.RestartOnExternalChanges = true;
            pollingConfig.SectionInformation.AllowDefinition          = ConfigurationAllowDefinition.MachineToApplication;

            ProviderSettings settings = new ProviderSettings();

            settings.Name = "AccessPollingProvider";
            settings.Type = "MetaBuilders.WebControls.AccessPollingProvider, MetaBuilders.WebControls";
            settings.Parameters.Add("connectionStringName", "MetaBuildersPolling");

            pollingConfig.Providers.Add(settings);

            if (config.ConnectionStrings.ConnectionStrings["MetaBuildersPolling"] == null)
            {
                config.ConnectionStrings.ConnectionStrings.Add(new ConnectionStringSettings("MetaBuildersPolling", "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=|DataDirectory|MetaBuildersPolling.mdb", "System.Data.OleDb"));
            }

            config.Save();
        }
Exemple #2
0
        /// <summary>
        /// Loads the configuration specified in web.config
        /// </summary>
        private static void Initialize()
        {
            // Avoid claiming lock if providers are already loaded
            if (provider == null)
            {
                lock ( syncLock )
                {
                    // Do this again to make sure _provider is still null
                    if (provider == null)
                    {
                        // Get a reference to the <metabuilders/polling> section
                        PollingConfig section = (PollingConfig)WebConfigurationManager.GetSection("metabuilders/polling");

                        if (section != null)
                        {
                            // Load registered providers and point provider to the default provider
                            providers = new PollingProviderCollection();
                            ProvidersHelper.InstantiateProviders(section.Providers, providers, typeof(PollingProvider));
                            provider = providers[section.DefaultProvider];
                        }
                        else
                        {
                            provider = new AccessPollingProvider();
                            NameValueCollection settings = new NameValueCollection();
                            settings.Add("connectionString", "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=|DataDirectory|MetaBuildersPolling.mdb");
                            provider.Initialize("AccessPollingProvider", settings);

                            providers = new PollingProviderCollection();
                            providers.Add(provider);
                        }

                        if (provider == null)
                        {
                            throw new ProviderException("Unable to load default PollingProvider");
                        }
                    }
                }
            }
        }