protected override void ProcessRecord()
        {
            // Use default logger
            var log = LogManager.GetLogger("root");

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

            if (ShouldProcess(Path, "Install update package"))
            {
                PerformInstallAction(
                    () =>
                {
                    var installer = new DiffInstaller(UpgradeAction);
                    var view      = UpdateHelper.LoadMetadata(Path);

                    bool hasPostAction;
                    string historyPath;
                    var entries = new List <ContingencyEntry>();
                    entries     = installer.InstallPackage(Path, InstallMode, log, entries, out hasPostAction,
                                                           out historyPath);
                    installer.ExecutePostInstallationInstructions(Path, historyPath, InstallMode, view, log,
                                                                  ref entries);
                    foreach (var entry in entries)
                    {
                        WriteObject(entry);
                    }
                    //UpdateHelper.SaveInstallationMessages(entries, historyPath);
                });
            }
        }
        public void InstallPackage(string path)
        {
            bool   hasPostAction;
            string historyPath;

            // Use default logger
            ILog log = LogManager.GetLogger("root");

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

            using (new SecurityDisabler())
            {
                DiffInstaller installer = new DiffInstaller(UpgradeAction.Upgrade);
                MetadataView  view      = UpdateHelper.LoadMetadata(path);

                //Get the package entries
                List <ContingencyEntry> entries = installer.InstallPackage(path, InstallMode.Install, log, out hasPostAction, out historyPath);

                installer.ExecutePostInstallationInstructions(path, historyPath, InstallMode.Install, view, log, ref entries);

#if SITECORE_6X
                UpdateHelper.SaveInstallationMessages(entries, historyPath);
#endif
            }
        }
        /// <summary>
        /// Executes the post install steps
        /// </summary>
        /// <param name="postStepDetails"></param>
        internal static void ExecutePostSteps(InstallLogger installLogger, PostStepDetails postStepDetails)
        {
            try
            {
                SetInstallerState(InstallerState.InstallingPostSteps);

                //Load the metadata from the update package
                MetadataView            metedateView = UpdateHelper.LoadMetadata(postStepDetails.PostStepPackageFilename);
                List <ContingencyEntry> logMessages  = new List <ContingencyEntry>();

                try
                {
                    //Execute the post install steps
                    DiffInstaller diffInstaller = new DiffInstaller(UpgradeAction.Upgrade);
                    diffInstaller.ExecutePostInstallationInstructions(postStepDetails.PostStepPackageFilename, postStepDetails.HistoryPath, InstallMode.Update, metedateView, installLogger, ref logMessages);
                }
                finally
                {
                    //Move the update package into the history folder
                    File.Move(postStepDetails.PostStepPackageFilename, Path.Combine(postStepDetails.HistoryPath, Path.GetFileName(postStepDetails.PostStepPackageFilename)));
                }
            }
            catch (Exception ex)
            {
                Log.Fatal("Post step execution failed", ex, "InstallPackage");

                installLogger.Fatal("Post step execution failed", ex);

                throw;
            }
            finally
            {
                SetInstallerState(InstallerState.Ready);
            }
        }
        protected override void ProcessRecord()
        {
            // Use default logger
            var log = LogManager.GetLogger("root");
            XmlConfigurator.Configure((XmlElement) ConfigurationManager.GetSection("log4net"));

            if (ShouldProcess(Path, "Install update package"))
            {
                PerformInstallAction(
                    () =>
                    {
                        var installer = new DiffInstaller(UpgradeAction);
                        var view = UpdateHelper.LoadMetadata(Path);

                        bool hasPostAction;
                        string historyPath;
                        var entries = new List<ContingencyEntry>();
                        entries = installer.InstallPackage(Path, InstallMode, log, entries, out hasPostAction,
                            out historyPath);
                        installer.ExecutePostInstallationInstructions(Path, historyPath, InstallMode, view, log,
                            ref entries);
                        foreach (var entry in entries)
                        {
                            WriteObject(entry);
                        }
                        //UpdateHelper.SaveInstallationMessages(entries, historyPath);
                    });
            }
        }
 public void InstallPackage(string path)
 {
     using (new SecurityDisabler())
     {
         var installer = new DiffInstaller(UpgradeAction.Upgrade);
         var view = UpdateHelper.LoadMetadata(path);
         string historyPath;
         bool hasPostAction;
         var entries = installer.InstallPackage(path, InstallMode.Install, null, out hasPostAction, out historyPath);
         installer.ExecutePostInstallationInstructions(path, historyPath, InstallMode.Install, view, null, ref entries);
         UpdateHelper.SaveInstallationMessages(entries, historyPath);
     }
 }
        public List <InstalledItems> installSitecoreUpdatePackage(string path)
        {
            checkFile(path);

            using (new SecurityDisabler())
            {
                var installer = new DiffInstaller(UpgradeAction.Upgrade);
                var view      = UpdateHelper.LoadMetadata(path);

                //Get the package entries
                bool   hasPostAction;
                string historyPath;
                try
                {
                    var entries = installer.InstallPackage(path, InstallMode.Install, log(), out hasPostAction,
                                                           out historyPath);

                    installer.ExecutePostInstallationInstructions(path, historyPath, InstallMode.Install, view, log(),
                                                                  ref entries);


                    var installedItems = new List <InstalledItems>();
                    installedItems =
                        entries.Select(
                            x =>
                            new InstalledItems
                    {
                        Action      = x.Action,
                        ItemPath    = _split(x.LongDescription, "Item path"),
                        ItemGUID    = _split(x.LongDescription, "Item ID"),
                        MessageType = x.MessageGroupDescription
                    }).ToList();


                    return(installedItems);
                }
                catch (PostStepInstallerException exception)
                {
                    foreach (var entry in exception.Entries)
                    {
                        log().Info(entry.Message);
                    }
                    throw exception;
                }
            }
        }
        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
            };
        }
        /// <summary>
        /// Executes the post install steps
        /// </summary>
        /// <param name="postStepDetails"></param>
        internal static void ExecutePostSteps(PostStepDetails postStepDetails)
        {
            InstallLogger installLogger = new InstallLogger(new RootLogger(Level.ALL));

            try
            {
                //Load the metadata from the update package
                MetadataView metedateView = UpdateHelper.LoadMetadata(postStepDetails.PostStepPackageFilename);
                List<ContingencyEntry> logMessages = new List<ContingencyEntry>();

                //Execute the post install steps
                DiffInstaller diffInstaller = new DiffInstaller(UpgradeAction.Upgrade);
                diffInstaller.ExecutePostInstallationInstructions(postStepDetails.PostStepPackageFilename, postStepDetails.HistoryPath, InstallMode.Update, metedateView, installLogger, ref logMessages);

                //Move the update package into the history folder
                File.Move(postStepDetails.PostStepPackageFilename, Path.Combine(postStepDetails.HistoryPath, Path.GetFileName(postStepDetails.PostStepPackageFilename)));
            }
            catch (Exception ex)
            {
                Log.Fatal("Post step execution failed", ex, "InstallPackage");
            }
            finally
            {
                //Write logs
                installLogger.WriteMessages(Path.Combine(postStepDetails.HistoryPath, "Install.log"));
            }
        }
        public PackageManifest Execute(string packagePath, bool disableIndexing)
        {
            if (!File.Exists(packagePath))
            {
                throw new NotFoundException();
            }

            using (new ShutdownGuard())
            {
                if (disableIndexing)
                {
                    Sitecore.Configuration.Settings.Indexing.Enabled = false;
                }

                var    installationInfo         = GetInstallationInfo(packagePath);
                string historyPath              = null;
                List <ContingencyEntry> entries = null;

                var logger = Sitecore.Diagnostics.LoggerFactory.GetLogger(this); // TODO abstractions
                try
                {
                    entries = UpdateHelper.Install(installationInfo, logger, out historyPath);

                    string error = string.Empty;

                    logger.Info("Executing post installation actions.");

                    MetadataView metadata = PreviewMetadataWizardPage.GetMetadata(packagePath, out error);

                    if (string.IsNullOrEmpty(error))
                    {
                        DiffInstaller diffInstaller = new DiffInstaller(UpgradeAction.Upgrade);
                        using (new SecurityDisabler())
                        {
                            diffInstaller.ExecutePostInstallationInstructions(packagePath, historyPath, installationInfo.Mode, metadata, logger, ref entries);
                        }
                    }
                    else
                    {
                        logger.Info("Post installation actions error.");
                        logger.Error(error);
                    }

                    logger.Info("Executing post installation actions finished.");

                    return(_manifestRepository.GetManifest(packagePath));
                }
                catch (PostStepInstallerException exception)
                {
                    entries     = exception.Entries;
                    historyPath = exception.HistoryPath;
                    throw;
                }
                finally
                {
                    if (disableIndexing)
                    {
                        Sitecore.Configuration.Settings.Indexing.Enabled = true;
                    }

                    try
                    {
                        SaveInstallationMessages(entries, historyPath);
                    }
                    catch (Exception)
                    {
                        logger.Error("Failed to record installation messages");
                        foreach (var entry in entries ?? Enumerable.Empty <ContingencyEntry>())
                        {
                            logger.Info(string.Format("Entry [{0}]-[{1}]-[{2}]-[{3}]-[{4}]-[{5}]-[{6}]-[{7}]-[{8}]-[{9}]-[{10}]-[{11}]",
                                                      entry.Action,
                                                      entry.Behavior,
                                                      entry.CommandKey,
                                                      entry.Database,
                                                      entry.Level,
                                                      entry.LongDescription,
                                                      entry.MessageGroup,
                                                      entry.MessageGroupDescription,
                                                      entry.MessageID,
                                                      entry.MessageType,
                                                      entry.Number,
                                                      entry.ShortDescription));
                        }
                        throw;
                    }
                }
            }
        }
