5using System.Xml.Schema;
6using System.Threading.Tasks;
25 private readonly
static Dictionary<string, ThemeDefinition> themeDefinitions =
new Dictionary<string, ThemeDefinition>();
29 private string themeId =
string.Empty;
30 private Dictionary<string, object> themeIdByAlternativeHost;
48 [DefaultValueStringEmpty]
52 set => this.themeId = value;
63 if (
string.IsNullOrEmpty(Host))
66 lock (themeDefinitions)
78 public override string Resource =>
"/Settings/Theme.md";
100 if (!
string.IsNullOrEmpty(this.themeId) && themeDefinitions.TryGetValue(
this.themeId, out
ThemeDefinition Def))
101 Theme.CurrentTheme = Def;
105 return Task.CompletedTask;
117 private void CheckLoaded()
119 if (themeDefinitions.Count > 0)
123 if (!Directory.Exists(ThemesFolder))
129 foreach (
string FileName
in Directory.GetFiles(ThemesFolder,
"*.xml", SearchOption.AllDirectories))
135 XSL.
Validate(FileName, Doc,
"Theme",
"http://waher.se/Schema/Theme.xsd", Schema);
138 themeDefinitions[Def.
Id] = Def;
154 await base.InitSetup(WebServer);
162 if (!
string.IsNullOrEmpty(this.themeId) && !themeDefinitions.ContainsKey(
this.themeId))
164 this.themeId =
string.Empty;
166 this.Completed = DateTime.MinValue;
167 this.Complete =
false;
172 if (
string.IsNullOrEmpty(this.themeId) && themeDefinitions.Count == 1)
176 this.themeId = Def2.
Id;
187 this.Updated = DateTime.Now;
191 if (!
string.IsNullOrEmpty(this.themeId) && themeDefinitions.TryGetValue(
this.themeId, out
ThemeDefinition Def))
192 Theme.CurrentTheme = Def;
193 else if (themeDefinitions.TryGetValue(
"CactusRose", out Def))
194 Theme.CurrentTheme = Def;
199 Theme.CurrentTheme = Def2;
204 this.themeIdByAlternativeHost =
new Dictionary<string, object>(StringComparer.InvariantCultureIgnoreCase);
206 this.themeIdByAlternativeHost[P.Key] = P.Value;
208 foreach (KeyValuePair<string, object> P
in this.themeIdByAlternativeHost)
210 if (P.Value is
string ThemeId && themeDefinitions.TryGetValue(
ThemeId, out Def))
211 Theme.SetTheme(P.Key, Def);
214 this.setTheme = WebServer.Register(
"/Settings/SetTheme",
null, this.SetTheme,
true,
false,
true);
225 return base.UnregisterSetup(WebServer);
250 string TabID = Request.
Header[
"X-TabID"];
251 if (
string.IsNullOrEmpty(TabID))
264 if (
string.IsNullOrEmpty(Host))
266 Theme.CurrentTheme = Def;
268 this.themeId = Def.Id;
275 lock (this.themeIdByAlternativeHost)
277 this.themeIdByAlternativeHost[Host] = Def;
282 Theme.SetTheme(Host, Def);
287 this.Updated = DateTime.Now;
294 new KeyValuePair<string, object>(
"themeId", Def.Id),
295 new KeyValuePair<string, object>(
"cssUrl", Def.CSSX),
296 },
false),
true,
"User");
298 Response.StatusCode = 200;
299 Response.StatusMessage =
"OK";
309 themeDefinitions.Values.CopyTo(Result, 0);
311 Array.Sort(Result, (t1, t2) => t1.
Title.CompareTo(t2.Title));
324 return themeDefinitions.TryGetValue(
ThemeId, out Definition);
339 if (
string.IsNullOrEmpty(Value))
340 return Task.FromResult(
false);
344 if (!themeDefinitions.ContainsKey(Value))
347 return Task.FromResult(
false);
350 this.themeId = Value;
352 return Task.FromResult(
true);
Contains information about a response to a content request.
bool HasError
If an error occurred.
object Decoded
Decoded object.
Helps with common JSON-related tasks.
static string Encode(string s)
Encodes a string for inclusion in JSON.
Helps with common XML-related tasks.
static XmlDocument LoadFromFile(string FileName)
Loads an XML document from a file.
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.
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< 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...
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...