Esempio n. 1
0
        private static void SaveToDatabase(IDictionary <string, Category> categories, ICollection <Post> posts, ICollection <Comment> comments)
        {
            try
            {
                ActiveRecordStarter.Initialize(typeof(Post).Assembly, ActiveRecordSectionHandler.Instance);
                Console.WriteLine("Creating database schema");
                ActiveRecordStarter.CreateSchema();
                Console.WriteLine("Schema created! Starting to save data");
                using (new SessionScope())
                {
                    foreach (Category category in categories.Values)
                    {
                        category.Create();
                    }

                    foreach (Post post in posts)
                    {
                        post.Create();
                    }
                    foreach (Comment comment in comments)
                    {
                        comment.Create();
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Failed to save to database: {0}", e);
            }
        }
Esempio n. 2
0
        public void StartUp()
        {
            ActiveRecordStarter.Initialize(ActiveRecordSectionHandler.Instance,
                                           new Type[] { typeof(Topic), typeof(Fact), typeof(WebCitation), typeof(PrintCitation) });

            // If you want to let ActiveRecord create the schema for you:
            ActiveRecordStarter.CreateSchema();

            Topic category = new Topic()
            {
                Name = "Earth"
            };

            category.SaveAndFlush();

            Fact newFact = new Fact()
            {
                Body = "The earth is round", Title = "Blah", Topic = category
            };

            newFact.SaveAndFlush();

            WebCitation citation = new WebCitation()
            {
                Author      = "ignu",
                PublishDate = new DateTime(2007, 1, 1),
                Title       = "blah",
                Url         = "http://www.yahoo.com",
                Fact        = newFact
            };

            citation.SaveAndFlush();
        }
        public void Can_initialize_and_create_schema()
        {
            var configurationSource = new XmlConfigurationSource("ActiveRecord.cfg.xml");

            ActiveRecordStarter.Initialize(typeof(Customer).Assembly, configurationSource);
            ActiveRecordStarter.CreateSchema();
        }
Esempio n. 4
0
        static void Main(string[] args)
        {
            ActiveRecordStarter.Initialize(ActiveRecordSectionHandler.Instance, typeof(Blog), typeof(Post));
            ActiveRecordStarter.CreateSchema();
            Blog b1 = new Blog("blog1")
            {
                Author = "Author1"
            };
            Blog b2 = new Blog("blog2")
            {
                Author = "Author2"
            };

            b1.Save();
            b2.Save();
            var post = new Post();

            post.Title     = "Title";
            post.Published = true;
            post.Contents  = "contents";
            post.Blog      = b1;
            post.SaveAndFlush();
            b1.SaveAndFlush();
            b2.SaveAndFlush();

            var blog = Blog.FindByName("blog1");

            Console.WriteLine("Blogs created: {0}", Blog.FindAll().Count());
            Console.WriteLine("Posts created: {0}", Post.FindAll().Count());
            Console.WriteLine("Done.");
        }
Esempio n. 5
0
        private static void InitialiseActiveRecord()
        {
            IConfigurationSource config = ActiveRecordSectionHandler.Instance;

            ActiveRecordStarter.Initialize(Assembly.GetExecutingAssembly(), config);
            ActiveRecordStarter.CreateSchema();

            using (new SessionScope())
            {
                var monorail = new Project {
                    Name = "MonoRail"
                };
                monorail.Save();

                var windsor = new Project {
                    Name = "Windsor"
                };
                windsor.Save();

                var activeRecord = new Project {
                    Name = "ActiveRecord"
                };
                activeRecord.Save();
            }
        }
Esempio n. 6
0
        // overrides the setup in the base class
        public void Prepare()
        {
            ActiveRecordStarter.ResetInitializationFlag();
            ActiveRecordStarter.Initialize(GetConfigSource(), typeof(Blog), typeof(Post));

            ActiveRecordStarter.CreateSchema();

            Post.DeleteAll();
            Blog.DeleteAll();

            Blog blog = new Blog();

            blog.Name   = "hammett's blog";
            blog.Author = "hamilton verissimo";

            blog.Save();

            Post p;

            p = new Post(blog, "a", "b", "c");
            p.Save();

            p = new Post(blog, "d", "e", "c");
            p.Save();

            p = new Post(blog, "f", "g", "h");
            p.Save();
        }
Esempio n. 7
0
        private static void InitDatabase()
        {
            var config          = ActiveRecordSectionHandler.Instance;
            var assemblyLibrary = Assembly.Load("FileProccesor");

            ActiveRecordStarter.Initialize(assemblyLibrary, config);

            switch (ConfigurationManager.AppSettings["Enviroment"])
            {
            case "Development":
                ActiveRecordStarter.DropSchema();
                ActiveRecordStarter.CreateSchema();
                break;

            case "Testing":
                ActiveRecordStarter.UpdateSchema();
                break;

            default:
                break;
            }


            var callbackContext = new CallbackContext("Conectado a la Base de Datos", ActiveRecordStarter.ConfigurationSource.ToString());

            var notification = new Notification(_application.Name, _notificationType.Name, DateTime.Now.Ticks.ToString(), "InitDatabase", "OK");

            _growl.Notify(notification, callbackContext);
        }
Esempio n. 8
0
        public static void Main()
        {
            ActiveRecordStarter.Initialize(
                new XmlConfigurationSource("../appconfig.xml"),
                typeof(Company), typeof(Client), typeof(Firm), typeof(Person));

            // If you want to let AR to create the schema

            ActiveRecordStarter.CreateSchema();

            // Common usage

            Client.DeleteAll();
            Firm.DeleteAll();
            Company.DeleteAll();

            Company company = new Company("Keldor");

            company.Save();

            Firm firm = new Firm("Johnson & Norman");

            firm.Save();

            Client client = new Client("hammett", firm);

            client.Save();

            // Dropping the schema

            ActiveRecordStarter.DropSchema();
        }
Esempio n. 9
0
        public static void Recreate()
        {
            ActiveRecordStarter.Initialize(
                ConfigurationSettings.GetConfig("activerecord") as IConfigurationSource,
                typeof(Blog), typeof(Person), typeof(Customer), typeof(Account),
                typeof(AccountPermission), typeof(ProductLicense));

            ActiveRecordStarter.CreateSchema();

            using (new SessionScope())
            {
                for (int i = 1; i <= 15; i++)
                {
                    Blog blog = new Blog();
                    blog.Name   = "Name " + i.ToString();
                    blog.Author = "Author " + i.ToString();
                    blog.Save();
                }

                for (int i = 1; i <= 15; i++)
                {
                    Person person = new Person();
                    person.Name  = "Name " + i.ToString();
                    person.Dob   = DateTime.Now;
                    person.Email = "name" + i.ToString() + "@server.com";
                    person.Save();
                }
            }
        }
Esempio n. 10
0
        private void InitActiveRecord()
        {
            var source = ActiveRecordSectionHandler.Instance;

            ActiveRecordStarter.Initialize(source, typeof(FileRecord), typeof(FileReference));
            new SessionScope(FlushAction.Never);
            ActiveRecordStarter.CreateSchema();
        }
Esempio n. 11
0
        public void Database()
        {
            MemoryAppender memoryAppender = new MemoryAppender();

            BasicConfigurator.Configure(LogManager.GetLogger(typeof(SchemaExport)).Logger.Repository, memoryAppender);
            ActiveRecordStarter.CreateSchema();
            PropertyBag["events"] = memoryAppender.GetEvents();
        }
Esempio n. 12
0
        public override void Init()
        {
            base.Init();

            XmlConfigurationSource config = (XmlConfigurationSource)GetConfigSource();

            ActiveRecordStarter.Initialize(config, typeof(EnumModel));
            ActiveRecordStarter.CreateSchema();
        }
Esempio n. 13
0
        public void SetupDatabase(string databaseFilePath, string databaseConfigFilePath, Assembly asm)
        {
            XmlConfigurationSource source = new XmlConfigurationSource(databaseConfigFilePath);

            ActiveRecordStarter.Initialize(asm, source);
            if (!DatabaseExists(databaseFilePath))
            {
                ActiveRecordStarter.CreateSchema();
            }
        }
Esempio n. 14
0
 public void InitDataBase()
 {
     if (!ActiveRecordStarter.IsInitialized)
     {
         IConfigurationSource source = System.Configuration.ConfigurationManager.GetSection("activerecord") as
                                       IConfigurationSource;
         ActiveRecordStarter.Initialize(typeof(EntityBase).Assembly, source);
     }
     ActiveRecordStarter.DropSchema();
     ActiveRecordStarter.CreateSchema();
 }
Esempio n. 15
0
 public void Create_DB()
 {
     try
     {
         ActiveRecordStarter.CreateSchema();
     }
     catch (Exception exception)
     {
         MessageBox.Show(exception.ToString());
     }
 }
Esempio n. 16
0
        public ActionResult Init()
        {
            ViewBag.Message = "Todo Creado";
            ActiveRecordStarter.CreateSchema();
            Initializer.CrearEscuelas();
            Initializer.CrearCategorias();
            Initializer.CrearPartidosPoliticos();
            Initializer.TratarExtranjero();

            return(View());
        }
Esempio n. 17
0
        /// <summary>
        /// Opens the file.
        /// </summary>
        private void OpenFile()
        {
            bool createSchema = false;

            if (!File.Exists(Filename))
            {
                createSchema = true;
                SqlCeEngine engine = new SqlCeEngine(SqlCE.GetConnectionString(Filename));
                engine.CreateDatabase();
                engine.Dispose();
            }


            if (!SqlCeTicketDataSource.ActiveRecordsInitialized)
            {
                IDictionary <string, string> properties = new Dictionary <string, string>();
                properties.Add("connection.driver_class", "NHibernate.Driver.SqlServerCeDriver");
                properties.Add("dialect", "NHibernate.Dialect.MsSqlCeDialect");
                properties.Add("connection.provider", "NHibernate.Connection.DriverConnectionProvider");
                properties.Add("connection.connection_string", SqlCE.GetConnectionString(Filename));
                properties.Add("proxyfactory.factory_class", "NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle");

                InPlaceConfigurationSource source = new InPlaceConfigurationSource();
                source.Add(typeof(ActiveRecordBase), properties);

                ActiveRecordStarter.Initialize(Assembly.GetExecutingAssembly(), source);
                SqlCeTicketDataSource.ActiveRecordsInitialized = true;
            }
            else
            {
                SqlCeConnection con = new SqlCeConnection(SqlCE.GetConnectionString(Filename));
                con.Open();
                DifferentDatabaseScope scope = new DifferentDatabaseScope(con);
            }

            if (createSchema)
            {
                ActiveRecordStarter.CreateSchema();
            }

            AllTickets = new ObservableCollection <ITicket>();
            IQueryable <ITicket> list = (from t in TicketRecord.Queryable
                                         select t).Cast <ITicket>();

            list.ToList().ForEach((Action <ITicket>) delegate(ITicket t)
            {
                t.PropertyChanged += new PropertyChangedEventHandler(ticket_PropertyChanged);
                AllTickets.Add(t);
            });
            AllTickets.CollectionChanged += new NotifyCollectionChangedEventHandler(Tickets_CollectionChanged);
            UpdateActiveTickets();
        }
Esempio n. 18
0
    public void EnsureActiveRecordInitialized()
    {
        if (arInitialized)
        {
            return;
        }

        arInitialized = true;

        ActiveRecordStarter.Initialize(typeof(Product).Assembly, ActiveRecordSectionHandler.Instance);

        ActiveRecordStarter.CreateSchema();
    }
Esempio n. 19
0
 private void CreateSchema()
 {
     try
     {
         Response.Write("开始创建数据库结构<br/>");
         ActiveRecordStarter.CreateSchema();
         Response.Write("......成功<br/>");
     }
     catch (Exception ex)
     {
         //Response.Write("......失败!原因:" + ex.Message + "<br/>");
         Response.Write(string.Format("......失败!原因: {0}<br/>", ex.Message));
     }
 }
Esempio n. 20
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            string ret = "<br />";

            if (!ActiveRecordStarter.IsInitialized)
            {
                IConfigurationSource source = System.Configuration.ConfigurationManager.GetSection("activerecord") as IConfigurationSource;
                ActiveRecordStarter.Initialize(typeof(SysUser).Assembly, source);
            }
            ret += "正在创建数据库...<br />";
            ActiveRecordStarter.CreateSchema();
            ret += "数据库创建完成...<br />";
            ret += "初始化完成...<br />";
            Response.Write(ret);
        }
Esempio n. 21
0
        public void CreateDB(string FileDB)
        {
            try
            {
                InitDB(FileDB);

                ActiveRecordStarter.CreateSchema();

                tInfo otInfo = new tInfo();

                otInfo.Version_DB = Resources.Version_DB_01;

                otInfo.SaveAndFlush();
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.ToString());
            }
        }
        public static void CreateAndPopulatePeopleTable()
        {
            ActiveRecordStarter.Initialize(
                ConfigurationSettings.GetConfig("activerecord") as IConfigurationSource,
                typeof(SimplePerson));

            ActiveRecordStarter.CreateSchema();

            using (new SessionScope())
            {
                for (int i = 1; i <= 15; i++)
                {
                    SimplePerson person = new SimplePerson();
                    person.Name = "Name " + i.ToString();
                    person.Age  = i;
                    person.Save();
                }
            }
        }
