// 初始化 // 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); }
// 初始化 // 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; }