4using System.Threading.Tasks;
28 private static string[] repairedCollections =
null;
34 private string databasePluginName =
null;
46 get => this.databasePluginName;
47 set => this.databasePluginName = value;
56 get => this.databasePluginSettings;
57 set => this.databasePluginSettings = value;
67 if (this.databasePlugin is
null)
69 if (this.databasePluginName is
null)
77 return this.databasePlugin;
89 return this.sniffableDatabase;
101 return this.sniffableLedger;
115 get => repairedCollections;
116 internal set => repairedCollections = value;
122 public override string Resource =>
"/Settings/Database.md";
146 if (!(Plugin is
null))
147 await
Plugin.ConfigureSettings(this.databasePluginSettings);
165 this.selectDatabase = WebServer.
Register(
"/Settings/SelectDatabase",
null, this.SelectDatabase,
true,
false,
true);
166 this.testDatabase = WebServer.
Register(
"/Settings/TestDatabase",
null, this.TestDatabase,
true,
false,
true);
168 return base.InitSetup(WebServer);
180 return base.UnregisterSetup(WebServer);
206 if (PluginType is
null)
218 if (this.databasePluginName != PluginName)
220 this.databasePlugin =
Plugin;
221 this.databasePluginName = PluginName;
222 this.databasePluginSettings =
Plugin.CreateNewSettings();
224 if (
string.IsNullOrEmpty(
Plugin.SettingsResource))
229 this.Complete =
false;
235 string Html =
string.Empty;
236 bool HasSettings =
false;
237 string ResourceName =
Plugin?.SettingsResource;
238 if (!
string.IsNullOrEmpty(ResourceName))
240 if (ResourceName.StartsWith(
"/"))
241 ResourceName = ResourceName[1..];
243 ResourceName = ResourceName.Replace(
'/', Path.DirectorySeparatorChar);
245 if (File.Exists(ResourceName))
250 Variables = Request.Session
263 {
"isDone", this.Step >= 1 },
264 {
"hasSettings", HasSettings },
265 {
"restart", Database.Locked }
280 if (Content.
HasError || !(Content.
Decoded is Dictionary<string, object> Form))
286 if (!Form.TryGetValue(
"save", out
object Obj) ||
287 !(Obj is
bool Save) ||
288 !Form.TryGetValue(
"Plugin", out Obj) ||
289 !(Obj is
string PluginName) ||
290 this.databasePluginName != PluginName ||
291 this.databasePlugin is
null ||
292 this.databasePluginSettings is
null)
298 await this.databasePlugin.Test(Form, Save, this.databasePluginSettings);
309 await Response.
Write(
"2");
311 await Response.
Write(
"1");
324 this.databasePlugin =
Plugin;
325 this.databasePluginName =
Plugin.GetType().FullName;
326 this.databasePluginSettings =
Plugin.CreateNewSettings();
329 return Task.FromResult(
true);
335 public const string GATEWAY_DB_PROVIDER = nameof(GATEWAY_DB_PROVIDER);
343 string ProviderType = Environment.GetEnvironmentVariable(GATEWAY_DB_PROVIDER);
344 if (
string.IsNullOrEmpty(ProviderType))
350 this.LogEnvironmentError(
"Database plugin not found.", GATEWAY_DB_PROVIDER, ProviderType);
362 this.LogEnvironmentError(ex.Message, GATEWAY_DB_PROVIDER, ProviderType);
368 this.LogEnvironmentError(
"Unable to instantiate database plugin.", GATEWAY_DB_PROVIDER, ProviderType);
376 if (!await
Plugin.TestEnvironmentVariables(
this, Settings))
385 this.databasePlugin =
Plugin;
386 this.databasePluginName = ProviderType;
387 this.databasePluginSettings = Settings;
Contains information about a response to a content request.
bool HasError
If an error occurred.
object Decoded
Decoded object.
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.
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.
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< ContentResponse > 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...
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 async Task< string > ReadAllTextAsync(string FileName)
Reads a text file asynchronously.
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.