protected override void OnOperationStarting(object sender, PackageOperationEventArgs e) { var context = _packageOperationContextService.CurrentContext; if (e.PackageOperationType == PackageOperationType.Uninstall) { _backupFileSystemService.BackupFolder(e.InstallPath); _rollbackPackageOperationService.PushRollbackAction(() => _backupFileSystemService.Restore(e.InstallPath), context); return; } if (e.PackageOperationType == PackageOperationType.Install) { _rollbackPackageOperationService.PushRollbackAction(() => _fileSystemService.DeleteDirectory(e.InstallPath), context); } base.OnOperationStarting(sender, e); }
protected override void OnOperationStarting(object sender, PackageOperationEventArgs e) { var packagesConfig = Catel.IO.Path.Combine(Catel.IO.Path.GetParentDirectory(e.InstallPath), "packages.config"); if (e.PackageOperationType == PackageOperationType.Uninstall) { _backupFileSystemService.BackupFolder(e.InstallPath); _backupFileSystemService.BackupFile(packagesConfig); _rollbackPackageOperationService.PushRollbackAction(() => { _backupFileSystemService.Restore(e.InstallPath); _backupFileSystemService.Restore(packagesConfig); }, CurrentContext); } if (e.PackageOperationType == PackageOperationType.Install) { _rollbackPackageOperationService.PushRollbackAction(() => { bool success = true; try { _directoryService.Delete(e.InstallPath); success = !_directoryService.Exists(e.InstallPath); } catch (Exception) { success = false; } finally { if (!success) { _fileSystemService.CreateDeleteme(e.PackageDetails.Id, e.InstallPath); Log.Error($"Failed to delete directory {e.InstallPath} during rollback actions."); } } }, CurrentContext ); } }