public void ModelCalculate() { if (!HasParaSet()) { throw new Exception("Model Parameters are not set!"); } bool restart_flg = false; double[] tmpInput = new double[dblInput.Length]; for (int i = 0; i < InputNum; i++) { tmpInput[i] = dblInput[i]; aspen.Tree.FindNode(Path_Input[i]).Value = tmpInput[i]; } System.Threading.Thread.Sleep(100); try { timer = new System.Threading.Thread(new System.Threading.ThreadStart(timecount)); timer.Start(); aspen.Run2(); for (int i = 0; i < OutputNum; i++) { dblOutput[i] = aspen.Tree.FindNode(Path_Output[i]).Value; } } catch (System.Exception ex) { Console.WriteLine("Crash, " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); if (timer != null && timer.ThreadState == System.Threading.ThreadState.WaitSleepJoin) { timer.Abort(); } timer = null; //scSQL.Stop(); //scSQL.WaitForStatus(ServiceControllerStatus.Stopped); //scSQL.Close(); aspen = null; SetPara(Store_strVal); Console.WriteLine("Restart, " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); restart_flg = true; System.Threading.Thread.Sleep(5000); throw new Exception(ex.Message); } if (restart_flg) { for (int i = 0; i < InputNum; i++) { aspen.Tree.FindNode(Path_Input[i]).Value = tmpInput[i]; } aspen.Run2(); for (int i = 0; i < OutputNum; i++) { dblOutput[i] = aspen.Tree.FindNode(Path_Output[i]).Value; } restart_flg = false; } if (timer != null && timer.ThreadState == System.Threading.ThreadState.WaitSleepJoin) { timer.Abort(); } timer = null; }
public bool SetPara(string strVal) { aspenc.ActiveDocument("asdsad"); aspenc.Activate(); if (!File.Exists(strVal)) { blErr = true; throw new Exception("Input Directory is not valid!"); } int tmpInputNum = 0; int tmpOutputNum = 0; int inputnum = 0; int outputnum = 0; List <string[]> Config = new List <string[]>(); Config = CSVOperation.ReadCSV(strVal); Path_AspenFile = Config[0][0]; for (int i = 0; i < Config.Count - 1; i++) { if (Config[1 + i][0] == "Input") { tmpInputNum = tmpInputNum + 1; } else if (Config[1 + i][0] == "Output") { tmpOutputNum = tmpOutputNum + 1; } } InputNum = tmpInputNum; OutputNum = tmpOutputNum; Path_Input = new string[InputNum]; Path_Output = new string[OutputNum]; dblInput = new double[InputNum]; dblOutput = new double[OutputNum]; for (int i = 0; i < Config.Count - 1; i++) { if (Config[1 + i][0] == "Input") { Path_Input[inputnum] = Config[1 + i][1]; inputnum = inputnum + 1; } else if (Config[1 + i][0] == "Output") { Path_Output[outputnum] = Config[1 + i][1]; outputnum = outputnum + 1; } } //scSQL = new ServiceController(); //scSQL.MachineName = "localhost"; //scSQL.ServiceName = "MSSQLSERVER"; //if (scSQL.Status == ServiceControllerStatus.Stopped) //{ // scSQL.Start(); //} aspen = new Happ.HappLS(); aspen.InitFromFile2(Path_AspenFile); aspen.Visible = true; aspen.SuppressDialogs = 1; blErr = false; timer = null; Store_strVal = strVal; return(true); }