Exemplo n.º 1
0
 public void CleanAllEntities()
 {
     using (var tx = new TransactionScope(TransactionScopeOption.RequiresNew))
         using (var nhSession = _sessionFactory.OpenSession())
         {
             nhSession.CreateQuery("delete CUSTIS.I18N.SampleDomainModel.Product").ExecuteUpdate();
             tx.Complete();
         }
 }
Exemplo n.º 2
0
        public void TestParameters()
        {
            var query = sessionFactory.OpenSession().CreateQuery("FROM Code WHERE Name = :a or Name = :b or Name = :c");
            var list  = query.NamedParameters;

            foreach (var param in list)
            {
                Console.WriteLine(param);
            }
            Console.WriteLine(DateTime.Now.Ticks);
        }
        public Reminders()
        {
            InitializeComponent();

            if (mySession != null && mySession.IsOpen)
            {
                mySession.Close();
            }
            if (mySessionFactory != null && !mySessionFactory.IsClosed)
            {
                mySessionFactory.Close();
            }
            // Initializing NHibernate
            myConfiguration = new Configuration();
            myConfiguration.Configure();
            mySessionFactory = myConfiguration.BuildSessionFactory();
            mySession        = mySessionFactory.OpenSession();

            //Show TaskNameFromDatabase in ListBox
            using (mySession.BeginTransaction())
            {
                ICriteria    criteria = mySession.CreateCriteria <ToDo>();
                IList <ToDo> list     = criteria.List <ToDo>().Where(a => a.Status == "ToDo" && (DateTime.Now < a.StartDate))
                                        .OrderBy(a => a.StartDate).OrderBy(a => a.EndDate).ToList();
                foreach (var item in list)
                {
                    listView_reminders.Items.Add(item.TaskName);
                    listView_reminders.Items.Add(item.StartDate.ToString("dd/MM/yyyy"));
                    listView_reminders.Items.Add(item.EndDate.ToString("dd/MM/yyyy"));
                }
            }
            ChangeView();
        }
Exemplo n.º 4
0
        public GroupingControlForm(NHibernate.ISessionFactory sessionFactory)
        {
            InitializeComponent();

            this.session = sessionFactory.OpenSession();

            tlvGroupedFiles.CanExpandGetter += x => (((tlvBranch)x).Data is SpectrumSourceGroup && ((tlvBranch)x).Children.Any());
            tlvGroupedFiles.ChildrenGetter  += getChildren;
            tlvGroups.AspectGetter          += x =>
            {
                var nodeTracker      = ((tlvBranch)x);
                var offsetCorrection = 0;
                while (nodeTracker.Parent.Text != null)
                {
                    offsetCorrection++;
                    nodeTracker = nodeTracker.Parent;
                }
                return(((tlvBranch)x).Text + new string(' ', offsetCorrection *7));
            };
            tlvGroups.AutoCompleteEditor = false;

            tlvGroups.ImageGetter += delegate(object x) { return((((tlvBranch)x).Data is SpectrumSourceGroup) ? Properties.Resources.XPfolder_closed : Properties.Resources.file); };

            ApplyDefaultGroups(null, null);
        }
Exemplo n.º 5
0
        internal NHibernate.ISession CreateSession()
        {
            lock (this)
            {
                _currentSession = _sessionFactory.OpenSession();
            }

            return(_currentSession);
        }
Exemplo n.º 6
0
        public static ISession GetCurrentSession()
        {
            if (currentSession == null)
            {
                currentSession = _sessionFactory.OpenSession();
            }

            return(currentSession);
        }
Exemplo n.º 7
0
 //delete from database
 private void button_deleteTask_Click(object sender, EventArgs e)
 {
     using (ISession session = mySessionFactory.OpenSession())
     {
         SqlConnection con = session.Connection as SqlConnection;
         SqlCommand    cmd = new SqlCommand($"Delete from ToDo where Id={id}", con);
         cmd.ExecuteNonQuery();
     }
     this.Close();
 }