Esempio n. 23
0
        private void CreateSchema()
        {
            try
            {
                if (!ActiveRecordStarter.IsInitialized)
                {
                    Response.Write("开始................初始化Castle<br/>");
                    IConfigurationSource source = System.Configuration.ConfigurationManager.GetSection("activerecord") as IConfigurationSource;
                    ActiveRecordStarter.Initialize(typeof(SysUser).Assembly, source);
                    Response.Write("成功................初始化Castle<br/>");
                }
                Response.Write("开始................CreateSchema<br/>");
                ActiveRecordStarter.CreateSchema();

                Response.Write("成功................CreateSchema<br/>");
            }
            catch (Exception e)
            {
                Response.Write(string.Format("异常位置:{0}<br/>{1}", "CreateSchema", e.Message));
            }
        }
Esempio n. 24
0
        private void DelegatebtnCreate_Click(object sender, EventArgs e)
        {
            try
            {
                if (!ActiveRecordStarter.IsInitialized)
                {
                    //如果ActiveRecordStarter框架没有初始化
                    IConfigurationSource source = System.Configuration.ConfigurationManager.GetSection("activerecord") as IConfigurationSource;
                    ActiveRecordStarter.Initialize(typeof(SysUser).Assembly, source);
                }
                Response.Write("正在创建数据库...<br />");
                ActiveRecordStarter.CreateSchema();
                Response.Write("创建数据库完成<br />");
                Response.Write("正在初始化数据...<br />");

                InitSysMenu();
                Response.Write("----系统菜单 初始化完毕!<br />");

                InitSysRole();
                Response.Write("----系统角色 初始化完毕!<br />");

                InitSysUser();
                Response.Write("----系统用户 初始化完毕!<br />");

                InitCar();
                Response.Write("----班车 初始化完毕!<br />");

                InitCarLine();
                Response.Write("----班车线路 初始化完毕!<br />");

                InitCarLineStation();
                Response.Write("----班车停靠站 初始化完毕!<br />");

                Response.Write("初始化数据完成<br />");
            }
            catch (Exception ex)
            {
                Response.Write("Error:" + ex.Message);
            }
        }
