Ejemplo n.º 1
0
        private void InitializeNHibernateSession()
        {
            var connectionString = ConfigurationManager.ConnectionStrings["FirstConnectionString"].ConnectionString;

            NhConfig.InitNhibernateSession(_webSessionStorage, GetCurrentUser, HttpContext.Current.IsDebuggingEnabled,
                                           new[] { Server.MapPath("~/bin/YouVote.Model.dll"), Server.MapPath("~/nhibernate.config") }, connectionString);
        }
Ejemplo n.º 2
0
        private static void Main(string[] args)
        {
            var config = new NhConfig {
                Name             = "NHTest",
                ConnectionString = "Data Source=(local);Initial Catalog=test;Integrated Security = true",
                // It can be defined in another assembly.
                MappingsAssemblies             = new Assembly[] { typeof(Product).Assembly },
                MappingsNamespace              = typeof(Product).Namespace,
                ValidationDefinitionsNamespace = typeof(Product).Namespace,
                ShowLogs = true,
                DropTablesCreateDbSchema = true,
                OutputXmlMappingsFile    = "mappings.xml",
                DbSchemaOutputFile       = "db.sql",
                // I want to ignore the base-type, Otherwise NHibernate would see the BaseEntity as an actual entity.
                BaseEntityToIgnore   = typeof(BaseEntity),
                MapAllEnumsToStrings = true,
                // Otherwise Enums will be mapped to integers automatically.
                AutoMappingOverride = modelMapper => {
                    modelMapper.BeforeMapProperty += (modelInspector, member, map) => {
                        // I want all of the "Name" fields to be unique.
                        if (member.LocalMember.Name.Equals("Name"))
                        {
                            map.Unique(true);
                        }
                    };
                },
                OnConfigCreated = cfg => {
                    // inject stuff to config here
                }
            };

            var addresses = InMemoryDataSource.CreateAddresses();
            var customers = InMemoryDataSource.CreateCustomers(addresses);

            InMemoryDataSource.AddRelatedCustomers(customers);
            var products = InMemoryDataSource.CreateProducts();
            var orders   = InMemoryDataSource.CreateOrders(customers, products);

            using (var sessionFactory = config.SetUpSessionFactory())
                using (var session = sessionFactory.OpenSession())
                    using (var tx = session.BeginTransaction()) {
                        // Save Products
                        foreach (var product in products)
                        {
                            session.SaveOrUpdate(product);
                        }

                        // Save Orders (also saves Customers and their Addresses & Contacts)
                        foreach (var order in orders)
                        {
                            session.SaveOrUpdate(order);
                        }

                        tx.Commit();
                    }

            Console.WriteLine("Press a key...");
            Console.Read();
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            if (1 > args.Length)
            {
                Console.WriteLine(@"Primul argument este calea catre fisier");
                return;
            }

            var filePath = args[0];

            if (!File.Exists(filePath))
            {
                Console.WriteLine(string.Format(@"Fisierul {0} nu exista", filePath));
                return;
            }

            var lineParsers   = new ILineParser[] { new RequestLineParser(), new SnmpLineParser() };
            var transformer   = new DictionaryToAtacLogTransformer();
            var logFileReader = new LogFileReader(filePath, lineParsers, transformer);

            var entities = logFileReader.Read();

            Console.WriteLine(entities.Count);

            var cnt = 0;

            var connectionString = ConfigurationManager.ConnectionStrings["conpot"].ConnectionString;

            using (var sessionFactory = new NhConfig(connectionString).Create())
            {
                using (var session = sessionFactory.OpenSession())
                {
                    foreach (var entity in entities)
                    {
                        session.Save(entity);
                        cnt++;

                        if (cnt % 300 == 0)
                        {
                            Console.WriteLine(string.Format(@"Saved {0}", cnt));
                        }
                    }

                    session.Flush();
                }
            }

            Console.WriteLine(string.Format(@"Saved {0}", cnt));
            Console.ReadLine();
        }
        static CountriesController()
        {
            var config = new NhConfig(connectionString);

            sessionFactory = config.Create();
        }