2using System.Collections.Generic;
4using System.Threading.Tasks;
27 private static string[] repairedCollections =
null;
33 private string databasePluginName =
null;
45 get => this.databasePluginName;
46 set => this.databasePluginName = value;
55 get => this.databasePluginSettings;
56 set => this.databasePluginSettings = value;
66 if (this.databasePlugin is
null)
68 if (this.databasePluginName is
null)
76 return this.databasePlugin;
87 if (this.sniffableDatabase is
null)
90 return this.sniffableDatabase;
101 if (this.sniffableLedger is
null)
104 return this.sniffableLedger;
118 get => repairedCollections;
119 internal set => repairedCollections = value;
125 public override string Resource =>
"/Settings/Database.md";
149 if (!(Plugin is
null))
150 await
Plugin.ConfigureSettings(this.databasePluginSettings);
168 this.selectDatabase = WebServer.
Register(
"/Settings/SelectDatabase",
null, this.SelectDatabase,
true,
false,
true);
169 this.testDatabase = WebServer.
Register(
"/Settings/TestDatabase",
null, this.TestDatabase,
true,
false,
true);
171 return base.InitSetup(WebServer);
183 return base.UnregisterSetup(WebServer);
199 if (!(Obj is
string PluginName))
208 if (this.databasePluginName != PluginName)
210 this.databasePlugin =
Plugin;
211 this.databasePluginName = PluginName;
212 this.databasePluginSettings =
Plugin.CreateNewSettings();
214 if (
string.IsNullOrEmpty(
Plugin.SettingsResource))
219 this.Complete =
false;
225 string Html =
string.Empty;
226 bool HasSettings =
false;
227 string ResourceName =
Plugin?.SettingsResource;
228 if (!
string.IsNullOrEmpty(ResourceName))
230 if (ResourceName.StartsWith(
"/"))
231 ResourceName = ResourceName.Substring(1);
233 ResourceName = ResourceName.Replace(
'/', Path.DirectorySeparatorChar);
235 if (File.Exists(ResourceName))
240 Variables = Request.Session
253 {
"isDone", this.Step >= 1 },
254 {
"hasSettings", HasSettings },
255 {
"restart", Database.Locked }
267 if (!(Obj is Dictionary<string, object> Form))
270 if (!Form.TryGetValue(
"save", out Obj) ||
271 !(Obj is
bool Save) ||
272 !Form.TryGetValue(
"Plugin", out Obj) ||
273 !(Obj is
string PluginName) ||
274 this.databasePluginName != PluginName ||
275 this.databasePlugin is
null ||
276 this.databasePluginSettings is
null)
281 await this.databasePlugin.Test(Form, Save, this.databasePluginSettings);
292 await Response.
Write(
"2");
294 await Response.
Write(
"1");
307 this.databasePlugin =
Plugin;
308 this.databasePluginName =
Plugin.GetType().FullName;
309 this.databasePluginSettings =
Plugin.CreateNewSettings();
312 return Task.FromResult(
true);
318 public const string GATEWAY_DB_PROVIDER = nameof(GATEWAY_DB_PROVIDER);
326 string ProviderType = Environment.GetEnvironmentVariable(GATEWAY_DB_PROVIDER);
327 if (
string.IsNullOrEmpty(ProviderType))
333 this.LogEnvironmentError(
"Database plugin not found.", GATEWAY_DB_PROVIDER, ProviderType);
345 this.LogEnvironmentError(ex.Message, GATEWAY_DB_PROVIDER, ProviderType);
351 this.LogEnvironmentError(
"Unable to instantiate database plugin.", GATEWAY_DB_PROVIDER, ProviderType);
359 if (!await
Plugin.TestEnvironmentVariables(
this, Settings))
368 this.databasePlugin =
Plugin;
369 this.databasePluginName = ProviderType;
370 this.databasePluginSettings = Settings;
static string GetBody(string Html)
Extracts the contents of the BODY element in a HTML string.
Helps with common JSON-related tasks.
static string Encode(string s)
Encodes a string for inclusion in JSON.
const string DefaultContentType
application/json
Contains a markdown document. This markdown document class supports original markdown,...
async Task< string > GenerateHTML()
Generates HTML from the markdown text.
static Task< MarkdownDocument > CreateAsync(string MarkdownText, params Type[] TransparentExceptionTypes)
Contains a markdown document. This markdown document class supports original markdown,...
Contains settings that the Markdown parser uses to customize its behavior.
Static class managing loading of resources stored as embedded resources or in content files.
static async Task< string > ReadAllTextAsync(string FileName)
Reads a text file asynchronously.
Plain text encoder/decoder.
const string DefaultContentType
text/plain
Static class managing the application event log. Applications and services log events on this static ...
static void Exception(Exception Exception, string Object, string Actor, string EventId, EventLevel Level, string Facility, string Module, params KeyValuePair< string, object >[] Tags)
Logs an exception. Event type will be determined by the severity of the exception.
Static class managing the runtime environment of the IoT Gateway.
static IUser AssertUserAuthenticated(HttpRequest Request, string Privilege)
Makes sure a request is being made from a session with a successful user login.
static IDatabaseProvider InternalDatabase
Local Internal Encrypted Object Database provider.
static string RootFolder
Web root folder.
static DatabaseConfiguration Instance
Current instance of configuration.
SniffableLedger SniffableLedger
Makes ledger activity sniffable.
override string ConfigPrivilege
Minimum required privilege for a user to be allowed to change the configuration defined by the class.
override int Priority
Priority of the setting. Configurations are sorted in ascending order.
override string Resource
Resource to be redirected to, to perform the configuration.
IDatabasePlugin DatabasePlugin
Current database plugin, if defined, null otherwise.
override Task InitSetup(HttpServer WebServer)
Initializes the setup object.
override async Task< bool > EnvironmentConfiguration()
Environment configuration by configuring values available in environment variables.
override async Task ConfigureSystem()
Is called during startup to configure the system.
static string[] RepairedCollections
Collections repaired during startup.
string DatabasePluginName
Full name of database plugin class.
override void SetStaticInstance(ISystemConfiguration Configuration)
Sets the static instance of the configuration.
SniffableDatabase SniffableDatabase
Makes database activity sniffable.
override Task< bool > SimplifiedConfiguration()
Simplified configuration by configuring simple default values.
override Task UnregisterSetup(HttpServer WebServer)
Unregisters the setup object.
override Task< string > Title(Language Language)
Gets a title for the system configuration.
DatabaseSettings DatabasePluginSettings
Settings for database plugin.
Interface for Database settings
Plugin for the local database.
Class that can be used to sniff on database updates.
Class that can be used to sniff on ledger activity.
Abstract base class for multi-step system configurations.
The request could not be understood by the server due to malformed syntax. The client SHOULD NOT repe...
Represents an HTTP request.
bool HasData
If the request has data.
async Task< object > DecodeDataAsync()
Decodes data sent in request.
Base class for all HTTP resources.
Represets a response of an HTTP client request.
async Task SendResponse()
Sends the response back to the client. If the resource is synchronous, there's no need to call this m...
async Task Write(byte[] Data)
Returns binary data in the response.
Implements an HTTP server.
HttpResource Register(HttpResource Resource)
Registers a resource with the server.
bool Unregister(HttpResource Resource)
Unregisters a resource from the server.
The server has not found anything matching the Request-URI. No indication is given of whether the con...
Static interface for database persistence. In order to work, a database provider has to be assigned t...
static bool Locked
If the datbase provider has been locked for the rest of the run-time of the application.
Static class that dynamically manages types and interfaces available in the runtime environment.
static Type GetType(string FullName)
Gets a type, given its full name.
static object Instantiate(Type Type, params object[] Arguments)
Returns an instance of the type Type . If one needs to be created, it is. If the constructor requires...
Contains information about a language.
Task< string > GetStringAsync(Type Type, int Id, string Default)
Gets the string value of a string ID. If no such string exists, a string is created with the default ...
Interface for Database plug-ins
Interface for system configurations. The gateway will scan all module for system configuration classe...
Task Update(object Object)
Updates an object in the database.