-
Notifications
You must be signed in to change notification settings - Fork 45
/
ConnectionBase.cs
79 lines (70 loc) · 2.13 KB
/
ConnectionBase.cs
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
using Couchbase;
using Couchbase.Configuration.Client;
using Couchbase.Core;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace DevGuide
{
/// <summary>
/// For an example of configuring the Couchbase connection through App.config/Web.config
/// see the ConnectionConfig class
/// </summary>
public class ConnectionBase
{
protected ICluster _cluster;
protected IBucket _bucket;
public ConnectionBase()
{
Connect();
}
private void Connect()
{
var config = GetConnectionConfig();
_cluster = new Cluster(config);
_cluster.Authenticate("Administrator", "password");
_bucket = _cluster.OpenBucket();
}
protected virtual ClientConfiguration GetConnectionConfig()
{
return new ClientConfiguration
{
Servers = new List<Uri> {
new Uri("http://localhost:8091/pools")
},
BucketConfigs = new Dictionary<string, BucketConfiguration>
{
{ "default", new BucketConfiguration
{
BucketName = "default",
UseSsl = false,
Password = "",
DefaultOperationLifespan = 2000,
PoolConfiguration = new PoolConfiguration
{
MaxSize = 10,
MinSize = 5,
SendTimeout = 12000
}
}}
}
};
}
private void Disconnect()
{
_cluster.CloseBucket(_bucket);
_bucket.Dispose();
_bucket = null;
_cluster.Dispose();
_cluster = null;
}
public virtual async Task ExecuteAsync()
{
Console.WriteLine("Connected to bucket '{0}'", _bucket.Name);
}
static void Main(string[] args)
{
new ConnectionBase().ExecuteAsync().Wait();
}
}
}