public static void FromTson(ITsonDeserializer serializer, RecordInfo info) { while (!serializer.IsEof) { switch ((MyIndex)serializer.ReadIndex()) { case MyIndex.Local: info.Local = serializer.ReadBool(); break; case MyIndex.Time: info.Time = serializer.ReadDateTime(); break; case MyIndex.Index: info.Index = serializer.ReadULong(); break; case MyIndex.ThreadID: info.ThreadID = serializer.ReadInt(); break; case MyIndex.RequestID: info.RequestID = serializer.ReadString(); break; case MyIndex.Name: info.Name = serializer.ReadString(); break; case MyIndex.Message: info.Message = serializer.ReadString(); break; case MyIndex.Type: info.Type = (LogType)serializer.ReadInt(); break; case MyIndex.TypeName: info.TypeName = serializer.ReadString(); break; case MyIndex.User: info.User = serializer.ReadString(); break; case MyIndex.Machine: info.Machine = serializer.ReadString(); break; } } }
/// <inheritdoc /> /// <summary> /// 执行命令 /// </summary> /// <param name="args"></param> /// <returns></returns> public override void Handle(PublishItem args) { try { if (args.Content != null) { LogRecorder.BaseRecorder.RecordLog(JsonConvert.DeserializeObject <List <RecordInfo> >(args.Content)); return; } if (args.Tson == null || args.Tson[0] == 0 || args.Tson[0] > 2) { return; } ITsonDeserializer serializer = args.Tson[0] == 1 ? new TsonDeserializerV1(args.Tson) as ITsonDeserializer : new TsonDeserializer(args.Tson); using (serializer) { switch (serializer.DataType) { case TsonDataType.Object: RecordInfo info = new RecordInfo(); RecordInfoTson.FromTson(serializer, info); LogRecorder.BaseRecorder.RecordLog(info); break; case TsonDataType.Array: serializer.ReadType(); int size = serializer.ReadLen(); List <RecordInfo> infos = new List <RecordInfo>(); for (int idx = 0; !serializer.IsBad && idx < size; idx++) { info = new RecordInfo(); serializer.Begin(out _); RecordInfoTson.FromTson(serializer, info); serializer.End(); infos.Add(info); } LogRecorder.BaseRecorder.RecordLog(infos); break; } } } catch (Exception e) { LogRecorder.Exception(e); } }
/// <summary> /// 反序列化 /// </summary> public void FromTson(ITsonDeserializer serializer, CountData data) { while (!serializer.IsEof) { int idx = serializer.ReadIndex(); switch (idx) { case Index_IsInner: data.IsInner = serializer.ReadBool(); break; case Index_Title: data.Title = serializer.ReadString(); break; case Index_Start: data.Start = serializer.ReadLong(); break; case Index_End: data.End = serializer.ReadLong(); break; case Index_ToId: data.ToId = serializer.ReadString(); break; case Index_FromId: data.FromId = serializer.ReadString(); break; case Index_Requester: data.Requester = serializer.ReadString(); break; case Index_HostName: data.HostName = serializer.ReadString(); break; case Index_ApiName: data.ApiName = serializer.ReadString(); break; case Index_Status: data.Status = (OperatorStatus)serializer.ReadInt(); break; case Index_Machine: data.Machine = serializer.ReadString(); break; case Index_Station: data.Station = serializer.ReadString(); break; case Index_User: data.User = serializer.ReadString(); break; case Index_RequestId: data.RequestId = serializer.ReadString(); break; } } }
/// <summary> /// 生成范围 /// </summary> /// <param name="s"></param> /// <returns></returns> public static TsonObjectScope CreateScope(ITsonDeserializer s) => new TsonObjectScope(s);
private TsonObjectScope(ITsonDeserializer s) { deserializer = s; DataType = s.Begin(out Ver); }