Example #1
0
        public ThemeInfo GetActiveTheme()
        {
            var defaultThemeDirectoryName = "Default";

            if (!DatabaseManager.IsDatabaseInstalled())
            {
                return(GetThemeInfo(new DirectoryInfo(defaultThemeDirectoryName)));
            }
            var generalSettings = DependencyResolver.Resolve <GeneralSettings>();

            if (_cachedThemeInfo != null && _cachedThemeInfo.DirectoryName == generalSettings.ActiveTheme)
            {
                return(_cachedThemeInfo);
            }
            var themeDirectoryName = generalSettings.ActiveTheme;

            if (themeDirectoryName.IsNullEmptyOrWhiteSpace())
            {
                themeDirectoryName = defaultThemeDirectoryName;
            }
            //does theme directory exist
            var themePath = GetThemePath(themeDirectoryName);

            if (!_localFileProvider.DirectoryExists(themePath))
            {
                //reset theme path to default
                themePath = GetThemePath(defaultThemeDirectoryName);
            }
            _cachedThemeInfo = GetThemeInfo(new DirectoryInfo(themePath));

            //load if there are any templates
            var templatesDirectory = _localFileProvider.CombinePaths(themePath, "Views", "Templates");

            if (_localFileProvider.DirectoryExists(templatesDirectory))
            {
                //get all the files
                var templateFiles = _localFileProvider.GetFiles(templatesDirectory, "*.html");
                foreach (var templateFile in templateFiles)
                {
                    var fileName = _localFileProvider.GetFileNameWithoutExtension(templateFile);
                    _cachedThemeInfo.Templates.TryAdd(fileName, $"Templates/{fileName}");
                }
            }
            return(_cachedThemeInfo);
        }