Ejemplo n.º 1
0
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            var source = (HealthStatus)value;

            var target = new HealthStatusData
            {
                Status = HealthConstants.HealthStatusDisplay[source.Status]
            };

            var healthy = source.Results.Where(r => r.Check.Status.IsHealthy())
                          .Select(c => new KeyValuePair <string, string>(c.Name, CheckMessage(c)))
                          .ToDictionary(pair => pair.Key, pair => pair.Value);

            var unhealthy = source.Results.Where(r => r.Check.Status.IsUnhealthy())
                            .Select(c => new KeyValuePair <string, string>(c.Name, CheckMessage(c)))
                            .ToDictionary(pair => pair.Key, pair => pair.Value);

            var degraded = source.Results.Where(r => r.Check.Status.IsDegraded())
                           .Select(c => new KeyValuePair <string, string>(c.Name, CheckMessage(c)))
                           .ToDictionary(pair => pair.Key, pair => pair.Value);

            var ignored = source.Results.Where(r => r.Check.Status.IsIgnored())
                          .Select(c => new KeyValuePair <string, string>(c.Name, CheckMessage(c)))
                          .ToDictionary(pair => pair.Key, pair => pair.Value);

            target.Healthy   = healthy.Any() ? healthy : null;
            target.Unhealthy = unhealthy.Any() ? unhealthy : null;
            target.Degraded  = degraded.Any() ? degraded : null;
            target.Ignored   = ignored.Any() ? ignored : null;

            serializer.Serialize(writer, target);
        }
Ejemplo n.º 2
0
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            var source = (HealthStatus)value;

            var target = new HealthStatusData
            {
                Status    = source.Status.Hummanize(),
                Timestamp = _clock.FormatTimestamp(_clock.UtcDateTime)
            };

            var healthy = source.Results.Where(r => r.Check.Status.IsHealthy())
                          .Select(c => new KeyValuePair <string, string>(c.Name, c.Check.Message))
                          .ToDictionary(pair => pair.Key, pair => pair.Value);

            var unhealthy = source.Results.Where(r => r.Check.Status.IsUnhealthy())
                            .Select(c => new KeyValuePair <string, string>(c.Name, c.Check.Message))
                            .ToDictionary(pair => pair.Key, pair => pair.Value);

            var degraded = source.Results.Where(r => r.Check.Status.IsDegraded())
                           .Select(c => new KeyValuePair <string, string>(c.Name, c.Check.Message))
                           .ToDictionary(pair => pair.Key, pair => pair.Value);

            var ignored = source.Results.Where(r => r.Check.Status.IsIgnored())
                          .Select(c => new KeyValuePair <string, string>(c.Name, c.Check.Message))
                          .ToDictionary(pair => pair.Key, pair => pair.Value);

            if (healthy.Any())
            {
                target.Healthy = healthy;
            }

            if (unhealthy.Any())
            {
                target.Unhealthy = unhealthy;
            }

            if (degraded.Any())
            {
                target.Degraded = degraded;
            }

            if (ignored.Any())
            {
                target.Ignored = ignored;
            }

            serializer.Serialize(writer, target);
        }
 public IndexModel(HealthStatusData data)
 {
     this.data = data;
 }