package _VisualDVM.GlobalData.Tasks; import Common.CommonConstants; import Common.Database.Objects.iDBObject; import Common.Utils.Utils_; import _VisualDVM.Constants; import _VisualDVM.Global; import _VisualDVM.GlobalData.Machine.Machine; import _VisualDVM.GlobalData.User.User; import _VisualDVM.ProjectData.Project.db_project_info; import _VisualDVM.Utils; import com.sun.org.glassfish.gmbal.Description; import java.io.File; import java.nio.file.Paths; import java.util.Date; public abstract class Task extends iDBObject { // // public TaskState state = TaskState.Inactive; //---------------------------------- public int machine_id = CommonConstants.Nan; public int user_id = CommonConstants.Nan; //----------------------------------- public String PID = ""; public String project_path;// путь к проекту. public String project_description; // краткое описание(чтобы не лезть в бд целевого проекта). только для таблицы. public int maxtime = 40; //результаты------------------------------- public double Time; //время выполнения. public long StartDate = 0; //дата начала выполнения public long EndDate = 0;//дата окончания выполнения //--------------------------------- @Description("IGNORE") public int progressStep = CommonConstants.Nan; @Description("IGNORE") public int progressAll = CommonConstants.Nan; public boolean belongsToProject(db_project_info project) { return this.project_path.equalsIgnoreCase(project.Home.getAbsolutePath()); } public void DropResults() throws Exception { Utils_.forceDeleteWithCheck(getOutputFile()); Utils_.forceDeleteWithCheck(getErrorsFile()); //- StartDate = 0; EndDate = 0; Time = 0; state = TaskState.Inactive; Global.mainModule.getDb().Update(this); } // // public abstract File getHome(); public File getLocalWorkspace() { return Paths.get(getHome().getAbsolutePath(), String.valueOf(id)).toFile(); } public File getOutputFile() { return Paths.get(getLocalWorkspace().getAbsolutePath(), Constants.out_file).toFile(); } public File getErrorsFile() { return Paths.get(getLocalWorkspace().getAbsolutePath(), Constants.err_file).toFile(); } public File getTimeFile() { return Paths.get(getLocalWorkspace().getAbsolutePath(), Constants.time_file).toFile(); } public abstract String getFullCommand(); public Date getEndDate() { return new Date(EndDate); } public Machine getMachine() { return Global.mainModule.getDb().getById(Machine.class, machine_id); } public User getUser() { return Global.mainModule.getDb().getById(User.class, user_id); } protected String getTextResult(File file) { return (file.exists()) ? Utils.ReadAllText(file) : "файл не найден. Задача еще не выполнялась или была завершена некорректно"; } //подразумевается, что выходные потоки задачи видны только при открытом проекте public String getOutput() { return getTextResult(getOutputFile()); } public String getErrors() { return getTextResult(getErrorsFile()); } public void RefreshTime() { Time = Double.parseDouble(Utils.ReadAllText(getTimeFile())); } public void MaximizeTime() { Time = maxtime + 1; } public void UpdateState(TaskState state_in) { if (state != state_in) { state = state_in; try { Global.mainModule.getDb().Update(this); } catch (Exception ex) { Utils_.MainLog.PrintException(ex); } } } public void Reset() { PID = ""; StartDate = 0; EndDate = 0; state = TaskState.Inactive; } public void setProgress(int progressStep_in, int progressAll_in) { progressStep = progressStep_in; progressAll = progressAll_in; } public void dropProgress() { progressStep = CommonConstants.Nan; progressAll = CommonConstants.Nan; } public boolean hasProgress() { return (progressStep != CommonConstants.Nan) && (progressAll != CommonConstants.Nan); } //--------------------------------- public void AnalyzeResultsTexts(db_project_info project) throws Exception { state = TaskState.Done; AnalyzeOutFile(project); AnalyzeErrorsFile(project); } public void AnalyzeOutFile(db_project_info project) throws Exception { } public void AnalyzeErrorsFile(db_project_info project) throws Exception { } public boolean isPassive() { return (state != TaskState.Queued) && (state != TaskState.Running); } }