Example #1
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="packages"></param>
        public static void Load(List<Package> packages)
        {
            try
            {
                foreach (var pkg in GetAllPublishedPackages().ToList())
                {
                    //System.Diagnostics.Debug.WriteLine(string.Format("{0}|{1}|{2}|{3}", pkg.Id, pkg.Version, pkg.IsLatestVersion, pkg.IconUrl));

                    var jp = new Package
                    {
                        Id = pkg.Id,
                        PackageType = pkg.PackageType,
                        Authors = string.IsNullOrEmpty(pkg.Authors) ? "unknown" : pkg.Authors,
                        Description = pkg.Description.Length > 140 ? string.Format("{0}...", pkg.Description.Substring(0, 140)) : pkg.Description,
                        DownloadCount = pkg.DownloadCount,
                        LastUpdated = pkg.LastUpdated.ToString("yyyy-MM-dd HH:mm"),// format for sort order to work with strings
                        Title = pkg.Title,
                        OnlineVersion = pkg.Version,
                        Website = pkg.ProjectUrl,
                        Tags = pkg.Tags,
                        IconUrl = pkg.IconUrl,
                        Location = "G"
                    };

                    // for themes or widgets, get screenshot instead of icon
                    // also get screenshot if icon is missing for package
                    if(pkg.Screenshots != null && pkg.Screenshots.Count > 0)
                    {
                        if ((pkg.PackageType == Constants.Theme || pkg.PackageType == Constants.Widget) || string.IsNullOrEmpty(pkg.IconUrl))
                        {
                            jp.IconUrl = pkg.Screenshots[0].ScreenshotUri;
                        }
                    }

                    // if both icon and screenshot missing, get default image for package type
                    if (string.IsNullOrEmpty(jp.IconUrl))
                        jp.IconUrl = DefaultThumbnail(pkg.PackageType);

                    if (!string.IsNullOrEmpty(jp.IconUrl) && !jp.IconUrl.StartsWith("http:"))
                        jp.IconUrl = Constants.GalleryUrl + jp.IconUrl;

                    if (!string.IsNullOrWhiteSpace(pkg.GalleryDetailsUrl))
                        jp.PackageUrl = PackageUrl(pkg.PackageType, pkg.Id);

                    //System.Diagnostics.Debug.WriteLine(string.Format("{0}|{1}|{2}|{3}", jp.Id, jp.OnlineVersion, jp.PackageType, jp.IconUrl));

                    packages.Add(jp);
                }
            }
            catch (Exception ex)
            {
                Utils.Log("BlogEngine.Core.Packaging.Load", ex);
            }   
        }
