Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
Theme.cs
1using SkiaSharp;
2using System;
4using System.Text;
5using Waher.Content;
8using Waher.Script;
13
15{
19 public class Theme : IConstant
20 {
21 private static readonly Dictionary<string, ThemeDefinition> definitionsPerDomain = new Dictionary<string, ThemeDefinition>(StringComparer.InvariantCultureIgnoreCase);
22 private static ThemeDefinition currentDefinition = null;
23
27 public Theme()
28 {
29 }
30
34 public string ConstantName => nameof(Theme);
35
39 public string[] Aliases => null;
40
46 {
47 ThemeDefinition Def = currentDefinition;
48
51 {
52 string Host = DomainSettings.IsAlternativeDomain(HostRef.Host);
53 if (!string.IsNullOrEmpty(Host))
54 Def = GetTheme(Host);
55 }
56
57 if (!(Variables is null))
58 {
61 }
62
63 return new ObjectValue(Def);
64 }
65
72 {
73 ThemeDefinition Def = currentDefinition;
74
75 if (!(Variables is null) &&
76 Variables.CurrentRequest is IHostReference HostRef)
77 {
78 string Host = DomainSettings.IsAlternativeDomain(HostRef.Host);
79 if (!string.IsNullOrEmpty(Host))
80 Def = GetTheme(Host);
81 }
82
83 return Def;
84 }
85
90 {
91 get => currentDefinition;
92 internal set => currentDefinition = value;
93 }
94
100 public static ThemeDefinition GetTheme(string Domain)
101 {
102 lock (definitionsPerDomain)
103 {
104 if (definitionsPerDomain.TryGetValue(Domain, out ThemeDefinition Result))
105 return Result;
106 }
107
108 return currentDefinition;
109 }
110
116 internal static void SetTheme(string Domain, ThemeDefinition Theme)
117 {
118 lock (definitionsPerDomain)
119 {
120 definitionsPerDomain[Domain] = Theme;
121 }
122 }
123
124 private static string ColorToString(SKColor Color)
125 {
126 StringBuilder sb = new StringBuilder();
127
128 sb.Append("#");
129 sb.Append(Color.Red.ToString("X2"));
130 sb.Append(Color.Green.ToString("X2"));
131 sb.Append(Color.Blue.ToString("X2"));
132
133 if (Color.Alpha != 255)
134 sb.Append(Color.Alpha.ToString("X2"));
135
136 return sb.ToString();
137 }
138
139 }
140}
Domain constant, contains the value of the gateway domain.
Definition: Domain.cs:13
string ConstantName
Name of the constant
Definition: Theme.cs:34
IElement GetValueElement(Variables Variables)
Gets the constant value element.
Definition: Theme.cs:45
static ThemeDefinition GetCurrentTheme(SessionVariables Variables)
Gets the current theme definition, based on the host information available in the session varaibles.
Definition: Theme.cs:71
static ThemeDefinition CurrentTheme
Current theme.
Definition: Theme.cs:90
static ThemeDefinition GetTheme(string Domain)
Gets the theme for a given domain.
Definition: Theme.cs:100
string[] Aliases
Optional aliases. If there are no aliases for the constant, null is returned.
Definition: Theme.cs:39
Contains properties for a theme.
SKColor GraphFgColor
Graph foreground color.
SKColor GraphBgColor
Graph background color.
Collection of session variables.
HttpRequest CurrentRequest
Reference to current request.
Base class for graphs.
Definition: Graph.cs:88
const string GraphFgColorVariableName
Variable name for graph foreground color.
Definition: Graph.cs:107
const string GraphBgColorVariableName
Variable name for graph background color.
Definition: Graph.cs:102
Collection of variables.
Definition: Variables.cs:25
Interface for objects that contain a reference to a host.
Basic interface for all types of elements.
Definition: IElement.cs:21
Base interface for constants that integrate into the script engine.
Definition: IConstant.cs:10