private PackageInstallationInfo BuildPackageInfo(string updatePackageFilename)
        {
            PackageInstallationInfo installationInfo = new PackageInstallationInfo
            {
                Action = UpgradeAction.Upgrade,
                Mode   = InstallMode.Install,
                Path   = updatePackageFilename,
            };

            return(installationInfo);
        }
        public static void SetProcessingMode(this PackageInstallationInfo info)
        {
            var prop = info.GetType().GetProperty("ProcessingMode", BindingFlags.Public | BindingFlags.Instance);

            if (prop == null || !prop.CanWrite)
            {
                //Pre Sitecore 8.2 Update 2 Versions have no such property
                return;
            }

            // ProcessingMode.All = 2147483647
            prop.SetValue(info, 2147483647);
        }
 private PackageInstallationInfo GetInstallationInfo(string packagePath)
 {
     var info = new PackageInstallationInfo
     {
         Mode = InstallMode.Install,
         Action = UpgradeAction.Upgrade,
         Path = packagePath
     };
     if (string.IsNullOrEmpty(info.Path))
     {
         throw new Exception("Package is not selected.");
     }
     return info;
 }
        private PackageInstallationInfo GetInstallationInfo(string packagePath)
        {
            var info = new PackageInstallationInfo
            {
                Mode   = InstallMode.Install,
                Action = UpgradeAction.Upgrade,
                Path   = packagePath
            };

            if (string.IsNullOrEmpty(info.Path))
            {
                throw new Exception("Package is not selected.");
            }
            return(info);
        }
        /// <summary>
        /// Installs a Sitecore Update Package.
        /// </summary>
        /// <param name="path">A path to a package that is reachable by the web server</param>
        public string InstallTdsPackage(string path)
        {
            using (new ShutdownGuard())
            {
                logEntries = new List <string>();
                PackageInstallationInfo installationInfo = new PackageInstallationInfo
                {
                    Mode   = InstallMode.Update,
                    Action = UpgradeAction.Upgrade,
                    Path   = path
                };

                string historyPath = null;
                List <ContingencyEntry> entries = null;
                try
                {
                    var action = (installationInfo.Action == UpgradeAction.Preview) ? "Analyzing" : "Installing";
                    this.WriteMessage($"{action} package: {installationInfo.Path}", null, Level.INFO, false);

                    entries = UpdateHelper.Install(installationInfo, this, out historyPath);
                }
                catch (PostStepInstallerException exception)
                {
                    entries     = exception.Entries;
                    historyPath = exception.HistoryPath;
                    foreach (var entry in entries)
                    {
                        this.WriteMessage(entry.Message, exception, Level.ERROR);
                    }
                    throw exception;
                }
                finally
                {
                    //UpdateHelper.SaveInstallationMessages(entries, historyPath);
                }
                return(historyPath);
            }
        }
        public IPackageInstallInfo Install(string path)
        {
            var packageMetaData = UpdateHelper.LoadMetadata(path);

            if (packageMetaData == null)
            {
                return new PackageInstallInfo
                {
                    Error = new PackageInstallError
                    {
                        Message = "Package not found"
                    }
                };
            }

            var tracker = TrackerFactory.Create(packageMetaData.CommandsCount);
            var logger = LoggerFactory.Create(tracker);
            var packageInstallationInfo = new PackageInstallationInfo
            {
                Action = Sitecore.Update.Installer.Utils.UpgradeAction.Upgrade,
                Mode = Sitecore.Update.Utils.InstallMode.Install,
                Path = path
            };
            var historyPath = string.Empty;
            var entries = UpdateHelper.Install(packageInstallationInfo, logger, out historyPath);
            var installer = new DiffInstaller(packageInstallationInfo.Action);

            installer.ExecutePostInstallationInstructions(packageInstallationInfo.Path, historyPath, packageInstallationInfo.Mode, packageMetaData, logger, ref entries);

            ActiveTracker.Tracker = null;

            return new PackageInstallInfo
            {
                Id = historyPath,
                CommandCount = packageMetaData.CommandsCount
            };
        }
        public string InstallTdsPackage(string path)
        {
            // Use default logger
            var log = LogManager.GetLogger("root");

            XmlConfigurator.Configure((XmlElement)ConfigurationManager.GetSection("log4net"));

            using (new ShutdownGuard())
            {
                List <string>           logEntries       = new List <string>();
                PackageInstallationInfo installationInfo = new PackageInstallationInfo {
                    Mode   = InstallMode.Update,
                    Action = UpgradeAction.Upgrade,
                    Path   = path
                };

                string historyPath = null;
                List <ContingencyEntry> entries = null;
                try
                {
                    log.Info($"Installing package: {installationInfo.Path}");
                    UpdateHelper.Install(installationInfo, log, out historyPath);
                }
                catch (PostStepInstallerException exception)
                {
                    foreach (var entry in exception.Entries)
                    {
                        log.Error(entry.Message);
                    }
                    throw exception;
                }
                finally
                {
                }
                return(historyPath);
            }
        }
        /// <summary>
        /// Installs the packages found in the package source folder.
        /// </summary>
        private void InstallPackages()
        {
            //Check to see if there is a post-step pending, and skip package install if there is
            if (File.Exists(Path.Combine(_packageSource, STARTUP_POST_STEP_PACKAGE_FILENAME)))
            {
                Log.Info("Install packages skipped because there is a post step pending", this);

                return;
            }

            InstallLogger installLogger = new InstallLogger(new RootLogger(Level.ALL));

            //Return if another installation is happening
            if (_installingPackage)
            {
                Log.Info("Install packages skipped because another package is being installed.", this);

                return;
            }

            try
            {
                //Block further package installs
                _installingPackage = true;

                //Find pending packages. This loop may not complete if there were binary/config changes
                foreach (string updatePackageFilename in Directory.GetFiles(_packageSource, "*.update", SearchOption.TopDirectoryOnly))
                {
                    if (ShutdownDetected)
                    {
                        Log.Info("Install packages aborting dur to shutdown", this);

                        break;
                    }

                    //Prevent shutdown
                    using (new ShutdownGuard())
                    {
                        PackageInstallationInfo installationInfo = new PackageInstallationInfo
                        {
                            Action = UpgradeAction.Upgrade,
                            Mode = InstallMode.Install,
                            Path = updatePackageFilename
                        };

                        string installationHistoryRoot = null;
                        List<ContingencyEntry> logMessages = new List<ContingencyEntry>();

                        try
                        {
                            //Run the installer
                            logMessages = UpdateHelper.Install(installationInfo, installLogger, out installationHistoryRoot);

                            if (_updateConfigurationFiles)
                            {
                                FindAndUpdateChangedConfigs(Path.GetFileNameWithoutExtension(updatePackageFilename));
                            }

                            //Sleep for 4 seconds to see if there was a file change that could cause a problem
                            Thread.Sleep(4000);

                            //Abort if Sitecore is shutting down. The install post steps will have to be completed later
                            if (ShutdownDetected)
                            {
                                RunPostStepsAtStartup(updatePackageFilename, installationHistoryRoot);

                                RestartSitecoreServer();

                                break;
                            }
                            else
                            {
                                ExecutePostSteps(new PostStepDetails
                                {
                                    HistoryPath = installationHistoryRoot,
                                    PostStepPackageFilename = updatePackageFilename
                                });
                            }
                        }
                        catch (PostStepInstallerException ex)
                        {
                            logMessages = ex.Entries;
                            installationHistoryRoot = ex.HistoryPath;

                            throw ex;
                        }
                        catch (Exception ex)
                        {
                            Log.Error("Package install failed", ex, this);

                            ThreadPool.QueueUserWorkItem(new WaitCallback((ctx) =>
                            {
                                try
                                {
                                    //The update package may be locked because the file object hasn't been disposed. Wait for it.
                                    Thread.Sleep(100);

                                    //I really hate this, but I couldn't find another reliable way to ensure the locked file is closed before I move it.
                                    GC.Collect(2);
                                    GC.WaitForPendingFinalizers();

                                    File.Move(updatePackageFilename, updatePackageFilename + ".error_" + DateTime.Now.ToString("yyyyMMdd.hhmmss"));
                                }
                                catch(Exception ex1)
                                {
                                    Log.Error("Error moving broken package", ex1, this);
                                }
                            }));

                            break;
                        }
                        finally
                        {
                            if (installationHistoryRoot != null)
                            {
                                //Write logs
                                installLogger.WriteMessages(Path.Combine(installationHistoryRoot, "Install.log"));

                                SaveInstallationMessages(installationHistoryRoot, logMessages);
                            }
                        }
                    }
                }
            }
            finally
            {
                _installingPackage = false;
            }
        }
        /// <summary>
        /// Installs a Sitecore Update Package.
        /// </summary>
        /// <param name="path">A path to a package that is reachable by the web server</param>
        public string InstallTdsPackage(string path)
        {
            using (new ShutdownGuard())
            {
                logEntries = new List<string>();
                PackageInstallationInfo installationInfo = new PackageInstallationInfo
                {
                    Mode = InstallMode.Update,
                    Action = UpgradeAction.Upgrade,
                    Path = path
                };

                string historyPath = null;
                List<ContingencyEntry> entries = null;
                try
                {
                    var action = (installationInfo.Action == UpgradeAction.Preview) ? "Analyzing" : "Installing";
                    this.WriteMessage($"{action} package: {installationInfo.Path}", null, Level.INFO, false);

                    entries = UpdateHelper.Install(installationInfo, this, out historyPath);
                }
                catch (PostStepInstallerException exception)
                {
                    entries = exception.Entries;
                    historyPath = exception.HistoryPath;
                    foreach (var entry in entries)
                    {
                        this.WriteMessage(entry.Message, exception, Level.ERROR);
                    }
                    throw exception;
                }
                finally
                {
                    //UpdateHelper.SaveInstallationMessages(entries, historyPath);
                }
                return historyPath;
            }
        }
        public string InstallTdsPackage(string path)
        {
            // Use default logger
            var log = LogManager.GetLogger("root");
            XmlConfigurator.Configure((XmlElement)ConfigurationManager.GetSection("log4net"));

            using (new ShutdownGuard())
            {
                List<string> logEntries = new List<string>();
                PackageInstallationInfo installationInfo =  new PackageInstallationInfo {
                                                                Mode = InstallMode.Update,
                                                                Action = UpgradeAction.Upgrade,
                                                                Path = path
                                                            };

                string historyPath = null;
                List<ContingencyEntry> entries = null;
                try
                {
                    log.Info($"Installing package: {installationInfo.Path}");
                    UpdateHelper.Install(installationInfo, log, out historyPath);
                }
                catch (PostStepInstallerException exception)
                {
                    foreach (var entry in exception.Entries)
                    {
                        log.Error(entry.Message);
                    }
                    throw exception;
                }
                finally
                {
                }
                return historyPath;
            }
        }
