Beispiel #1
0
        internal static BsonDocument CreateCommand(TopologyVersion topologyVersion = null, TimeSpan?maxAwaitTime = null)
        {
            Ensure.That(
                (topologyVersion == null && !maxAwaitTime.HasValue) ||
                (topologyVersion != null && maxAwaitTime.HasValue),
                $"Both {nameof(topologyVersion)} and {nameof(maxAwaitTime)} must be filled or null.");

            return(new BsonDocument
            {
                { "isMaster", 1 },
                { "topologyVersion", () => topologyVersion.ToBsonDocument(), topologyVersion != null },
                { "maxAwaitTimeMS", () => (long)maxAwaitTime.Value.TotalMilliseconds, maxAwaitTime.HasValue }
            });
        }
        internal static BsonDocument CreateCommand(ServerApi serverApi, bool helloOk = false, TopologyVersion topologyVersion = null, TimeSpan? maxAwaitTime = null, bool loadBalanced = false)
        {
            Ensure.That(
                (topologyVersion == null && !maxAwaitTime.HasValue) ||
                (topologyVersion != null && maxAwaitTime.HasValue),
                $"Both {nameof(topologyVersion)} and {nameof(maxAwaitTime)} must be filled or null.");

            var helloCommandName = helloOk || serverApi != null ? "hello" : OppressiveLanguageConstants.LegacyHelloCommandName;
            return new BsonDocument
            {
                { helloCommandName, 1 },
                { "helloOk", true },
                { "topologyVersion", () => topologyVersion.ToBsonDocument(), topologyVersion != null },
                { "maxAwaitTimeMS", () => (long)maxAwaitTime.Value.TotalMilliseconds, maxAwaitTime.HasValue },
                { "loadBalanced", true, loadBalanced }
            };
        }