public static IActiveRecordConfiguration CreateConfiguration(this IActiveRecordConfiguration source, string name, Action <SessionFactoryConfig> action)
        {
            var cfg = source.CreateConfiguration(name);

            action(cfg);
            return(source);
        }
Esempio n. 2
0
 public SessionFactoryConfig(IActiveRecordConfiguration source)
 {
     Assemblies   = new List <Assembly>();
     Contributors = new List <INHContributor>();
     Properties   = new NameValueCollection();
     Name         = string.Empty;
     Source       = source;
 }
 public SessionFactoryConfig(IActiveRecordConfiguration source)
 {
     Assemblies = new List<Assembly>();
     Contributors = new List<INHContributor>();
     Properties = new NameValueCollection();
     Name = string.Empty;
     Source = source;
 }
        private SqlConnection CreateSqlConnection2()
        {
            IActiveRecordConfiguration config = GetConfigSource();

            var db2 = config.GetConfiguration("Test2ARBase");

            return(new SqlConnection(db2.Properties["connection.connection_string"]));
        }
        public void GetConnectionStringFromWebConfig()
        {
            IActiveRecordConfiguration source = ConfigurationManager.GetSection("activerecord-asp-net-2.0") as IActiveRecordConfiguration;

            var config = source.GetConfiguration(string.Empty);

            string expected = config.Properties["connection.connection_string"];

            Assert.AreEqual("Test Connection String", expected);
        }
 public static SessionFactoryConfig CreateConfiguration(this IActiveRecordConfiguration source, string name)
 {
     source.Add(new SessionFactoryConfig(source)
     {
         Name = name
     });
     return(source.GetConfiguration(name)
            .ConnectionProvider <DriverConnectionProvider>()
            .UseSecondLevelCache(false)
            );
 }
Esempio n. 7
0
        public void BasicConfigurationApi()
        {
            IActiveRecordConfiguration configuration = AR.Configure()
                                                       .Flush(DefaultFlushType.Leave)
                                                       .UseThreadScopeInfo <SampleThreadScopeInfo>()
                                                       .UseSessionFactoryHolder <SampleSessionFactoryHolder>();

            Assert.That(configuration.ThreadScopeInfoImplementation, Is.EqualTo(typeof(SampleThreadScopeInfo)));
            Assert.That(configuration.SessionFactoryHolderImplementation, Is.EqualTo(typeof(SampleSessionFactoryHolder)));
            Assert.That(configuration.DefaultFlushType, Is.EqualTo(DefaultFlushType.Leave));
        }
Esempio n. 8
0
        /// <summary>
        /// Initialize the mappings using the configuration and
        /// the list of types
        /// </summary>
        private static void CreateSessionFactoryAndRegisterToHolder(IActiveRecordConfiguration source)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }

            lock (LockConfig)
            {
                if (Holder == null)
                {
                    // First initialization
                    Holder = CreateSessionFactoryHolderImplementation(source);
                    RaiseSessionFactoryHolderCreated(Holder);
                }
            }
        }
        public SessionFactoryHolder(IActiveRecordConfiguration source)
        {
            ConfigurationSource = source;
            ThreadScopeInfo = CreateThreadScopeInfoImplementation(source);

            foreach (var key in source.GetAllConfigurationKeys()) {

                var config = source.GetConfiguration(key);

                foreach (var asm in config.Assemblies) {
                    if (RegisteredAssemblies.Contains(asm))
                        throw new ActiveRecordException(string.Format("Assembly {0} has already been registered.", asm));

                }

                RegisterConfiguration(config);
            }
        }
Esempio n. 10
0
        IThreadScopeInfo CreateThreadScopeInfoImplementation(IActiveRecordConfiguration source)
        {
            if (source.ThreadScopeInfoImplementation == null)
            {
                return(new ThreadScopeInfo());
            }

            var threadScopeType = source.ThreadScopeInfoImplementation;

            if (!typeof(IThreadScopeInfo).IsAssignableFrom(threadScopeType))
            {
                var message = String.Format("The specified type {0} does " + "not implement the interface IThreadScopeInfo", threadScopeType.FullName);

                throw new ActiveRecordInitializationException(message);
            }

            return((IThreadScopeInfo)Activator.CreateInstance(threadScopeType));
        }