Esempio n. 25
0
        private static void InitDatabase()
        {
            var config          = ActiveRecordSectionHandler.Instance;
            var assemblyLibrary = Assembly.Load("FileProccesor");

            ActiveRecordStarter.Initialize(assemblyLibrary, config);

            switch (ConfigurationManager.AppSettings["Enviroment"])
            {
            case "Development":
                ActiveRecordStarter.DropSchema();
                ActiveRecordStarter.CreateSchema();
                break;

            case "Testing":
                ActiveRecordStarter.UpdateSchema();
                break;

            default:
                break;
            }
        }
Esempio n. 26
0
        /// <summary>
        /// The common test setup code. To activate it in a specific test framework,
        /// it must be called from a framework-specific setup-Method.
        /// </summary>
        public virtual void SetUp()
        {
            ActiveRecordStarter.ResetInitializationFlag();
            Dictionary <string, string> properties = new Dictionary <string, string>();

            properties.Add("connection.driver_class", "NHibernate.Driver.SQLite20Driver");
            properties.Add("dialect", "NHibernate.Dialect.SQLiteDialect");
            properties.Add("connection.provider", typeof(InMemoryConnectionProvider).AssemblyQualifiedName);
            properties.Add("connection.connection_string", "Data Source=:memory:;Version=3;New=True");
            properties.Add("proxyfactory.factory_class", "Castle.ActiveRecord.ByteCode.ProxyFactoryFactory, Castle.ActiveRecord");
            foreach (var p in GetProperties())
            {
                properties[p.Key] = p.Value;
            }

            var config = new InPlaceConfigurationSource();

            config.Add(typeof(ActiveRecordBase), properties);
            foreach (var type in GetAdditionalBaseClasses())
            {
                config.Add(type, properties);
            }
            Configure(config);

            var types      = GetTypes();
            var assemblies = GetAssemblies();

            if (types == null)
            {
                types = new Type[0];
            }
            if (assemblies == null)
            {
                assemblies = new Assembly[0];
            }

            ActiveRecordStarter.Initialize(assemblies, config, types);
            ActiveRecordStarter.CreateSchema();
        }