Exemplo n.º 8
0
        /// <summary>
        /// Gets the unit of work.
        /// </summary>
        /// <returns></returns>
        private IUnitOfWork GetUnitOfWork()
        {
            var cfg = new Configuration();

            cfg.Configure();
            cfg.AddAssembly(Assembly.Load("CRM.Dal.Nhibernate"));
            NHibernate.ISessionFactory factory = cfg.BuildSessionFactory();
            ISession session = factory.OpenSession();

            return(new UnitOfWork(session));
        }
Exemplo n.º 9
0
        public IsobaricMappingForm(NHibernate.ISessionFactory sessionFactory)
        {
            InitializeComponent();

            this.session = sessionFactory.OpenSession();

            acStrings = new AutoCompleteStringCollection();
            acStrings.Add("Reference");
            acStrings.Add("Empty");

            isobaricMappingTables = new Dictionary <QuantitationMethod, DataGridView>();
        }
Exemplo n.º 10
0
 public void InitializingHibernate()
 {
     if (mySession != null && mySession.IsOpen)
     {
         mySession.Close();
     }
     if (mySessionFactory != null && !mySessionFactory.IsClosed)
     {
         mySessionFactory.Close();
     }
     myConfiguration = new Configuration();
     myConfiguration.Configure();
     mySessionFactory = myConfiguration.BuildSessionFactory();
     mySession        = mySessionFactory.OpenSession();
 }
Exemplo n.º 11
0
        public void reminder()
        {
            DateTime date         = DateTime.Now;
            DateTime date_plusOne = date.AddDays(1);

            if (mySession != null && mySession.IsOpen)
            {
                mySession.Close();
            }
            if (mySessionFactory != null && !mySessionFactory.IsClosed)
            {
                mySessionFactory.Close();
            }
            // Initializing NHibernate
            myConfiguration = new Configuration();
            myConfiguration.Configure();
            mySessionFactory = myConfiguration.BuildSessionFactory();
            mySession        = mySessionFactory.OpenSession();
            int i = 0;

            //I'm checking if there are any new tasks tomorrow
            using (mySession.BeginTransaction())
            {
                ICriteria    criteria = mySession.CreateCriteria <ToDo>();
                IList <ToDo> list     = criteria.List <ToDo>().Where(a => a.Status == "ToDo" && (date
                                                                                                 <= a.StartDate && date_plusOne >= a.StartDate)).ToList();
                i = 0;
                foreach (var item in list)
                {
                    i++;
                }
            }
            if (i > 0)
            {
                Alert alert = new Alert();
                alert.showAlert("Jutro masz nowe zadania do zrobienia !");
            }

            button_TodoList.Text = "Rzeczy \ndo zrobienia";
        }
Exemplo n.º 12
0
 /// <summary>
 /// Opens database connection and begins transaction.
 /// </summary>
 public void BeginTransaction()
 {
     Session = _sessionFactory.OpenSession();
     CurrentSessionContext.Bind(Session);
     _transaction = Session.BeginTransaction();
 }
Exemplo n.º 13
0
 public static void OpenSession()
 {
     HttpContext.Current.Items[SessionKey] = _sessionFactory.OpenSession();
 }
Exemplo n.º 14
0
 public virtual void openConnection()
 {
     Session = sessionFactory.OpenSession();
 }
Exemplo n.º 15
0
        public ITransaction Create(ITransaction parent)
        {
            var session = _sessionFactory.OpenSession();

            return(new NHTransaction(session, parent));
        }
Exemplo n.º 16
0
        private IUnitOfWork GetUnitOfWork()
        {
            ISession session = _sessionFactory.OpenSession();

            return(new UnitOfWork(session));
        }
Exemplo n.º 17
0
 public UnitOfWork(NHibernate.ISessionFactory sessionFactory)
 {
     _sessionFactory = sessionFactory;
     Session = _sessionFactory.OpenSession();
     _transaction = Session.BeginTransaction();
 }