BlogEngine.Core.Packaging.FileSystem.InstallPackage C# (CSharp) Method

InstallPackage() public static method

Copy uncompressed package files to application directories
public static InstallPackage ( string pkgId, string version ) : List
pkgId string Package Id
version string Package Version
return List
        public static List<PackageFile> InstallPackage(string pkgId, string version)
        {
            var packgeFiles = new List<PackageFile>();

            var content = HttpContext.Current.Server.MapPath(Utils.ApplicationRelativeWebRoot +
                string.Format("App_Data/packages/{0}.{1}/content", pkgId, version));

            var lib = HttpContext.Current.Server.MapPath(Utils.ApplicationRelativeWebRoot +
                string.Format("App_Data/packages/{0}.{1}/lib", pkgId, version));

            var root = HttpContext.Current.Server.MapPath(Utils.ApplicationRelativeWebRoot);
            var bin = HttpContext.Current.Server.MapPath(Utils.ApplicationRelativeWebRoot + "bin");

            // copy content files
            var source = new DirectoryInfo(content);
            var target = new DirectoryInfo(root);

            fileOrder = 0;
            CopyDirectory(source, target, pkgId, packgeFiles);

            // copy DLLs from lib to bin
            if (Directory.Exists(lib))
            {
                source = new DirectoryInfo(lib);
                target = new DirectoryInfo(bin);

                fileOrder = 0;
                CopyDirectory(source, target, pkgId, packgeFiles);
            }

            return packgeFiles;
        }

Usage Example

Example #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"
            });
        }
All Usage Examples Of BlogEngine.Core.Packaging.FileSystem::InstallPackage