Esempio n. 1
0
 public void GetObjectDatas(string ObjectName, List <SyncDataOP> DataList)
 {
     using (SqlConnection Conn = new SqlConnection(_ConnString))
     {
         string         strSql    = "select * from TAB_Sync_Store_Data where ObjectName = @ObjectName";
         SqlParameter[] sqlParams = new SqlParameter[] {
             new SqlParameter("ObjectName", ObjectName)
         };
         DataTable dt = TF.DB.DBUtility.SqlHelper.ExecuteDataset(Conn, CommandType.Text, strSql, sqlParams).Tables[0];
         for (int i = 0; i < dt.Rows.Count; i++)
         {
             SyncDataOP dop = new SyncDataOP();
             dop.Key = dt.Rows[i]["Key"].ToString();
             //此处故意不获取内容,为的是考虑效率
             dop.Json = "";
             //dop.Json = dt.Rows[i]["Json"].ToString();
             dop.Version = dt.Rows[i]["Version"].ToString();
             dop.OP      = 0;
             DataList.Add(dop);
         }
     }
 }
Esempio n. 2
0
        public static void Update(string ObjectName, ISyncSource SourceUtils, ISyncStore StoreUtils)
        {
            SyncObject sourceObject = new SyncObject();

            if (!SourceUtils.GetObject(ObjectName, sourceObject))
            {
                throw new NullReferenceException("目标数据源无此对象:" + ObjectName);
            }
            SyncObject storeObject = new SyncObject();

            if (!StoreUtils.GetObject(ObjectName, storeObject))
            {
                storeObject.ObjectName    = ObjectName;
                storeObject.ObjectVersion = "";
            }

            if (sourceObject.ObjectVersion == storeObject.ObjectVersion)
            {
                //比对版本,一致则退出
                return;
            }
            //加载本地数据信息
            List <SyncDataOP> storeDataList = new List <SyncDataOP>();

            StoreUtils.GetObjectDatas(ObjectName, storeDataList);

            List <SyncData> sourceDataList = new List <SyncData>();

            SourceUtils.GetDataList(ObjectName, sourceDataList);

            //遍历数据源索引
            foreach (var item in sourceDataList)
            {
                //本地仓储无数据则条件索引
                if (!storeDataList.Exists((SyncDataOP s) => s.Key == item.Key))
                {
                    SyncDataOP dop = new SyncDataOP();
                    dop.Key     = item.Key;
                    dop.Json    = item.Json;
                    dop.Version = item.Version;
                    dop.OP      = 1;
                    storeDataList.Add(dop);
                }
                else
                {
                    //已有不同则更新
                    if (storeDataList.Find((SyncDataOP s) => s.Key == item.Key).Version != item.Version)
                    {
                        storeDataList.Find((SyncDataOP s) => s.Key == item.Key).Version = item.Version;
                        storeDataList.Find((SyncDataOP s) => s.Key == item.Key).Json    = item.Json;
                        storeDataList.Find((SyncDataOP s) => s.Key == item.Key).OP      = 2;
                    }
                }
            }
            //判断本地仓储是否有删除的
            foreach (var item in storeDataList)
            {
                if (!sourceDataList.Exists((SyncData s) => s.Key == item.Key))
                {
                    item.OP = 3;
                }
            }

            //保存本地存储索引信息
            foreach (var item in storeDataList)
            {
                SyncData d = new SyncData();
                d.Key     = item.Key;
                d.Json    = item.Json;
                d.Version = item.Version;
                if (item.OP == 0)
                {
                    continue;
                }
                if (item.OP == 1)
                {
                    StoreUtils.AddData(storeObject.ObjectName, d);
                }
                if (item.OP == 2)
                {
                    StoreUtils.UpdateData(storeObject.ObjectName, d);
                }
                if (item.OP == 3)
                {
                    StoreUtils.DeleteData(storeObject.ObjectName, d);
                }
                StoreUtils.AddUserIndex(storeObject, d, item.OP);
            }
            //保存本地对象版本信息
            if (storeObject.ObjectVersion == "")
            {
                storeObject.ObjectVersion = sourceObject.ObjectVersion;
                StoreUtils.AddObject(storeObject);
            }
            else
            {
                storeObject.ObjectVersion = sourceObject.ObjectVersion;
                StoreUtils.UpdateObject(storeObject);
            }
        }