Exemple #1
0
        /// <summary>
        /// upsert into mongodb。處理寫入mongodb。
        /// </summary>
        /// <typeparam name="T">mongodb collection 對應到C# class</typeparam>
        /// <param name="observed">observed operation</param>
        /// <param name="database">mongodb IMongoDatabase</param>
        /// <param name="collectionName">collection name</param>
        /// <param name="filter">呼叫方要upsert的過濾條件</param>
        /// <param name="update">每次provider push出來是Row類型,透過委派由呼叫方完成寫入update definition</param>
        /// <param name="options">mongodb update option</param>
        /// <returns></returns>
        public static MongoDbUpdateOperation <T> MongoDbUpsert <T>(this IObservableOperation observed,
                                                                   MongoDB.Driver.IMongoDatabase database,
                                                                   string collectionName,
                                                                   Func <Row, MongoDB.Driver.FilterDefinition <T> > filter,
                                                                   Func <Row, MongoDB.Driver.UpdateDefinition <T> > update,
                                                                   MongoDB.Driver.UpdateOptions options = null)
        {
            var mongoDbOperation = new MongoDbUpdateOperation <T>(new CommandActivator(), database, collectionName, filter, update, options);

            observed.Subscribe(mongoDbOperation);
            return(mongoDbOperation);
        }
Exemple #2
0
        public AlertingRepository(string connection)
        {
            if (string.IsNullOrWhiteSpace(connection))
            {
                connection = "mongodb://localhost:27017";
            }

            _client = new MongoDB.Driver.MongoClient(connection);
            _database = _client.GetDatabase("local",  null);
            _alertTypes = _database.GetCollection<AlertType>("alerttypes");

            var filter = new MongoDB.Bson.BsonDocument();
            long count = _alertTypes.Count(filter);

            // AddTestData();
        }
Exemple #3
0
 public Collection(MongoDB.Driver.IMongoDatabase db)
 {
     collection = db.GetCollection <BsonDocument>(collectionName);
 }
Exemple #4
0
 public void callWebHook(MongoDB.Driver.IMongoDatabase db, Newtonsoft.Json.Linq.JObject webHookBody)
 {
     throw new NotImplementedException();
 }
Exemple #5
0
 public void handle(RegistrationInfoFactory infoFactory, IrcDotNet.IrcClient client, FehBot bot, MongoDB.Driver.IMongoDatabase db, IrcDotNet.IrcUser from, IrcDotNet.IrcChannel to, string message)
 {
     throw new NotImplementedException();
 }
Exemple #6
0
 public Database()
 {
     database = Connection.Instance.client.GetDatabase(databaseName);
 }
Exemple #7
0
 public MongodbProvider(MongoDB.Driver.IMongoDatabase database)
 {
     _database = database;
 }
Exemple #8
0
 static PostToDB()
 {
     HttpClient    = new HttpClient();
     MongoClient   = new MongoDB.Driver.MongoClient("mongodb://127.0.0.1:27017");
     MongoDatabase = MongoClient.GetDatabase("spider");
 }
Exemple #9
0
        public void FileToDatabase(object obj)
        {
            MongoDB.Driver.MongoClient    client   = new MongoDB.Driver.MongoClient("mongodb://localhost");
            MongoDB.Driver.IMongoDatabase dataBase = client.GetDatabase("UserCenter");
            MongoDB.Driver.IMongoCollection <UserInfo> userInfoDb = dataBase.GetCollection <UserInfo>("UserInfo");
            int successNumber = 0;
            int repeatNumber  = 0;
            int totaleNumber  = 0;

            for (int ver = 136; ver < 256; ver++)
            {
                WriterFile(obj.ToString() + "线程开始同步");
                string versionName  = string.Format("{0}_登录成功(1)_.txt", ver.ToString("D3"));
                string fileFullPath = txtFilePath.Text + "\\" + versionName;
                if (File.Exists(fileFullPath))
                {
                    fileFullPath = txtFilePath.Text + "\\" + versionName;
                    WriterFile(obj.ToString() + "线程开始同步" + versionName);
                    StreamReader sr = new StreamReader(fileFullPath, Encoding.Default);
                    String       line;
                    DateTime     currentTime = DateTime.Now;
                    line = sr.ReadToEnd();
                    sr.Close();

                    string[] lineArray = Regex.Split(line, "\r\n");
                    for (int i = 0; i < lineArray.Length; i++)
                    {
                        MatchCollection collection = Regex.Matches(lineArray[i], "^(.*)----(.*)$");
                        if (collection.Count > 0)
                        {
                            UserInfo userInfo = new UserInfo {
                                UserName = collection[0].Groups[1].Value, Password = collection[0].Groups[2].Value
                            };
                            totaleNumber++;
                            //MongoDB.Driver.Builders<UserInfo>.Filter filter=
                            //MongoDB.Driver.Builders<UserInfo>.Filter;
                            MongoDB.Driver.FilterDefinitionBuilder <UserInfo> filerBuilder = new MongoDB.Driver.FilterDefinitionBuilder <UserInfo>();
                            MongoDB.Driver.FilterDefinition <UserInfo>        filter       = filerBuilder.Where(c => c.UserName == userInfo.UserName && c.Password == userInfo.Password);
                            if (userInfoDb.Count(filter) == 0)
                            {
                                userInfoDb.InsertOne(userInfo);
                                successNumber++;
                            }
                            else
                            {
                                repeatNumber++;
                            }
                            if (totaleNumber % 100000 == 0)
                            {
                                WriterFile(string.Format(obj.ToString() + "线程:共{0},成功{1},失败{2},用时{3},当前时间:{4}",
                                                         totaleNumber, successNumber, repeatNumber, DateTime.Now - currentTime, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")));
                                currentTime = DateTime.Now;
                            }
                        }
                    }

                    lineArray = null;
                    GC.Collect();
                }
            }
            WriterFile(obj + "线程结束同步");
        }