Exemplo n.º 1
0
        private DiagnosticInfo CheckProvider(ISessionFactoryProvider prov)
        {
            try
            {
                var sessionFactory = _sessionFactoryManager.GetSessionFactory(prov.Nick);
                using (var session = sessionFactory.OpenSession())
                {
                    if (prov.IsSkipHealthCheckEntity)
                    {
                        Logger.LogDiagnostic($"Orm provider with nick {prov.Nick} has been diagnosed successfully");
                        return(new DiagnosticInfo($"DB: {prov.Nick}", string.Empty));
                    }

                    var allClassMetadata = session.SessionFactory.GetAllClassMetadata();
                    foreach (var entity in allClassMetadata)
                    {
                        Logger.LogDiagnostic($"Diagnose the orm entity {entity.Key}");
                        session.CreateCriteria(entity.Key)
                        .SetTimeout(DiagnosticTimeout)
                        .SetMaxResults(1)
                        .List();
                        Logger.LogDiagnostic($"Orm entity {entity.Key} has been diagnosed successfully");
                    }
                }

                Logger.LogDiagnostic($"Orm provider with nick {prov.Nick} has been diagnosed successfully");
                return(new DiagnosticInfo($"DB: {prov.Nick}", string.Empty));
            }
            catch (Exception e)
            {
                Logger.LogDiagnostic($"Diagnostic of orm provider with nick {prov.Nick} has been failed with error: {e}");
                return(new DiagnosticInfo($"DB: {prov.Nick}", string.Empty, DiagnosticStatus.DbConnectionError, string.Empty, e.ToString()));
            }
        }
Exemplo n.º 2
0
        /// <inheritdoc cref="ISessionManager"/>
        public ISession GetSession(string nick)
        {
            var sessionFactory = _sessionFactoryManager.GetSessionFactory(nick);
            var session        = GetCurrentSession(sessionFactory);

            session.DefaultReadOnly = _settings == null;
            Logger.LogDebugFormat("The nhibernate session has been got. SessionId: {0}, ReadOnly: {1}, Nick: {2}", session.GetHashCode(),
                                  session.DefaultReadOnly, nick);

            if (_settings == null)
            {
                return(session);
            }

            Logger.LogDebugFormat("A unit of work has been registered, starting the transaction with a level: {0}", _settings.IsolationLevel);
            session.BeginTransaction(_settings.IsolationLevel);

            return(session);
        }