public DailyItemCount GetItem(string name) { DailyItemCount item = FindItem(name); if (item != null) { return(item); } _lock.EnterWriteLock(); try { if (_table.ContainsKey(name)) { return(_table[name]); } if (_table.Count > MAX_COUNT) { throw new Exception("DailyItem 数量超过 " + MAX_COUNT); } item = new DailyItemCount(); _table.Add(name, item); return(item); } finally { _lock.ExitWriteLock(); } }
// 初始化 // parameters: public int Open( // string strMongoDbConnStr, MongoClient client, string strInstancePrefix, out string strError) { strError = ""; #if NO if (string.IsNullOrEmpty(strMongoDbConnStr) == true) { strError = "strMongoDbConnStr 参数值不应为空"; return(-1); } #endif if (string.IsNullOrEmpty(strInstancePrefix) == false) { strInstancePrefix = strInstancePrefix + "_"; } _logDatabaseName = strInstancePrefix + "accessLog"; #if NO try { this._mongoClient = new MongoClient(strMongoDbConnStr); } catch (Exception ex) { strError = "初始化 MongoClient 时出错: " + ex.Message; return(-1); } #endif // var server = client.GetServer(); { // var db = server.GetDatabase(this._logDatabaseName); var db = client.GetDatabase(this._logDatabaseName); _logCollection = db.GetCollection <AccessLogItem>("accessLog"); // _logCollection.DropAllIndexes(); // if (_logCollection.GetIndexes().Count == 0) if (_logCollection.Indexes.List().ToList().Count == 0) { #if NO _logCollection.CreateIndex(new IndexKeysBuilder().Ascending("OperTime"), IndexOptions.SetUnique(false)); #endif CreateIndex(); } } _itemCount = new DailyItemCount(); string date = GetToday(); _itemCount.SetValue(date, GetItemCount(date)); return(0); }
public void SetValue(string name, string strDate, long lValue) { DailyItemCount item = GetItem(name); item.SetValue(strDate, lValue); }
public long GetValue(string name, string strDate, int nInc) { DailyItemCount item = GetItem(name); return(item.GetValue(strDate, nInc)); }
// 初始化 // parameters: public int Open( // string strMongoDbConnStr, MongoClient client, string strInstancePrefix, out string strError) { strError = ""; #if NO if (string.IsNullOrEmpty(strMongoDbConnStr) == true) { strError = "strMongoDbConnStr 参数值不应为空"; return -1; } #endif if (string.IsNullOrEmpty(strInstancePrefix) == false) strInstancePrefix = strInstancePrefix + "_"; _logDatabaseName = strInstancePrefix + "accessLog"; #if NO try { this._mongoClient = new MongoClient(strMongoDbConnStr); } catch (Exception ex) { strError = "初始化 MongoClient 时出错: " + ex.Message; return -1; } #endif var server = client.GetServer(); { var db = server.GetDatabase(this._logDatabaseName); _logCollection = db.GetCollection<AccessLogItem>("accessLog"); // _logCollection.DropAllIndexes(); if (_logCollection.GetIndexes().Count == 0) { #if NO _logCollection.CreateIndex(new IndexKeysBuilder().Ascending("OperTime"), IndexOptions.SetUnique(false)); #endif CreateIndex(); } } _itemCount = new DailyItemCount(); string date = GetToday(); _itemCount.SetValue(date, GetItemCount(date)); return 0; }