123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- /* ==============================================================================
- * 功能描述:StringExtend
- * 创 建 者:Garrett
- * 创建日期:2018/5/29 10:51:45
- * ==============================================================================*/
- using System;
- using Newtonsoft.Json.Linq;
- using SAGA.DotNetUtils;
- using SAGA.DotNetUtils.Extend;
- namespace MBIUtility.Extend
- {
- /// <summary>
- /// StringExtend
- /// </summary>
- public static class StringExtend
- {
- /// <summary>
- /// 云平台BIMId转化为Revit Id
- /// 去掉文件名前缀,找不到返回值为0
- /// </summary>
- /// <returns></returns>
- 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;
- }
- }
- /// <summary>
- /// 仅保留岗位,没有对应模型的bimid
- /// 格式为:
- /// a,只有楼层 id,没有模型bimid
- /// b,""
- /// </summary>
- /// <returns></returns>
- public static bool IsOnlyDutyNoModelBIMID(this string cbimId)
- {
- var strs = cbimId.Split(':');
- return strs.Length != 2;
- }
- /// <summary>
- /// 云平台BIMId转化为Floor Id
- /// 去掉文件名后缀
- /// </summary>
- /// <returns></returns>
- public static string GetFloorId(this string cbimId)
- {
- string bimId = cbimId;
- var strs = cbimId.Split(':');
- if (strs.Length > 1)
- bimId = strs[0];
- return bimId;
- }
-
- /// <summary>
- /// 返回数据是验证-带message
- /// </summary>
- /// <param name="request"></param>
- /// <returns></returns>
- 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;
- }
- /// <summary>
- /// 返回数据是验证
- /// </summary>
- /// <param name="request"></param>
- /// <returns></returns>
- 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;
- }
- /// <summary>
- /// 返回数据是否正确
- /// 数据格式为result,message
- /// </summary>
- /// <param name="request"></param>
- /// <returns></returns>
- 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;
- }
- /// <summary>
- /// 返回的集合不为空集合
- /// </summary>
- /// <param name="request"></param>
- /// <returns></returns>
- 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;
- }
- }
- }
|