/**
  * 同步金币获取记录信息
  */
 public void SyncCoinInfo(string uid)
 {
     if (!string.IsNullOrEmpty(uid))
     {
         StartCoroutine(SqliteOpenHelper.AsyncQuery("ch_coin", null
                                                    , delegate(LinkedList <Dictionary <string, object> > coinData)
         {
             //TODO 上传金币记录到服务器
             Task.Run(delegate
             {
                 var sb = new StringBuilder();
                 foreach (var item in coinData)
                 {
                     if (item.ContainsKey("_id"))
                     {
                         sb.Append(item["_id"]);
                         sb.Append(",");
                     }
                 }
                 if (sb.Length > 0)
                 {
                     SqliteOpenHelper.GetInstance().Delete("ch_coin"
                                                           , $"_id in ({sb.Remove(sb.Length - 1, 1)})");
                 }
             });
         }, $"uid = {uid}", limit: 20));
     }
 }
 private void Awake()
 {
     if (null == Instance)
     {
         DestroyImmediate(gameObject);
         return;
     }
     Instance = this;
     SqliteOpenHelper.GetInstance();
 }
Esempio n. 3
0
 public static SqliteOpenHelper GetInstance()
 {
     if (null == _instance)
     {
         lock (SqliteLock)
         {
             if (null == _instance)
             {
                 _instance = new SqliteOpenHelper();
             }
         }
     }
     return(_instance);
 }
 public void SyncClsAndChs(string uid)
 {
     if (!string.IsNullOrEmpty(uid))
     {
         StartCoroutine(SqliteOpenHelper
                        .AsyncQuery("update_class", null
                                    , delegate(LinkedList <Dictionary <string, object> > cls)
         {
             StartCoroutine(SqliteOpenHelper
                            .AsyncQuery("update_ch", null
                                        , delegate(LinkedList <Dictionary <string, object> > chs)
             {
                 JsonMapper.ToJson(cls);
                 JsonMapper.ToJson(chs);
                 Task.Run(delegate
                 {
                     foreach (var item in cls)
                     {
                         SqliteOpenHelper.GetInstance()
                         .Update("update_class", new string[] { "is_need_sync" }
                                 , new object[] { 0 },
                                 $"_id = {item["_id"]} AND is_need_sync = {0}");
                     }
                     foreach (var item in chs)
                     {
                         SqliteOpenHelper.GetInstance()
                         .Update("update_ch", new string[] { "is_need_sync" }
                                 , new object[] { 0 },
                                 $"_id = {item["_id"]} AND is_need_sync = {0}");
                     }
                 });
             }
                                        , $"is_need_sync = {1} AND uid = {uid}"));
         }
                                    , $"is_need_sync = {1} AND uid = {uid}", limit: 20));
     }
 }
