Example #1
0
 public void Flush()
 {
     if (_session != null)
     {
         _session.Flush();
         _session.Clear();
         _session.Close();
         _session.Dispose();
         _session = null;
     }
 }
Example #2
0
        /// <summary>
        /// Closes the current session object from http context. This should be called on end request.
        /// </summary>
        public void CloseSession()
        {
            if (HttpContext.Current != null)
            {
                _logger.Debug("Closing NHibernate session from the HttpContext.");

                var session = HttpContext.Current.Items[SessionKey] as ISession;

                if (session != null)
                {
                    if (session.IsOpen)
                    {
                        session.Close();
                        session.Dispose();
                    }
                    HttpContext.Current.Items.Remove(SessionKey);
                }
            }

            if (_currentSession == null)
            {
                return;
            }
            if (_currentSession.IsOpen)
            {
                _logger.Debug("Closing NHibernate session from the current thread.");

                _currentSession.Close();
                _currentSession.Dispose();
            }
            _currentSession = null;
        }
Example #3
0
        public void AfterInvoke(object correlationState)
        {
            foreach (ISessionFactory sessionFactory in sfp)
            {
                ISession session = CurrentSessionContext.Unbind(sessionFactory);
                if (!session.IsOpen)
                {
                    continue;
                }

                try
                {
                    session.Flush();
                    if (session.Transaction.IsActive)
                    {
                        session.Transaction.Commit();
                    }
                }
                catch (Exception)
                {
                    if (session.Transaction.IsActive)
                    {
                        session.Transaction.Rollback();
                    }
                    throw;
                }
                finally
                {
                    session.Close();
                    session.Dispose();
                }
            }
        }
Example #4
0
 /// <summary>
 /// 解除ISession对象绑定并且关闭只读数据库连接
 /// </summary>
 public static void UnbindReadonlySession()
 {
     if (m_ReadonlySessionFactory != null && NHibernate.Context.CurrentSessionContext.HasBind(ReadonlySessionFactory))
     {
         NHibernate.ISession sess = NHibernate.Context.CurrentSessionContext.Unbind(ReadonlySessionFactory);
         sess.Close();
     }
 }
Example #5
0
 public void CloseSession()
 {
     if (CurrentSessionContext.HasBind(_sessionFactory))
     {
         NHibernate.ISession session = CurrentSessionContext.Unbind(_sessionFactory);
         session.Close();
         session.Dispose();
     }
 }
Example #6
0
 public void ClearSession()
 {
     ClearData(true);
     if (session != null && session.IsOpen)
     {
         session.Close();
         session.Dispose();
         session = null;
     }
 }
Example #7
0
        /// <summary>
        /// 关闭当前会话
        /// </summary>
        public static void CloseSession()
        {
            HttpContext context = HttpContext.Current;

            NH.ISession currentSession = context.Items[CurrentSessionKey] as NH.ISession;

            if (currentSession == null)
            {
                return;
            }

            currentSession.Close();
            context.Items.Remove(CurrentSessionKey);
        }
Example #8
0
        public void DisposeCurrent()
        {
            if (!context.Items.ContainsKey(CURRENT_SESSION_KEY))
            {
                return;
            }
            ISession session = RetrieveSession();

            if (session != null && session.IsOpen)
            {
                session.Close();
            }
            context.Items.Remove(CURRENT_SESSION_KEY);
        }
Example #9
0
 public void Close(NHibernate.ISession session)
 {
     if (session != null)
     {
         try
         {
             if (session.IsOpen)
             {
                 session.Close();
             }
         }
         catch (Exception)
         {
         }
     }
 }
Example #10
0
 private void CloseSession()
 {
     session.Close();
     session.Dispose();
     session = null;
 }
