/* ============================================================================== * 功能描述:StringExtend * 创 建 者:Garrett * 创建日期:2018/5/29 10:51:45 * ==============================================================================*/ using System; using Newtonsoft.Json.Linq; using SAGA.DotNetUtils; using SAGA.DotNetUtils.Extend; namespace MBIUtility.Extend { /// /// StringExtend /// public static class StringExtend { /// /// 云平台BIMId转化为Revit Id /// 去掉文件名前缀,找不到返回值为0 /// /// public static int GetBIMID(this string cbimId) { try { string bimId = cbimId; var strs = cbimId.Split(':'); if (strs.Length > 1) bimId = strs[1]; return bimId.ToInt(); } catch (Exception e) { Console.WriteLine(e); return 0; } } /// /// 仅保留岗位,没有对应模型的bimid /// 格式为: /// a,只有楼层 id,没有模型bimid /// b,"" /// /// public static bool IsOnlyDutyNoModelBIMID(this string cbimId) { var strs = cbimId.Split(':'); return strs.Length != 2; } /// /// 云平台BIMId转化为Floor Id /// 去掉文件名后缀 /// /// public static string GetFloorId(this string cbimId) { string bimId = cbimId; var strs = cbimId.Split(':'); if (strs.Length > 1) bimId = strs[0]; return bimId; } /// /// 返回数据是验证-带message /// /// /// public static bool IsSuccessRequest(this string request, ref string msg) { bool result = false; if (request.IsNullOrEmpty()) return result; try { JObject jObject = JObject.Parse(request); result = jObject["Result"].ToString() == "success"; msg = jObject["ResultMsg"].ToString(); } catch (Exception e) { result = false; msg = e.StackTrace; } return result; } /// /// 返回数据是验证 /// /// /// public static bool IsSuccessRequest(this string request) { bool result = false; if (request.IsNullOrEmpty()) return result; try { JObject jObject = JObject.Parse(request); result = jObject["Result"].ToString() == "success"; } catch (Exception e) { result = false; } return result; } /// /// 返回数据是否正确 /// 数据格式为result,message /// /// /// public static bool IsSuccessRequest2(this string request, ref string msg) { bool result = false; if (request.IsNullOrEmpty()) return result; try { JObject jObject = JObject.Parse(request); result = jObject["result"].ToString() == "success"; msg = jObject["message"].ToString(); } catch (Exception e) { result = false; } return result; } /// /// 返回的集合不为空集合 /// /// /// public static bool IsRequestHasItem(this string request) { bool result = false; if (IsSuccessRequest(request)) { try { JObject jObject = JObject.Parse(request); if (jObject.IsContainKeyEx("Count")) { result = jObject.GetValueEx("Count").ToInt() != 0; } else { if (jObject.IsContainKeyEx("Content")) result = ((JArray)jObject["Content"]).Count != 0; } } catch (Exception e) { result = false; } } return result; } } }