Esempio n. 27
0
        private static void ConfigureDatabase()
        {
            ActiveRecordStarter.Initialize(
                InPlaceConfigurationSource.BuildForMSSqlServer("localhost", "test"),
                typeof(Customer),
                typeof(CustomerOperation),
                typeof(Operation));
            ActiveRecordStarter.CreateSchema();
            Customer customer = new Customer();

            customer.Name = "oren";
            ActiveRecordMediator.Save(customer);

            Operation op = new Operation();

            op.Name = "View";
            ActiveRecordMediator.Save(op);

            CustomerOperation co = new CustomerOperation();

            co.Customer  = customer;
            co.Operation = op;
            ActiveRecordMediator.Save(co);
        }
Esempio n. 28
0
        private void btnConnect_Click(object sender, EventArgs e)
        {
            ActiveRecordStarter.ResetInitializationFlag();

            IDictionary <string, string> properties = new Dictionary <string, string>
            {
                { "connection.driver_class", "NHibernate.Driver.SqlClientDriver" },
                { "dialect", "NHibernate.Dialect.MsSql2008Dialect" },
                { "connection.provider", "NHibernate.Connection.DriverConnectionProvider" },


                //Catalog Name Table. Как создать БД с помощью метода ActiveRecordStarter.CreateSchema();
                //пока выяснить не удалось но CreateSchema() прекрасно добавляет таблицы к БД
                { "connection.connection_string", "Data Source=PC;Initial Catalog=vvv;Integrated Security=True" },
                {
                    "proxyfactory.factory_class",
                    @"NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle"
                }
            };



            try
            {
                InPlaceConfigurationSource source = new InPlaceConfigurationSource();
                source.Add(typeof(ActiveRecordBase), properties);

                ActiveRecordStarter.Initialize(source, MainDBHelper.GetTypes());

                ActiveRecordStarter.CreateSchema();
            }
            catch (Exception e1)
            {
                MessageBox.Show(e1.ToString());
            }
        }
