InstallPackage() публичный статический Метод

Copy uncompressed package files to application directories
public static InstallPackage ( string pkgId, string version ) : List
pkgId string Package Id
version string Package Version
Результат List
Пример #1
0
        /// <summary>
        /// Install package
        /// </summary>
        /// <param name="pkgId"></param>
        public static JsonResponse InstallPackage(string pkgId)
        {
            try
            {
                if (BlogService.InstalledFromGalleryPackages() != null &&
                    BlogService.InstalledFromGalleryPackages().Find(p => p.PackageId == pkgId) != null)
                {
                    UninstallPackage(pkgId);
                }

                var packageManager = new PackageManager(
                    _repository,
                    new DefaultPackagePathResolver(BlogSettings.Instance.GalleryFeedUrl),
                    new PhysicalFileSystem(HttpContext.Current.Server.MapPath(Utils.ApplicationRelativeWebRoot + "App_Data/packages"))
                    );

                var package = _repository.FindPackage(pkgId);

                packageManager.InstallPackage(package, false, true);

                var iPkg = new InstalledPackage {
                    PackageId = package.Id, Version = package.Version.ToString()
                };
                BlogService.InsertPackage(iPkg);

                var packageFiles = FileSystem.InstallPackage(package.Id, package.Version.ToString());
                BlogService.InsertPackageFiles(packageFiles);

                Blog.CurrentInstance.Cache.Remove(Constants.CacheKey);

                Utils.Log(string.Format("Installed package {0} by {1}", pkgId, Security.CurrentUser.Identity.Name));
            }
            catch (Exception ex)
            {
                Utils.Log("BlogEngine.Core.Packaging.Installer.InstallPackage(" + pkgId + ")", ex);
                try
                {
                    UninstallPackage(pkgId);
                }
                catch (Exception)
                {
                    // just trying to clean up if package did not installed properly
                }
                return(new JsonResponse {
                    Success = false, Message = "Error installing package, see logs for details"
                });
            }

            return(new JsonResponse {
                Success = true, Message = "Package successfully installed"
            });
        }
Пример #2
0
        /// <summary>
        /// Install package
        /// </summary>
        /// <param name="pkgId"></param>
        public static bool InstallPackage(string pkgId)
        {
            try
            {
                // if package already installed - uninstall it
                if (BlogService.InstalledFromGalleryPackages() != null)
                {
                    if (BlogService.InstalledFromGalleryPackages().Find(p => p.PackageId == pkgId) != null)
                    {
                        UninstallPackage(pkgId);
                    }
                }

                var packageManager = new PackageManager(_repository,
                                                        new DefaultPackagePathResolver(BlogConfig.GalleryFeedUrl),
                                                        new PhysicalFileSystem(HttpContext.Current.Server.MapPath(Utils.ApplicationRelativeWebRoot + "App_Data/packages"))
                                                        );

                var package = _repository.FindPackage(pkgId);

                packageManager.InstallPackage(package, false, true);

                var iPkg = new InstalledPackage {
                    PackageId = package.Id, Version = package.Version.ToString()
                };
                BlogService.InsertPackage(iPkg);

                var packageFiles = FileSystem.InstallPackage(package);

                BlogService.InsertPackageFiles(packageFiles);

                Blog.CurrentInstance.Cache.Remove(Constants.CacheKey);

                CustomFieldsParser.ClearCache();

                Utils.Log($"Installed package {pkgId} by {Security.CurrentUser.Identity.Name}");
            }
            catch (Exception ex)
            {
                Utils.Log("BlogEngine.Core.Packaging.Installer.InstallPackage(" + pkgId + ")", ex);
                UninstallPackage(pkgId);
                throw;
            }

            return(true);
        }