Example #11
0
        public async Task <object> Post()
        {
            OnepNetwork onepNetwork = null;

            {
                onepNetwork = new OnepNetwork()
                {
                    McpProjectId = Guid.NewGuid().ToString(),
                    Name         = "Test 01"
                };
                var onepFiberTL1 = new OnepFibertl()
                {
                    Name        = "FS01_1",
                    Length      = 30,
                    Loss        = 30 * 0.25,
                    OnepNetwork = onepNetwork
                };
                var onepFiberTL2 = new OnepFibertl()
                {
                    Name        = "FS01_2",
                    Length      = 30,
                    Loss        = 30 * 0.25,
                    OnepNetwork = onepNetwork
                };
                onepFiberTL1.OnepTopologicallinkMemberByUniMate = onepFiberTL2;
                onepFiberTL2.OnepTopologicallinkMemberByUniMate = onepFiberTL1;

                onepNetwork.OnepFibertls.Add(onepFiberTL1);
                onepNetwork.OnepFibertls.Add(onepFiberTL2);

                /////////

                var onepTP1 = new OnepTerminationpoint()
                {
                    Name        = "TP 01",
                    Ptp         = 1,
                    Role        = 2,
                    OnepNetwork = onepNetwork
                };
                var onepTP2 = new OnepTerminationpoint()
                {
                    Name        = "TP 02",
                    Ptp         = 1,
                    Role        = 2,
                    OnepNetwork = onepNetwork
                };

                onepNetwork.OnepTerminationpoints.Add(onepTP1);
                onepNetwork.OnepTerminationpoints.Add(onepTP2);

                onepTP1.OnepTopologicallinksForAEndTP.Add(onepFiberTL1);
                onepTP1.OnepTopologicallinksForZEndTP.Add(onepFiberTL2);
                onepFiberTL1.OnepTerminationpointByAEndTP = onepTP1;
                onepFiberTL2.OnepTerminationpointByAEndTP = onepTP2;

                onepTP2.OnepTopologicallinksForAEndTP.Add(onepFiberTL2);
                onepTP2.OnepTopologicallinksForZEndTP.Add(onepFiberTL1);
                onepFiberTL1.OnepTerminationpointByZEndTP = onepTP2;
                onepFiberTL2.OnepTerminationpointByZEndTP = onepTP1;

                var onepAmpTP1 = new OnepAmptp()
                {
                    TargetGain           = 2.1,
                    OnepNetwork          = onepNetwork,
                    OnepTerminationpoint = onepTP1
                };
                onepTP1.OnepAmpRole = onepAmpTP1;
                onepNetwork.OnepAmptps.Add(onepAmpTP1);

                var onepAmpTP2 = new OnepAmptp()
                {
                    TargetGain           = 1.9,
                    OnepNetwork          = onepNetwork,
                    OnepTerminationpoint = onepTP2
                };
                onepTP2.OnepAmpRole = onepAmpTP2;
                onepNetwork.OnepAmptps.Add(onepAmpTP2);
            }

            // TODO : Json serialization not working due to circular references

            //var onepNetworkAsJsonString = JsonConvert.SerializeObject(onepNetwork);
            //Debug.WriteLine(onepNetworkAsJsonString);

            using (var tx = _session.BeginTransaction())
            {
                try
                {
                    await _session.SaveOrUpdateAsync(onepNetwork).ConfigureAwait(false);

                    tx.Commit();
                }
                catch (Exception ex)
                {
                    Debugger.Break();

                    Debug.WriteLine(ex.ToString());
                    tx.Rollback();
                    throw;
                }
            }

            // Simulate LE Run
            Debugger.Break();
            _session.Close();
            var session2      = _sessionFactory.OpenSession();
            var onepNetwork_x = session2.Get <OnepNetwork>(onepNetwork.Id);

            // Apply object Updates
            // Replace TP01 by new TP03, but move the same AmpRole object to TP03
            {
                var onepTP3 = new OnepTerminationpoint()
                {
                    Name        = "TP 03",
                    Ptp         = 1,
                    Role        = 2,
                    OnepNetwork = onepNetwork_x
                };

                var onepTP1 = onepNetwork_x.OnepTerminationpoints.Where(p => p.Name == "TP 01").FirstOrDefault();
                onepNetwork_x.OnepTerminationpoints.Remove(onepTP1);
                onepNetwork_x.OnepTerminationpoints.Add(onepTP3);
                var onepFiberTL1 = onepNetwork_x.OnepFibertls.Where(p => p.Name == "FS01_1").FirstOrDefault();
                var onepFiberTL2 = onepNetwork_x.OnepFibertls.Where(p => p.Name == "FS01_2").FirstOrDefault();
                onepFiberTL1.OnepTerminationpointByAEndTP = null;
                onepFiberTL2.OnepTerminationpointByZEndTP = null;

                onepTP3.OnepTopologicallinksForAEndTP.Add(onepFiberTL1);
                onepTP3.OnepTopologicallinksForZEndTP.Add(onepFiberTL2);
                onepFiberTL1.OnepTerminationpointByAEndTP = onepTP3;
                onepFiberTL2.OnepTerminationpointByZEndTP = onepTP3;

                var onepAmpTP1 = onepTP1.OnepAmpRole;
                onepTP3.OnepAmpRole = onepAmpTP1;

                //onepTP1.OnepAmpRole = null; // This is not required
                //onepTP1.OnepNetwork = null;
                //onepTP1.OnepTopologicallinksForAEndTP.Clear();
                onepTP1.OnepTopologicallinksForAEndTP = null; // These are required, otherwise we get an exception "deleted entity will be resaved"
                //onepTP1.OnepTopologicallinksForZEndTP.Clear();
                onepTP1.OnepTopologicallinksForZEndTP = null; // These are required, otherwise we get an exception "deleted entity will be resaved"
            }


            //{
            //    var onepTP1 = onepNetwork_x.OnepTerminationpoints.Where(p => p.Name == "TP 01").FirstOrDefault();

            //    onepNetwork_x.OnepTerminationpoints.Remove(onepTP1);
            //    var amptp = onepTP1.OnepAmpRole;
            //    onepNetwork_x.OnepAmptps.Remove(amptp);
            //}
            Debugger.Break();
            session2.Close();
            var session3 = _sessionFactory.OpenSession();

            using (var tx = session3.BeginTransaction())
            {
                try
                {
                    await session3.SaveOrUpdateAsync(onepNetwork_x).ConfigureAwait(false);

                    tx.Commit();
                }
                catch (Exception ex)
                {
                    Debugger.Break();

                    Debug.WriteLine(ex.ToString());
                    tx.Rollback();
                    throw;
                }
            }

            return(new { Id = onepNetwork.Id });
        }
