using inmydata.Dashboard.UI.Model;
using System.Text.RegularExpressions;
using System.Globalization;
public static void Main()
var customJson = "{\r\n\tpageTitle: \"MultiAnalytics\",\r\n\tshowChat: false,\r\n\tloader: \"anon\",\r\n\tmainColour: \"#1f6c94\",\r\n\tfontUrl: \"https://fonts.googleapis.com/css2?family=Montserrat:wght@300&display=swap\",\r\n\tfontFamily: \"Montserrat\",\r\n\tshowEmailFooter: false,\r\n\tproductName: \"MultiAnalytics\",\r\n\tdefaultAdmins: [\"support@multifreight.com\",\"nfinch@datapa.com\"],\r\n\tDefaultLightTheme: {\"IMD_BACKGROUND_COLOR\":{\"R\":245,\"G\":248,\"B\":250,\"A\":255,\"HexNoAlpha\":\"#F5F8FA\",\"Alpha\":100},\"IMD_SVG_COLOR\":\"brightness(0) saturate(100%) invert(14%) sepia(20%) saturate(462%) hue-rotate(183deg) brightness(98%) contrast(95%)\",\"IMD_SVG_GRID_ROW_HEADER_COLOR\":\"invert(13%) sepia(1%) saturate(0%) hue-rotate(222deg) brightness(88%) contrast(88%)\",\"IMD_COLOR\":{\"R\":41,\"G\":41,\"B\":41,\"A\":255,\"HexNoAlpha\":\"#292929\",\"Alpha\":100},\"IMD_COLOR_FADED\":{\"R\":41,\"G\":41,\"B\":41,\"A\":170,\"HexNoAlpha\":\"#292929\",\"Alpha\":0},\"IMD_TOTAL_COLOR\":{\"R\":66,\"G\":68,\"B\":70,\"A\":255,\"HexNoAlpha\":\"#424446\",\"Alpha\":100},\"IMD_DASHBOARD_TILE_COLOR\":{\"R\":168,\"G\":188,\"B\":209,\"A\":255,\"HexNoAlpha\":\"#A8BCD1\",\"Alpha\":100},\"IMD_DASHBOARD_TILE_TEXT_COLOR\":{\"R\":41,\"G\":41,\"B\":41,\"A\":255,\"HexNoAlpha\":\"#292929\",\"Alpha\":100},\"IMD_VIS_TILE_COLOR\":{\"R\":168,\"G\":188,\"B\":209,\"A\":255,\"HexNoAlpha\":\"#A8BCD1\",\"Alpha\":100},\"IMD_VIS_TILE_TEXT_COLOR\":{\"R\":41,\"G\":41,\"B\":41,\"A\":255,\"HexNoAlpha\":\"#292929\",\"Alpha\":100},\"IMD_TOTAL_BACKGROUND_COLOR\":{\"R\":207,\"G\":206,\"B\":209,\"A\":255,\"HexNoAlpha\":\"#CFCED1\",\"Alpha\":100},\"IMD_GRID_HEADER_COLOR\":{\"R\":221,\"G\":230,\"B\":238,\"A\":255,\"HexNoAlpha\":\"#DDE6EE\",\"Alpha\":100},\"IMD_GRID_ROW_HEADER_COLOR\":{\"R\":238,\"G\":242,\"B\":246,\"A\":255,\"HexNoAlpha\":\"#EEF2F6\",\"Alpha\":100},\"IMD_GRID_ROW_BORDER\":{\"R\":226,\"G\":231,\"B\":234,\"A\":255,\"HexNoAlpha\":\"#E2E7EA\",\"Alpha\":100},\"IMD_GRID_COLUMN_BORDER\":{\"R\":245,\"G\":248,\"B\":250,\"A\":255,\"HexNoAlpha\":\"#F5F8FA\",\"Alpha\":100},\"IMD_PANEL_BACKGROUND\":{\"R\":41,\"G\":62,\"B\":82,\"A\":255,\"HexNoAlpha\":\"#293E52\",\"Alpha\":100},\"IMD_PANEL_TEXT\":{\"R\":245,\"G\":248,\"B\":250,\"A\":255,\"HexNoAlpha\":\"#F5F8FA\",\"Alpha\":100},\"IMD_PANEL_BACKGROUND_HOVER\":{\"R\":41,\"G\":41,\"B\":41,\"A\":255,\"HexNoAlpha\":\"#292929\",\"Alpha\":100},\"IMD_PANEL_HOVER_TEXT\":{\"R\":245,\"G\":248,\"B\":250,\"A\":255,\"HexNoAlpha\":\"#F5F8FA\",\"Alpha\":100},\"IMD_PANEL_BUTTON\":{\"R\":41,\"G\":62,\"B\":82,\"A\":255,\"HexNoAlpha\":\"#293E52\",\"Alpha\":100},\"IMD_GRID_BORDER_COLOR\":{\"R\":222,\"G\":222,\"B\":222,\"A\":255,\"HexNoAlpha\":\"#DEDEDE\",\"Alpha\":100},\"IMD_GRID_HEADER_TEXT\":{\"R\":41,\"G\":41,\"B\":41,\"A\":255,\"HexNoAlpha\":\"#292929\",\"Alpha\":100},\"IMD_FONT_FAMILY\":\"\\\"Outfit\\\"\",\"IMD_FONT_SIZE\":\"16px\",\"IMD_FONT_WEIGHT\":\"normal\",\"IMD_NODE_COLOR\":{\"R\":83,\"G\":104,\"B\":124,\"A\":255,\"HexNoAlpha\":\"#53687C\",\"Alpha\":100},\"IMD_NODE_TEXT_COLOR\":{\"R\":245,\"G\":248,\"B\":250,\"A\":255,\"HexNoAlpha\":\"#F5F8FA\",\"Alpha\":100},\"IMD_INVERT_ICONS\":\"invert(0)\",\"IMD_BRAND_COLOR\":{\"R\":221,\"G\":51,\"B\":51,\"A\":255,\"HexNoAlpha\":\"#DD3333\",\"Alpha\":100},\"IMD_ACCORDION_HEADER\":{\"R\":207,\"G\":206,\"B\":209,\"A\":255,\"HexNoAlpha\":\"#CFCED1\",\"Alpha\":100},\"IMD_ACCORDION_HEADER_TEXT\":{\"R\":41,\"G\":41,\"B\":41,\"A\":255,\"HexNoAlpha\":\"#292929\",\"Alpha\":100},\"IMD_DISABLED_BUTTON\":{\"R\":204,\"G\":204,\"B\":204,\"A\":255,\"HexNoAlpha\":\"#CCCCCC\",\"Alpha\":100},\"IMD_SCROLLBAR_BACKGROUND\":{\"R\":238,\"G\":238,\"B\":238,\"A\":255,\"HexNoAlpha\":\"#EEEEEE\",\"Alpha\":100},\"IMD_SCROLLBAR_THUMB\":{\"R\":207,\"G\":206,\"B\":209,\"A\":255,\"HexNoAlpha\":\"#CFCED1\",\"Alpha\":100},\"IMD_SPLITTER_COLOR\":{\"R\":238,\"G\":238,\"B\":238,\"A\":255,\"HexNoAlpha\":\"#EEEEEE\",\"Alpha\":100},\"IMD_BORDER_RADIUS\":\"0px\",\"IMD_SELECTED_ITEM_TEXT\":{\"R\":255,\"G\":255,\"B\":255,\"A\":255,\"HexNoAlpha\":\"#FFFFFF\",\"Alpha\":100},\"IMD_SELECTED_ITEM_COLOR\":{\"R\":83,\"G\":104,\"B\":124,\"A\":255,\"HexNoAlpha\":\"#53687C\",\"Alpha\":100},\"IMD_SHADOW\":{\"R\":41,\"G\":41,\"B\":41,\"A\":34,\"HexNoAlpha\":\"#292929\",\"Alpha\":0},\"TOOLBAR_ICON_COLOR\":{\"R\":255,\"G\":255,\"B\":255,\"A\":255,\"HexNoAlpha\":\"#FFFFFF\",\"Alpha\":100},\"TOOLBAR_ICON_SELECTED_COLOR\":{\"R\":83,\"G\":104,\"B\":124,\"A\":255,\"HexNoAlpha\":\"#53687C\",\"Alpha\":100}}\r\n}";
var customisation = JsonConvert.DeserializeObject<Customisation>(customJson);
Console.Write(JsonConvert.SerializeObject((customisation)));
namespace inmydata.Dashboard.UI.Model
public class ThemeSettings
const string _HeaderText = "";
public ThemeSettings(ThemeName themeName)
ResetDefaultValues(themeName);
public SeriesColor IMD_BACKGROUND_COLOR { get; set; }
public string IMD_SVG_COLOR { get; set; }
public string IMD_SVG_GRID_ROW_HEADER_COLOR { get; set; }
public SeriesColor IMD_COLOR { get; set; }
public SeriesColor IMD_COLOR_FADED { get; set; }
public SeriesColor IMD_TOTAL_COLOR { get; set; }
public SeriesColor IMD_DASHBOARD_TILE_COLOR { get; set; }
public SeriesColor IMD_DASHBOARD_TILE_TEXT_COLOR { get; set; }
public SeriesColor IMD_VIS_TILE_COLOR { get; set; }
public SeriesColor IMD_VIS_TILE_TEXT_COLOR { get; set; }
public SeriesColor IMD_TOTAL_BACKGROUND_COLOR { get; set; }
public SeriesColor IMD_GRID_HEADER_COLOR { get; set; }
public SeriesColor IMD_GRID_ROW_HEADER_COLOR { get; set; }
public SeriesColor IMD_GRID_ROW_BORDER { get; set; }
public SeriesColor IMD_GRID_COLUMN_BORDER { get; set; }
public SeriesColor IMD_PANEL_BACKGROUND { get; set; }
public SeriesColor IMD_PANEL_TEXT { get; set; }
public SeriesColor IMD_PANEL_BACKGROUND_HOVER { get; set; }
public SeriesColor IMD_PANEL_HOVER_TEXT { get; set; }
public SeriesColor IMD_PANEL_BUTTON { get; set; }
public SeriesColor IMD_GRID_BORDER_COLOR { get; set; }
public SeriesColor IMD_GRID_HEADER_TEXT { get; set; }
public string IMD_FONT_FAMILY { get; set; }
public string IMD_FONT_SIZE { get; set; }
public string IMD_FONT_WEIGHT { get; set; }
public SeriesColor IMD_NODE_COLOR { get; set; }
public SeriesColor IMD_NODE_TEXT_COLOR { get; set; }
public string IMD_INVERT_ICONS { get; set; }
public SeriesColor IMD_BRAND_COLOR { get; set; }
public SeriesColor IMD_ACCORDION_HEADER { get; set; }
public SeriesColor IMD_ACCORDION_HEADER_TEXT { get; set; }
public SeriesColor IMD_DISABLED_BUTTON { get; set; }
public SeriesColor IMD_SCROLLBAR_BACKGROUND { get; set; }
public SeriesColor IMD_SCROLLBAR_THUMB { get; set; }
public SeriesColor IMD_SPLITTER_COLOR { get; set; }
public string IMD_BORDER_RADIUS { get; set; }
public SeriesColor IMD_SELECTED_ITEM_TEXT { get; set; }
public SeriesColor IMD_SELECTED_ITEM_COLOR { get; set; }
public SeriesColor IMD_SHADOW { get; set; }
public SeriesColor TOOLBAR_ICON_COLOR { get; set; }
public SeriesColor TOOLBAR_ICON_SELECTED_COLOR { get; set; }
#region Reset Default Values
public void ResetDefaultValues(ThemeName themeName)
IMD_BACKGROUND_COLOR = new SeriesColor("#F5F8FA");
IMD_SVG_COLOR = "brightness(0) saturate(100%) invert(14%) sepia(20%) saturate(462%) hue-rotate(183deg) brightness(98%) contrast(95%)";
IMD_SVG_GRID_ROW_HEADER_COLOR = "invert(13%) sepia(1%) saturate(0%) hue-rotate(222deg) brightness(88%) contrast(88%)";
IMD_COLOR = new SeriesColor("#292929");
IMD_COLOR_FADED = new SeriesColor("#292929aa");
IMD_TOTAL_COLOR = new SeriesColor("#424446");
IMD_DASHBOARD_TILE_COLOR = new SeriesColor("#a8bcd1");
IMD_DASHBOARD_TILE_TEXT_COLOR = new SeriesColor("#292929");
IMD_VIS_TILE_COLOR = new SeriesColor("#a8bcd1");
IMD_VIS_TILE_TEXT_COLOR = new SeriesColor("#292929");
IMD_TOTAL_BACKGROUND_COLOR = new SeriesColor("#cfced1");
IMD_GRID_HEADER_COLOR = new SeriesColor("#dde6ee");
IMD_GRID_ROW_HEADER_COLOR = new SeriesColor("#eef2f6");
IMD_GRID_ROW_BORDER = new SeriesColor("#E2E7EA");
IMD_GRID_COLUMN_BORDER = new SeriesColor("#F5F8FA");
IMD_PANEL_BACKGROUND = new SeriesColor("#293E52");
IMD_PANEL_TEXT = new SeriesColor("#F5F8FA");
IMD_PANEL_BACKGROUND_HOVER = new SeriesColor("#dd3333");
IMD_PANEL_HOVER_TEXT = new SeriesColor("#F5F8FA");
IMD_PANEL_BUTTON = new SeriesColor("#293E52");
IMD_GRID_BORDER_COLOR = new SeriesColor("#DEDEDE");
IMD_GRID_HEADER_TEXT = new SeriesColor("#292929");
IMD_FONT_FAMILY = "\"Outfit\"";
IMD_FONT_WEIGHT = "normal";
IMD_NODE_COLOR = new SeriesColor("#DD3333");
IMD_NODE_TEXT_COLOR = new SeriesColor("#F5F8FA");
IMD_INVERT_ICONS = "invert(0)";
IMD_BRAND_COLOR = new SeriesColor("#DD3333");
IMD_ACCORDION_HEADER = new SeriesColor("#cfced1");
IMD_ACCORDION_HEADER_TEXT = new SeriesColor("#292929");
IMD_DISABLED_BUTTON = new SeriesColor("#CCC");
IMD_SCROLLBAR_BACKGROUND = new SeriesColor("#EEEEEE");
IMD_SCROLLBAR_THUMB = new SeriesColor("#cfced1");
IMD_SPLITTER_COLOR = new SeriesColor("#EEEEEE");
IMD_BORDER_RADIUS = "0px";
IMD_SELECTED_ITEM_TEXT = new SeriesColor("#FFFFFF");
IMD_SELECTED_ITEM_COLOR = new SeriesColor("#53687C");
IMD_SHADOW = new SeriesColor("#29292922");
TOOLBAR_ICON_COLOR = new SeriesColor("#FFFFFF");
TOOLBAR_ICON_SELECTED_COLOR = new SeriesColor("#dd3333");
IMD_BACKGROUND_COLOR = new SeriesColor("#303030");
IMD_SVG_COLOR = "brightness(0) saturate(100%) invert(100%) sepia(100%) saturate(1%) hue-rotate(146deg) brightness(101%) contrast(101%)";
IMD_SVG_GRID_ROW_HEADER_COLOR = "brightness(0) saturate(100%) invert(42%) sepia(11%) saturate(627%) hue-rotate(172deg) brightness(94%) contrast(92%)";
IMD_COLOR = new SeriesColor("#FFFFFF");
IMD_COLOR_FADED = new SeriesColor("#FFFFFF33");
IMD_TOTAL_COLOR = new SeriesColor("#303030");
IMD_DASHBOARD_TILE_COLOR = new SeriesColor("#a8bcd1");
IMD_DASHBOARD_TILE_TEXT_COLOR = new SeriesColor("#292929");
IMD_VIS_TILE_COLOR = new SeriesColor("#a8bcd1");
IMD_VIS_TILE_TEXT_COLOR = new SeriesColor("#292929");
IMD_TOTAL_BACKGROUND_COLOR = new SeriesColor("#C5CED8");
IMD_GRID_HEADER_COLOR = new SeriesColor("#505050");
IMD_GRID_ROW_HEADER_COLOR = new SeriesColor("#4A4A4A");
IMD_GRID_ROW_BORDER = new SeriesColor("#3F4039");
IMD_GRID_COLUMN_BORDER = new SeriesColor("#303030");
IMD_PANEL_BACKGROUND = new SeriesColor("#1C1C1C");
IMD_PANEL_TEXT = new SeriesColor("#FFFFFF");
IMD_PANEL_BACKGROUND_HOVER = new SeriesColor("#FFFFFF");
IMD_PANEL_HOVER_TEXT = new SeriesColor("#1C1C1C");
IMD_PANEL_BUTTON = new SeriesColor("#FFFFFF");
IMD_GRID_BORDER_COLOR = new SeriesColor("#424446");
IMD_GRID_HEADER_TEXT = new SeriesColor("#FFFFFF");
IMD_FONT_FAMILY = "\"Outfit\"";
IMD_FONT_WEIGHT = "\"normal\"";
IMD_NODE_COLOR = new SeriesColor("#DD3333");
IMD_NODE_TEXT_COLOR = new SeriesColor("#FFFFFF");
IMD_INVERT_ICONS = "invert(1)";
IMD_BRAND_COLOR = new SeriesColor("#DD3333");
IMD_ACCORDION_HEADER = new SeriesColor("#505050");
IMD_ACCORDION_HEADER_TEXT = new SeriesColor("#FFFFFF");
IMD_DISABLED_BUTTON = new SeriesColor("#505050");
IMD_SCROLLBAR_BACKGROUND = new SeriesColor("#333333");
IMD_SCROLLBAR_THUMB = new SeriesColor("#505050");
IMD_SPLITTER_COLOR = new SeriesColor("#252525");
IMD_BORDER_RADIUS = "0px";
IMD_SELECTED_ITEM_TEXT = new SeriesColor("#000000");
IMD_SELECTED_ITEM_COLOR = new SeriesColor("#989DA6");
IMD_SHADOW = new SeriesColor("#00000055");
TOOLBAR_ICON_COLOR = new SeriesColor("#FFFFFF");
TOOLBAR_ICON_SELECTED_COLOR = new SeriesColor("#FFFFFF");
public void ApplyTheme(ThemeSettings themeSettings)
if (themeSettings == null)
throw new Exception("themeSettings is null");
Type type = this.GetType();
PropertyInfo[] props = type.GetProperties();
foreach (PropertyInfo prop in props)
if (prop.GetSetMethod(true) != null && prop.GetSetMethod(true).IsPrivate)
if ((prop.GetSetMethod().Attributes & MethodAttributes.Static) != 0)
if (!prop.PropertyType.IsAssignableFrom(prop.PropertyType))
prop.SetValue(this, prop.GetValue(themeSettings, null), null);
var rv = _HeaderText + "\r\n\r\n:root {\r\n";
foreach (PropertyInfo property in this.GetType().GetProperties().Where(p => p.CanWrite))
rv += " --" + property.Name.Replace("_", "-") + ": " + (property.PropertyType == typeof(SeriesColor) ? ((SeriesColor)property.GetValue(this)).Hex : (string)property.GetValue(this)) + ";\r\n";
public struct SeriesColor : IEquatable<SeriesColor>
public SeriesColor(byte red, byte green, byte blue)
public SeriesColor(byte red, byte green, byte blue, byte alpha)
public SeriesColor(string hex)
var str = ValidatedHexColor(hex);
[Newtonsoft.Json.JsonIgnore]
return HexNoAlpha + (A == 255 ? "" : A.ToString("X2"));
var str = ValidatedHexColor(value);
return "#" + R.ToString("X2") + G.ToString("X2") + B.ToString("X2");
return Convert.ToInt32(A / 255 * 100);
#region private functions
private static string ValidatedHexColor(string value)
var str = value.TrimStart('#');
if (!new Regex("^(?:[0-9a-fA-F]{3,4}){1,2}$").IsMatch(str))
throw new ArgumentException(value + " is not a valid hex color");
str = new string (str[0], 2) + new string (str[1], 2) + new string (str[2], 2);
str = new string (str[0], 2) + new string (str[1], 2) + new string (str[2], 2) + new string (str[3], 2);
private static byte RfromHex(string hex)
return byte.Parse(hex.Substring(0, 2), NumberStyles.HexNumber);
private static byte GfromHex(string hex)
return byte.Parse(hex.Substring(2, 2), NumberStyles.HexNumber);
private static byte BfromHex(string hex)
return byte.Parse(hex.Substring(4, 2), NumberStyles.HexNumber);
private static byte AfromHex(string hex)
return hex.Length != 8 ? (byte)255 : byte.Parse(hex.Substring(6, 2), NumberStyles.HexNumber);
public bool Equals(SeriesColor other)
return R == other.R && G == other.G && B == other.B && A == other.A;
public override bool Equals(object obj)
if (typeof(SeriesColor) == obj.GetType())
return Equals((SeriesColor)obj);
public override int GetHashCode() => (R, G, B, A).GetHashCode();
public static bool operator ==(SeriesColor lhs, SeriesColor rhs)
public static bool operator !=(SeriesColor lhs, SeriesColor rhs) => !(lhs == rhs);
public class Customisation
public string LogoBase64 { get; set; }
public string LogoSrc { get; set; } = "/images/inmydata.png";
public string LogoSmallSrc { get; set; }
public string LogoHref { get; set; }
public string MainColour { get; set; }
public string PageTitle { get; set; }
public bool ShowLoginBanner { get; set; } = true;
public string LoginBanner { get; set; } = "/images/leftbanner.jpg";
public string FooterHtml { get; set; }
public bool ShowChat { get; set; } = true;
public string Loader { get; set; }
public string ProductName { get; set; } = "inmydata";
public string FontUrl { get; set; }
public string FontFamily { get; set; }
public string FaviconSrc { get; set; } = "/images/inmydata.ico";
public string FaviconType { get; set; } = "image/x-icon";
public bool ShowEmailFooter { get; set; } = true;
public string PwaImage512 { get; set; }
public string PwaImage192 { get; set; }
public ThemeSettings DefaultLightTheme { get; set; }
public ThemeSettings DefaultDarkTheme { get; set; }