BlogEngine.Core.Packaging.PackageRepository.GetPackage C# (CSharp) Method

GetPackage() public static method

Package by ID
public static GetPackage ( string pkgId ) : JsonPackage
pkgId string Package ID
return BlogEngine.Core.Json.JsonPackage
        public static JsonPackage GetPackage(string pkgId)
        {
            return CachedPackages.FirstOrDefault(pkg => pkg.Id == pkgId);
        }

Usage Example

Esempio n. 1
0
        /// <summary>
        /// Remove package files
        /// </summary>
        /// <param name="pkgId">Package Id</param>
        public static void UninstallPackage(string pkgId)
        {
            var installedFiles = BlogService.InstalledFromGalleryPackageFiles(pkgId);
            var pkg            = PackageRepository.GetPackage(pkgId);

            foreach (var file in installedFiles.OrderByDescending(f => f.FileOrder))
            {
                var fullPath = HttpContext.Current.Server.MapPath(Path.Combine(Utils.RelativeWebRoot, file.FilePath));

                if (file.IsDirectory)
                {
                    var folder = new DirectoryInfo(fullPath);
                    if (folder.Exists)
                    {
                        if (folder.GetFileSystemInfos().Length == 0)
                        {
                            ForceDeleteDirectory(fullPath);
                        }
                        else
                        {
                            Utils.Log(string.Format("Package Uninstaller: can not remove directory if it is not empty ({0})", fullPath));
                        }
                    }
                }
                else if (File.Exists(fullPath))
                {
                    File.Delete(fullPath);
                }
            }

            if (!string.IsNullOrWhiteSpace(pkg.LocalVersion))
            {
                var pkgDir = string.Format("{0}.{1}", pkgId, pkg.LocalVersion);

                // clean up removing installed version
                pkgDir = HttpContext.Current.Server.MapPath(string.Format("{0}App_Data/packages/{1}", Utils.ApplicationRelativeWebRoot, pkgDir));
                if (Directory.Exists(pkgDir))
                {
                    ForceDeleteDirectory(pkgDir);
                }
            }
        }