up
Some checks failed
AOC Guard CI / aoc-guard (push) Has been cancelled
AOC Guard CI / aoc-verify (push) Has been cancelled
Concelier Attestation Tests / attestation-tests (push) Has been cancelled
Docs CI / lint-and-preview (push) Has been cancelled
Export Center CI / export-ci (push) Has been cancelled
Scanner Analyzers / Discover Analyzers (push) Has been cancelled
Scanner Analyzers / Build Analyzers (push) Has been cancelled
Scanner Analyzers / Test Language Analyzers (push) Has been cancelled
Scanner Analyzers / Validate Test Fixtures (push) Has been cancelled
Scanner Analyzers / Verify Deterministic Output (push) Has been cancelled
Policy Lint & Smoke / policy-lint (push) Has been cancelled
Some checks failed
AOC Guard CI / aoc-guard (push) Has been cancelled
AOC Guard CI / aoc-verify (push) Has been cancelled
Concelier Attestation Tests / attestation-tests (push) Has been cancelled
Docs CI / lint-and-preview (push) Has been cancelled
Export Center CI / export-ci (push) Has been cancelled
Scanner Analyzers / Discover Analyzers (push) Has been cancelled
Scanner Analyzers / Build Analyzers (push) Has been cancelled
Scanner Analyzers / Test Language Analyzers (push) Has been cancelled
Scanner Analyzers / Validate Test Fixtures (push) Has been cancelled
Scanner Analyzers / Verify Deterministic Output (push) Has been cancelled
Policy Lint & Smoke / policy-lint (push) Has been cancelled
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
<PropertyGroup>
|
||||
<!-- Keep Concelier test harness active while trimming Mongo dependencies. Allow opt-out per project. -->
|
||||
<UseConcelierTestInfra Condition="'$(UseConcelierTestInfra)'==''">true</UseConcelierTestInfra>
|
||||
<!-- Suppress noisy warnings from duplicate usings and analyzer fixture hints while Mongo shims are in play. -->
|
||||
<NoWarn>$(NoWarn);CS0105;RS1032;RS2007;xUnit1041;NU1510</NoWarn>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<!-- Concelier is migrating off MongoDB; strip implicit Mongo2Go/Mongo driver packages inherited from the repo root. -->
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System.Collections;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace MongoDB.Bson
|
||||
@@ -55,6 +56,9 @@ namespace MongoDB.Bson
|
||||
public bool IsInt32 => BsonType == BsonType.Int32;
|
||||
public bool IsInt64 => BsonType == BsonType.Int64;
|
||||
|
||||
public BsonValue this[string key] => AsBsonDocument[key];
|
||||
public BsonValue this[int index] => AsBsonArray[index];
|
||||
|
||||
public string AsString => RawValue switch
|
||||
{
|
||||
null => string.Empty,
|
||||
@@ -135,6 +139,10 @@ namespace MongoDB.Bson
|
||||
public bool Equals(BsonValue? other) => other is not null && Equals(RawValue, other.RawValue);
|
||||
public override bool Equals(object? obj) => obj is BsonValue other && Equals(other);
|
||||
public override int GetHashCode() => RawValue?.GetHashCode() ?? 0;
|
||||
public static bool operator ==(BsonValue? left, string? right) => string.Equals(left?.AsString, right, StringComparison.Ordinal);
|
||||
public static bool operator !=(BsonValue? left, string? right) => !(left == right);
|
||||
public static bool operator ==(string? left, BsonValue? right) => right == left;
|
||||
public static bool operator !=(string? left, BsonValue? right) => !(left == right);
|
||||
|
||||
public static BsonValue Create(object? value) => BsonDocument.ToBsonValue(value);
|
||||
|
||||
@@ -177,6 +185,24 @@ namespace MongoDB.Bson
|
||||
}
|
||||
|
||||
public byte[] Bytes { get; }
|
||||
|
||||
public Guid ToGuid()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (Bytes.Length == 16)
|
||||
{
|
||||
return new Guid(Bytes);
|
||||
}
|
||||
|
||||
var asString = Encoding.UTF8.GetString(Bytes);
|
||||
return Guid.TryParse(asString, out var guid) ? guid : Guid.Empty;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return Guid.Empty;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class BsonDocument : BsonValue, IDictionary<string, BsonValue>
|
||||
@@ -221,7 +247,7 @@ namespace MongoDB.Bson
|
||||
|
||||
public int ElementCount => _values.Count;
|
||||
|
||||
public BsonValue this[string key]
|
||||
public new BsonValue this[string key]
|
||||
{
|
||||
get => _values[key];
|
||||
set => _values[key] = value ?? new BsonValue();
|
||||
@@ -252,6 +278,21 @@ namespace MongoDB.Bson
|
||||
public BsonValue GetValue(string key, BsonValue defaultValue)
|
||||
=> _values.TryGetValue(key, out var value) ? value : defaultValue;
|
||||
|
||||
public string ToJson() => ToJson(null);
|
||||
|
||||
public string ToJson(MongoDB.Bson.IO.JsonWriterSettings? settings)
|
||||
{
|
||||
var ordered = _values
|
||||
.OrderBy(static kvp => kvp.Key, StringComparer.Ordinal)
|
||||
.ToDictionary(static kvp => kvp.Key, static kvp => BsonTypeMapper.MapToDotNetValue(kvp.Value));
|
||||
var options = new JsonSerializerOptions { WriteIndented = settings?.Indent ?? false };
|
||||
return JsonSerializer.Serialize(ordered, options);
|
||||
}
|
||||
|
||||
public byte[] ToBson() => Encoding.UTF8.GetBytes(ToJson());
|
||||
|
||||
public IEnumerable<BsonElement> Elements => _values.Select(static kvp => new BsonElement(kvp.Key, kvp.Value ?? new BsonValue()));
|
||||
|
||||
public BsonDocument DeepClone()
|
||||
{
|
||||
var copy = new BsonDocument();
|
||||
@@ -353,7 +394,7 @@ namespace MongoDB.Bson
|
||||
}
|
||||
}
|
||||
|
||||
public BsonValue this[int index]
|
||||
public new BsonValue this[int index]
|
||||
{
|
||||
get => _items[index];
|
||||
set => _items[index] = value ?? new BsonValue();
|
||||
@@ -384,6 +425,18 @@ namespace MongoDB.Bson
|
||||
internal override BsonValue Clone() => new BsonArray(_items.Select(i => i.Clone()));
|
||||
}
|
||||
|
||||
public sealed class BsonElement
|
||||
{
|
||||
public BsonElement(string name, BsonValue value)
|
||||
{
|
||||
Name = name;
|
||||
Value = value ?? new BsonValue();
|
||||
}
|
||||
|
||||
public string Name { get; }
|
||||
public BsonValue Value { get; }
|
||||
}
|
||||
|
||||
public readonly struct ObjectId : IEquatable<ObjectId>
|
||||
{
|
||||
private readonly string _value;
|
||||
@@ -423,6 +476,16 @@ namespace MongoDB.Bson
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public static class BsonJsonExtensions
|
||||
{
|
||||
public static string ToJson(this IEnumerable<BsonDocument> documents, MongoDB.Bson.IO.JsonWriterSettings? settings = null)
|
||||
{
|
||||
var options = new JsonSerializerOptions { WriteIndented = settings?.Indent ?? false };
|
||||
var payload = documents?.Select(BsonTypeMapper.MapToDotNetValue).ToList() ?? new List<object?>();
|
||||
return JsonSerializer.Serialize(payload, options);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace MongoDB.Bson.Serialization.Attributes
|
||||
@@ -438,3 +501,18 @@ namespace MongoDB.Bson.Serialization.Attributes
|
||||
public string ElementName { get; }
|
||||
}
|
||||
}
|
||||
|
||||
namespace MongoDB.Bson.IO
|
||||
{
|
||||
public enum JsonOutputMode
|
||||
{
|
||||
Strict,
|
||||
RelaxedExtendedJson
|
||||
}
|
||||
|
||||
public sealed class JsonWriterSettings
|
||||
{
|
||||
public bool Indent { get; set; }
|
||||
public JsonOutputMode OutputMode { get; set; } = JsonOutputMode.Strict;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,8 +15,6 @@ using Microsoft.Extensions.Logging.Abstractions;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Microsoft.Extensions.Time.Testing;
|
||||
using MongoDB.Bson;
|
||||
using MongoDB.Bson.Serialization;
|
||||
using MongoDB.Bson.Serialization.Serializers;
|
||||
using MongoDB.Driver;
|
||||
using StellaOps.Concelier.Models;
|
||||
using StellaOps.Concelier.Connector.Common;
|
||||
|
||||
Reference in New Issue
Block a user