Ejemplo n.º 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"
            });
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 3
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(string.Format("Installed package {0} by {1}", pkgId, Security.CurrentUser.Identity.Name));
            }
            catch (Exception ex)
            {
                Utils.Log("BlogEngine.Core.Packaging.Installer.InstallPackage(" + pkgId + ")", ex);
                UninstallPackage(pkgId);
                throw;
            }

            return true;
        }
Ejemplo n.º 4
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" };
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Log of all installed packages
        /// </summary>
        /// <param name="package">Intalled package</param>
        public override void SavePackage(InstalledPackage package)
        {
            var fileName = Path.Combine(dataFolder, Constants.InstalledPackagesXml);
            
            var packages = FillPackages() ?? new List<InstalledPackage>();
            int pkgIndex = -1;

            for (int index = 0; index < packages.Count; index++)
            {
                var p = packages[index];
                if (p.PackageId == package.PackageId)
                {
                    pkgIndex = index;
                    break;
                }
            }

            if(pkgIndex >= 0)
                packages.RemoveAt(pkgIndex);

            packages.Add(package);

            using (var writer = new XmlTextWriter(fileName, Encoding.UTF8))
            {
                writer.Formatting = Formatting.Indented;
                writer.Indentation = 4;
                writer.WriteStartDocument(true);
                writer.WriteStartElement("InstalledPackages");

                foreach (var p in packages)
                {
                    writer.WriteStartElement("item");
                    writer.WriteAttributeString("id", p.PackageId);
                    writer.WriteAttributeString("version", p.Version);
                    writer.WriteEndElement();
                }
                    
                writer.WriteEndElement();
            }

        }
        /// <summary>
        /// Gets all installed from gallery packages
        /// </summary>
        /// <returns>List of installed packages</returns>
        public override List<InstalledPackage> FillPackages()
        {
            var packages = new List<InstalledPackage>();

            using (var conn = this.CreateConnection())
            {
                if (conn.HasConnection)
                {
                    using (var cmd = conn.CreateTextCommand(string.Format("SELECT PackageId, Version FROM {0}Packages ", tablePrefix)))
                    {
                        using (var rdr = cmd.ExecuteReader())
                        {
                            while (rdr.Read())
                            {
                                var p = new InstalledPackage()
                                {
                                    PackageId = rdr.GetString(0),
                                    Version = rdr.GetString(1)
                                };

                                packages.Add(p);
                            }
                        }
                    }
                }
            }

            return packages;
        }
        /// <summary>
        /// Log of all installed packages
        /// </summary>
        /// <param name="package">Intalled package</param>
        public override void SavePackage(InstalledPackage package)
        {
            using (var conn = CreateConnection())
            {
                if (conn.HasConnection)
                {
                    var sqlQuery = string.Format("INSERT INTO {0}Packages (PackageId, Version) VALUES ({1}PackageId, {1}Version)", this.tablePrefix, this.parmPrefix);

                    using (var cmd = conn.CreateTextCommand(sqlQuery))
                    {
                        var parms = cmd.Parameters;
                        parms.Add(conn.CreateParameter(FormatParamName("PackageId"), package.PackageId));
                        parms.Add(conn.CreateParameter(FormatParamName("Version"), package.Version));
 
                        cmd.ExecuteNonQuery();
                    }
                }
            }
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Save installed gallery package
 /// </summary>
 /// <param name="package">Installed package</param>
 public static void InsertPackage(InstalledPackage package)
 {
     Provider.SavePackage(package);
 }