package Common.Passes.All; import Common.Current; import Common.Global; import Common.UI.UI; import Common.Utils.Utils; import Repository.ServerCode; import Repository.ServerExchangeUnit_2021; import Repository.TestingSystem.Common.TestingServer; import Common.Passes.Pass_2021; import Common.Passes.Server.TestingSystemPass; import org.apache.commons.io.FileUtils; import java.io.File; public class SynchronizeTestsTasks extends Pass_2021 { byte[] db_file_bytes; File new_db_file; @Override protected boolean canStart(Object... args) throws Exception { db_file_bytes = null; new_db_file = null; if (Current.getAccount().CheckRegistered(Log)) { TestingSystemPass download = new TestingSystemPass() { @Override protected boolean needsAnimation() { return false; } @Override public String getDescription() { return "Загрузка базы тестовых задач"; } @Override protected void ServerAction() throws Exception { Command(new ServerExchangeUnit_2021(ServerCode.ReceiveTestsTasksDatabase, Current.getAccount().email)); db_file_bytes = (byte[]) response.object; } }; return download.Do(); } return false; } @Override protected boolean needsAnimation() { return false; } @Override public String getIconPath() { return "/icons/ComponentsActual.png"; } @Override public String getButtonText() { return ""; } @Override protected void performPreparation() throws Exception { Global.testingServer.account_db.Disconnect(); } @Override protected void showPreparation() throws Exception { Global.testingServer.account_db.SaveLastSelections(); Global.testingServer.account_db.packages.ClearUI(); Global.testingServer.account_db.sapforTasksPackages.ClearUI(); } @Override protected void body() throws Exception { Utils.unpackFile(db_file_bytes, new_db_file = Utils.getTempFileName("tdb")); if (new_db_file.exists()) { Utils.forceDeleteWithCheck(Global.testingServer.account_db.getFile()); FileUtils.moveFile(new_db_file, Global.testingServer.account_db.getFile()); Global.testingServer.account_db.setFile(Current.getAccount().email); } //-- Global.testingServer.account_db.Connect(); Global.testingServer.account_db.CreateAllTables(); Global.testingServer.account_db.prepareTablesStatements(); Global.testingServer.account_db.Synchronize(); UI.getMainWindow().getTestingWindow().RemountTestTable(); //-- } @Override protected boolean validate() { return (db_file_bytes != null); } @Override protected void showFinish() throws Exception { Global.testingServer.account_db.packages.ShowUI(); Global.testingServer.account_db.sapforTasksPackages.ShowUI(); Global.testingServer.account_db.RestoreLastSelections(); if (!Global.testingServer.account_db.hasActivePackages()) { Global.properties.updateField("AutoCheckTesting", false); TestingServer.TimerOff(); UI.testingBar.ShowAutoCheckTesting(); } } }