public static BootstrapThemeConfiguration GetOrCreateThemeConfiguration(string theme = null) { if (string.IsNullOrEmpty(theme)) theme = "Default"; BootstrapThemeConfiguration themeItem; try { themeItem = N2.Find.Items .Where .Type.Eq(typeof (BootstrapThemeConfiguration)) .And .Name.Eq(theme.ToLower()) .Select<BootstrapThemeConfiguration>() .FirstOrDefault(); } catch (Exception ex) { // when product isn't installed yet, (no db, etc), catch errors and return empty (no variable overrides) theme configuartion themeItem = new BootstrapThemeConfiguration(); } if (themeItem == null) { themeItem = new BootstrapThemeConfiguration(); themeItem.Name = theme.ToLower(); Context.Persister.Save(themeItem); } return themeItem; }
public static Dictionary<string, string> GetThemeVariables(BootstrapThemeConfiguration configuration) { var variables = new Dictionary<string, string>(); var definition = N2.Context.Definitions.GetDefinition(configuration); foreach (var lessVariableEditable in definition.Editables.Where(x => x is Details.EditableLessVariableAttribute).Cast<Details.EditableLessVariableAttribute>()) { if (variables.ContainsKey(lessVariableEditable.LessVariableName)) throw new Exception("You cannot have multipe less variable declarations (" + lessVariableEditable.LessVariableName + ")"); variables[lessVariableEditable.LessVariableName] = (string)configuration[lessVariableEditable.Name]; } return variables; }