Example #12
0
        public void ApplyQonverterSettings(IDictionary<Analysis, QonverterSettings> qonverterSettings)
        {
            clearData();
            setControlsWhenDatabaseLocked(true);

            var workerThread = new BackgroundWorker()
            {
                WorkerReportsProgress = true,
                WorkerSupportsCancellation = true
            };

            workerThread.DoWork += (s, e) =>
            {
                var qonverter = new Qonverter();
                qonverter.QonversionProgress += progressMonitor.UpdateProgress;
                foreach (var item in qonverterSettings)
                    qonverter.SettingsByAnalysis[(int) item.Key.Id] = item.Value.ToQonverterSettings();

                //qonverter.LogQonversionDetails = true;
                qonverter.Reset(Text);
                qonverter.Qonvert(Text);
            };

            workerThread.RunWorkerCompleted += (s, e) =>
            {
                if (e.Result is Exception)
                {
                    Program.HandleException(e.Result as Exception);
                    setControlsWhenDatabaseLocked(false);
                    return;
                }

                lock (session)
                {
                    var sessionFactory = DataModel.SessionFactoryFactory.CreateSessionFactory(Text, new SessionFactoryConfig { WriteSqlToConsoleOut = true });
                    session = sessionFactory.OpenSession();
                    //session.CreateSQLQuery("PRAGMA temp_store=MEMORY").ExecuteUpdate();
                    _layoutManager.SetSession(session);

                    // delete old filters since they are not valid with different qonverter settings
                    session.CreateSQLQuery("DELETE FROM FilterHistory").ExecuteUpdate();
                    session.Clear();

                    if (basicFilter == null)
                        basicFilter = new DataFilter()
                        {
                            MaximumQValue = 0.02,
                            MinimumDistinctPeptides = 2,
                            MinimumSpectra = 2,
                            MinimumAdditionalPeptides = 1,
                            GeneLevelFiltering = false,
                            DistinctMatchFormat = new DistinctMatchFormat
                            {
                                IsChargeDistinct = true,
                                IsAnalysisDistinct = false,
                                AreModificationsDistinct = true,
                                ModificationMassRoundToNearest = 1.0m
                            }
                        };

                    basicFilterControl.DataFilter = basicFilter;

                    viewFilter = basicFilter;

                    session.Close();
                    sessionFactory.Close();
                }

                progressMonitor = new ProgressMonitor();
                progressMonitor.ProgressUpdate += progressMonitor_ProgressUpdate;
                basicFilterControl = new BasicFilterControl();
                basicFilterControl.BasicFilterChanged += basicFilterControl_BasicFilterChanged;
                basicFilterControl.ShowQonverterSettings += ShowQonverterSettings;
                dataFilterPopup = new Popup(basicFilterControl) { FocusOnOpen = true };
                dataFilterPopup.Closed += dataFilterPopup_Closed;
                new Thread(() => OpenFiles(new List<string> { Text }, null)).Start();
            };

            workerThread.RunWorkerAsync();
        }