Esempio n. 29
0
 /// <summary>
 /// (Drops and re-)creates the Schema of all tables that this has originally initialized with.
 /// </summary>
 public static void CreateSchema()
 {
     ActiveRecordStarter.CreateSchema();
 }
Esempio n. 30
0
        static void Main(string[] args)
        {
            IConfigurationSource config = ActiveRecordSectionHandler.Instance;

            ActiveRecordStarter.Initialize(Assembly.GetExecutingAssembly(), config);
            ActiveRecordStarter.CreateSchema();

            using (new SessionScope())
            {
                var monorail = new Project {
                    Name = "MonoRail"
                };
                monorail.Save();

                var windsor = new Project {
                    Name = "Windsor"
                };
                windsor.Save();

                var activeRecord = new Project {
                    Name = "ActiveRecord"
                };
                activeRecord.Save();

                var issue1 = new Issue
                {
                    Summary     = "Something went wrong",
                    Description = "blah blah",
                    Project     = monorail,
                    Type        = IssueType.Bug
                };
                issue1.Save();

                var issue2 = new Issue
                {
                    Summary     = "Here is a great idea",
                    Description = "blah blah",
                    Project     = windsor,
                    Type        = IssueType.NewFeature
                };
                issue2.Save();

                var issue3 = new Issue
                {
                    Summary     = "Another thing went wrong",
                    Description = "blah blah",
                    Project     = windsor,
                    Type        = IssueType.Bug
                };
                issue3.Save();
            }

            using (new SessionScope())
            {
                var mr = Project.Find(1);
                mr.Name = "MonoRail 2.0";
                mr.Save();

                IList <Issue> bugs = Issue.FindAllBugs();
                foreach (var bug in bugs)
                {
                    Console.WriteLine("Bug found: " + bug.Summary + ", in project: " + bug.Project.Name);
                }
            }

            Console.WriteLine("Done");
            Console.ReadLine();
        }