Пример #1
0
        /// <summary>
        /// Returns all themes that have been imported earlier from GitHub repository.
        /// </summary>
        /// <param name="ensureOnlyFiles">A list of theme file names (without directory information) to treat as white-list - all other files will be deleted.</param>
        /// <returns>Themes.</returns>
        private GitHubThemeResult GetImportedThemesInternal(IEnumerable <string> ensureOnlyFiles = null)
        {
            GitHubThemeResult   ret           = null;
            GitHubInMemoryTheme inMemoryTheme = null;

            inMemoryTheme = GetUrlSpecifiedTheme();

            if (inMemoryTheme != null)
            {
                ret = new GitHubThemeResult()
                {
                    Themes = new List <GitHubTheme>()
                    {
                        new GitHubTheme()
                        {
                            Id   = inMemoryTheme.Id,
                            Name = inMemoryTheme.Name
                        }
                    },
                    Checksum = CalculateChecksum(inMemoryTheme)
                };
            }
            else
            {
                ret = ThemeSource.GetImportedThemes <GitHubTheme, GitHubThemeResult>("~/Assets/css/Themes/", ensureOnlyFiles);
            }

            return(ret);
        }
Пример #2
0
        /// <summary>
        /// Returns the theme which is specified via URL.
        /// </summary>
        /// <returns>Theme.</returns>
        private GitHubInMemoryTheme GetUrlSpecifiedTheme()
        {
            GitHubInMemoryTheme ret = null;
            string inMemoryThemeUrl = ThemeSource.GetThemeUrlFromRequest(HttpContext.Current.Request);

            if (!string.IsNullOrEmpty(inMemoryThemeUrl))
            {
                ret = GitHubInMemoryThemeCache.Read();

                if (ret == null || string.Compare(inMemoryThemeUrl, ret.Uri, true) != 0)
                {
                    ret = ThemeSource.CreateThemeInstance <GitHubInMemoryTheme>(inMemoryThemeUrl, t =>
                    {
                        t.Uri     = inMemoryThemeUrl;
                        t.Content = Encoding.UTF8.GetBytes(ThemeSource.DownloadString(inMemoryThemeUrl));
                    });

                    if (ret.Content != null && ret.Content.Length > 0)
                    {
                        GitHubInMemoryThemeCache.Update(ret);
                    }
                    else
                    {
                        ret = null;
                    }
                }
            }

            return(ret);
        }
Пример #3
0
        /// <summary>
        /// Returns the bundle stream for given themes.
        /// </summary>
        /// <param name="themes">Themes.</param>
        /// <returns>Bundle stream.</returns>
        public Stream GetBundleStream(GitHubThemeResult themes = null)
        {
            Stream ret = null;
            GitHubInMemoryTheme inMemoryTheme = null;

            if (themes == null)
            {
                inMemoryTheme = GetUrlSpecifiedTheme();

                if (inMemoryTheme != null)
                {
                    ret = new MemoryStream(inMemoryTheme.Content);
                }
            }

            if (ret == null)
            {
                if (themes == null)
                {
                    themes = ImportThemes();
                }

                ret = ThemeSource.GetBundleStream <GitHubTheme, GitHubThemeResult>("~/Assets/css/Themes/", themes);
            }

            return(ret);
        }
Пример #4
0
            /// <summary>
            /// Reads from cache.
            /// </summary>
            /// <returns>Result.</returns>
            public static GitHubInMemoryTheme Read()
            {
                GitHubInMemoryTheme ret = null;

                if (_result != null && DateTime.UtcNow.Subtract(_result.Item2).TotalMinutes < 1)
                {
                    lock (_lock)
                    {
                        if (_result != null)
                        {
                            ret = _result.Item1;
                        }
                    }
                }

                return(ret);
            }
Пример #5
0
 /// <summary>
 /// Updates the cache.
 /// </summary>
 /// <param name="result">Result.</param>
 public static void Update(GitHubInMemoryTheme result)
 {
     _result = new Tuple <GitHubInMemoryTheme, DateTime>(result, DateTime.UtcNow);
 }
Пример #6
0
 /// <summary>
 /// Calculates the checksum for given theme.
 /// </summary>
 /// <param name="theme">Theme.</param>
 /// <returns>Checksum.</returns>
 private string CalculateChecksum(GitHubInMemoryTheme theme)
 {
     return(Utils.Crypto.GetHash(theme.Uri));
 }