Пример #1
0
        /// <summary>
        /// Json package representing current selected theme
        /// </summary>
        /// <param name="themeId">Theme id</param>
        /// <returns>Json package</returns>
        public static JsonPackage GetCurrentTheme(string themeId)
        {
            // first try to pull theme metadata from manifest file
            var jp = FileSystem.GetThemeManifest(themeId);

            if (jp != null)
            {
                if (string.IsNullOrEmpty(jp.IconUrl))
                {
                    jp.IconUrl = DefaultIconUrl(jp);
                }
                return(jp);
            }


            // if no manifest file, check themes in online gallery
            // and if found create manifest file using package info
            var srs = new PackagingSource {
                FeedUrl = _feedUrl
            };
            var gPkg = GetPublishedPackages(srs).ToList().Where(p => p.Id == themeId).FirstOrDefault();

            if (gPkg != null)
            {
                if (gPkg.Screenshots != null && gPkg.Screenshots.Count > 0)
                {
                    gPkg.IconUrl = string.Format("http://dnbegallery.org{0}", gPkg.Screenshots[0].ScreenshotUri);
                }

                jp = FileSystem.WriteThemeManifest(gPkg.Id, gPkg.Description, gPkg.Authors, gPkg.ProjectUrl, gPkg.Version, gPkg.IconUrl);
                if (jp != null)
                {
                    return(jp);
                }
            }

            // generate default blank manifest if both methods failed
            var jpw = FileSystem.WriteThemeManifest(themeId);

            if (jpw != null)
            {
                jp = jpw;
            }

            // return default values if theme folder read only
            if (jp == null)
            {
                jp = new JsonPackage {
                    Id = themeId, Authors = "Unknown", IconUrl = Utils.ApplicationRelativeWebRoot + "pics/Theme.png"
                }
            }
            ;

            return(jp);
        }