public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            Breadcrumb breadcrumb = (Breadcrumb)value;
            JArray     a          = new JArray(breadcrumb.ToJArray());

            a.WriteTo(writer);
        }
        private static Breadcrumb SessionStartBreadcrumb(List <Breadcrumb> session)
        {
            // First Breadcrumb in session (Launch Breadcrumb equivalent to "session_start").
            Breadcrumb answer = null;

            if (session.Count > 0)
            {
                answer = session[0];
            }
            return(answer);
        }
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            Breadcrumb breadcrumb = null;
            // Load JArray from stream .  For better or worse, probably a bit of the latter,
            // Newtonsoft.Json deserializes a persisted timestamp string as a JTokenType.Date .
            JArray a = JArray.Load(reader);

            if (IsBreadcrumbJson(a))
            {
                // Extract values from "JArray a" .
                string         timestamp      = JsonUtils.JsonDateToGMTDateString(a[(int)BreadcrumbIndex.Timestamp]);
                BreadcrumbType breadcrumbType = (BreadcrumbType)(long)((JValue)(a[(int)BreadcrumbIndex.Type])).Value;
                Object         data           = null;
                // Launch = 0,      // 0 - session launched      ; --
                // Text,            // 1 - user breadcrumb       ; {text:,level:}
                // Network,         // 2 - network breadcrumb    ; [verb,url,...,statusCode,errorCode]
                // Event,           // 3 - app event             ; {event:}
                // Reachability,    // 4 - network change        ; {change:,type:,oldType:,newType:}
                // View,            // 5 - uiview change / load  ; {event:,viewName:}
                // Error,           // 6 - handled exception     ; {name:,reason:}
                // Crash,           // 7 - crash                 ; {name:,reason:}
                if (breadcrumbType == BreadcrumbType.Launch)
                {
                    // SPEC: "[Session launched] is special in that it will only have a timestamp
                    // and breadcrumb type field".
                }
                else
                {
                    JToken dataToken = a[(int)BreadcrumbIndex.Data];
                    switch (breadcrumbType)
                    {
                    case BreadcrumbType.Network:
                        data = dataToken.ToObject(typeof(Endpoint));
                        break;

                    default:
                        // TODO: This might be good enough, but should double check again later.
                        data = dataToken.ToObject(typeof(Dictionary <string, Object>));
                        break;
                    }
                }
                // Call Breadcrumb constructor.
                breadcrumb = new Breadcrumb(
                    timestamp,
                    breadcrumbType,
                    data
                    );
            }
            return(breadcrumb);
        }
        internal static List <UserBreadcrumb> ExtractUserBreadcrumbs(long beginTime, long endTime)
        {
            // Extract UserBreadcrumb's from converted userBreadcrumb's filtered by time. (UserflowReport "breadcrumbs")
            List <Breadcrumb> list = userBreadcrumbs.RecentBreadcrumbs(beginTime, endTime);
            {
                Breadcrumb sessionStartBreadcrumb = SessionStartBreadcrumb(userBreadcrumbs.current_session);
                if ((sessionStartBreadcrumb != null) &&
                    (list.IndexOf(sessionStartBreadcrumb) < 0))
                {
                    // Add session start breadcrumb at the begining, this if statement should always be true
                    // In case we didn't log session start breadcrumb, we don't want to send an empty breadcrumb
                    // and bread the server
                    list.Insert(0, sessionStartBreadcrumb);
                }
            }
            List <UserBreadcrumb> answer = ConvertToUserBreadcrumbs(list, false);

            return(answer);
        }
        internal UserBreadcrumb(Breadcrumb breadcrumb, bool windowsStyle)
        {
            // Convert a Breadcrumb into a UserBreadcrumb
            this.timestamp = breadcrumb.GetTimestamp();
            string message = "";

            switch (breadcrumb.GetBreadcrumbType())
            {
            case BreadcrumbType.Launch:
                message = "session_start";
                break;

            case BreadcrumbType.Text:
            {
                // 1 - user breadcrumb       ; {text:,level:}
                Dictionary <string, Object> data = (Dictionary <string, Object>)breadcrumb.GetData();
                message = (string)data["text"];
            }
            break;
            }
            this.message      = message;
            this.windowsStyle = windowsStyle;
        }