Ejemplo n.º 1
0
        public void CreateApplication()
        {
            if (appService == null)
            {
                IApplicationContext context = ContextRegistry.GetContext();
                appService = (IAspnetApplicationService)context.GetObject("AspnetApplicationService");
            }

            Assert.IsNotNull(appService);

            AspnetApplication app = appService.CreateOrLoadApplication("TestApp");
            Assert.AreNotEqual(-1, app.ApplicationId);

            Console.WriteLine("The id of TestApp is :" + app.ApplicationId);

            app = appService.GetApplication(app.ApplicationId);
            appService.DeleteApplication(app);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes the provider.
        /// </summary>
        /// <param name="config">A collection of the name/value pairs representing the provider-specific
        /// attributes specified in the configuration for this provider.</param>
        /// <param name="name">The friendly name of the provider.</param>
        /// <exception cref="ArgumentNullException">The name of the provider is null.</exception>
        /// <exception cref="InvalidOperationException">An attempt is made to call <see cref="Initialize(System.String,System.Collections.Specialized.NameValueCollection)"></see> on a provider after the provider has already been initialized.</exception>
        /// <exception cref="ArgumentException">The name of the provider has a length of zero.</exception>
        public override void Initialize(string name, NameValueCollection config)
        {
            // Initialize values from Web.config.
            if (null == config)
            {
                throw (new ArgumentNullException("config"));
            }
            if (string.IsNullOrEmpty(name))
            {
                name = "NHibernateRoleProvider";
            }
            if (string.IsNullOrEmpty(config["description"]))
            {
                config.Remove("description");
                config.Add("description", "NHibernate Role Provider");
            }

            // Call the base class implementation.
            base.Initialize(name, config);

            if (_aspnetMembershipService == null)
            {
                IApplicationContext context = ContextRegistry.GetContext();
                _aspnetMembershipService = (IAspnetMembershipService)context.GetObject("IAspnetMembershipService");
            }

            if (_aspnetApplicationService == null)
            {
                IApplicationContext context = ContextRegistry.GetContext();
                _aspnetApplicationService = (IAspnetApplicationService)context.GetObject("IAspnetApplicationService");
            }

            if (_aspnetRoleService == null)
            {
                IApplicationContext context = ContextRegistry.GetContext();
                _aspnetRoleService = (IAspnetRoleService)context.GetObject("IAspnetRoleService");
            }

            string appName = ConfigurationUtil.GetConfigValue(config["applicationName"], System.Web.Hosting.HostingEnvironment.ApplicationVirtualPath);
            application =
             _aspnetApplicationService.CreateOrLoadApplication(appName);

            if (config["writeExceptionsToEventLog"] != null)
            {
                if (config["writeExceptionsToEventLog"].ToUpper() == "TRUE")
                {
                    pWriteExceptionsToEventLog = true;
                }
            }

            // Load configuration data.
            //application = _applicationService.CreateOrLoadApplication(appName);

            //application =
            //    NHibernateProviderEntityHelper.CreateOrLoadApplication(
            //        ConfigurationUtil.GetConfigValue(config["applicationName"], HostingEnvironment.ApplicationVirtualPath));
        }