/// <summary> /// 计算表达式 /// 语法: expression if expression else expression /// Example: $%提箱点编号% if str(%任务性质%) == "进口拆箱" else %装货地%$ /// </summary> /// <param name="expression"></param> /// <param name="entity"></param> /// <returns></returns> public object CalculateExpression(string expression, object entity) { if (string.IsNullOrEmpty(expression)) { return(null); } expression = PythonScript.TryRemoveExpressionQuotos(expression); bool?isEvalutionEngineExpression = IsEvaluationEngineExpression(expression); if (isEvalutionEngineExpression.HasValue && isEvalutionEngineExpression.Value) { string ownExpression = EntityHelper.ReplaceEntity(expression, entity); object result = m_evaluationEngine.CalculateExpression(ownExpression, null); ExceptionProcess.ProcessWithResume(new NotSupportedException(string.Format("{0} 请使用Python表达式.", expression))); return(result); } try { try { return(m_entityPython.CalculateExpression(expression, entity)); } catch (Exception) { string ownExpression = EntityHelper.ReplaceEntity(expression, entity); ownExpression = ownExpression.Replace("\"\"", "None"); return(m_entityPython.CalculateExpression(ownExpression, entity)); } } catch (Exception ex) { if (!isEvalutionEngineExpression.HasValue && ex.GetType().ToString().Contains("Microsoft.Scripting.SyntaxErrorException")) { string ownExpression = EntityHelper.ReplaceEntity(expression, entity); object result = null; try { result = m_evaluationEngine.CalculateExpression(ownExpression, null); ExceptionProcess.ProcessWithResume(new NotSupportedException(string.Format("{0} 请使用Python表达式.", expression))); } catch (Exception) { throw; } return(result); } else { throw; } } }
/// <summary> /// /// </summary> /// <param name="userInfo"></param> public void GetUserConfigurationData(UserConfigurationInfo userInfo) { try { m_dal.GetUserConfigurationData(userInfo); } catch (Exception ex) { ExceptionProcess.ProcessWithResume(ex); return; } }
/// <summary> /// 得到所有<see cref="AlertInfo"/>数据 /// </summary> /// <returns>警告信息</returns> public IList <AlertInfo> GetAlertInfo() { try { return(GetInfos <AlertInfo>(string.Format("IsFixed = false and (RecipientUser = '******' or RecipientRole in '{1}", SystemConfiguration.UserName, Feng.Utils.ConvertHelper.StringArrayToString(SystemConfiguration.Roles)))); } catch (Exception ex) { ExceptionProcess.ProcessWithResume(ex); return(null); } }
/// <summary> /// /// </summary> /// <typeparam name="T"></typeparam> /// <param name="queryString"></param> /// <param name="parameters"></param> /// <returns></returns> public IList <T> GetInfos <T>(string queryString, Dictionary <string, object> parameters) where T : class, new() { try { return(m_dal.GetInfos <T>(queryString, parameters)); } catch (Exception ex) { ExceptionProcess.ProcessWithResume(ex); } return(EmptyInstance.GetEmpty <List <T> >()); }
internal T GetInfo <T>(string idName) where T : class, new() { try { return(m_dal.GetInfo <T>(idName)); } catch (Exception ex) { ExceptionProcess.ProcessWithResume(ex); } return(null); }
/// <summary> /// 得到顶级<see cref="MenuInfo"/>数(Parent is null) /// </summary> /// <returns>顶级菜单信息</returns> public IList <MenuInfo> GetTopMenuInfos() { try { IList <MenuInfo> listAll = null; listAll = Cache.TryGetCache <IList <MenuInfo> >(GetCacheKey <MenuInfo>("All"), new Func <IList <MenuInfo> >(delegate() { try { return(GetInfos <MenuInfo>()); } catch (Exception ex) { ExceptionProcess.ProcessWithResume(ex); return(null); } })); if (listAll == null) { return(null); } ICache c = ServiceProvider.GetService <ICache>(); if (c != null) { foreach (MenuInfo info in listAll) { c.Put(GetCacheKey <MenuInfo>(info.ID), info); } } IList <MenuInfo> listTop = new List <MenuInfo>(); foreach (MenuInfo menu in listAll) { if (menu.ParentMenu == null) { listTop.Add(menu); SearchMenuChilds(menu, listAll); } } return(listTop); } catch (Exception ex) { ExceptionProcess.ProcessWithResume(ex); return(null); } }
/// <summary> /// 计算简单表达式,无参数. /// 注意,iif不能嵌套。应该用中间变量,例如 $a := iif[%票.卸箱地编号% = "900125", "900005", %票.卸箱地编号%];iif[%票.卸箱地编号% = 900125", "900005", a]$ /// 注意,最后不能加分号。 /// 要计算的,前后加$, 要实体类中变量的,加%% /// </summary> /// <param name="expression"></param> /// <param name="processParams"></param> /// <returns></returns> public object CalculateExpression(string expression, Dictionary <string, object> processParams) { expression = PythonScript.TryRemoveExpressionQuotos(expression); bool?isEvaluationEngineExp = IsEvaluationEngineExpression(expression); if (isEvaluationEngineExp.HasValue && isEvaluationEngineExp.Value) { ExceptionProcess.ProcessWithResume(new NotSupportedException(string.Format("{0} 请使用Python表达式.", expression))); return(m_evaluationEngine.CalculateExpression(expression, processParams)); } else { // 尝试先以Python方式运行 try { if (expression.Contains("result")) { return(m_python.ExecuteStatement(expression, processParams)); } else { return(m_python.CalculateExpression(expression, processParams)); } } catch (Exception ex) { if (!isEvaluationEngineExp.HasValue && ex is Microsoft.Scripting.SyntaxErrorException || ex.InnerException is Microsoft.Scripting.SyntaxErrorException) { object result = null; try { result = m_evaluationEngine.CalculateExpression(expression, processParams); ExceptionProcess.ProcessWithResume(new NotSupportedException(string.Format("{0} 请使用Python表达式.", expression))); } catch (Exception) { throw ex; } return(result); } else { throw; } } } }
///// <summary> ///// ///// </summary> ///// <returns></returns> //public IList<ServerTaskScheduleInfo> GetTaskScheduleInfo() //{ // try // { // return m_dal.GetTaskScheduleInfo(); // } // catch (Exception ex) // { // ExceptionProcess.ProcessWithResume(ex); // return null; // } //} ///// <summary> ///// ///// </summary> ///// <returns></returns> //public IList<WebServiceInfo> GetWebServiceInfos() //{ // try // { // return m_dal.GetWebServiceInfos(); // } // catch (Exception ex) // { // ExceptionProcess.ProcessWithResume(ex); // return null; // } //} /// <summary> /// /// </summary> /// <param name="paramName"></param> /// <returns></returns> public IList <ParamCreatorInfo> GetParamCreatorInfos(string paramName) { try { return(Cache.TryGetCache <IList <ParamCreatorInfo> >(GetCacheKey <ParamCreatorInfo>(paramName), new Func <IList <ParamCreatorInfo> >(delegate() { return GetInfos <ParamCreatorInfo>(string.Format("ParamName = '{0}'", paramName)); }))); } catch (Exception ex) { ExceptionProcess.ProcessWithResume(ex); return(null); } }
/// <summary> /// 根据<see cref="P:ReportDataInfo.ReportName"/>得到<see cref="ReportDataInfo"/>信息 /// </summary> /// <param name="reportName"></param> /// <returns></returns> public IList <ReportDataInfo> GetReportDataInfo(string reportName) { try { return(Cache.TryGetCache <IList <ReportDataInfo> >(GetCacheKey <ReportDataInfo>(reportName), new Func <IList <ReportDataInfo> >(delegate() { return GetInfos <ReportDataInfo>(string.Format("Report.ID = '{0}'", reportName)); }))); } catch (Exception ex) { ExceptionProcess.ProcessWithResume(ex); return(null); } }
///// <summary> ///// 得到所有<see cref="AlertRuleInfo"/>数据 ///// </summary> ///// <returns>警告配置信息</returns> //public IList<AlertRuleInfo> GetAlertRuleInfo() //{ // try // { // return GetAlertRuleInfo(); // } // catch (Exception ex) // { // ExceptionProcess.ProcessWithResume(ex); // return null; // } //} /// <summary> /// 根据<see cref="P:ReportInfo.Name"/>得到<see cref="ReportInfo"/>信息 /// </summary> /// <param name="reportName"></param> /// <returns></returns> public ReportInfo GetReportInfo(string reportName) { try { return(Cache.TryGetCache <ReportInfo>(GetCacheKey <ReportInfo>(reportName), new Func <ReportInfo>(delegate() { return GetInfo <ReportInfo>(reportName); }))); } catch (Exception ex) { ExceptionProcess.ProcessWithResume(ex); return(null); } }
/// <summary> /// 根据<see cref="GridFilterInfo.GridName"/>得到<see cref="GridFilterInfo"/>数据 /// </summary> /// <param name="gridName"></param> /// <returns>表格筛选配置信息</returns> public IList <GridFilterInfo> GetGridFilterInfos(string gridName) { return(Cache.TryGetCache <IList <GridFilterInfo> >(GetCacheKey <GridFilterInfo>(gridName), new Func <IList <GridFilterInfo> >(delegate() { try { return GetInfos <GridFilterInfo>(string.Format("GridName = '{0}'", gridName)); } catch (Exception ex) { ExceptionProcess.ProcessWithResume(ex); return null; } }))); }
/// <summary> /// 根据<see cref="P:WindowMenuInfo.Name"/>得到<see cref="WindowMenuInfo"/>数据 /// </summary> /// <param name="windowName"></param> /// <returns>普通窗口工具栏按钮配置信息</returns> public IList <WindowMenuInfo> GetWindowMenuInfo(string windowName) { try { return(Cache.TryGetCache <IList <WindowMenuInfo> >(GetCacheKey <WindowMenuInfo>(windowName), new Func <IList <WindowMenuInfo> >(delegate() { return GetInfos <WindowMenuInfo>(string.Format("Window.ID = '{0}'", windowName)); }))); } catch (Exception ex) { ExceptionProcess.ProcessWithResume(ex); return(null); } }
/// <summary> /// 根据<see cref="P:Feng.ProcessInfo.Name"/>得到<see cref="ProcessInfo"/>数据 /// </summary> /// <param name="processName"></param> /// <returns>过程配置信息</returns> public ProcessInfo GetProcessInfo(string processName) { try { return(Cache.TryGetCache <ProcessInfo>(GetCacheKey <ProcessInfo>(processName), new Func <ProcessInfo>(delegate() { return GetInfo <ProcessInfo>(processName); }))); } catch (Exception ex) { ExceptionProcess.ProcessWithResume(ex); return(null); } }
/// <summary> /// 根据<see cref="P:Feng.EventProcessInfo.EventName"/>得到<see cref="EventProcessInfo"/>数据 /// </summary> /// <param name="eventName"></param> /// <returns>过程配置信息</returns> public IList <EventProcessInfo> GetEventProcessInfos(string eventName) { try { return(Cache.TryGetCache <IList <EventProcessInfo> >(GetCacheKey <EventProcessInfo>(eventName), new Func <IList <EventProcessInfo> >(delegate() { return GetInfos <EventProcessInfo>(string.Format("EventName = '{0}'", eventName)); }))); } catch (Exception ex) { ExceptionProcess.ProcessWithResume(ex); return(null); } }
/// <summary> /// 根据<see cref="WindowSelectInfo.GroupName"/>得到<see cref="WindowSelectInfo"/>数据 /// </summary> /// <param name="groupName"></param> /// <returns>选择窗体配置信息</returns> public IList <WindowSelectInfo> GetWindowSelectInfo(string groupName) { return(Cache.TryGetCache <IList <WindowSelectInfo> >(GetCacheKey <WindowSelectInfo>(groupName), new Func <IList <WindowSelectInfo> >(delegate() { try { return GetInfos <WindowSelectInfo>(string.Format("GroupName = '{0}'", groupName)); } catch (Exception ex) { ExceptionProcess.ProcessWithResume(ex); return null; } }))); }
/// <summary> /// /// </summary> /// <typeparam name="T"></typeparam> /// <param name="queryString"></param> /// <returns></returns> public IList <T> GetInfos <T>(string queryString) where T : class, new() { try { return(Cache.TryGetCache <IList <T> >(GetCacheKey <T>(queryString), new Func <IList <T> >(delegate() { return m_dal.GetInfos <T>(queryString); }))); } catch (Exception ex) { ExceptionProcess.ProcessWithResume(ex); } return(EmptyInstance.GetEmpty <List <T> >()); }
public static Track ConvertToTrack(string gpxString) { gpx.gpxType gpx = null; try { var xmlSerialize = new System.Xml.Serialization.XmlSerializer(typeof(gpx.gpxType)); var stream = new System.IO.StringReader(gpxString); gpx = (gpx.gpxType)xmlSerialize.Deserialize(stream); } catch (Exception ex) { ExceptionProcess.ProcessWithNotify(ex); return(null); } Track track = new Track(); track.TrackPoints = new List <TrackPoint>(); track.StartTime = gpx.metadata.timeSpecified ? (DateTime?)gpx.metadata.time : null; track.TrackPoints = new List <TrackPoint>(); foreach (var i in gpx.trk) { foreach (var j in i.trkseg) { foreach (var k in j.trkpt) { var p = new TrackPoint(); p.Altitude = k.eleSpecified ? (double)k.ele : 0; p.Latitude = (double)k.lat; p.Longitude = (double)k.lon; p.GpsTime = k.timeSpecified ? k.time : DateTime.MinValue; p.MessageTime = p.GpsTime; p.VehicleName = gpx.creator; p.Track = track; track.TrackPoints.Add(p); } } } return(track); }
/// <summary> /// 根据<see cref="GridColumnWarningInfo.GroupName"/>得到<see cref="GridColumnWarningInfo"/>数据 /// </summary> /// <param name="groupName"></param> /// <returns>表格警示单元格配置信息</returns> public IList <GridColumnWarningInfo> GetWarningInfo(string groupName) { if (string.IsNullOrEmpty(groupName)) { return(null); } return(Cache.TryGetCache <IList <GridColumnWarningInfo> >(GetCacheKey <GridColumnWarningInfo>(groupName), new Func <IList <GridColumnWarningInfo> >(delegate() { try { return GetInfos <GridColumnWarningInfo>(string.Format("GroupName = '{0}'", groupName)); } catch (Exception ex) { ExceptionProcess.ProcessWithResume(ex); return null; } }))); }
/// <summary> /// 根据用户名得到用户数据 /// </summary> /// <param name="userName"></param> /// <returns>用户设置信息</returns> public UserConfigurationInfo GetUserConfigurationInfo(string userName) { try { var list = m_dal.GetInfos <UserConfigurationInfo>(string.Format("UserName = '******'", userName)); if (list != null && list.Count > 0) { return(list[0]); } else { return(null); } } catch (Exception ex) { ExceptionProcess.ProcessWithResume(ex); return(null); } }
/// <summary> /// Occur when Load Thread is done /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected virtual void LoadWork_WorkerDone(object sender, WorkerDoneEventArgs <DataLoadedEventArgs> e) { // 当中途停止,e.Interrupted = true, result = null; DataLoadedEventArgs e2 = e.Result; try { if (this.DisplayManager != null && e2 != null && e2.DataSource != null) { this.DisplayManager.SetDataBinding(e2.DataSource, string.Empty); } } finally { OnDataLoaded(e2); } if (e.Exception != null) { ExceptionProcess.ProcessWithNotify(e.Exception); } }
/// <summary> /// DecryptSymmetric /// 如失败,返回null /// </summary> /// <param name="cipherbytes"></param> /// <returns></returns> public static byte[] DecryptSymmetric(byte[] cipherbytes) { if (SystemConfiguration.LiteMode) { throw new InvalidOperationException("you'd better not use Microsoft Enterprise Library method!"); } if (cipherbytes == null) { return(null); } TryCreateKeys(); try { return(Microsoft.Practices.EnterpriseLibrary.Security.Cryptography.Cryptographer.DecryptSymmetric(symmProvider, cipherbytes)); } catch (Exception ex) { ExceptionProcess.ProcessWithResume(ex); return(null); } }
/// <summary> /// /// </summary> /// <param name="entity"></param> /// <param name="fullPropertyName"></param> /// <returns></returns> public object GetPropertyValue(object entity, string fullPropertyName) { if (entity == null) { return(null); } if (entity is IEntity) { Type type = entity.GetType(); object nextValue = null; object nowValue = entity; string[] ss = fullPropertyName.Split(new char[] { '.' }); for (int i = 0; i < ss.Length; ++i) { // NHibernate proxy type //while (!type.FullName.StartsWith(m_defaultAssemblyNamespace)) // type = type.BaseType; try { nextValue = type.InvokeMember(ss[i], BindingFlags.GetProperty | BindingFlags.Instance | BindingFlags.Public, null, nowValue, null); } catch (Exception ex) { ExceptionProcess.ProcessWithResume(ex); // 有时候确实没这个属性,但为了不需要更多的配置,默认读取。例如大写金额 // ExceptionProcess.ProcessWithNotify(ex); throw; // return null; } nowValue = nextValue; if (nextValue == null) { nowValue = null; break; } if (i < ss.Length - 1) { type = nextValue.GetType(); } } return(nowValue); } #if !SILVERLIGHT else if (entity is System.Data.DataRowView) { try { object ret = ((System.Data.DataRowView)entity)[fullPropertyName]; if (ret == System.DBNull.Value) { return(null); } else { return(ret); } } catch (Exception ex) { ExceptionProcess.ProcessWithResume(ex); // 有时候确实没这个属性,但为了不需要更多的配置,默认读取。例如大写金额 //ExceptionProcess.ProcessWithNotify(ex); return(null); } } #endif else if (entity is IDictionary <string, object> ) { IDictionary <string, object> d = entity as IDictionary <string, object>; if (d.ContainsKey(fullPropertyName)) { return(d[fullPropertyName]); } else { return(null); } } else { throw new NotSupportedException(string.Format("Now only IEntity or DataRowView is supported, {0} is not supported !", entity.GetType().ToString())); } }
/// <summary> /// 按照自定义规则按照地址导航程序到某个界面 /// http://cd/{action}/exp={exp}&order={order}&pos={pos} /// http://cd/action/查询统计_人员单位/?exp=编号 = 100000&order=编号&pos=1 /// </summary> /// <param name="app"></param> /// <param name="address"></param> public static void NavigateTo(this IApplication app, string address) { if (string.IsNullOrEmpty(address) || !address.StartsWith(s_addressHeader)) { return; } string content = address.Substring(s_addressHeader.Length); if (!content.Contains("action/")) { content = Decrypt(content); address = s_addressHeader + content; } UriTemplate template = new UriTemplate("action/{action}/?exp={exp}&order={order}&pos={pos}"); Uri baseAddress = new Uri(s_addressHeader + SystemConfiguration.ApplicationName); Uri fullUri = new Uri(address); // Match a URI to a template UriTemplateMatch results = template.Match(baseAddress, fullUri); if (results != null && results.BaseUri == baseAddress) { try { IDisplayManagerContainer dmC = app.ExecuteAction(results.BoundVariables["action"]) as IDisplayManagerContainer; if (dmC == null) { return; } if (dmC.DisplayManager != null && dmC.DisplayManager.SearchManager != null) { var t = results.BoundVariables["first"]; if (t != null) { int?first = Feng.Utils.ConvertHelper.ToInt(t); if (first.HasValue) { dmC.DisplayManager.SearchManager.FirstResult = first.Value; } } t = results.BoundVariables["count"]; if (t != null) { int?count = Feng.Utils.ConvertHelper.ToInt(t); if (count.HasValue) { dmC.DisplayManager.SearchManager.MaxResult = count.Value; } } t = results.BoundVariables["exp"]; if (t != null) { var exp = SearchExpression.Parse(t); var order = SearchOrder.Parse(results.BoundVariables["order"]); if (exp != null) { dmC.DisplayManager.SearchManager.LoadData(exp, order); dmC.DisplayManager.Position = 0; } } } } catch (Exception ex) { ExceptionProcess.ProcessWithNotify(ex); } } }