-
Notifications
You must be signed in to change notification settings - Fork 1
/
MongoAdminDatabase.cs
250 lines (209 loc) · 8.11 KB
/
MongoAdminDatabase.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CSMongo.Results;
using CSMongo.Commands;
using CSMongo.Bson;
using CSMongo.Responses;
namespace CSMongo {
/// <summary>
/// Creates a connection to the administrative database for the Mongo instance
/// </summary>
public class MongoAdminDatabase : IDisposable {
#region Constructors
/// <summary>
/// Creates access to the admin database using the provided information
/// </summary>
public MongoAdminDatabase(string connectionString) {
MongoConnectionString connection = MongoConnectionString.Parse(connectionString);
this._Database = new MongoDatabase(
Mongo.DefaultAdminDatabase,
connection.Host,
connection.Port,
connection.Username,
connection.Password,
connection.AutoConnect
);
}
/// <summary>
/// Creates access to the admin database using the provided information
/// </summary>
public MongoAdminDatabase(string host, bool autoConnect)
: this(host, Mongo.DefaultPort, null, null, autoConnect) {
}
/// <summary>
/// Creates access to the admin database using the provided information
/// </summary>
public MongoAdminDatabase(string host, int port)
: this(host, port, null, null, true) {
}
/// <summary>
/// Creates access to the admin database using the provided information
/// </summary>
public MongoAdminDatabase(string host, int port, bool autoConnect)
: this(host, port, null, null, true) {
}
/// <summary>
/// Creates access to the admin database using the provided information
/// </summary>
public MongoAdminDatabase(string host, string username, string password)
: this(host, Mongo.DefaultPort, username, password, true) {
}
/// <summary>
/// Creates access to the admin database using the provided information
/// </summary>
public MongoAdminDatabase(string host, int port, string username, string password, bool autoConnect) {
this._Database = new MongoDatabase(Mongo.DefaultAdminDatabase, host, port, username, password, autoConnect);
}
#endregion
#region Properties
/// <summary>
/// Returns the connection managing this database
/// </summary>
public MongoConnection Connection {
get { return this._Database.Connection; }
}
//the database to perform connections on behalf of
private MongoDatabase _Database;
#endregion
#region Methods
/// <summary>
/// Sends the log out request to the server
/// </summary>
public void Logout() {
this._Database.Logout();
}
/// <summary>
/// Checks the status of the database for the oplogging value
/// </summary>
public MethodResult CheckOpLogging() {
return MongoDatabaseCommands.GetOpLogging(this._Database);
}
/// <summary>
/// Returns the build info for the current database
/// </summary>
public BuildInfoResult GetBuildInfo() {
return MongoDatabaseCommands.GetBuildInfo(this._Database);
}
/// <summary>
/// Gets a list of all databases available
/// </summary>
public ListDatabasesResult GetDatabases() {
return MongoDatabaseCommands.ListDatabases(this._Database);
}
/// <summary>
/// Performs an FSync command against the database
/// </summary>
public FSyncResult FSync() {
return this.FSync(false);
}
/// <summary>
/// Performs an FSync command against the database
/// </summary>
public FSyncResult FSync(bool async) {
return MongoDatabaseCommands.FSync(this._Database, async);
}
/// <summary>
/// Handles copying a database to another location
/// </summary>
public MethodResult CopyDatabase(string from, string targetConnectionString) {
MongoConnectionString connection = MongoConnectionString.Parse(targetConnectionString);
return this.CopyDatabase(
from,
connection.Database,
connection.Host,
connection.Port,
connection.Username,
connection.Password
);
}
/// <summary>
/// Handles copying a database to another location
/// </summary>
public MethodResult CopyDatabase(string from, string to, string host) {
return this.CopyDatabase(from, to, host, Mongo.DefaultPort, string.Empty, string.Empty);
}
/// <summary>
/// Handles copying a database to another location
/// </summary>
public MethodResult CopyDatabase(string from, string to, string host, string username, string password) {
return this.CopyDatabase(from, to, host, Mongo.DefaultPort, username, password);
}
/// <summary>
/// Handles copying a database to another location
/// </summary>
public MethodResult CopyDatabase(string from, string to, string host, int port, string username, string password) {
return MongoDatabaseCommands.CopyDatabase(this._Database, from, to, host, port, username, password);
}
/// <summary>
/// Sends the shutdown signal to the database
/// </summary>
public void Shutdown() {
MongoDatabaseCommands.Shutdown(this._Database);
}
/// <summary>
/// Clears any errors from the server
/// </summary>
public MethodResult ResetErrors() {
return MongoDatabaseCommands.ResetErrors(this._Database);
}
/// <summary>
/// Returns the most recent error from the server
/// </summary>
public GetLastErrorResult GetLastError() {
return MongoDatabaseCommands.GetLastError(this._Database);
}
/// <summary>
/// Returns a previous error message from the server
/// </summary>
public GetPreviousErrorResult GetPreviousError() {
return MongoDatabaseCommands.GetPreviousError(this._Database);
}
/// <summary>
/// Causes an error on the server -- Uh... wut?
/// </summary>
public ForceErrorResult ForceError() {
return MongoDatabaseCommands.ForceError(this._Database);
}
/// <summary>
/// Returns the OpTime value from the server
/// </summary>
public GetOpTimeResult GetOpTime() {
return MongoDatabaseCommands.GetOpTime(this._Database);
}
/// <summary>
/// Manually invokes a command against the database
/// </summary>
public MethodResult RunCommand(object arguments) {
return this._Database.RunCommand(arguments);
}
/// <summary>
/// Manually invokes a command against the database
/// </summary>
public MethodResult RunCommand(object arguments, bool expectResponse) {
return this._Database.RunCommand(arguments, expectResponse);
}
/// <summary>
/// Manually invokes a command against the database
/// </summary>
public MethodResult RunCommand(BsonObject arguments) {
return this._Database.RunCommand(arguments);
}
/// <summary>
/// Manually invokes a command against the database
/// </summary>
public MethodResult RunCommand(BsonObject arguments, bool expectResponse) {
return this._Database.RunCommand(arguments, expectResponse);
}
#endregion
#region IDisposable Members
/// <summary>
/// Handles cleaning up this database connection
/// </summary>
public void Dispose() {
this._Database.Dispose();
}
#endregion
}
}