Beispiel #1
0
        private static void CreateData(string name, decimal hourlyRate)
        {
            using(new ConsoleColorer(name))
            using (ISession session = factories[name].OpenSession())
            using (ITransaction tx = session.BeginTransaction())
            {
                var salary = new Salary { HourlyRate = hourlyRate, Name = "MinPay" };
                var emp = new Employee { Name = "ayende", Salary = salary };

                session.Save(salary);
                session.Save(emp);

                session.Save(new TimesheetEntry
                                 {
                                     Employee = emp,
                                     Start = DateTime.Today.AddHours(8),
                                     End = DateTime.Today.AddHours(17)
                                 });

                session.Save(new TimesheetEntry
                                 {
                                     Employee = emp,
                                     Start = DateTime.Today.AddDays(1).AddHours(8),
                                     End = DateTime.Today.AddDays(1).AddHours(19)
                                 });

                tx.Commit();
            }
        }
Beispiel #2
0
        private static void CreateData(string name, decimal hourlyRate)
        {
            using (new ConsoleColorer(GetColorForName(name)))
            using (ISession session = factories[name].OpenSession())
            using (ITransaction tx = session.BeginTransaction())
            {
                Salary salary;
                if (name == "nhibernate") // probably want a smarter way to do this
                {
                    salary = new Salary
                                 {
                                     HourlyRate = hourlyRate,
                                     Name = "MinPay"
                                 };
                }
                else
                {
                    salary = new SalaryWithOvertimeAndBehavior
                                 {
                                     HourlyRate = hourlyRate,
                                     Name = "WithOvertime",
                                     OvertimeHourlySalary = hourlyRate*2
                                 };
                }
                var emp = new Employee {Name = "ayende", Salary = salary};

                session.Save(salary);
                session.Save(emp);

                session.Save(new TimesheetEntry
                                 {
                                     Employee = emp,
                                     Start = DateTime.Today.AddHours(8),
                                     End = DateTime.Today.AddHours(17)
                                 });

                session.Save(new TimesheetEntry
                                 {
                                     Employee = emp,
                                     Start = DateTime.Today.AddDays(1).AddHours(8),
                                     End = DateTime.Today.AddDays(1).AddHours(19)
                                 });

                tx.Commit();
            }
        }
Beispiel #3
0
        private static void Main(string[] args)
        {
            XmlConfigurator.Configure(new FileInfo("nhprof.log4net.config"));

            Configuration cfg = new Configuration()
                .Configure("nhibernate.cfg.xml");

            cfg.SetProperty("hibernate.search.default.directory_provider",
                            typeof (FSDirectoryProvider).AssemblyQualifiedName);
            cfg.SetProperty(Environment.AnalyzerClass,
                            typeof (StopAnalyzer).AssemblyQualifiedName);

            cfg.SetListener(ListenerType.PostUpdate, new FullTextIndexEventListener());
            cfg.SetListener(ListenerType.PostInsert, new FullTextIndexEventListener());
            cfg.SetListener(ListenerType.PostDelete, new FullTextIndexEventListener());

            using (new ConsoleColorer("nhibernate"))
                new SchemaExport(cfg).Execute(true, true, false, true);

            ISessionFactory factory = cfg.BuildSessionFactory();
            using (IFullTextSession s = Search
                .CreateFullTextSession(factory.OpenSession()))
            using (ITransaction tx = s.BeginTransaction())
            {
                s.PurgeAll(typeof (Employee));
                s.PurgeAll(typeof (Salary));

                var salary = new Salary
                                 {
                                     Name = "MinPay",
                                     HourlyRate = 22m
                                 };
                var emp = new Employee
                              {
                                  Name = "ayende",
                                  Salary = salary
                              };
                s.Save(salary);
                s.Save(emp);


                tx.Commit();
            }

            Thread.Sleep(1500);
            Console.Clear();
            using (IFullTextSession s = Search.CreateFullTextSession(factory.OpenSession()))
            using (ITransaction tx = s.BeginTransaction())
            {
                var employees = s.CreateFullTextQuery<Employee>("Name", "a*")
                    .List<Employee>();
                foreach (Employee employee in employees)
                {
                    Console.WriteLine("Employee: " + employee.Name);
                    Console.WriteLine("Salary: {0} - {1:C}",
                                      employee.Salary.Name,
                                      employee.Salary.HourlyRate);
                }

                var salaries = s.CreateFullTextQuery<Salary>("HourlyRate:[20 TO 25]")
                    .List<Salary>();
                foreach (var salary in salaries)
                {
                    Console.WriteLine("Salaray: {0} - {1:C}", salary.Name, salary.HourlyRate);
                }

                tx.Commit();
            }
        }