2using System.Collections.Generic;
3using System.Threading.Tasks;
17 [CollectionName(
"SystemConfigurations")]
21 private TaskCompletionSource<bool> completionSource =
null;
24 private Guid objectId = Guid.Empty;
25 private DateTime created = DateTime.MinValue;
26 private DateTime updated = DateTime.MinValue;
27 private DateTime completed = DateTime.MinValue;
28 private bool complete =
false;
37 set => this.objectId = value;
47 set => this.complete = value;
53 [DefaultValueDateTimeMinValue]
57 set => this.created = value;
63 [DefaultValueDateTimeMinValue]
67 set => this.updated = value;
73 [DefaultValueDateTimeMinValue]
76 get => this.completed;
77 set => this.completed = value;
120 return Task.CompletedTask;
129 return Task.CompletedTask;
139 this.completionSource =
new TaskCompletionSource<bool>();
141 this.configResource = WebServer.
Register(
"/Settings/ConfigComplete",
null, this.
ConfigComplete,
true,
false,
true);
143 return this.completionSource.Task;
152 if (!(this.configResource is
null))
155 this.configResource =
null;
158 return Task.CompletedTask;
172 Response.StatusCode = 200;
197 this.complete =
true;
198 this.completed = DateTime.Now;
199 this.updated = DateTime.Now;
201 if (!ReloadConfiguration)
209 this.completionSource?.TrySetResult(ReloadConfiguration);
218 return Task.FromResult(
false);
302 if (Max ==
int.MaxValue)
304 this.
LogEnvironmentError(
"Value not in valid range. Must be at least " + Min.ToString() +
".",
305 EnvironmentVariable, Value);
307 else if (Min ==
int.MinValue)
309 this.
LogEnvironmentError(
"Value not in valid range. Must be at most " + Max.ToString() +
".",
310 EnvironmentVariable, Value);
314 this.
LogEnvironmentError(
"Value not in valid range. Must be between " + Min.ToString() +
" and " + Max.ToString() +
".",
315 EnvironmentVariable, Value);
328 if (
string.IsNullOrEmpty(Message))
329 Message =
"Environment Variable contains an invalid value.";
331 Message =
"Environment Variable contains an invalid value: " + Message;
333 Log.
Error(Message, EnvironmentVariable,
string.Empty,
"ConfigError",
334 new KeyValuePair<string, object>(
"EnvironmentVariable", EnvironmentVariable),
335 new KeyValuePair<string, object>(
"Value", Value));
347 Value = Environment.GetEnvironmentVariable(VariableName) ??
string.Empty;
348 if (!
string.IsNullOrEmpty(Value))
420 if (!
int.TryParse(s, out Value))
443 if (i < Min || i > Max)
469 if (!TimeSpan.TryParse(s, out TimeSpan TS) || TS < TimeSpan.Zero || TS.TotalHours >= 24)
495 if (!
XML.
TryParse(s, out DateTime TP) || TP.TimeOfDay != TimeSpan.Zero)
Helps with parsing of commong data types.
static bool TryParse(string s, out double Value)
Tries to decode a string encoded double.
Helps with common XML-related tasks.
static bool TryParse(string s, out DateTime Value)
Tries to decode a string encoded DateTime.
Static class managing the application event log. Applications and services log events on this static ...
static void Error(string Message, string Object, string Actor, string EventId, EventLevel Level, string Facility, string Module, string StackTrace, params KeyValuePair< string, object >[] Tags)
Logs an error event.
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.
Abstract base class for system configurations.
virtual Task InitSetup(HttpServer WebServer)
Initializes the setup object.
bool TryGetEnvironmentVariable(string VariableName, bool Required, out bool Value)
Tries to get a Boolean-valued environment variable.
bool Complete
If the configuration is complete.
void LogEnvironmentVariableInvalidRangeError(int Min, int Max, string EnvironmentVariable, object Value)
Logs an error to the event log, telling the operator an environment variable value is not within a va...
bool TryGetEnvironmentVariable(string VariableName, out bool Value, bool Default)
Tries to get a Boolean-valued environment variable.
DateTime Updated
When the object was updated.
abstract Task< string > Title(Language Language)
Gets a title for the system configuration.
bool TryGetEnvironmentVariable(string VariableName, bool Required, out TimeSpan? Value)
Tries to get a time-valued environment variable.
void LogEnvironmentVariableInvalidDateError(string EnvironmentVariable, object Value)
Logs an error to the event log, telling the operator an environment variable value is not a valid dat...
virtual Task< bool > SetupConfiguration(HttpServer WebServer)
Waits for the user to provide configuration.
abstract Task ConfigureSystem()
Is called during startup to configure the system.
abstract int Priority
Priority of the setting. Configurations are sorted in ascending order.
bool TryGetEnvironmentVariable(string VariableName, bool Required, out int Value)
Tries to get a integer-valued environment variable.
bool TryGetEnvironmentVariable(string VariableName, bool Required, out DateTime? Value)
Tries to get a date-valued environment variable.
abstract string ConfigPrivilege
Minimum required privilege for a user to be allowed to change the configuration defined by the class.
async Task MakeCompleted(bool ReloadConfiguration)
Sets the configuration task as completed.
void LogEnvironmentVariableMissingError(string EnvironmentVariable, object Value)
Logs an error to the event log, telling the operator an environment variable value is missing.
abstract string Resource
Resource to be redirected to, to perform the configuration.
virtual Task< bool > SimplifiedConfiguration()
Simplified configuration by configuring simple default values.
DateTime Created
When the object was created.
abstract Task< bool > EnvironmentConfiguration()
Environment configuration by configuring values available in environment variables.
void LogEnvironmentVariableInvalidBooleanError(string EnvironmentVariable, object Value)
Logs an error to the event log, telling the operator an environment variable value is not a valid Boo...
virtual Task UnregisterSetup(HttpServer WebServer)
Unregisters the setup object.
void LogEnvironmentVariableInvalidIntegerError(string EnvironmentVariable, object Value)
Logs an error to the event log, telling the operator an environment variable value is not a valid int...
bool TryGetEnvironmentVariable(string VariableName, int Min, int Max, bool Required, ref int Value)
Tries to get a integer-valued environment variable within a range.
virtual async Task ConfigComplete(HttpRequest Request, HttpResponse Response)
Method is called when the user completes the current configuration task.
void LogEnvironmentError(string EnvironmentVariable, object Value)
Logs an error to the event log, telling the operator an environment variable value contains an error.
virtual Task MakeCompleted()
Sets the configuration task as completed.
abstract void SetStaticInstance(ISystemConfiguration Configuration)
Sets the static instance of the configuration.
void LogEnvironmentError(string Message, string EnvironmentVariable, object Value)
Logs an error to the event log, telling the operator an environment variable value contains an error.
DateTime Completed
When the configuration was completed.
bool TryGetEnvironmentVariable(string VariableName, bool Required, out string Value)
Tries to get a string-valued environment variable.
void LogEnvironmentVariableInvalidTimeError(string EnvironmentVariable, object Value)
Logs an error to the event log, telling the operator an environment variable value is not a valid tim...
virtual Task CleanupAfterConfiguration(HttpServer WebServer)
Cleans up after configuration has been performed.
Represents an HTTP request.
Base class for all HTTP resources.
Represets a response of an HTTP client request.
Implements an HTTP server.
HttpResource Register(HttpResource Resource)
Registers a resource with the server.
bool Unregister(HttpResource Resource)
Unregisters a resource from the server.
Static interface for database persistence. In order to work, a database provider has to be assigned t...
static async Task Update(object Object)
Updates an object in the database.
Contains information about a language.
Interface for system configurations. The gateway will scan all module for system configuration classe...
Task Update(object Object)
Updates an object in the database.