public void undeploy(bool isUninstall = false)
        {
            if (this.Deployment == null)
            {
                return;
            }

            var    strategy = this.Deployment.installedApplicationSettings.GetApplicationMountStrategy();
            string basePath = UtilsSystem.CombinePaths(this.GlobalSettings.GetDefaultApplicationStorage().path, this.Deployment.getShortId());

            switch (strategy)
            {
            case ApplicationMountStrategy.Copy:
            case ApplicationMountStrategy.Move:
                UtilsSystem.DeleteDirectoryAndCloseProcesses(basePath, this.Logger, UtilsSystem.DefaultProcessWhitelist, 100);
                break;

            case ApplicationMountStrategy.Link:
                UtilsJunction.RemoveJunction(this.Deployment.appPath);
                UtilsSystem.DeleteDirectoryAndCloseProcesses(basePath, this.Logger, UtilsSystem.DefaultProcessWhitelist, 100);
                break;

            case ApplicationMountStrategy.Original:
                // Do nothing!
                break;

            default:
                throw new Exception("Option not supported.");
            }

            if (!isUninstall)
            {
                return;
            }

            var canonicalPath = this.Deployment.GetSetting <string>("appstorage.canonical", null, this.Logger);

            if (Directory.Exists(canonicalPath) && UtilsJunction.IsJunctionOrSymlink(canonicalPath))
            {
                Directory.Delete(canonicalPath);
            }

            // Usually the IIS site has been closed a few fractions of a second
            // before this is called, so the folders have probably not yet
            // been released, waitPauseMs at least 10 seconds.
            UtilsSystem.DeleteDirectoryAndCloseProcesses(this.Deployment.GetSetting <string>("appstorage.temp", null, this.Logger), this.Logger, UtilsSystem.DefaultProcessWhitelist, 60);
            UtilsSystem.DeleteDirectoryAndCloseProcesses(this.Deployment.GetSetting <string>("appstorage.log", null, this.Logger), this.Logger, UtilsSystem.DefaultProcessWhitelist, 60);
            UtilsSystem.DeleteDirectoryAndCloseProcesses(this.Deployment.GetSetting <string>("appstorage.remote_temp", null, this.Logger), this.Logger, UtilsSystem.DefaultProcessWhitelist, 60);
            UtilsSystem.DeleteDirectoryAndCloseProcesses(this.Deployment.GetSetting <string>("appstorage.remote_log", null, this.Logger), this.Logger, UtilsSystem.DefaultProcessWhitelist, 60);

            var settings = this.GetSettings();

            var groups = this.GlobalSettings.userGroups ?? new List <string>();

            // add legacy group chef_users
            groups.Add(LEGACY_CHEF_USERS_GROUPNAME);

            // Remove user from all groups before deleting
            foreach (var groupIdentifier in groups)
            {
                UtilsWindowsAccounts.EnsureUserNotInGroup(this.Deployment.WindowsUsernameFqdn(), groupIdentifier, this.Logger, this.GlobalSettings.directoryPrincipal);
            }

            // Add the user to any user groups defined at the application level
            foreach (var groupIdentifier in settings.user_groups ?? new List <string>())
            {
                UtilsWindowsAccounts.EnsureUserNotInGroup(this.Deployment.WindowsUsernameFqdn(), groupIdentifier, this.Logger, this.GlobalSettings.directoryPrincipal);
            }

            UtilsWindowsAccounts.DeleteUser(this.Deployment.WindowsUsernameFqdn(), this.GlobalSettings.directoryPrincipal);
        }