Exemple #1
0
        public bool Equals(HerculesTags other)
        {
            if (other == null)
            {
                return(false);
            }

            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            if (tags.Count != other.tags.Count)
            {
                return(false);
            }

            foreach (var pair in tags)
            {
                if (!other.tags.TryGetValue(pair.Key, out var otherValue) || !Equals(pair.Value, otherValue))
                {
                    return(false);
                }
            }

            return(true);
        }
Exemple #2
0
 public HerculesTagsBuilder(HerculesTags startingTags)
 {
     foreach (var pair in startingTags)
     {
         Set(pair.Key, pair.Value);
     }
 }
        public static string Render([NotNull] HerculesTags tags, int startingDepth = 0)
        {
            var builder = new StringBuilder();

            Render(tags, builder, startingDepth);

            return(builder.ToString());
        }
        private static void Render([NotNull] HerculesTags tags, [NotNull] StringBuilder builder, int depth)
        {
            if (tags.Count == 0)
            {
                builder
                .Indent(depth)
                .Append(OpeningCurlyBracket)
                .Append(ClosingCurlyBracket);

                return;
            }

            builder
            .Indent(depth)
            .AppendLine(OpeningCurlyBracket);

            var counter = 0;

            foreach (var pair in tags)
            {
                builder
                .Indent(depth + 1)
                .Append(Quote)
                .Append(pair.Key)
                .Append(Quote)
                .Append(Colon)
                .Append(Space);

                if (HasChildren(pair.Value))
                {
                    builder.AppendLine();
                    Render(pair.Value, builder, depth + 1);
                }
                else
                {
                    Render(pair.Value, builder, 0);
                }

                if (++counter < tags.Count)
                {
                    builder.Append(Comma);
                }

                builder.AppendLine();
            }

            builder
            .Indent(depth)
            .Append(ClosingCurlyBracket);
        }
        public static IHerculesTagsBuilder AddTags(this IHerculesTagsBuilder builder, HerculesTags tags)
        {
            foreach (var tag in tags)
            {
                var key   = tag.Key;
                var value = tag.Value;

                switch (value.Type)
                {
                case HerculesValueType.String:
                    builder.AddValue(key, value.AsString);
                    break;

                case HerculesValueType.Long:
                    builder.AddValue(key, value.AsLong);
                    break;

                case HerculesValueType.Guid:
                    builder.AddValue(key, value.AsGuid);
                    break;

                case HerculesValueType.Container:
                    builder.AddContainer(key, tagsBuilder => tagsBuilder.AddTags(value.AsContainer));
                    break;

                case HerculesValueType.Int:
                    builder.AddValue(key, value.AsInt);
                    break;

                case HerculesValueType.Double:
                    builder.AddValue(key, value.AsDouble);
                    break;

                case HerculesValueType.Bool:
                    builder.AddValue(key, value.AsBool);
                    break;

                case HerculesValueType.Null:
                    builder.AddNull(key);
                    break;

                case HerculesValueType.Byte:
                    builder.AddValue(key, value.AsByte);
                    break;

                case HerculesValueType.Short:
                    builder.AddValue(key, value.AsShort);
                    break;

                case HerculesValueType.Float:
                    builder.AddValue(key, value.AsFloat);
                    break;

                case HerculesValueType.Vector:
                    builder.AddVector(key, value.AsVector);
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(value.Type), value.Type, "Unknown tag type.");
                }
            }

            return(builder);
        }
Exemple #6
0
 public HerculesEvent(DateTimeOffset timestamp, [NotNull] HerculesTags tags)
 {
     Timestamp = timestamp;
     Tags      = tags ?? throw new ArgumentNullException(nameof(tags));
 }