Exemple #1
0
 public static Boolean TestAccount(DatabaseAccountToken token, Boolean testMapping = false)
 {
     try
     {
         Configuration configuration = new Configuration();
         configuration.SetProperty(NHibernate.Cfg.Environment.ConnectionString, token.ConnectionString);
         configuration.SetProperty(NHibernate.Cfg.Environment.ConnectionDriver, String.Format("NHibernate.Driver.{0}", token.DatabaseDriver));
         configuration.SetProperty(NHibernate.Cfg.Environment.Dialect, String.Format("NHibernate.Dialect.{0}", token.DatabaseDialect));
         if (testMapping)
         {
             configuration.AddXml(token.Mapping);
             using (ISessionFactory sessionFactory = configuration.BuildSessionFactory())
             {
                 using (ISession session = sessionFactory.OpenSession())
                 {
                     return(session.IsConnected);
                 }
             }
         }
         else
         {
             using (ISessionFactory sessionFactory = configuration.BuildSessionFactory())
             {
                 using (ISession session = sessionFactory.OpenSession())
                 {
                     return(session.IsConnected);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         return(false);
     }
 }
        public ISessionFactory GetSessionFactory(DatabaseAccountToken token)
        {
            ISessionFactory sessionFactory;
            bool isSessionFactoryGot = sesionFactoryDictionary.TryGetValue(token.TokenId, out sessionFactory);
            if (isSessionFactoryGot)
            {
                return sessionFactory;
            }
            else
            {
                if (token != null)
                {
                    Add(token);
                    isSessionFactoryGot = sesionFactoryDictionary.TryGetValue(token.TokenId, out sessionFactory);
                }
                if (isSessionFactoryGot)
                {
                    return sessionFactory;
                }
                else
                {
                    throw new Exception("Can't create sessionFactory");
                }

            }
        }
 public static Boolean TestAccount(DatabaseAccountToken token, Boolean testMapping = false)
 {
     try
     {
         Configuration configuration = new Configuration();
         configuration.SetProperty(NHibernate.Cfg.Environment.ConnectionString, token.ConnectionString);
         configuration.SetProperty(NHibernate.Cfg.Environment.ConnectionDriver, String.Format("NHibernate.Driver.{0}", token.DatabaseDriver));
         configuration.SetProperty(NHibernate.Cfg.Environment.Dialect, String.Format("NHibernate.Dialect.{0}", token.DatabaseDialect));
         if (testMapping)
         {
             configuration.AddXml(token.Mapping);
             using (ISessionFactory sessionFactory = configuration.BuildSessionFactory())
             {
                 using (ISession session = sessionFactory.OpenSession())
                 {
                     return session.IsConnected;
                 }
             }
         }
         else
         {
             using (ISessionFactory sessionFactory = configuration.BuildSessionFactory())
             {
                 using (ISession session = sessionFactory.OpenSession())
                 {
                     return session.IsConnected;
                 }
             }
         }
     }
     catch (Exception ex)
     {
         return false;
     }
 }
Exemple #4
0
        public ISessionFactory GetSessionFactory(DatabaseAccountToken token)
        {
            ISessionFactory sessionFactory;
            bool            isSessionFactoryGot = sesionFactoryDictionary.TryGetValue(token.TokenId, out sessionFactory);

            if (isSessionFactoryGot)
            {
                return(sessionFactory);
            }
            else
            {
                if (token != null)
                {
                    Add(token);
                    isSessionFactoryGot = sesionFactoryDictionary.TryGetValue(token.TokenId, out sessionFactory);
                }
                if (isSessionFactoryGot)
                {
                    return(sessionFactory);
                }
                else
                {
                    throw new Exception("Can't create sessionFactory");
                }
            }
        }
        public IAccountToken Convert(Token token)
        {
            DatabaseAccountToken targetToken = new DatabaseAccountToken();

            targetToken.TokenId   = token.TokenId;
            targetToken.TokenName = token.TokenName;
            if (token.Tokens != null)
            {
                targetToken.Mapping = (from tok in token.Tokens
                                       where tok.Key == "Mapping"
                                       select tok.Value).SingleOrDefault();

                targetToken.Password = (from tok in token.Tokens
                                        where tok.Key == "Password"
                                        select tok.Value).SingleOrDefault();

                targetToken.ConnectionString = (from tok in token.Tokens
                                                where tok.Key == "ConnectionString"
                                                select tok.Value).SingleOrDefault();

                targetToken.UserName = (from tok in token.Tokens
                                        where tok.Key == "UserName"
                                        select tok.Value).SingleOrDefault();

                targetToken.DataSource = (from tok in token.Tokens
                                          where tok.Key == "DataSource"
                                          select tok.Value).SingleOrDefault();

                String dialect = (from tok in token.Tokens
                                  where tok.Key == "DatabaseDialect"
                                  select tok.Value).SingleOrDefault();

                DatabaseDialect dbDialect;
                Enum.TryParse(dialect, out dbDialect);
                targetToken.DatabaseDialect = dbDialect;

                String Driver = (from tok in token.Tokens
                                 where tok.Key == "DatabaseDriver"
                                 select tok.Value).SingleOrDefault();

                DatabaseDriver dbDriver;
                Enum.TryParse(Driver, out dbDriver);
                targetToken.DatabaseDriver = dbDriver;
            }

            return(targetToken);
        }
        public Token Convert(IAccountToken token)
        {
            Token targetToken = new Token();
            DatabaseAccountToken paramToken = (DatabaseAccountToken)token;

            targetToken.TokenId   = paramToken.TokenId;
            targetToken.TokenName = paramToken.TokenName;
            targetToken.Tokens.Add("ConnectionString", paramToken.ConnectionString);
            targetToken.Tokens.Add("UserName", paramToken.UserName);
            targetToken.Tokens.Add("Password", paramToken.Password);
            targetToken.Tokens.Add("DataSource", paramToken.DataSource);
            targetToken.Tokens.Add("Mapping", paramToken.Mapping);
            targetToken.Tokens.Add("DatabaseDriver", paramToken.DatabaseDriver.ToString());
            targetToken.Tokens.Add("DatabaseDialect", paramToken.DatabaseDialect.ToString());

            return(targetToken);
        }
        public IAccountSettings TestAccount(IAccountSettings accountnForTest)
        {
            DatabaseAccountSettings accountForTestDB = (DatabaseAccountSettings)accountnForTest;
            DatabaseAccountToken    tokenForTest     = accountForTestDB.Tokens.FirstOrDefault();
            Boolean result = false;

            if (tokenForTest != null)
            {
                if (tokenForTest.Mapping == null)
                {
                    result = ClientNHibernateSessionFactory.TestAccount(tokenForTest);
                }
                else
                {
                    result = ClientNHibernateSessionFactory.TestAccount(tokenForTest, true);
                }
            }
            accountForTestDB.TestResult = result;
            return(accountForTestDB);
        }
        public IAccountSettings Convert(ServiceAccount serviceAccount)
        {
            DatabaseAccountSettings target = new DatabaseAccountSettings();
            target.ID = serviceAccount.ServiceAccountId;
            target.Name = serviceAccount.ServiceAccountName;
            target.Source = serviceAccount.Source;
            target.MinUpdateTime = serviceAccount.MinUpdateTime * 60000;
            target.AccountVersion = serviceAccount.AccountVersion;
            target.Tokens = new List<DatabaseAccountToken>();

            if (serviceAccount.Tokens.Count > 0)
            {
                foreach (Token token in serviceAccount.Tokens)
                {
                    DatabaseAccountToken targetToken = new DatabaseAccountToken();
                    targetToken = (DatabaseAccountToken)targetToken.Convert(token);
                    target.Tokens.Add(targetToken);
                }
            }
            return target;
        }
        public IAccountSettings Convert(ServiceAccount serviceAccount)
        {
            DatabaseAccountSettings target = new DatabaseAccountSettings();

            target.ID             = serviceAccount.ServiceAccountId;
            target.Name           = serviceAccount.ServiceAccountName;
            target.Source         = serviceAccount.Source;
            target.MinUpdateTime  = serviceAccount.MinUpdateTime * 60000;
            target.AccountVersion = serviceAccount.AccountVersion;
            target.Tokens         = new List <DatabaseAccountToken>();

            if (serviceAccount.Tokens.Count > 0)
            {
                foreach (Token token in serviceAccount.Tokens)
                {
                    DatabaseAccountToken targetToken = new DatabaseAccountToken();
                    targetToken = (DatabaseAccountToken)targetToken.Convert(token);
                    target.Tokens.Add(targetToken);
                }
            }
            return(target);
        }
        public void Add(DatabaseAccountToken configFile)
        {
            try
            {
                if (sesionFactoryDictionary.ContainsKey(configFile.TokenId))
                {
                    return;
                }
                else
                {
                    Configuration configuration = new Configuration();
                    configuration.SetProperty(NHibernate.Cfg.Environment.ConnectionString, configFile.ConnectionString);
                    configuration.SetProperty(NHibernate.Cfg.Environment.ConnectionDriver, String.Format("NHibernate.Driver.{0}", configFile.DatabaseDriver));
                    configuration.SetProperty(NHibernate.Cfg.Environment.Dialect, String.Format("NHibernate.Dialect.{0}", configFile.DatabaseDialect));
                    configuration.AddXml(configFile.Mapping);

                    sesionFactoryDictionary.Add(configFile.TokenId, configuration.BuildSessionFactory());
                }
            }
            catch (Exception ex)
            {
                log.Error("Can't create sessionFactory", ex);
            }
        }
Exemple #11
0
        public void Add(DatabaseAccountToken configFile)
        {
            try
            {
                if (sesionFactoryDictionary.ContainsKey(configFile.TokenId))
                {
                    return;
                }
                else
                {
                    Configuration configuration = new Configuration();
                    configuration.SetProperty(NHibernate.Cfg.Environment.ConnectionString, configFile.ConnectionString);
                    configuration.SetProperty(NHibernate.Cfg.Environment.ConnectionDriver, String.Format("NHibernate.Driver.{0}", configFile.DatabaseDriver));
                    configuration.SetProperty(NHibernate.Cfg.Environment.Dialect, String.Format("NHibernate.Dialect.{0}", configFile.DatabaseDialect));
                    configuration.AddXml(configFile.Mapping);

                    sesionFactoryDictionary.Add(configFile.TokenId, configuration.BuildSessionFactory());
                }
            }
            catch (Exception ex)
            {
                log.Error("Can't create sessionFactory", ex);
            }
        }
        public IAccountToken Convert(Token token)
        {
            DatabaseAccountToken targetToken = new DatabaseAccountToken();
            targetToken.TokenId = token.TokenId;
            targetToken.TokenName = token.TokenName;
            if (token.Tokens != null)
            {

                targetToken.Mapping = (from tok in token.Tokens
                                       where tok.Key == "Mapping"
                                       select tok.Value).SingleOrDefault();

                targetToken.Password = (from tok in token.Tokens
                                        where tok.Key == "Password"
                                        select tok.Value).SingleOrDefault();

                targetToken.ConnectionString = (from tok in token.Tokens
                                                where tok.Key == "ConnectionString"
                                                select tok.Value).SingleOrDefault();

                targetToken.UserName = (from tok in token.Tokens
                                        where tok.Key == "UserName"
                                        select tok.Value).SingleOrDefault();

                targetToken.DataSource = (from tok in token.Tokens
                                          where tok.Key == "DataSource"
                                          select tok.Value).SingleOrDefault();

                String dialect = (from tok in token.Tokens
                                    where tok.Key == "DatabaseDialect"
                                    select tok.Value).SingleOrDefault();

                DatabaseDialect dbDialect;
                Enum.TryParse(dialect, out dbDialect);
                targetToken.DatabaseDialect = dbDialect;

                String Driver = (from tok in token.Tokens
                                  where tok.Key == "DatabaseDriver"
                                 select tok.Value).SingleOrDefault();

                DatabaseDriver dbDriver;
                Enum.TryParse(Driver, out dbDriver);
                targetToken.DatabaseDriver = dbDriver;
            }

            return targetToken;
        }