예제 #10
0
        public PackageManifest Execute(string packagePath, bool disableIndexing)
        {
            if (!File.Exists(packagePath)) throw new NotFoundException();

            using (new ShutdownGuard())
            {
                if (disableIndexing)
                {
                    Sitecore.Configuration.Settings.Indexing.Enabled = false;
                }

                var installationInfo = GetInstallationInfo(packagePath);
                string historyPath = null;
                List<ContingencyEntry> entries = null;

                var logger = Sitecore.Diagnostics.LoggerFactory.GetLogger(this); // TODO abstractions
                try
                {
                    entries = UpdateHelper.Install(installationInfo, logger, out historyPath);

                    string error = string.Empty;

                    logger.Info("Executing post installation actions.");

                    MetadataView metadata = PreviewMetadataWizardPage.GetMetadata(packagePath, out error);

                    if (string.IsNullOrEmpty(error))
                    {
                        DiffInstaller diffInstaller = new DiffInstaller(UpgradeAction.Upgrade);
                        using (new SecurityDisabler())
                        {
                            diffInstaller.ExecutePostInstallationInstructions(packagePath, historyPath, installationInfo.Mode, metadata, logger, ref entries);
                        }
                    }
                    else
                    {
                        logger.Info("Post installation actions error.");
                        logger.Error(error);
                    }

                    logger.Info("Executing post installation actions finished.");

                    return _manifestRepository.GetManifest(packagePath);

                }
                catch (PostStepInstallerException exception)
                {
                    entries = exception.Entries;
                    historyPath = exception.HistoryPath;
                    throw;
                }
                finally
                {
                    if (disableIndexing)
                    {
                        Sitecore.Configuration.Settings.Indexing.Enabled = true;
                    }

                    try
                    {
                        SaveInstallationMessages(entries, historyPath);
                    }
                    catch (Exception)
                    {
                        logger.Error("Failed to record installation messages");
                        foreach (var entry in entries ?? Enumerable.Empty<ContingencyEntry>())
                        {
                            logger.Info(string.Format("Entry [{0}]-[{1}]-[{2}]-[{3}]-[{4}]-[{5}]-[{6}]-[{7}]-[{8}]-[{9}]-[{10}]-[{11}]",
                                entry.Action,
                                entry.Behavior,
                                entry.CommandKey,
                                entry.Database,
                                entry.Level,
                                entry.LongDescription,
                                entry.MessageGroup,
                                entry.MessageGroupDescription,
                                entry.MessageID,
                                entry.MessageType,
                                entry.Number,
                                entry.ShortDescription));
                        }
                        throw;
                    }
                }
            }
        }
예제 #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;
            }
        }