예제 #1
0
        /// <summary>
        /// 获取一个可操作性的实例
        /// </summary>
        /// <param name="type"></param>
        /// <param name="exData"></param>
        /// <returns></returns>
        public static DataStorage GetInstance(DBType dbType, object exData = null)
        {
            DataStorage.Register();
            DataStorage inst = new DataStorage();

            if (DBType.MongoDB == dbType)
            {
                inst.mongo = MongoDB.GetInst("mongodb");
            }
            else if (DBType.SQLServer == dbType)
            {
                inst.sqlserver = SQLServer.GetInstance("sqlserver");
            }
            return(inst);
        }
예제 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="keyName"></param>
        /// <param name="dbType">mongo,sqlserver,mysql,redis</param>
        /// <returns></returns>
        public static DataStorage GetInstance(string keyName = "140", string dbType = "mongo")
        {
            DataStorage.Register();
            DataStorage inst = new DataStorage();

            if ("mongo" == dbType)
            {
                inst.mongo = MongoDB.GetInst(keyName);
            }
            else if ("sqlserver" == dbType)
            {
                inst.sqlserver = SQLServer.GetInstance(keyName);
                inst.sqlserver.UpdateSysObject(true);
            }
            return(inst);
        }
예제 #3
0
        /// <summary>
        /// 移动数据
        /// </summary>
        /// <param name="sourceKeyName"></param>
        /// <param name="sourceDbName"></param>
        /// <param name="sourceCollectionName"></param>
        /// <param name="sourceFilter"></param>
        /// <param name="targetKeyName"></param>
        /// <param name="targetDbName"></param>
        /// <param name="targetCollectionName"></param>
        /// <param name="needDeleteSource"></param>
        public static void MoveCollection(string sourceKeyName, string sourceDbName, string sourceCollectionName, string sourceFilter, string targetKeyName, string targetDbName, string targetCollectionName, bool needDeleteSource = false)
        {
            var sourceInst = MongoDB.GetInst(sourceKeyName);
            var targetInst = MongoDB.GetInst(targetKeyName);
            var count      = 0;

            sourceInst.EventTraverse += (object sender, EventArgs e) =>
            {
                var ee     = e as EventProcEventArgs;
                var dict   = ee.Default as Dictionary <string, object>;
                var filter = string.Format("{{\"_id\":\"{0}\"}}", dict["_id"]);
                targetInst.Save2(targetDbName, targetCollectionName, filter, dict);
                Console.WriteLine("正在转移数据 {0} 已转移 {1}", dict["_id"], ++count);
                if (true == needDeleteSource)
                {
                    sourceInst.Delete(sourceDbName, sourceCollectionName, filter);
                }
            };

            sourceInst.Find(sourceDbName, sourceCollectionName, sourceFilter);
        }