using CommonBase; using Hydro.Core.Model; using Hydro.HydraulicOptimizer; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; namespace Hydro.MapView { public class calc { public WDNModelOptimizer wdo; public DateTime time = DateTime.Now; public DateTime T_time = DateTime.Now; public WdnmoParam wParam = null; public List GetCalcResult(string InpPath, WdnmoParam wP, string configPath = null) { string result = null; Console.Write("请输入重复计算次数:(默认:1)"); string sr; T_time = DateTime.Now; GeneticParams gparam = new GeneticParams(0); var wdo = new WDNModelOptimizer(gparam); WdnmoParam param; #region bak1 wParam = wP; param = wParam; #endregion bak1 time = DateTime.Now; if (configPath == null) configPath = System.IO.Directory.GetCurrentDirectory() + "\\" + "config_calc.wdb"; ; string path = configPath; result = wdo.Init(path, InpPath, onFinish, onError, null, param, false); if (result != null) { wdo.Close(); throw new Exception(result); //return null; //return; } result = wdo.Run(param, false); while (true) { lock (lockobj) { if (isFinished) { if (wdo != null) wdo.Close(); break; } } } //wParam.ResultPoints.ForEach(p => p.Value = num); return wParam.ResultPoints; } object lockobj = new object(); public string getStringByJson(string path) { StreamReader sr = new StreamReader(path); string s = sr.ReadToEnd(); sr.Close(); return s; } public bool isFinished = false; public object FOBJ = new object(); public void onFinish(dynamic modelParams) { var param = modelParams as WdnmoParam; new Thread(() => { Thread.Sleep(100); if (wdo != null) wdo.Close(); }).Start(); this.wParam = param; lock (lockobj) { isFinished = true; } } public void onError(dynamic result) { //MessageBox.Show("原因:" + result, "计算失败"); new Thread(() => { Thread.Sleep(1000); if (wdo != null) wdo.Close(); }).Start(); lock (lockobj) { isFinished = true; } throw new Exception("计算失败,原因:" + result); } } }