Exemplo n.º 1
0
        /// <summary>
        /// 添加数据
        /// </summary>
        /// <param name="data">数据</param>
        public static void AddData(List <Dic> data)
        {
            // 初始化数据库
            MongoDatabase mongoDatabase = MongoFactory.GetMongoDatabaseByDic();
            // 初始化表
            MongoCollection mongoCollection = mongoDatabase.GetCollection("dicTable");

            // 插入数据
            foreach (var item in data)
            {
                mongoCollection.Insert(item);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 更新数据
        /// </summary>
        /// <param name="data">数据</param>
        public static void UpdateData(List <Dic> data)
        {
            // 初始化数据库
            MongoDatabase mongoDatabase = MongoFactory.GetMongoDatabaseByDic();
            // 初始化表
            MongoCollection mongoCollection = mongoDatabase.GetCollection("dicTable");

            foreach (var item in data)
            {
                var query = GetQueryCondition(item);
                mongoCollection.Remove(query);
                mongoCollection.Insert(item);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// 根据key查看数据
        /// </summary>
        /// <param name="key">key</param>
        /// <returns>数据</returns>
        public static List <Dic> ViewTheData(string key)
        {
            // 初始化数据库
            MongoDatabase mongoDatabase = MongoFactory.GetMongoDatabaseByDic();
            // 初始化表
            MongoCollection    mongoCollection = mongoDatabase.GetCollection("dicTable");
            List <IMongoQuery> queryList       = new List <IMongoQuery>
            {
                Query.EQ("Key", key)
            };
            IMongoQuery query = Query.And(queryList);
            List <Dic>  dics  = mongoCollection.FindAs <Dic>(query).ToList();

            return(dics);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 设置更新时间
        /// </summary>
        /// <param name="code">业务代码</param>
        /// <param name="dateTime">更新时间</param>
        public static void SetUpdateTime(string code, DateTime dateTime)
        {
            MongoDatabase      mongoDatabase   = MongoFactory.GetMongoDatabaseByDic();
            MongoCollection    mongoCollection = mongoDatabase.GetCollection("UpdateTime");
            List <IMongoQuery> queryList       = new List <IMongoQuery>
            {
                Query.EQ("Key", code)
            };
            var query = Query.And(queryList);

            mongoCollection.Remove(query);
            UpdateTime updateTime = new UpdateTime
            {
                Key  = code,
                Time = dateTime
            };

            mongoCollection.Insert(updateTime);
        }
Exemplo n.º 5
0
        /// <summary>
        /// 获取最后更新时间
        /// </summary>
        /// <param name="code">业务代码</param>
        /// <returns>时间</returns>
        public static DateTime GetLastUpdateTime(string code)
        {
            MongoDatabase      mongoDatabase   = MongoFactory.GetMongoDatabaseByDic();
            MongoCollection    mongoCollection = mongoDatabase.GetCollection("UpdateTime");
            List <IMongoQuery> queryList       = new List <IMongoQuery>
            {
                Query.EQ("Key", code)
            };
            var query = Query.And(queryList);
            List <UpdateTime> time = mongoCollection.FindAs <UpdateTime>(query).ToList();

            if (time.Count == 0)
            {
                return(default(DateTime));
            }
            else
            {
                return(time[0].Time);
            }
        }