示例#11
0
        public IPackageInstallInfo Install(string path)
        {
            var packageMetaData = UpdateHelper.LoadMetadata(path);

            if (packageMetaData == null)
            {
                return(new PackageInstallInfo
                {
                    Error = new PackageInstallError
                    {
                        Message = "Package not found"
                    }
                });
            }

            var tracker = TrackerFactory.Create(packageMetaData.CommandsCount);
            var logger  = LoggerFactory.Create(tracker);

            try
            {
                logger.Info(string.Format("Beginning update package installation: {0}", path));

                var packageInstallationInfo = new PackageInstallationInfo
                {
                    Action = Sitecore.Update.Installer.Utils.UpgradeAction.Upgrade,
                    Mode   = Sitecore.Update.Utils.InstallMode.Install,
                    Path   = path
                };
                var historyPath = string.Empty;
                var entries     = UpdateHelper.Install(packageInstallationInfo, logger, out historyPath);
                var installer   = new DiffInstaller(packageInstallationInfo.Action);

                using (new SecurityDisabler())
                {
                    installer.ExecutePostInstallationInstructions(packageInstallationInfo.Path, historyPath,
                                                                  packageInstallationInfo.Mode, packageMetaData, logger, ref entries);
                }

                ActiveTracker.Tracker = null;

                logger.Info(string.Format("Completed update package installation: {0}", path));

                return(new PackageInstallInfo
                {
                    Id = historyPath,
                    CommandCount = packageMetaData.CommandsCount
                });
            }
            catch (ThreadAbortException ex)
            {
                logger.Error("Update package installation failed.  The application's execution timeout may have been exceeded.  Update /configuration/system.web/httpRuntime/@executionTimeout to increase the timeout.", ex);

                return(new PackageInstallInfo
                {
                    Error = new PackageInstallError
                    {
                        Message = "Installation failed.  The application's execution timeout may have been exceeded.  Check the Sitecore log for details."
                    }
                });
            }
            catch (Exception ex)
            {
                logger.Error(string.Format("Update package installation failed: {0}", path), ex);

                return(new PackageInstallInfo
                {
                    Error = new PackageInstallError
                    {
                        Message = "Installation failed.  Check the Sitecore log for details."
                    }
                });
            }
            finally
            {
                ActiveTracker.Tracker = null;
            }
        }