예제 #1
0
        /// <summary>
        /// Fors the specified expression.
        /// </summary>
        /// <typeparam name="TProperty">The type of the property.</typeparam>
        /// <param name="expression">The expression.</param>
        /// <param name="param">The parameter.</param>
        /// <returns></returns>
        public IFilterBuilder <TDocument> For <TProperty>(Expression <Func <TDocument, TProperty> > expression, TProperty param)
        {
            var propertyName = ExpressionUtils.GetMemberName(expression);

            _filter = Builders <TDocument> .Filter.Eq(propertyName, param);

            return(this);
        }
예제 #2
0
 public bool RemovePerson(string phoneNumber)
 {
     try
     {
         MongoDB.Driver.FilterDefinition <T> filter = builder.AnyEq(t => t.PhoneNumbers, phoneNumber);
         Storage.Collection.DeleteOne(filter);
         return(true);
     }
     catch
     {
         return(false);
     }
 }
예제 #3
0
 public bool RemovePerson(long id)
 {
     try
     {
         MongoDB.Driver.FilterDefinition <T> filter = builder.Eq(t => t.Id, id);
         Storage.Collection.DeleteOne(filter);
         return(true);
     }
     catch
     {
         return(false);
     }
 }
예제 #4
0
        public static List <T> Save_And_GetDiffer <T>(IMongoDatabase mDB, string tablename, List <T> currentList,
                                                      MongoDB.Driver.FilterDefinition <T> mFilter, Func <List <T>, List <T>, List <T> > action, Action <List <T>, string> action1 = null)
            where T : new()
        {
            if (currentList.Count == 0)
            {
                return(currentList);
            }
            List <T> result = new List <T>();

            //  var issuseFileFullName = BuildFileFullName(string.Format("Match_{0}_List.json", gameCode), issuseNumber);
            // var customerSavePath = new string[] { "CTZQ", issuseNumber };
            if (action1 != null)
            {
                action1(currentList, tablename);
            }
            try
            {
                string currentListStr = KaSon.FrameWork.Common.JSON.JsonHelper.Serialize(currentList);

                // string tablename = Lottery.CrawGetters.InitConfigInfo.MongoTableSettings["CTZQMatch"].ToString();IssuseNumber  IssuseNumber
                //   var mFilter = MongoDB.Driver.Builders<CTZQ_MatchInfo>.Filter.Eq(b => b.GameType, GameType) & Builders<CTZQ_MatchInfo>.Filter.Eq(b => b.IssuseNumber, issuseNumber);

                var coll = mDB.GetCollection <T>(tablename);
                // var count = coll.Find(mFilter).CountDocuments();
                var document = coll.Find(mFilter).ToList <T>();
                // BsonDocument one = coll.fincou;
                // var updated = Builders<BsonDocument>.Update.Set("Content", currentListStr);
                if (document.Count > 0)
                {//更新
                    coll.DeleteMany(mFilter);

                    result = action(document, currentList);
                }
                else
                {
                    result = currentList;
                }
                coll.InsertMany(currentList);
            }
            catch (Exception)
            {
                throw;
            }


            return(result);
        }
예제 #5
0
        //test
        public List <InfoBO> FindTargetByTag(Dictionary <string, List <string> > tagGroups)
        {
            if (tagGroups.Count() == 0)
            {
                return(GetInfos());
            }


            IMongoCollection <InfoBO> collection = _client.
                                                   GetDatabase(Configuration["MongoSetting:InfoSetting:Database"])
                                                   .GetCollection <InfoBO>(Configuration["MongoSetting:InfoSetting:Collection"]);

            List <InfoBO> ret = new List <InfoBO>();

            FilterDefinitionBuilder <InfoBO> builder = new FilterDefinitionBuilder <InfoBO>();

            List <FilterDefinition <InfoBO> > filters = new List <FilterDefinition <InfoBO> >();

            foreach (var it in tagGroups)
            {
                string        tagGroupName = it.Key;
                List <string> tagsInGroup  = it.Value;

                Builders <InfoBO> .Filter.Exists(x => x.tags, true);

                var filter1 = builder.Exists(x => x.tags[tagGroupName], false);
                var filter2 = builder.AnyIn(r => r.tags[tagGroupName], it.Value);
                var filter  = filter1 | filter2;

                filters.Add(filter);
            }
            MongoDB.Driver.FilterDefinition <InfoBO> finalFiter = filters.Count == 1 ? filters[0] : builder.And(filters);

            ret = collection.Find(finalFiter).ToList();

            return(ret);
        }
        public static void Update <T>(MongoDB.Driver.FilterDefinition <T> filter, Dictionary <string, object> properties, bool updateOne, bool IsUpsert)
        {
            var update = Builders <T> .Update.Set(properties.First().Key, properties.First().Value);

            foreach (var property in properties)
            {
                //to implement multiple updates in a decent way, not done yet, must do task.
                update.AddToSet(property.Key, property.Value);
                if (updateOne)
                {
                    GetCollection <T>()
                    .UpdateOneAsync(filter, update, new UpdateOptions {
                        IsUpsert = IsUpsert
                    });
                }
                else
                {
                    GetCollection <T>()
                    .UpdateMany(filter, update, new UpdateOptions {
                        IsUpsert = IsUpsert
                    });
                }
            }
        }
