2using System.Collections.Generic;
5using System.Xml.Schema;
6using System.Threading.Tasks;
24 private readonly
static Dictionary<string, ThemeDefinition> themeDefinitions =
new Dictionary<string, ThemeDefinition>();
28 private string themeId =
string.Empty;
29 private Dictionary<string, object> themeIdByAlternativeHost;
47 [DefaultValueStringEmpty]
51 set => this.themeId = value;
62 if (
string.IsNullOrEmpty(Host))
65 lock (themeDefinitions)
77 public override string Resource =>
"/Settings/Theme.md";
99 if (!
string.IsNullOrEmpty(this.themeId) && themeDefinitions.TryGetValue(
this.themeId, out
ThemeDefinition Def))
100 Theme.CurrentTheme = Def;
104 return Task.CompletedTask;
126 await base.InitSetup(WebServer);
130 if (Directory.Exists(ThemesFolder))
132 foreach (
string FileName
in Directory.GetFiles(ThemesFolder,
"*.xml", SearchOption.AllDirectories))
136 XmlDocument Doc =
new XmlDocument()
138 PreserveWhitespace =
true
142 XSL.
Validate(FileName, Doc,
"Theme",
"http://waher.se/Schema/Theme.xsd", Schema);
145 themeDefinitions[Def.
Id] = Def;
157 if (!
string.IsNullOrEmpty(this.themeId) && !themeDefinitions.ContainsKey(
this.themeId))
159 this.themeId =
string.Empty;
161 this.Completed = DateTime.MinValue;
162 this.Complete =
false;
167 if (
string.IsNullOrEmpty(this.themeId) && themeDefinitions.Count == 1)
171 this.themeId = Def2.
Id;
182 this.Updated = DateTime.Now;
186 if (!
string.IsNullOrEmpty(this.themeId) && themeDefinitions.TryGetValue(
this.themeId, out Def))
187 Theme.CurrentTheme = Def;
188 else if (themeDefinitions.TryGetValue(
"CactusRose", out Def))
189 Theme.CurrentTheme = Def;
194 Theme.CurrentTheme = Def2;
199 this.themeIdByAlternativeHost =
new Dictionary<string, object>(StringComparer.InvariantCultureIgnoreCase);
201 this.themeIdByAlternativeHost[P.Key] = P.Value;
203 foreach (KeyValuePair<string, object> P
in this.themeIdByAlternativeHost)
205 if (P.Value is
string ThemeId && themeDefinitions.TryGetValue(
ThemeId, out Def))
206 Theme.SetTheme(P.Key, Def);
209 this.setTheme = WebServer.Register(
"/Settings/SetTheme",
null, this.SetTheme,
true,
false,
true);
220 return base.UnregisterSetup(WebServer);
239 string TabID = Request.
Header[
"X-TabID"];
240 if (
string.IsNullOrEmpty(TabID))
247 if (
string.IsNullOrEmpty(Host))
249 Theme.CurrentTheme = Def;
251 this.themeId = Def.Id;
258 lock (this.themeIdByAlternativeHost)
260 this.themeIdByAlternativeHost[Host] = Def;
265 Theme.SetTheme(Host, Def);
270 this.Updated = DateTime.Now;
277 new KeyValuePair<string, object>(
"themeId", Def.Id),
278 new KeyValuePair<string, object>(
"cssUrl", Def.CSSX),
279 },
false),
true,
"User");
281 Response.StatusCode = 200;
291 themeDefinitions.Values.CopyTo(Result, 0);
293 Array.Sort(Result, (t1, t2) => t1.
Title.CompareTo(t2.Title));
306 return themeDefinitions.TryGetValue(
ThemeId, out Definition);
321 if (
string.IsNullOrEmpty(Value))
322 return Task.FromResult(
false);
324 if (!themeDefinitions.ContainsKey(Value))
327 return Task.FromResult(
false);
330 this.themeId = Value;
332 return Task.FromResult(
true);
Helps with common JSON-related tasks.
static string Encode(string s)
Encodes a string for inclusion in JSON.
Static class managing loading of XSL resources stored as embedded resources or in content files.
static XmlSchema LoadSchema(string ResourceName)
Loads an XML schema from an embedded resource.
static void Validate(string ObjectID, XmlDocument Xml, params XmlSchema[] Schemas)
Validates an XML document given a set of XML schemas.
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.
The ClientEvents class allows applications to push information asynchronously to web clients connecte...
static Task< int > PushEvent(string[] TabIDs, string Type, object Data)
Puses an event to a set of Tabs, given their Tab IDs.
Static class managing the runtime environment of the IoT Gateway.
static HttpServer HttpServer
HTTP Server
static IUser AssertUserAuthenticated(HttpRequest Request, string Privilege)
Makes sure a request is being made from a session with a successful user login.
static string AppDataFolder
Application data folder.
Returns the time elapsed since the gateway was started.
DateTime Updated
When the object was updated.
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 base class for multi-step system configurations.
int Step
Configuration step.
override void SetStaticInstance(ISystemConfiguration Configuration)
Sets the static instance of the configuration.
override int Priority
Priority of the setting. Configurations are sorted in ascending order.
static ThemeDefinition[] GetDefinitions()
Gets available theme definitions.
override Task< string > Title(Runtime.Language.Language Language)
Gets a title for the system configuration.
string GetThemeId(IHostReference HostReference)
Gets the Theme ID that corresponds to a host.
override async Task InitSetup(HttpServer WebServer)
Initializes the setup object.
override Task< bool > EnvironmentConfiguration()
Environment configuration by configuring values available in environment variables.
static bool TryGetTheme(string ThemeId, out ThemeDefinition Definition)
Tries to get the theme definition, given its ID.
override string ConfigPrivilege
Minimum required privilege for a user to be allowed to change the configuration defined by the class.
override string Resource
Resource to be redirected to, to perform the configuration.
const string GATEWAY_THEME_ID
ID of theme to use.
override Task UnregisterSetup(HttpServer WebServer)
Unregisters the setup object.
override Task ConfigureSystem()
Is called during startup to configure the system.
static ThemeConfiguration Instance
Current instance of configuration.
ThemeConfiguration()
Theme Configuration
string ThemeId
ID of Selected theme
Contains properties for a theme.
string Title
A human readable title for the theme.
string Id
ID of the theme.
The request could not be understood by the server due to malformed syntax. The client SHOULD NOT repe...
Represents an HTTP request.
HttpRequestHeader Header
Request header.
bool HasData
If the request has data.
string Host
Host reference. (Value of Host header, without the port number)
async Task< object > DecodeDataAsync()
Decodes data sent in request.
Base class for all HTTP resources.
Represets a response of an HTTP client request.
Implements an HTTP server.
bool Unregister(HttpResource Resource)
Unregisters a resource from the server.
async Task SetETagSalt(string NewSalt)
Sets a new salt value used when calculating ETag values.
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 async Task Update(object Object)
Updates an object in the database.
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 ...
Contains information about a namespace in a language.
Static class managing persistent host settings. Host settings default to runtime settings if host-spe...
static Task< Dictionary< string, object > > GetHostValuesAsync(string Key)
Gets available settings for a given key, indexed by host.
static async Task< bool > SetAsync(string Host, string Key, string Value)
Sets a string-valued setting.
Interface for objects that contain a reference to a host.
string Host
Host reference.
Interface for system configurations. The gateway will scan all module for system configuration classe...