Esempio n. 11
0
        public void BasicConfigurationApi()
        {
            IActiveRecordConfiguration configuration = Configure.ActiveRecord
                                                       .ForWeb()
                                                       .Flush(DefaultFlushType.Leave)
                                                       .UseThreadScopeInfo <SampleThreadScopeInfo>()
                                                       .UseSessionFactoryHolder <SampleSessionFactoryHolder>()
                                                       .MakeLazyByDefault()
                                                       .VerifyModels()
                                                       .RegisterSearch();

            Assert.That(configuration.ThreadScopeInfoImplementation, Is.EqualTo(typeof(SampleThreadScopeInfo)));
            Assert.That(configuration.SessionfactoryHolderImplementation, Is.EqualTo(typeof(SampleSessionFactoryHolder)));
            Assert.That(configuration.DefaultFlushType, Is.EqualTo(DefaultFlushType.Leave));
            Assert.That(configuration.WebEnabled, Is.True);
            Assert.That(configuration.Lazy, Is.True);
            Assert.That(configuration.Verification, Is.True);
            Assert.That(configuration.Searchable, Is.True);
        }
Esempio n. 12
0
        public SessionFactoryHolder(IActiveRecordConfiguration source)
        {
            ConfigurationSource = source;
            ThreadScopeInfo     = CreateThreadScopeInfoImplementation(source);

            foreach (var key in source.GetAllConfigurationKeys())
            {
                var config = source.GetConfiguration(key);

                foreach (var asm in config.Assemblies)
                {
                    if (RegisteredAssemblies.Contains(asm))
                    {
                        throw new ActiveRecordException(string.Format("Assembly {0} has already been registered.", asm));
                    }
                }

                RegisterConfiguration(config);
            }
        }
Esempio n. 13
0
 public MySessionFactoryHolder(IActiveRecordConfiguration source)
     : base(source)
 {
 }
 public static IActiveRecordConfiguration UseThreadScopeInfo(this IActiveRecordConfiguration source, Type type)
 {
     source.ThreadScopeInfoImplementation = type;
     return(source);
 }
Esempio n. 15
0
 /// <summary>
 /// Initialize the mappings using the configuration and
 /// checking all the types on the specified Assemblies
 /// </summary>
 public static void Initialize(this IActiveRecordConfiguration source)
 {
     CreateSessionFactoryAndRegisterToHolder(source);
 }
Esempio n. 16
0
        /// <summary>
        /// Initialize the mappings using the configuration and 
        /// the list of types
        /// </summary>
        private static void CreateSessionFactoryAndRegisterToHolder(IActiveRecordConfiguration source)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }

            lock(LockConfig)
            {
                if (Holder == null) {
                    // First initialization
                    Holder = CreateSessionFactoryHolderImplementation(source);
                    RaiseSessionFactoryHolderCreated(Holder);
                }
            }
        }
