/* * /// <summary> * /// Specifies command line arguments for application startup; overrides any startup arguments (<see cref="CommandLineArguments"/>) * /// set so far. * /// </summary> * public void SetControlCode(string code) { * AddTextFile(code, "control.cs"); * * string PrjName = InteractiveShell.WorkflowMgm.CurrentProject; * if (string.IsNullOrWhiteSpace(PrjName)) { * throw new NotSupportedException("Project management not initialized - set project name (try e.g. 'WorkflowMgm.CurrentProject = \"BlaBla\"')."); * } * * string[] args = new string[] { * "--control", "control.cs", * "--prjnmn", PrjName, * "--sesnmn", this.Name * }; * * for (int i = 0; i < args.Length; i++) { * m_EnvironmentVars.Add("BOSSS_ARG_" + i, args[i]); * } * } */ /// <summary> /// Specifies the control object for application startup; overrides any startup arguments (<see cref="CommandLineArguments"/>) /// set so far. /// </summary> public void SetControlObject(BoSSS.Solution.Control.AppControl ctrl) { TestActivation(); // serialize control object // ======================== ctrl.VerifyEx(); string ControlName, text; int index = -1; if (ctrl.GeneratedFromCode) { text = ctrl.ControlFileText; ControlName = "control.cs"; index = ctrl.ControlFileText_Index; } else { text = ctrl.Serialize(); ControlName = "control.obj"; } byte[] buffer = Encoding.UTF8.GetBytes(text); AdditionalDeploymentFiles.Add(new Tuple <byte[], string>(buffer, ControlName)); // Project & Session Name // ====================== string PrjName = InteractiveShell.WorkflowMgm.CurrentProject; if (string.IsNullOrWhiteSpace(PrjName)) { throw new NotSupportedException("Project management not initialized - set project name (try e.g. 'WorkflowMgm.CurrentProject = \"BlaBla\"')."); } string[] args = new string[] { "--control", "control.obj", "--prjnmn", PrjName, "--sesnmn", this.Name }; if (index >= 0) { ArrayTools.Cat(args, "--pstudy_case", index.ToString()); } for (int i = 0; i < args.Length; i++) { m_EnvironmentVars.Add("BOSSS_ARG_" + i, args[i]); } // }
private void FiddleControlFile(BatchProcessorClient bpc) { if (m_ctrl == null) { return; } // check the database // ================== IDatabaseInfo ctrl_db = m_ctrl.GetDatabase(); if (bpc.AllowedDatabases != null && bpc.AllowedDatabases.Count > 0) { IDatabaseInfo newDb = null; if (ctrl_db == null) { newDb = bpc.AllowedDatabases[0]; } else { bool ok = false; foreach (var allow_dba in bpc.AllowedDatabases) { if (allow_dba.Equals(ctrl_db)) { ok = true; break; } } if (!ok) { newDb = bpc.AllowedDatabases[0]; } } if (newDb != null) { Console.WriteLine("Resetting database for control object to " + newDb.ToString()); //newDb.AlternateDbPaths m_ctrl.SetDatabase(newDb); ctrl_db = newDb; } Console.WriteLine("Submitting job with the following database info: "); Console.WriteLine("Primary: " + m_ctrl.DbPath); if (ctrl_db.AlternateDbPaths != null && ctrl_db.AlternateDbPaths.Length > 0) { int cnt = 0; foreach (var t in ctrl_db.AlternateDbPaths) { Console.WriteLine($" Alternative[{cnt}]: {t.DbPath}, MachineFilter: '{t.MachineFilter}'"); cnt++; } } else { Console.WriteLine("No alternative paths specified."); } } else { Console.WriteLine(""); } // check grid & restart info // ========================= if (ctrl_db != null) { if (!m_ctrl.GridGuid.Equals(Guid.Empty)) { var GridIn_ctrl_db = ctrl_db.Grids.FirstOrDefault(GrdInf => GrdInf.ID.Equals(m_ctrl.GridGuid)); if (GridIn_ctrl_db == null) { Console.WriteLine($"Grid {m_ctrl.GridGuid} is not present in database - copy to target system..."); var grid2copy = InteractiveShell.AllGrids.FirstOrDefault(dbGrid => dbGrid.ID.Equals(m_ctrl.GridGuid)); if (grid2copy == null) { // maybe replace exception with a warning, if job should be tried anyway throw new IOException($"Unable to find grid '{m_ctrl.GridGuid}' in any database - job will most likely crash."); } else { grid2copy.Copy(ctrl_db); } Console.WriteLine("done."); } } else { Console.Error.WriteLine($"Warning: no grid seems to be specified for the job to submit."); } if (m_ctrl.RestartInfo != null) { Guid Rstsess_guid = m_ctrl.RestartInfo.Item1; var Rstsess_ctrl_db = ctrl_db.Sessions.FirstOrDefault(sinf => sinf.ID.Equals(Rstsess_guid)); if (Rstsess_ctrl_db == null) { Console.WriteLine($"Session {m_ctrl.GridGuid} to restart from is not present in database - copy to target system..."); var sess_2copy = InteractiveShell.AllSessions.FirstOrDefault(sinf => sinf.ID.Equals(Rstsess_guid)); if (sess_2copy == null) { // maybe replace exception with a warning, if job should be tried anyway throw new IOException($"Unable to find session '{sess_2copy}' in any database - job will most likely crash."); } else { sess_2copy.Copy(ctrl_db); } Console.WriteLine("done."); } } } else { Console.Error.WriteLine($"Warning: no database is set for the job to submit; nothing ma be saved."); } // finally, serialize the object // ============================= { string text; m_ctrl_index = -1; if (m_ctrl.GeneratedFromCode) { text = m_ctrl.ControlFileText; ControlName = "control.cs"; m_ctrl_index = m_ctrl.ControlFileText_Index; } else { text = m_ctrl.Serialize(); ControlName = "control.obj"; } byte[] buffer = Encoding.UTF8.GetBytes(text); int remIdx = AdditionalDeploymentFiles.IndexWhere(tt => tt.Item2 == ControlName); if (remIdx >= 0) { AdditionalDeploymentFiles.RemoveAt(remIdx); } AdditionalDeploymentFiles.Add(new Tuple <byte[], string>(buffer, ControlName)); } }