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

            action(cfg);
            return(source);
        }
Exemplo n.º 2
0
 public SessionFactoryConfig(IActiveRecordConfiguration source)
 {
     Assemblies   = new List <Assembly>();
     Contributors = new List <INHContributor>();
     Properties   = new NameValueCollection();
     Name         = string.Empty;
     Source       = source;
 }
Exemplo n.º 3
0
 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)
            );
 }
Exemplo 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));
        }
Exemplo 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);
                }
            }
        }
Exemplo n.º 9
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);
            }
        }
Exemplo 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));
        }
Exemplo 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);
        }
Exemplo 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);
            }
        }
Exemplo n.º 13
0
 public MySessionFactoryHolder(IActiveRecordConfiguration source)
     : base(source)
 {
 }
Exemplo n.º 14
0
 public static IActiveRecordConfiguration UseThreadScopeInfo(this IActiveRecordConfiguration source, Type type)
 {
     source.ThreadScopeInfoImplementation = type;
     return(source);
 }
Exemplo 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);
 }
Exemplo 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);
                }
            }
        }
Exemplo 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);
            }
        }
Exemplo n.º 18
0
 public static IActiveRecordConfiguration Lazy(this IActiveRecordConfiguration source, bool lazy)
 {
     source.Lazy = lazy;
     return(source);
 }
Exemplo n.º 19
0
 public static IActiveRecordConfiguration AutoImport(this IActiveRecordConfiguration source, bool autoimport)
 {
     source.AutoImport = autoimport;
     return(source);
 }
Exemplo n.º 20
0
 public static IActiveRecordConfiguration Debug(this IActiveRecordConfiguration source, bool isdebug)
 {
     source.Debug = isdebug;
     return(source);
 }
Exemplo n.º 21
0
 public static IActiveRecordConfiguration Flush(this IActiveRecordConfiguration source, DefaultFlushType flushType)
 {
     source.DefaultFlushType = flushType;
     return(source);
 }
Exemplo n.º 22
0
 public static IActiveRecordConfiguration UseSessionFactoryHolder(this IActiveRecordConfiguration source, Type type)
 {
     source.SessionFactoryHolderImplementation = type;
     return(source);
 }
Exemplo n.º 23
0
 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();
 }
Exemplo 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>();
 }
Exemplo 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);
            }
        }
Exemplo n.º 31
0
 public SampleSessionFactoryHolder(IActiveRecordConfiguration source) : base(source)
 {
 }
Exemplo n.º 32
0
 public static IActiveRecordConfiguration UseThreadScopeInfo <T>(this IActiveRecordConfiguration source) where T : IThreadScopeInfo
 {
     return(source.UseThreadScopeInfo(typeof(T)));
 }