/
FbConfiguration.cs
228 lines (199 loc) · 6.32 KB
/
FbConfiguration.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
/*
* The contents of this file are subject to the Initial
* Developer's Public License Version 1.0 (the "License");
* you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
* https://github.com/FirebirdSQL/NETProvider/blob/master/license.txt.
*
* Software distributed under the License is distributed on
* an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for the specific
* language governing rights and limitations under the License.
*
* All Rights Reserved.
*/
//$Authors = Carlos Guzman Alvarez, Jiri Cincura (jiri@cincura.net)
using System;
using FirebirdSql.Data.Common;
namespace FirebirdSql.Data.Services
{
public sealed class FbConfiguration : FbService
{
public FbConfiguration(string connectionString = null)
: base(connectionString)
{ }
public void SetSqlDialect(int sqlDialect)
{
StartSpb = new ServiceParameterBuffer();
StartSpb.Append(IscCodes.isc_action_svc_properties);
StartSpb.Append(IscCodes.isc_spb_dbname, Database);
StartSpb.Append(IscCodes.isc_spb_prp_set_sql_dialect, sqlDialect);
Open();
StartTask();
Close();
}
public void SetSweepInterval(int sweepInterval)
{
StartSpb = new ServiceParameterBuffer();
StartSpb.Append(IscCodes.isc_action_svc_properties);
StartSpb.Append(IscCodes.isc_spb_dbname, Database);
StartSpb.Append(IscCodes.isc_spb_prp_sweep_interval, sweepInterval);
Open();
StartTask();
Close();
}
public void SetPageBuffers(int pageBuffers)
{
StartSpb = new ServiceParameterBuffer();
StartSpb.Append(IscCodes.isc_action_svc_properties);
StartSpb.Append(IscCodes.isc_spb_dbname, Database);
StartSpb.Append(IscCodes.isc_spb_prp_page_buffers, pageBuffers);
Open();
StartTask();
Close();
}
public void DatabaseShutdown(FbShutdownMode mode, int seconds)
{
StartSpb = new ServiceParameterBuffer();
StartSpb.Append(IscCodes.isc_action_svc_properties);
StartSpb.Append(IscCodes.isc_spb_dbname, Database);
switch (mode)
{
case FbShutdownMode.Forced:
StartSpb.Append(IscCodes.isc_spb_prp_shutdown_db, seconds);
break;
case FbShutdownMode.DenyTransaction:
StartSpb.Append(IscCodes.isc_spb_prp_deny_new_transactions, seconds);
break;
case FbShutdownMode.DenyConnection:
StartSpb.Append(IscCodes.isc_spb_prp_deny_new_attachments, seconds);
break;
}
Open();
StartTask();
Close();
}
public void DatabaseShutdown2(FbShutdownOnlineMode mode, FbShutdownType type, int seconds)
{
StartSpb = new ServiceParameterBuffer();
StartSpb.Append(IscCodes.isc_action_svc_properties);
StartSpb.Append(IscCodes.isc_spb_dbname, Database);
StartSpb.Append(IscCodes.isc_spb_prp_shutdown_mode, FbShutdownOnlineModeToIscCode(mode));
switch (type)
{
case FbShutdownType.ForceShutdown:
StartSpb.Append(IscCodes.isc_spb_prp_force_shutdown, seconds);
break;
case FbShutdownType.AttachmentsShutdown:
StartSpb.Append(IscCodes.isc_spb_prp_attachments_shutdown, seconds);
break;
case FbShutdownType.TransactionsShutdown:
StartSpb.Append(IscCodes.isc_spb_prp_transactions_shutdown, seconds);
break;
}
Open();
StartTask();
Close();
}
public void DatabaseOnline()
{
StartSpb = new ServiceParameterBuffer();
StartSpb.Append(IscCodes.isc_action_svc_properties);
StartSpb.Append(IscCodes.isc_spb_dbname, Database);
StartSpb.Append(IscCodes.isc_spb_options, IscCodes.isc_spb_prp_db_online);
Open();
StartTask();
Close();
}
public void DatabaseOnline2(FbShutdownOnlineMode mode)
{
StartSpb = new ServiceParameterBuffer();
StartSpb.Append(IscCodes.isc_action_svc_properties);
StartSpb.Append(IscCodes.isc_spb_dbname, Database);
StartSpb.Append(IscCodes.isc_spb_prp_online_mode, FbShutdownOnlineModeToIscCode(mode));
Open();
StartTask();
Close();
}
public void ActivateShadows()
{
StartSpb = new ServiceParameterBuffer();
StartSpb.Append(IscCodes.isc_action_svc_properties);
StartSpb.Append(IscCodes.isc_spb_dbname, Database);
StartSpb.Append(IscCodes.isc_spb_options, IscCodes.isc_spb_prp_activate);
Open();
StartTask();
Close();
}
public void SetForcedWrites(bool forcedWrites)
{
StartSpb = new ServiceParameterBuffer();
StartSpb.Append(IscCodes.isc_action_svc_properties);
StartSpb.Append(IscCodes.isc_spb_dbname, Database);
if (forcedWrites)
{
StartSpb.Append(IscCodes.isc_spb_prp_write_mode, (byte)IscCodes.isc_spb_prp_wm_sync);
}
else
{
StartSpb.Append(IscCodes.isc_spb_prp_write_mode, (byte)IscCodes.isc_spb_prp_wm_async);
}
Open();
StartTask();
Close();
}
public void SetReserveSpace(bool reserveSpace)
{
StartSpb = new ServiceParameterBuffer();
StartSpb.Append(IscCodes.isc_action_svc_properties);
StartSpb.Append(IscCodes.isc_spb_dbname, Database);
if (reserveSpace)
{
StartSpb.Append(IscCodes.isc_spb_prp_reserve_space, (byte)IscCodes.isc_spb_prp_res);
}
else
{
StartSpb.Append(IscCodes.isc_spb_prp_reserve_space, (byte)IscCodes.isc_spb_prp_res_use_full);
}
Open();
StartTask();
Close();
}
public void SetAccessMode(bool readOnly)
{
StartSpb = new ServiceParameterBuffer();
StartSpb.Append(IscCodes.isc_action_svc_properties);
StartSpb.Append(IscCodes.isc_spb_dbname, Database);
StartSpb.Append(IscCodes.isc_spb_prp_access_mode, (byte)(readOnly ? IscCodes.isc_spb_prp_am_readonly : IscCodes.isc_spb_prp_am_readwrite));
Open();
StartTask();
Close();
}
public void NoLinger()
{
StartSpb = new ServiceParameterBuffer();
StartSpb.Append(IscCodes.isc_action_svc_properties);
StartSpb.Append(IscCodes.isc_spb_dbname, Database);
StartSpb.Append(IscCodes.isc_spb_options, IscCodes.isc_spb_prp_nolinger);
Open();
StartTask();
Close();
}
byte FbShutdownOnlineModeToIscCode(FbShutdownOnlineMode mode)
{
switch (mode)
{
case FbShutdownOnlineMode.Normal:
return IscCodes.isc_spb_prp_sm_normal;
case FbShutdownOnlineMode.Multi:
return IscCodes.isc_spb_prp_sm_multi;
case FbShutdownOnlineMode.Single:
return IscCodes.isc_spb_prp_sm_single;
case FbShutdownOnlineMode.Full:
return IscCodes.isc_spb_prp_sm_full;
default:
throw new ArgumentOutOfRangeException(nameof(mode));
}
}
}
}