예제 #7
0
        public static List <KeyValuePair <DBChangeState, T> > BuildNewMatchList <T>(IMongoDatabase mDB, string tablename, List <T> currentList,
                                                                                    MongoDB.Driver.FilterDefinition <T> mFilter, Func <List <T>, List <T>, List <T> > action, Action <List <T>, string> action1 = null)
            where T : new()
        {
            var result = new List <KeyValuePair <DBChangeState, T> >();

            if (currentList.Count == 0)
            {
                return(result);
            }
            //  var issuseFileFullName = BuildFileFullName(string.Format("Match_{0}_List.json", gameCode), issuseNumber);
            // var customerSavePath = new string[] { "CTZQ", issuseNumber };
            if (action1 != null)
            {
                action1(currentList, tablename);
            }
            try
            {
                string currentListStr = KaSon.FrameWork.Common.JSON.JsonHelper.Serialize(currentList);

                // string tablename = Lottery.CrawGetters.InitConfigInfo.MongoTableSettings["CTZQMatch"].ToString();IssuseNumber  IssuseNumber
                //   var mFilter = MongoDB.Driver.Builders<CTZQ_MatchInfo>.Filter.Eq(b => b.GameType, GameType) & Builders<CTZQ_MatchInfo>.Filter.Eq(b => b.IssuseNumber, issuseNumber);
                List <T> rn = new List <T>();
                if (mFilter == null)
                {
                    mFilter = Builders <T> .Filter.Empty;
                }

                var coll = mDB.GetCollection <T>(tablename);
                // var count = coll.Find(mFilter).CountDocuments();
                var document = coll.Find(mFilter).ToList <T>();


                // BsonDocument one = coll.fincou;
                // var updated = Builders<BsonDocument>.Update.Set("Content", currentListStr);
                if (document.Count > 0)
                {//更新
                 //Thread.Sleep(2000);
                 //  var text = document["Content"].ToString().Trim();//.Replace("var data=", "").Replace("];", "]");
                 //  var oldList = string.IsNullOrEmpty(text) ? new List<CTZQ_MatchInfo>() : KaSon.FrameWork.Common.JSON.JsonHelper.Deserialize<List<CTZQ_MatchInfo>>(text);
                    var newList = action(document, currentList);
                    coll.DeleteMany(mFilter);
                    //UpdateResult uresult = coll.UpdateOne(mFilter, updated);
                    //if (uresult.ModifiedCount > 0)
                    //{
                    //    //成功修改一行以上
                    //}
                    foreach (var item in newList)
                    {
                        result.Add(new KeyValuePair <DBChangeState, T>(DBChangeState.Update, item));
                    }
                }
                else
                {
                    foreach (var item in currentList)
                    {
                        result.Add(new KeyValuePair <DBChangeState, T>(DBChangeState.Add, item));
                    }
                    //BsonDocument bson = new BsonDocument();
                    //bson.Add("GameCode", gameCode);
                    //bson.Add("IssuseNumber", issuseNumber);
                    //bson.Add("Content", currentListStr);
                }
                coll.InsertMany(currentList);
            }
            catch (Exception EX)
            {
                throw;
            }

            //if (File.Exists(issuseFileFullName))
            //{
            //    var text = File.ReadAllText(issuseFileFullName).Trim().Replace("var data=", "").Replace("];", "]");
            //    var oldList = string.IsNullOrEmpty(text) ? new List<C_CTZQ_Match>() :JSONHelper.Deserialize<List<C_CTZQ_Match>>(text);
            //    var newList = GetNewMatch(oldList, currentList);
            //    //ServiceHelper.CreateOrAppend_JSONFile(issuseFileFullName, JSONHelper.Serialize(currentList), (log) =>
            //    //{
            //    //    this.WriteLog(log);
            //    //});
            //    foreach (var item in newList)
            //    {
            //        result.Add(new KeyValuePair<DBChangeState, C_CTZQ_Match>(DBChangeState.Update, item));
            //    }


            //    //上传文件
            //    //ServiceHelper.PostFileToServer(issuseFileFullName, customerSavePath, (log) =>
            //    //{
            //    //    this.WriteLog(log);
            //    //});
            //    return result;
            //}

            ////录入到monodb


            //currentListStr = JSONHelper.Serialize(currentList);
            //BsonDocument bson = new BsonDocument();
            //bson.Add("GameCode", gameCode);
            //bson.Add("IssuseNumber", issuseNumber);
            //bson.Add("Content", currentListStr);
            //var mFilter = MongoDB.Driver.Builders<MongoDB.Bson.BsonDocument>.Filter.Eq("GameCode", gameCode) & Builders<BsonDocument>.Filter.Eq("IssuseNumber", issuseNumber);
            //// var mUpdateDocument =Builders<MongoDB.Bson.BsonDocument>.Update.Set("Content", content);
            //try
            //{
            //    var coll = mDB.GetCollection<BsonDocument>(tablename);
            //    coll.DeleteMany(mFilter);
            //    coll.InsertOne(bson);
            //}
            //catch (Exception)
            //{

            //    throw;
            //}
            ////try
            ////{
            ////    ServiceHelper.CreateOrAppend_JSONFile(issuseFileFullName, JSONHelper.Serialize(currentList), (log) =>
            ////    {
            ////        this.WriteLog(log);
            ////    });
            ////}
            ////catch (Exception ex)
            ////{
            ////    this.WriteLog(string.Format("第一次写入 {0}  文件失败:{1}", issuseFileFullName, ex.ToString()));
            ////}
            ////上传文件
            ////ServiceHelper.PostFileToServer(issuseFileFullName, customerSavePath, (log) =>
            ////{
            ////    this.WriteLog(log);
            ////});
            //foreach (var item in currentList)
            //{
            //    result.Add(new KeyValuePair<DBChangeState, C_CTZQ_Match>(DBChangeState.Add, item));
            //}
            return(result);
        }