Esempio n. 5
0
        public static void SynClsAndChsLog(string uid, List <Dictionary <string, object> > cls
                                           , List <Dictionary <string, object> > chs)
        {
            if (!string.IsNullOrEmpty(uid))
            {
                Task.Run(delegate
                {
                    if (null != cls && 0 < cls.Count)
                    {
                        using (var reader = SqliteOpenHelper.GetInstance().Query("update_class"
                                                                                 , new[] { "_id", "uid", "u_cls_id", "is_need_sync" }
                                                                                 , $"uid = '{uid}'"))
                        {
                            var idM   = new Dictionary <string, int>();
                            var syncM = new Dictionary <string, int>();
                            if (null != reader)
                            {
                                while (reader.Read())
                                {
                                    var id         = reader.GetInt32(0);
                                    var isNeedSync = reader.GetInt32(3);
                                    var key        = $"{reader.GetString(1)}#{reader.GetString(2)}";
                                    idM[key]       = id;
                                    syncM[key]     = isNeedSync;
                                }

                                reader.Close();
                            }

                            foreach (var item in cls)
                            {
                                var columns = item.Keys.ToArray();
                                var values  = new object[item.Keys.Count];
                                for (var i = 0; i < columns.Length; i++)
                                {
                                    values[i] = item[columns[i]];
                                    if (null != values[i])
                                    {
                                        var data = values[i] as JsonData;
                                        if (null != data && data.IsString)
                                        {
                                            values[i] = data.ToString();
                                        }
                                    }
                                }
                                var key = $"{item["uid"]}#{item["u_cls_id"]}";
                                if (syncM.ContainsKey(key))
                                {
                                    if (1 != syncM[key])
                                    {
                                        SqliteOpenHelper.GetInstance().Update("update_class", columns, values
                                                                              , $"_id = {idM[key]}");
                                    }
                                }
                                else
                                {
                                    SqliteOpenHelper.GetInstance()
                                    .Insert("update_class", columns, values);
                                }
                            }
                        }
                    }

                    if (null != chs && 0 < chs.Count)
                    {
                        using (var reader = SqliteOpenHelper.GetInstance().Query("update_ch"
                                                                                 , new[] { "_id", "uid", "u_cls_id", "u_ch_id", "is_need_sync" }
                                                                                 , $"uid = '{uid}'"))
                        {
                            var idM   = new Dictionary <string, int>();
                            var syncM = new Dictionary <string, int>();
                            if (null != reader)
                            {
                                while (reader.Read())
                                {
                                    var id         = reader.GetInt32(0);
                                    var isNeedSync = reader.GetInt32(4);
                                    var key        = $"{reader.GetString(1)}#{reader.GetString(2)}#{reader.GetString(3)}";
                                    idM[key]       = id;
                                    syncM[key]     = isNeedSync;
                                }
                                reader.Close();
                            }

                            foreach (var item in chs)
                            {
                                var columns = item.Keys.ToArray();
                                var values  = new object[item.Keys.Count];
                                for (var i = 0; i < columns.Length; i++)
                                {
                                    values[i] = item[columns[i]];
                                    if (null != values[i])
                                    {
                                        var data = values[i] as JsonData;
                                        if (null != data && data.IsString)
                                        {
                                            values[i] = data.ToString();
                                        }
                                    }
                                }
                                var key = $"{item["uid"]}#{item["u_cls_id"]}#{item["u_ch_id"]}";
                                if (syncM.ContainsKey(key))
                                {
                                    if (1 != syncM[key])
                                    {
                                        SqliteOpenHelper.GetInstance().Update("update_ch", columns, values
                                                                              , $"_id = {idM[key]}");
                                    }
                                }
                                else
                                {
                                    SqliteOpenHelper.GetInstance()
                                    .Insert("update_ch", columns, values);
                                }
                            }
                        }
                    }
                });
            }
        }
 /**
  * 同步学习记录信息
  */
 public void SyncLearnLog(string uid)
 {
     if (!string.IsNullOrEmpty(uid))
     {
         StartCoroutine(SqliteOpenHelper.AsyncQuery("rec_class", null
                                                    , delegate(LinkedList <Dictionary <string, object> > recClassData)
         {
             StartCoroutine(SqliteOpenHelper.AsyncQuery("rec_ch", null
                                                        , delegate(LinkedList <Dictionary <string, object> > recChData)
             {
                 StartCoroutine(SqliteOpenHelper.AsyncQuery("rec_wrong", null
                                                            , delegate(LinkedList <Dictionary <string, object> > recWrongData)
                 {
                     var data     = new Dictionary <string, object>(3);
                     data["cls"]  = recClassData;
                     data["ch"]   = recChData;
                     data["errs"] = recWrongData;
                     var dataJson = JsonMapper.ToJson(data);
                     Debug.Log(dataJson);
                     Task.Run(delegate
                     {
                         if (null != recClassData)
                         {
                             foreach (var item in recClassData)
                             {
                                 if (item.ContainsKey("_id"))
                                 {
                                     SqliteOpenHelper.GetInstance()
                                     .Delete("rec_class"
                                             , $"_id = {item["_id"]}");
                                 }
                             }
                         }
                         if (null != recChData)
                         {
                             foreach (var item in recChData)
                             {
                                 if (item.ContainsKey("_id"))
                                 {
                                     SqliteOpenHelper.GetInstance()
                                     .Delete("rec_ch"
                                             , $"_id = {item["_id"]}");
                                 }
                             }
                         }
                         if (null != recWrongData)
                         {
                             foreach (var item in recWrongData)
                             {
                                 if (item.ContainsKey("_id"))
                                 {
                                     SqliteOpenHelper.GetInstance()
                                     .Delete("rec_wrong"
                                             , $"_id = {item["_id"]}");
                                 }
                             }
                         }
                     });
                 }
                                                            , $"uid = {uid}", limit: 20));
             }
                                                        , $"uid = {uid}", limit: 20));
         }
                                                    , $"uid = {uid}", limit: 20));
     }
 }