This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void Put(IEnumerable<User> users) | |
{ | |
AssertIsStarted(); | |
Task.Run(async () => | |
await _collection.InsertManyAsync( | |
users.Select(x => x.ConvertUserToBson()))) | |
.Wait(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void Put(User user) | |
{ | |
AssertIsStarted(); | |
Task.Run(async () => | |
await _collection.ReplaceOneAsync( | |
new BsonDocument("_id", user.ID), | |
user.ConvertUserToBson())) | |
.Wait(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public IEnumerable GetAll() | |
{ | |
AssertIsStarted(); | |
return | |
_collection.FindAsync(new BsonDocument()) | |
.Result.ToListAsync() | |
.Result.Select(doc => doc.ConvertBsonToUser()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public User Get(string username) | |
{ | |
AssertIsStarted(); | |
return _collection | |
.Find(new BsonDocument("username", username)) | |
.FirstAsync().Result.ConvertBsonToUser(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public override void Start() | |
{ | |
base.Start(); | |
_collection = this.Database.GetCollection(_collectionName); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private readonly string _collectionName; | |
private IMongoCollection _collection; | |
public MongoDBUserStore(string connStr, string dbName, string collectionName) : base(connStr, dbName) | |
{ | |
_collectionName = collectionName; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections.Generic; | |
using Inversion.Data; | |
using Harness.Example.Model; | |
namespace Harness.Example.Store | |
{ | |
public interface IUserStore : IStore | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Linq; | |
using MongoDB.Bson; | |
using Harness.Example.Model; | |
namespace Harness.Example.Store | |
{ | |
public static class MongoDBUserEx | |
{ | |
public static BsonDocument ConvertUserToBson(this User user) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Xml; | |
using Newtonsoft.Json.Linq; | |
using Inversion; | |
namespace Harness.Example.Model | |
{ | |
public class User : IData | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using MongoDB.Bson; | |
using MongoDB.Driver; | |
namespace Inversion.Data | |
{ | |
public class MongoDBStore : StoreBase | |
{ | |
protected IMongoDatabase Database; | |
private MongoClient _client; |