Beispiel #1
0
        public string GetName(string key)
        {
            if (dbDriver == null)
            {
                dbDriver = Get.i.DBFactory.LoadDefaultDatabase(PROVIDERS_STORE_SCHEMA);
                dbDriver.Connect();
            }

            var names = dbDriver.DB.GetCollection <NameRecord>(NAMES_COLLECTION);

            if (names.Exists(n => n.Key.Equals(key)))
            {
                NameRecord name = names.FindOne(n => n.Key.Equals(key));
                name.Counter++;
                names.Update(name);

                Logger.Debug("Key [{0}] already exists and next counter value [{1}] will be returned", name.Key, name.Counter);

                return(name.Key + "_" + name.Counter);
            }
            else
            {
                NameRecord name = new NameRecord(key, 1);
                names.Insert(name);

                Logger.Debug("Key [{0}] doesn't exists in collection; Creating new entry with counter value [{1}]", name.Key, name.Counter);

                return(name.Key + "_" + name.Counter);
            }
        }
Beispiel #2
0
        private static void Main(string[] args)
        {
            _serverListFetcher = new ServerListFetcher();
            _serverDataFetcher = new ServerDataFetcher();

            _serverDatas = new List <ServerData>();

            _dbDriver = new PostgreSQLDBDriver();
            _dbDriver.Connect();

            while (true)
            {
                _serverAddresses = _serverListFetcher.FetchServerList(("master.zandronum.com", 15300)).ToList();
                _serverDatas.Clear();

                Console.WriteLine($"[{DateTime.Now}] Got servers list. {_serverAddresses.Count} total");
                _serverDataFetcher.FetchServerData(_serverAddresses, _serverDatas);
                Console.WriteLine($"[{DateTime.Now}] Got {_serverDatas.Count} servers data.");

                _dbDriver.InsertServerData(_serverDatas);

                GC.Collect();
                Thread.Sleep(ServersUpdateInteval);
            }
        }
Beispiel #3
0
 private void CheckAndConnect()
 {
     if (dbDriver == null)
     {
         dbDriver = Get.i.DBFactory.LoadDefaultDatabase(PROVIDERS_STORE_SCHEMA);
         dbDriver.Connect();
     }
 }
Beispiel #4
0
 public ORMHelper()
 {
     DBSource = OrmEntry.CreateDBSource();
     //注册主实体定义
     DBSource.DataEntityTypes.Add(Customer.DefaultType);
     DBSource.DataEntityTypes.Add(Product.DefaultType);
     DBSource.DataEntityTypes.Add(Quotation.DefaultType);
     //添加数据库驱动
     this.DBDriver = new SqlServerDriver();
     this.DBDriver.ConnectionString = ConnectionString;
 }
		public JanusDatabaseManager(IServiceProvider provider)
			: base(provider)
		{
			if (provider == null)
				throw new ArgumentNullException("provider");
			_currentDriverName = Config.Instance.DbDriver;
			var info = _drvManager.GetDriverInfo(_currentDriverName);
			_currentDriver = _drvManager.GetDriver(_currentDriverName);
			_bltDataProvider = _currentDriver.CreateDataProvider();
			_connectionString = Config.Instance.ConnectionString;
			_rwLock = info.LockRequired ? (IJanusRWLock)new StandardJanusRWLock() : EmptyJanusRWLock.LockInstance;
		}
Beispiel #6
0
        public void TestLoadDatabaseAndDriverConnect()
        {
            dbDriver = factory.LoadDefaultDatabase("Test.db");
            Assert.AreEqual(ConnectionStatus.Disconnected, dbDriver.ConnectionStatus);

            dbDriver.Connect();
            Assert.AreEqual(ConnectionStatus.Connected, dbDriver.ConnectionStatus);

            Assert.AreEqual("Test.db", dbDriver.Schema);

            Setup();
        }
        public JanusDatabaseManager(IServiceProvider provider)
            : base(provider)
        {
            if (provider == null)
            {
                throw new ArgumentNullException("provider");
            }
            _currentDriverName = Config.Instance.DbDriver;
            var info = _drvManager.GetDriverInfo(_currentDriverName);

            _currentDriver    = _drvManager.GetDriver(_currentDriverName);
            _bltDataProvider  = _currentDriver.CreateDataProvider();
            _connectionString = Config.Instance.ConnectionString;
            _rwLock           = info.LockRequired ? (IJanusRWLock) new StandardJanusRWLock() : EmptyJanusRWLock.LockInstance;
        }
Beispiel #8
0
        /// <summary>
        /// 通过config配置的DbDriver,创建数据库,需要手动关闭连接
        /// </summary>
        /// <returns></returns>
        public static Database.BDClass CreateDBConnector()
        {
            if (iDrv != null)
            {
                return(iDrv.CreateDBase());
            }

            var appset = System.Configuration.ConfigurationManager.AppSettings["DbDriver"];

            if (string.IsNullOrEmpty(appset))
            {
                throw new Exception("使用Shotgun.PagePlus时,请在appseting中指定DbDriver");
            }
            if (appset.EndsWith(".dll", StringComparison.OrdinalIgnoreCase))
            {
                appset = appset.Substring(0, appset.Length - 4);
            }
            var allAss = AppDomain.CurrentDomain.GetAssemblies();
            // var ff= from a in allAss where
            var ass = Array.Find(allAss, e => e.GetName().Name.Equals(appset, StringComparison.OrdinalIgnoreCase));

            if (ass == null)
            {
                var path = HttpContext.Current.Request.MapPath(string.Format("~/bin/{0}.dll", appset));
                ass = System.Reflection.Assembly.LoadFile(path);
                if (ass == null)
                {
                    throw new System.IO.FileNotFoundException("在appseting中指定DbDriver不存在", appset);
                }
            }

            var drv = (Shotgun.Database.IDBDriver)ass.CreateInstance(TypeName);

            if (drv == null)
            {
                throw new Exception(string.Format("在{0}中找不到{1}", appset, TypeName));
            }
            iDrv = (Shotgun.Database.IDBDriver)drv;
            return(iDrv.CreateDBase());
        }
 public ApiConnection(IDBDriver dbDriver)
 {
     this.DAO = dbDriver;
 }
 public DefaultObjectsStore()
 {
     dbDriver = Get.i.DBFactory.LoadDefaultDatabase(OBJECTS_STORE_SCHEMA);
     dbDriver.Connect();
 }