예제 #8
0
        public static void Write_Trend_JSON <T>(IMongoDatabase mDB, string tablename, List <T> collection, List <C_BJDC_Match> CurrentMatchList, MongoDB.Driver.FilterDefinition <T> mFilter = null)
            where T : IBJDCBallBaseInfo
        {
            var coll = mDB.GetCollection <T>(tablename);

            foreach (var item in collection)
            {
                try
                {
                    // v
                    //   ServiceHelper.BuildList_GN(mDB, "BJDC_ZJQ_SpInfo", collection, null, mFilter);

                    //var fileName = string.Format("ZJQ_SP_Trend_{0}.json", item.MatchOrderId);
                    //var fileFullName = BuildFileFullName(fileName, item.IssuseNumber);
                    var league = CurrentMatchList.FirstOrDefault(p => p.IssuseNumber == item.IssuseNumber && p.MatchOrderId == item.MatchOrderId);
                    if (league == null || league.MatchState == (int)BJDCMatchState.Stop)
                    {
                    }
                    else
                    {
                        //  var dlist = coll.Find<T>(mFilter).ToList();
                        coll.InsertOne(item);
                    }
                }
                catch (Exception ex)
                {
                    //this.WriteLog(string.Format("写入第{0}期,赛事{1} SP值走势失败:{2}", item.IssuseNumber, item.MatchOrderId, ex.ToString()));
                    continue;
                }
            }
        }
 public static void Update <T>(MongoDB.Driver.FilterDefinition <T> filter, Dictionary <string, object> properties, bool updateOne)
 {
     Update <T>(filter, properties, false, true);
 }