/// <summary>
        /// The uCommerce post installation step.
        /// </summary>
        /// <remarks>
        /// There is a race condition between upgrading the database and upgrading the binaries. :-(
        ///
        /// Upgrade the database first, and the old binaries might not work with the new database.
        /// Upgrade the binaries first, and the new binaries might not work with the old database.
        ///
        /// We have one observation indicating a failed installation because the new binaries was
        /// activated before the database scripts were done, resulting in a broken system.
        ///
        /// The problem is probably going to grow, as more database migrations are added.
        ///
        /// We have chosen to upgrade the database first.
        /// This is because the database upgrade takes a long time in the clean scenario, but is
        /// relatively faster in upgrade scenarios.
        ///
        /// So for clean installs there are no old binaries, so the race condition is void.
        /// - Jesper
        /// </remarks>
        public PostInstallationStep()
        {
            var sitecoreInstallerLoggingService = new SitecoreInstallerLoggingService();
            IDatabaseAvailabilityService sitefinityDatabaseAvailabilityService =
                new SitecoreDatabaseAvailabilityService();
            var installationConnectionStringLocator = new SitecoreInstallationConnectionStringLocator();
            var runtimeVersionChecker =
                new RuntimeVersionChecker(installationConnectionStringLocator, sitecoreInstallerLoggingService);
            var updateService = new UpdateService(installationConnectionStringLocator, runtimeVersionChecker,
                                                  sitefinityDatabaseAvailabilityService);
            var sitecoreVersionChecker = new SitecoreVersionChecker();

            _postInstallationSteps = new List <IPostStep>();

            _postInstallationSteps.Add(new SitecorePreRequisitesChecker());
            _postInstallationSteps.Add(new InitializeObjectFactory());
            _postInstallationSteps.Add(new InstallDatabase("~/sitecore modules/Shell/ucommerce/install"));
            _postInstallationSteps.Add(new InstallDatabaseSitecore("~/sitecore modules/Shell/ucommerce/install"));
            _postInstallationSteps.Add(new UpdateUCommerceAssemblyVersionInDatabase(updateService,
                                                                                    runtimeVersionChecker, sitecoreInstallerLoggingService));

            _postInstallationSteps.Add(new CopyFile(sourceVirtualPath: "~/web.config",
                                                    targetVirtualPath: "~/web.config.{DateTime.Now.Ticks}.backup"));
            _postInstallationSteps.Add(new SitecoreWebconfigMerger(sitecoreVersionChecker));
            _postInstallationSteps.Add(new SeperateConfigSectionInNewFile("configuration/sitecore/settings",
                                                                          "~/web.config", "~/App_Config/Include/.Sitecore.Settings.config"));
            _postInstallationSteps.Add(new MoveDirectory("~/sitecore modules/shell/ucommerce/install/binaries",
                                                         "~/bin/uCommerce", overwriteTarget: true));

            _postInstallationSteps.Add(new DeleteFile("~/bin/ucommerce/Ucommerce.Installer.dll"));

            // Remove old UCommerce.Transactions.Payment.dll from /bin since payment methods have been moved to Apps.
            _postInstallationSteps.Add(new DeleteFile("~/bin/Ucommerce.Transactions.Payments.dll"));
            // Remove ServiceStack folder
            _postInstallationSteps.Add(new DeleteDirectory("~/sitecore modules/Shell/Ucommerce/Apps/ServiceStack"));

            // Remove RavenDB apps (in V9 Raven has been replaced by Lucene)
            _postInstallationSteps.Add(new DeleteDirectory("~/sitecore modules/Shell/Ucommerce/Apps/RavenDB25"));
            _postInstallationSteps.Add(
                new DeleteDirectory("~/sitecore modules/Shell/Ucommerce/Apps/RavenDB25.disabled"));
            _postInstallationSteps.Add(new DeleteDirectory("~/sitecore modules/Shell/Ucommerce/Apps/RavenDB30"));
            _postInstallationSteps.Add(
                new DeleteDirectory("~/sitecore modules/Shell/Ucommerce/Apps/RavenDB30.disabled"));
            // Enable ExchangeRateAPICurrencyConversion app
            _postInstallationSteps.Add(new MoveDirectory(
                                           "~/sitecore modules/Shell/Ucommerce/Apps/ExchangeRateAPICurrencyConversion.disabled",
                                           "~/sitecore modules/Shell/Ucommerce/Apps/ExchangeRateAPICurrencyConversion", true));

            // Remove Catalogs app since it was moved into Core
            _postInstallationSteps.Add(new DeleteDirectory("~/sitecore modules/Shell/Ucommerce/Apps/Catalogs"));
            _postInstallationSteps.Add(
                new DeleteDirectory("~/sitecore modules/Shell/Ucommerce/Apps/Catalogs.disabled"));
            _postInstallationSteps.Add(
                new EnableSitecoreCompatibilityApp(sitecoreVersionChecker, sitecoreInstallerLoggingService));

            // Remove CatalogSearch widget
            _postInstallationSteps.Add(
                new DeleteDirectory("~/sitecore modules/Shell/Ucommerce/Apps/Widgets/CatalogSearch"));
            _postInstallationSteps.Add(
                new DeleteDirectory("~/sitecore modules/Shell/Ucommerce/Apps/Widgets/CatalogSearch.disabled"));

            // Enable Sanitization app
            _postInstallationSteps.Add(new MoveDirectory(
                                           "~/sitecore modules/Shell/Ucommerce/Apps/Sanitization.disabled",
                                           "~/sitecore modules/Shell/Ucommerce/Apps/Sanitization", true));

            //Clean up unused configuration since payment integration has move to apps
            _postInstallationSteps.Add(
                new DeleteFile("~/sitecore modules/shell/ucommerce/Configuration/Payments.config"));

            _postInstallationSteps.Add(new MoveUcommerceBinaries());
            _postInstallationSteps.Add(new MoveResourceFiles());

            ComposeConfiguration();
            ComposePipelineConfiguration();
            _postInstallationSteps.Add(
                new RenameConfigDefaultFilesToConfigFilesStep("~/sitecore modules/Shell/uCommerce/Apps", false));
            _postInstallationSteps.Add(new MoveDirectoryIfTargetExist(
                                           "~/sitecore modules/Shell/uCommerce/Apps/SimpleInventory.disabled",
                                           "~/sitecore modules/Shell/uCommerce/Apps/SimpleInventory"));
            _postInstallationSteps.Add(new MoveDirectoryIfTargetExist(
                                           "~/sitecore modules/Shell/uCommerce/Apps/Acquire and Cancel Payments.disabled",
                                           "~/sitecore modules/Shell/uCommerce/Apps/Acquire and Cancel Payments"));
            //Create back up and remove old files
            RemovedRenamedPipelines();

            _postInstallationSteps.Add(new CreateApplicationShortcuts());
            _postInstallationSteps.Add(new CreateSpeakApplicationIfSupported(sitecoreVersionChecker));

            // Move sitecore config includes into the right path
            ComposeMoveSitecoreConfigIncludes(sitecoreVersionChecker);

            _postInstallationSteps.Add(new MigrateIdTableValues());
        }
        private void ComposeMoveSitecoreConfigIncludes(SitecoreVersionChecker versionChecker)
        {
            _postInstallationSteps.Add(new MoveFile(
                                           "~/sitecore modules/Shell/ucommerce/install/configInclude/Sitecore.uCommerce.Databases.config",
                                           "~/App_Config/include/Sitecore.uCommerce.Databases.config",
                                           backupTarget: true));

            _postInstallationSteps.Add(new MoveFile(
                                           "~/sitecore modules/Shell/ucommerce/install/configInclude/Sitecore.uCommerce.Dataproviders.config",
                                           "~/App_Config/include/Sitecore.uCommerce.Dataproviders.config",
                                           backupTarget: true));

            _postInstallationSteps.Add(new MoveFile(
                                           "~/sitecore modules/Shell/ucommerce/install/configInclude/Sitecore.uCommerce.Events.config",
                                           "~/App_Config/include/Sitecore.uCommerce.Events.config",
                                           backupTarget: true));

            _postInstallationSteps.Add(new MoveFile(
                                           "~/sitecore modules/Shell/ucommerce/install/configInclude/Sitecore.uCommerce.IdTable.config",
                                           "~/App_Config/include/Sitecore.uCommerce.IdTable.config",
                                           backupTarget: true));

            _postInstallationSteps.Add(new MoveFile(
                                           "~/sitecore modules/Shell/ucommerce/install/configInclude/Sitecore.uCommerce.Sites.config",
                                           "~/App_Config/include/Sitecore.uCommerce.Sites.config",
                                           backupTarget: true));

            _postInstallationSteps.Add(new MoveFile(
                                           "~/sitecore modules/Shell/ucommerce/install/configInclude/Sitecore.uCommerce.Pipelines.getItemPersonalizationVisibility.config",
                                           "~/App_Config/include/Sitecore.uCommerce.Pipelines.getItemPersonalizationVisibility.config",
                                           backupTarget: true));

            if (versionChecker.IsEqualOrGreaterThan(new Version(9, 3)))
            {
                _postInstallationSteps.Add(new MoveFile(
                                               "~/sitecore modules/Shell/ucommerce/install/configInclude/Sitecore.uCommerce.Pipelines.HttpRequestBegin.9.3.config",
                                               "~/App_Config/include/Sitecore.uCommerce.Pipelines.HttpRequestBegin.config",
                                               backupTarget: true));
            }
            else
            {
                _postInstallationSteps.Add(new MoveFile(
                                               "~/sitecore modules/Shell/ucommerce/install/configInclude/Sitecore.uCommerce.Pipelines.HttpRequestBegin.config",
                                               "~/App_Config/include/Sitecore.uCommerce.Pipelines.HttpRequestBegin.config",
                                               backupTarget: true));
            }

            if (versionChecker.IsEqualOrGreaterThan(new Version(9, 1)))
            {
                _postInstallationSteps.Add(new MoveFile(
                                               "~/sitecore modules/Shell/ucommerce/install/configInclude/Sitecore.uCommerce.Pipelines.PreProcessRequest.9.1.config",
                                               "~/App_Config/include/Sitecore.uCommerce.Pipelines.PreProcessRequest.config",
                                               backupTarget: true));
            }
            else
            {
                _postInstallationSteps.Add(new MoveFile(
                                               "~/sitecore modules/Shell/ucommerce/install/configInclude/Sitecore.uCommerce.Pipelines.PreProcessRequest.config",
                                               "~/App_Config/include/Sitecore.uCommerce.Pipelines.PreProcessRequest.config",
                                               backupTarget: true));
            }

            _postInstallationSteps.Add(new MoveFile(
                                           "~/sitecore modules/Shell/ucommerce/install/configInclude/Sitecore.uCommerce.Settings.config",
                                           "~/App_Config/include/Sitecore.uCommerce.Settings.config",
                                           backupTarget: true));

            _postInstallationSteps.Add(new MoveFile(
                                           "~/sitecore modules/Shell/ucommerce/install/configInclude/Sitecore.uCommerce.Pipelines.ModifyPipelines.config.disabled",
                                           "~/App_Config/include/Sitecore.uCommerce.Pipelines.ModifyPipelines.config.disabled",
                                           backupTarget: true));

            _postInstallationSteps.Add(new MoveFileIfTargetExist(
                                           "~/App_Config/include/Sitecore.uCommerce.Pipelines.ModifyPipelines.config.disabled",
                                           "~/App_Config/include/Sitecore.uCommerce.Pipelines.ModifyPipelines.config",
                                           backupTarget: true));

            if (versionChecker.IsLowerThan(new Version(8, 2)))
            {
                _postInstallationSteps.Add(new MoveFile(
                                               "~/sitecore modules/Shell/ucommerce/install/configInclude/Sitecore.uCommerce.WebApiConfiguration.config.disabled",
                                               "~/App_Config/include/Sitecore.uCommerce.WebApiConfiguration.config",
                                               backupTarget: true));
            }

            _postInstallationSteps.Add(new MoveFile(
                                           "~/sitecore modules/Shell/ucommerce/install/configInclude/Sitecore.uCommerce.initialize.config",
                                           "~/App_Config/include/Sitecore.uCommerce.initialize.config",
                                           backupTarget: true));

            _postInstallationSteps.Add(new MoveFile(
                                           "~/sitecore modules/Shell/ucommerce/install/configInclude/Sitecore.uCommerce.Log4net.config",
                                           "~/App_Config/include/Sitecore.uCommerce.Log4net.config",
                                           backupTarget: true));
        }