blob: b85dab1da7c27170c4cd830901eb88e5fa413944 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
using MongoDB.Driver;
using System;
using System.Collections.Generic;
using System.Text;
using Tango.DAL.Entities;
namespace Tango.DAL.Mongo
{
public class MongoUnitOfWork : IUnitOfWork
{
private IMongoDatabase _database;
private MongoClient _client;
private IClientSessionHandle _sessionHandler;
private bool _commited;
private IRepository<OrganizationEntity> _organizations;
private IRepository<MachineEntity> _machines;
public MongoUnitOfWork(MongoDataBaseSettings settings)
{
_client = new MongoClient(settings.Address);
_database = _client.GetDatabase(settings.DatabaseName);
_sessionHandler = _client.StartSession();
}
public IRepository<OrganizationEntity> Organizations
{
get
{
return _organizations ?? new MongoRepository<OrganizationEntity>(_database);
}
}
public IRepository<MachineEntity> Machines
{
get
{
return _machines ?? new MongoRepository<MachineEntity>(_database);
}
}
public void Commit()
{
_sessionHandler.CommitTransaction();
}
public void Dispose()
{
if (!_commited)
{
_sessionHandler.AbortTransaction();
}
}
}
}
|