Ejemplo n.º 1
0
        public void WriteDataToJson(List <Player> players)
        {
            if (players == null)
            {
                throw new NullPlayersException(nameof(players));
            }
            var json = _jsonProvider.SerializeObject(players);

            _fileProvider.WriteAllText(GetConnectionString(), json);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 计算行记录的哈希值
        /// 1-32位为表结构的哈希值,33-64位为数据的哈希值
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="entity"></param>
        /// <param name="onlyStruct">仅计算表结构的哈希</param>
        /// <returns></returns>
        public static string GetEntityHash <T>(T entity, bool onlyStruct = false)
        {
            IJsonProvider jsonProvider = JsonFactory.GetProvider();
            var           tableInfo    = TableInfo.GetTableInfo <T>();
            string        structMD5    = EncryptUtil.GetMD5(tableInfo.GetColumnsStr());

            if (onlyStruct)
            {
                return(structMD5);
            }
            //计算数据的MD5时应该忽略BaseEntity中的所有可能的字段
            var    dataDict = GetEntityDict(entity, true);
            string dataMD5  = EncryptUtil.GetMD5(jsonProvider.SerializeObject(dataDict));

            return(string.Format("{0}{1}", structMD5, dataMD5));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 将指定的消息对象集合序列化为Json字符串集合
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="datas"></param>
        /// <returns></returns>
        private string[] SendObject <T>(T[] datas)
        {
            if (datas == null)
            {
                throw new ArgumentNullException("datas", "发送的数据不能为空!");
            }
            List <string> jsons = new List <string>();

            datas.ToList().ForEach(data =>
            {
                string json = _jsonProvider.SerializeObject <T>(data);
                if (json == null)
                {
                    throw new Exception("序列化发送数据失败!");
                }
                jsons.Add(json);
            });
            return(jsons.ToArray());
        }
Ejemplo n.º 4
0
 public string Serialize <TEvent>(TEvent domainEvent) where TEvent : IDomainEvent
 {
     return(_jsonProvider.SerializeObject <TEvent>(domainEvent));
 }
Ejemplo n.º 5
0
 static string ToJson(object value, Encoding encoding, IJsonProvider jsonProvider)
 {
     return(jsonProvider.SerializeObject(value, encoding));
 }
 public string Serialize <T>(T objectValue)
 {
     return(_jsonProvider.SerializeObject <T>(objectValue));
 }
        public override void SetDataCore <T>(string key, T value, double cacheMinutes = -1)
        {
            var jsonStr = _jsonProvider.SerializeObject(value);

            SetString(key, jsonStr, cacheMinutes);
        }