| | |
| | | using HStation.Model; |
| | | using Microsoft.VisualBasic; |
| | | |
| | | namespace HStation.Service |
| | | { |
| | |
| | | /// 修正(无法修正会抛出异常) |
| | | /// </summary> |
| | | /// <param name="rhs">RevitModel</param> |
| | | public static void Correct(this Model.RevitModel rhs) |
| | | public static bool Correct(this Model.RevitModel rhs, out string msg) |
| | | { |
| | | if (rhs == null) |
| | | { |
| | | throw new Exception("数据为空"); |
| | | msg = "数据为空"; |
| | | return false; |
| | | } |
| | | Zero(rhs); |
| | | First(rhs); |
| | | Second(rhs); |
| | | Three(rhs); |
| | | if (!Zero(rhs, out msg)) |
| | | { |
| | | return false; |
| | | } |
| | | if (!First(rhs, out msg)) |
| | | { |
| | | return false; |
| | | } |
| | | if (!Second(rhs, out msg)) |
| | | { |
| | | return false; |
| | | } |
| | | if (!Three(rhs, out msg)) |
| | | { |
| | | return false; |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | //前提:验证合法性 |
| | | private static void Zero(Model.RevitModel rhs) |
| | | private static bool Zero(Model.RevitModel rhs, out string msg) |
| | | { |
| | | msg = string.Empty; |
| | | var allWaterSourceList = rhs.GetAllWaterSources(); |
| | | if (allWaterSourceList == null || allWaterSourceList.Count < 1) |
| | | { |
| | | throw new Exception("无水源"); |
| | | msg = "无水源"; |
| | | return false; |
| | | } |
| | | var allJunctionList = rhs.GetAllJunctions(); |
| | | if (allJunctionList == null || allJunctionList.Count < 1) |
| | | { |
| | | throw new Exception("无连接节点"); |
| | | msg = "无连接节点"; |
| | | return false; |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | //第一步:检查集合初始化 |
| | | private static void First(Model.RevitModel rhs) |
| | | private static bool First(Model.RevitModel rhs, out string msg) |
| | | { |
| | | msg = string.Empty; |
| | | if (rhs.Reservoirs == null) |
| | | { |
| | | rhs.Reservoirs = new List<Model.RevitReservoir>(); |
| | |
| | | { |
| | | rhs.Valves = new List<Model.RevitValve>(); |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | //第二步:检查上下游编码 |
| | | private static void Second(Model.RevitModel rhs) |
| | | private static bool Second(Model.RevitModel rhs, out string msg) |
| | | { |
| | | msg = string.Empty; |
| | | var allParterList = rhs.GetAllParters(); |
| | | var allLinks = rhs.GetAllLinks(); |
| | | foreach (var link in allLinks) |
| | | { |
| | | var startLinkParter = allParterList.Find(x => x.Id == link.StartCode); |
| | | if (startLinkParter == null) |
| | | { |
| | | msg = $"管段: {link.Id} 上游节点错误"; |
| | | return false; |
| | | } |
| | | link.StartCode = startLinkParter.Code; |
| | | var endLinkParter = allParterList.Find(x => x.Id == link.EndCode); |
| | | if (endLinkParter == null) |
| | | { |
| | | msg = $"管段: {link.Id} 下游节点错误"; |
| | | return false; |
| | | } |
| | | link.EndCode = endLinkParter.Code; |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | //第三步:按照水力结构进行修正 |
| | | private static void Three(Model.RevitModel rhs) |
| | | private static bool Three(Model.RevitModel rhs, out string msg) |
| | | { |
| | | msg = string.Empty; |
| | | var allLinks = rhs.GetAllLinks(); |
| | | foreach (var link in allLinks) |
| | | { |
| | |
| | | (endLinkParter as IRevitLink).StartCode = junction.Code; |
| | | } |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | } |