using System; using System.Collections.Generic; using System.Linq; using System.Threading; using System.Threading.Tasks; using MongoDB.Bson; using MongoDB.Driver; using MongoDB.Driver.Core.Bindings; using MongoDB.Driver.Core.Clusters; using MongoDB.Driver.Core.Servers; using MongoDB.Driver.Core.WireProtocol.Messages.Encoders; using MongoDB.Driver.Linq; using xDataService.Mongo; namespace xDataService.Extensions { public static class XMongoDbExtensions { public static Guid ToGuid (this ObjectId source) { // var bytes = source .ToByteArray () .Concat (new byte[] { 5, 5, 5, 5 }) .ToArray (); // var result = new Guid (bytes); // return result; } public static ObjectId ToObjectId (this Guid source) { // var bytes = source .ToByteArray () .Take (12) .ToArray (); // var result = new ObjectId (bytes); // return result; } public static IAsyncEnumerable ToAsyncEnumerable (this IAsyncCursorSource asyncCursorSource) { return new XAsyncEnumerableAdapter (asyncCursorSource); } public static async IAsyncEnumerable ToAsyncEnumerable (this IAsyncCursor source) { while (await source.MoveNextAsync ()) { foreach (var current in source.Current) { yield return current; } } } public static XMongoAsyncCursor ToAsyncCursor (this IQueryable source) { return new XMongoAsyncCursor (source); } } }