Пример #1
0
            /// <summary>
            /// Deserialise a timeline event from JSON
            /// </summary>
            /// <param name="jsnReader">A JsonReader for the trace file</param>
            /// <param name="serializer">A JsonSerializer</param>
            /// <param name="trace">The trace assocated with the timeline event</param>
            public TIMELINE_EVENT(JsonReader jsnReader, JsonSerializer serializer, TraceRecord trace) : base(eLogFilterBaseType.TimeLine)
            {
                jsnReader.Read();
                JArray?itemMeta = serializer.Deserialize <JArray>(jsnReader);

                if (itemMeta is null || itemMeta.Count != 3)
                {
                    return;
                }

                _eventType = itemMeta[0].ToObject <eTimelineEvent>();
                JToken idTok  = itemMeta[1];
                JToken pIdTok = itemMeta[2];


                //_item = item;
                switch (_eventType)
                {
                case eTimelineEvent.ProcessStart:
                case eTimelineEvent.ProcessEnd:
                    SetIDs(ID: idTok.ToObject <ulong>(), parentID: pIdTok.ToObject <ulong>());
                    _item  = trace.GetTraceByID(ID) !;
                    Inited = true;
                    break;

                case eTimelineEvent.ThreadStart:
                case eTimelineEvent.ThreadEnd:
                    Debug.Assert(trace.ParentTrace == null || idTok.ToObject <ulong>() == trace.ParentTrace.PID);
                    SetIDs(ID: idTok.ToObject <ulong>());
                    _item  = trace.GetProtoGraphByTID(ID) !;
                    Inited = true;
                    break;

                case eTimelineEvent.APICall:

                    jsnReader.Read();
                    JArray?apiArr = serializer.Deserialize <JArray>(jsnReader);
                    if (apiArr is null)
                    {
                        Logging.RecordError("No APICALL data in timeline api event");
                        return;
                    }
                    if (!APICALL.TryDeserialise(apiArr, trace, out APICALL? apiObj) || apiObj is null)
                    {
                        Logging.RecordError("Bad APICALL data in timeline api event");
                        return;
                    }

                    SetIDs(ID: idTok.ToObject <ulong>(), parentID: pIdTok.ToObject <ulong>());
                    _item  = apiObj;
                    Inited = true;
                    break;

                default:
                    Debug.Assert(false, "Bad timeline event");
                    break;
                }
            }