Esempio n. 17
0
        private static ISessionFactoryHolder CreateSessionFactoryHolderImplementation(IActiveRecordConfiguration source)
        {
            if (source.SessionFactoryHolderImplementation == null)
            {
                return(new SessionFactoryHolder(source));
            }

            var sessionFactoryHolderType = source.SessionFactoryHolderImplementation;

            if (!typeof(ISessionFactoryHolder).IsAssignableFrom(sessionFactoryHolderType))
            {
                var message =
                    String.Format("The specified type {0} does " + "not implement the interface ISessionFactoryHolder",
                                  sessionFactoryHolderType.FullName);

                throw new ActiveRecordException(message);
            }

            try {
                return((ISessionFactoryHolder)Activator.CreateInstance(sessionFactoryHolderType, new object[] { source }));
            } catch (Exception e) {
                var message =
                    String.Format("The specified type {0} does " + "not implement a constructor that accepts an IActiveRecordCConfiguration",
                                  sessionFactoryHolderType.FullName);

                throw new ActiveRecordException(message, e);
            }
        }
 public static IActiveRecordConfiguration Lazy(this IActiveRecordConfiguration source, bool lazy)
 {
     source.Lazy = lazy;
     return(source);
 }
 public static IActiveRecordConfiguration AutoImport(this IActiveRecordConfiguration source, bool autoimport)
 {
     source.AutoImport = autoimport;
     return(source);
 }
 public static IActiveRecordConfiguration Debug(this IActiveRecordConfiguration source, bool isdebug)
 {
     source.Debug = isdebug;
     return(source);
 }
 public static IActiveRecordConfiguration Flush(this IActiveRecordConfiguration source, DefaultFlushType flushType)
 {
     source.DefaultFlushType = flushType;
     return(source);
 }
 public static IActiveRecordConfiguration UseSessionFactoryHolder(this IActiveRecordConfiguration source, Type type)
 {
     source.SessionFactoryHolderImplementation = type;
     return(source);
 }
 public static IActiveRecordConfiguration UseSessionFactoryHolder <T>(this IActiveRecordConfiguration source) where T : ISessionFactoryHolder
 {
     return(source.UseSessionFactoryHolder(typeof(T)));
 }
 protected virtual void MapTypes(IActiveRecordConfiguration cfg)
 {
     cfg.MapTypesFromAssemblyContaining <Customer>();
 }
 private static Configuration BuildConfiguration(IActiveRecordConfiguration source)
 {
     return source.GetConfiguration(string.Empty).BuildConfiguration();
 }
Esempio n. 26
0
        IThreadScopeInfo CreateThreadScopeInfoImplementation(IActiveRecordConfiguration source)
        {
            if (source.ThreadScopeInfoImplementation == null)
                return new ThreadScopeInfo();

            var threadScopeType = source.ThreadScopeInfoImplementation;

            if (!typeof(IThreadScopeInfo).IsAssignableFrom(threadScopeType))
            {
                var message = String.Format("The specified type {0} does " + "not implement the interface IThreadScopeInfo", threadScopeType.FullName);

                throw new ActiveRecordInitializationException(message);
            }

            return (IThreadScopeInfo) Activator.CreateInstance(threadScopeType);
        }
 private static Configuration BuildConfiguration(IActiveRecordConfiguration source)
 {
     return(source.GetConfiguration(string.Empty).BuildConfiguration());
 }
        protected override void MapTypes(IActiveRecordConfiguration cfg)
        {
//			cfg.MapTypes(typeof(ValidatingCustomer));
        }
 protected virtual void MapTypes(IActiveRecordConfiguration cfg)
 {
     cfg.MapTypesFromAssemblyContaining<Customer>();
 }
Esempio n. 30
0
        private static ISessionFactoryHolder CreateSessionFactoryHolderImplementation(IActiveRecordConfiguration source)
        {
            if (source.SessionFactoryHolderImplementation == null)
                return new SessionFactoryHolder(source);

            var sessionFactoryHolderType = source.SessionFactoryHolderImplementation;

            if (!typeof(ISessionFactoryHolder).IsAssignableFrom(sessionFactoryHolderType))
            {
                var message =
                    String.Format("The specified type {0} does " + "not implement the interface ISessionFactoryHolder",
                                  sessionFactoryHolderType.FullName);

                throw new ActiveRecordException(message);
            }

            try {
                return (ISessionFactoryHolder) Activator.CreateInstance(sessionFactoryHolderType, new object[] {source});
            } catch (Exception e) {
                var message =
                    String.Format("The specified type {0} does " + "not implement a constructor that accepts an IActiveRecordCConfiguration",
                                  sessionFactoryHolderType.FullName);

                throw new ActiveRecordException(message, e);
            }
        }
Esempio n. 31
0
 public SampleSessionFactoryHolder(IActiveRecordConfiguration source) : base(source)
 {
 }
 public static IActiveRecordConfiguration UseThreadScopeInfo <T>(this IActiveRecordConfiguration source) where T : IThreadScopeInfo
 {
     return(source.UseThreadScopeInfo(typeof(T)));
 }