Example #2
0
        /// <summary>
        /// Load gallery packages
        /// </summary>
        /// <param name="packages">Packages to load</param>
        public static void Load(List<Package> packages)
        {
            try
            {
                var packs = GetNugetPackages().ToList();
                var extras = GetPackageExtras();

                foreach (var pkg in packs)
                {
                    if (pkg.IsLatestVersion)
                    {
                        var jp = new Package
                        {
                            Id = pkg.Id,
                            Authors = pkg.Authors == null ? "unknown" : string.Join(", ", pkg.Authors),
                            Description = pkg.Description.Length > 140 ? string.Format("{0}...", pkg.Description.Substring(0, 140)) : pkg.Description,
                            DownloadCount = pkg.DownloadCount,
                            LastUpdated = pkg.Published != null ? pkg.Published.Value.ToString("yyyy-MM-dd HH:mm") : "", // format for sort order to work with strings
                            Title = string.IsNullOrEmpty(pkg.Title) ? pkg.Id : pkg.Title,
                            OnlineVersion = pkg.Version.ToString(),
                            Website = pkg.ProjectUrl == null ? null : pkg.ProjectUrl.ToString(),
                            Tags = pkg.Tags,
                            IconUrl = pkg.IconUrl == null ? null : pkg.IconUrl.ToString()
                        };

                        if (!string.IsNullOrEmpty(jp.IconUrl) && !jp.IconUrl.StartsWith("http:"))
                            jp.IconUrl = Constants.GalleryUrl + jp.IconUrl;

                        if (string.IsNullOrEmpty(jp.IconUrl))
                            jp.IconUrl = DefaultThumbnail("");

                        if (extras != null && extras.Count() > 0)
                        {
                            var extra = extras.Where(e => e.Id.ToLower() == pkg.Id.ToLower() + "." + pkg.Version).FirstOrDefault();

                            if (extra != null)
                            {
                                jp.Extra = extra;
                                jp.DownloadCount = extra.DownloadCount;
                                jp.Rating = extra.Rating;
                                jp.PackageType = extra.PkgType.ToString();
                            }
                        }
                        packages.Add(jp);
                    }
                }

            }
            catch (Exception ex)
            {
                Utils.Log("BlogEngine.Core.Packaging.Load", ex);
            }   
        }
        /// <summary>
        /// Update package metadata
        /// </summary>
        /// <param name="item">Package object</param>
        /// <returns>True if success</returns>
        public bool Update(Package item)
        {
            if (!Security.IsAdministrator)
                throw new System.UnauthorizedAccessException();

            if (item == null)
                return false;

            switch (item.PackageType)
            {
                case "Extension":
                    if (!string.IsNullOrEmpty(item.Id))
                    {
                        var ext = ExtensionManager.GetExtension(item.Id);

                        if (ext == null)
                        {
                            // handle when extension and package ID different
                            var map = Packaging.FileSystem.ExtansionMap();
                            foreach (var m in map)
                            {
                                if (m.Value.ToString() == item.Id)
                                {
                                    ext = ExtensionManager.GetExtension(m.Key);
                                    ExtensionManager.ChangeStatus(m.Key, item.Enabled);
                                    break;
                                }
                            }
                        }
                        else
                        {
                            ExtensionManager.ChangeStatus(item.Id, item.Enabled);
                        }

                        ext.Priority = item.Priority;
                        ExtensionManager.SaveToStorage(ext);
                        Blog.CurrentInstance.Cache.Remove(Constants.CacheKey);
                    }
                    break;
                case "Theme":
                    break;
                case "Widget":
                    break;
                default:
                    break;
            }
            return true;
        }
        /// <summary>
        /// Update package metadata
        /// </summary>
        /// <param name="item">Package object</param>
        /// <returns>True if success</returns>
        public bool Update(Package item)
        {
            if (!Security.IsAdministrator)
                throw new System.UnauthorizedAccessException();

            if (item == null)
                return false;

            switch (item.PackageType)
            {
                case "Extension":
                    if (!string.IsNullOrEmpty(item.Id))
                    {
                        var ext = ExtensionManager.GetExtension(item.Id);

                        if (ext != null)
                        {
                            ext.Priority = item.Priority;
                            ExtensionManager.ChangeStatus(item.Id, item.Enabled);
                            ExtensionManager.SaveToStorage(ext);
                            Blog.CurrentInstance.Cache.Remove(Constants.CacheKey);
                        }
                        else
                        {
                            Utils.Log(string.Format("Failed to find extension {0} while trying to update package repository", item.Id));
                        }
                    }
                    break;
                case "Theme":
                    break;
                case "Widget":
                    break;
                default:
                    break;
            }
            return true;
        }
        static void LoadExtensions(List<Package> packages)
        {
            var extensions = ExtensionManager.Extensions.Where(x => x.Key != "MetaExtension").ToList();

            foreach (KeyValuePair<string, ManagedExtension> ext in extensions)
            {
                var x = ExtensionManager.GetExtension(ext.Key);

                var adminPage = string.IsNullOrEmpty(x.AdminPage) ?
                string.Format(Utils.RelativeWebRoot + "admin/Extensions/Settings.aspx?ext={0}&enb={1}", x.Name, x.Enabled) :
                string.Format(x.AdminPage, x.Name, x.Enabled);

                // If extension name in gallery differ from package ID
                // they will show as 2 extensions in the list.
                // To avoid, we can add mapping to /app_data/extensionmap.txt
                // in format "ExtensionId=PackageName" to map exension id to package id
                var map = Packaging.FileSystem.ExtansionMap();
                var extId = map.ContainsKey(x.Name) ? map[x.Name] : x.Name;
                var existingPackage = packages.Where(p => p.Id == extId).FirstOrDefault();

                if (existingPackage == null)
                {
                    var p = new Package
                    {
                        Id = x.Name,
                        PackageType = "Extension",
                        Title = x.Name,
                        Description = x.Description,
                        LocalVersion = x.Version,
                        Authors = x.Author,
                        IconUrl = "http://dnbegallery.org/cms/Themes/OrchardGallery/Content/Images/extensionDefaultIcon.png",
                        Enabled = x.Enabled,
                        Priority = x.Priority,
                        SettingsUrl = x.Settings.Count > 0 ? adminPage : "",
                        Location = "L"
                    };
                    packages.Add(p);
                }
                else
                {
                    existingPackage.LocalVersion = x.Version;
                    existingPackage.Enabled = x.Enabled;
                }
            }
        }
        /// <summary>
        /// Load extensions from extensions manager
        /// </summary>
        /// <returns>List of installed extensions</returns>
        public static List<Package> LoadExtensions()
        {
            var extensions = ExtensionManager.Extensions.Where(x => x.Key != "MetaExtension").ToList();
            var packages = new List<Package>();

            foreach (KeyValuePair<string, ManagedExtension> ext in extensions)
            {
                var x = ExtensionManager.GetExtension(ext.Key);
                var adminPage = string.IsNullOrEmpty(x.AdminPage) ?
                string.Format(Utils.RelativeWebRoot + "admin/Extensions/Settings.aspx?ext={0}&enb={1}", x.Name, x.Enabled) :
                string.Format(x.AdminPage, x.Name, x.Enabled);

                var onlineVersion = GetInstalledVersion(x.Name);
                var p = new Package
                {
                    Id = x.Name,
                    PackageType = "Extension",
                    Title = x.Name,
                    Description = x.Description,
                    LocalVersion = x.Version,
                    OnlineVersion = onlineVersion,
                    Authors = x.Author,
                    IconUrl = string.Format("{0}Content/images/blog/ext.png", Utils.ApplicationRelativeWebRoot),
                    Enabled = x.Enabled,
                    Priority = x.Priority,
                    SettingsUrl = x.Settings.Count > 0 ? adminPage : ""
                };
                if (!string.IsNullOrEmpty(onlineVersion))
                {
                    var extra = Gallery.GetPackageExtra(x.Name + "." + onlineVersion);
                    p.DownloadCount = extra.DownloadCount;
                    p.Rating = extra.Rating;
                }
                packages.Add(p);
            }
            return packages;
        }
        static Package GetPackageManifest(string id, string pkgType)
        {
            var jp = new Package { Id = id, PackageType = pkgType };

            var pkgUrl = pkgType == "Theme" ?
                string.Format("{0}Custom/Themes/{1}/theme.xml", Utils.ApplicationRelativeWebRoot, id) :
                string.Format("{0}Custom/Widgets/{1}/widget.xml", Utils.ApplicationRelativeWebRoot, id);

            var pkgPath = HttpContext.Current.Server.MapPath(pkgUrl);
            try
            {
                if (File.Exists(pkgPath))
                {
                    using (var textReader = new XmlTextReader(pkgPath))
                    {
                        textReader.Read();

                        while (textReader.Read())
                        {
                            textReader.MoveToElement();

                            if (textReader.Name == "description")
                                jp.Description = textReader.ReadString();

                            if (textReader.Name == "authors")
                                jp.Authors = textReader.ReadString();

                            if (textReader.Name == "website")
                                jp.Website = textReader.ReadString();

                            if (textReader.Name == "version")
                                jp.LocalVersion = textReader.ReadString();

                            if (textReader.Name == "iconurl")
                                jp.IconUrl = textReader.ReadString();
                        }
                        textReader.Close();
                    }
                    return jp;
                }
            }
            catch (Exception ex)
            {
                Utils.Log("Packaging.FileSystem.GetPackageManifest", ex);
            }
            return null;
        }
        static string DefaultIconUrl(Package pkg)
        {
            var validImages = new List<string> {"icon.jpg", "icon.png", "icon.gif", "screenshot.jpg", "screenshot.png", "theme.jpg", "theme.png"};
            var pkgDir = pkg.PackageType == "Widget" ? "Custom/Widgets" : "Custom/Themes";

            foreach (var img in validImages)
            {
                var url = string.Format("{0}{1}/{2}/{3}",
                Utils.ApplicationRelativeWebRoot, pkgDir, pkg.Id, img);

                url = url.Replace("/themes", "/Custom/Themes");
                url = url.Replace("/widgets", "/Custom/Widgets");

                var path = HttpContext.Current.Server.MapPath(url);

                if (File.Exists(path)) return url;
            }

            if (pkg.PackageType == "Widget")
                return Utils.ApplicationRelativeWebRoot + "Content/images/blog/Widget.png";

            return Utils.ApplicationRelativeWebRoot + "Content/images/blog/Theme.png";
        }
 public bool Update(Package item)
 {
     return true;
 }