/// <summary>发送消息 /// /// </summary> /// <param name="messageEntity"></param> public static void AddMessage(CacheMessageEntity messageEntity) { if (AppClient != null) { string strContent = JsonConvert.SerializeObject(messageEntity, Formatting.Indented); Message message = new Message { Command = Command.Send, Content = strContent }; SendMessage(AppClient, message); } }
/// <summary>处理接受到的消息 /// /// </summary> /// <param name="data"></param> /// <param name="responseChannel"></param> public static void Received(NetworkData data, IConnection responseChannel) { try { var message = MessageConverter.ToMessage(data); if (message.Command == Command.Send) { if (message.Content.Contains("join group successful")) { return; } CacheMessageEntity entity = JsonConvert.DeserializeObject <CacheMessageEntity>(message.Content); string strKey = entity.CacheKey; string strOperation = entity.Operation; DataTable dtCacheTable = entity.DataTableCache; //新增缓存配置,同步缓存 if (strOperation == "Add") { SynLocalCacheByCacheConfig(dtCacheTable); } //删除缓存配置,同步缓存 else if (strOperation == "Delete") { string strTableName = dtCacheTable.Rows[0]["TableName"].ToString(); string strId = dtCacheTable.Rows[0]["Id"].ToString(); IDbHelper helper = GlobalHelp.GetDataAccessSqliteHelper(); helper.CreateCommand("DELETE FROM CacheConfig WHERE Id=" + strId + ""); helper.ExecuteNonQuery(); helper.CreateCommand("DROP Table IF EXISTS [" + strTableName + "]"); helper.ExecuteNonQuery(); if (CacheManager.CacheDictionary.ContainsKey(strTableName)) { CacheManager.CacheDictionary.Remove(strTableName); } } } } catch (Exception) { } }