/// <summary>
        /// 判断用户是否满足一定的规则(按照.config文件里定义的规则名称)
        /// </summary>
        /// <param name="rulenName">规则名称</param>
        /// <returns></returns>
        public static bool AuthorizeByRuleName(string rulenName, System.Security.Principal.IPrincipal principal = null)
        {
            if (principal == null)
            {
                principal = System.Threading.Thread.CurrentPrincipal;
            }
            string key = "Authority.AuthorizeByRuleName:" + rulenName;

            return(Cache.TryGetCache <bool>(key, new Func <bool>(delegate()
            {
                try
                {
                    return AuthorizationFactory.GetAuthorizationProvider().Authorize(principal, rulenName);
                }
                catch (Exception)
                {
                    try
                    {
                        return AuthorizationFactory.GetAuthorizationProvider().Authorize(principal, "Others");
                    }
                    catch (Exception ex)
                    {
                        ExceptionProcess.ProcessWithResume(ex);
                        return false;
                    }
                }
            })));
        }
 /// <summary>
 /// 根据<see cref="GridRowInfo.GridName"/>得到<see cref="GridRowInfo"/>数据
 /// </summary>
 /// <param name="gridName"></param>
 /// <returns>表格行配置信息</returns>
 public GridRowInfo GetGridRowInfo(string gridName)
 {
     return(Cache.TryGetCache <GridRowInfo>(GetCacheKey <GridRowInfo>(gridName), new Func <GridRowInfo>(delegate()
     {
         try
         {
             IList <GridRowInfo> ret = GetInfos <GridRowInfo>(string.Format("GridName = '{0}'", gridName));
             if (ret.Count > 0)
             {
                 return ret[0];
             }
             else
             {
                 ret = GetInfos <GridRowInfo>(string.Format("GridName = '{0}'", m_defaultName));
                 if (ret.Count > 0)
                 {
                     return ret[0];
                 }
                 else
                 {
                     return m_defaultGridRowInfo;
                 }
             }
         }
         catch (Exception ex)
         {
             ExceptionProcess.ProcessWithResume(ex);
             return null;
         }
     })));
 }
Beispiel #3
0
        /// <summary>
        /// DecryptSymmetric
        /// </summary>
        /// <param name="cipherText"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        public static string DecryptSymmetric(string cipherText, string key)
        {
            if (string.IsNullOrEmpty(cipherText))
            {
                return(null);
            }

            try
            {
                ICryptoTransform cryptTrans = CreateDecryptor(key);

                byte[]       cipherData = Convert.FromBase64String(cipherText);
                MemoryStream ms         = new MemoryStream();

                CryptoStream cst = new CryptoStream(ms, cryptTrans, CryptoStreamMode.Write);
                cst.Write(cipherData, 0, cipherData.Length);
                cst.Close();

                byte[] b = ms.ToArray();
                return(System.Text.Encoding.Unicode.GetString(b));
            }
            catch (Exception ex)
            {
                ExceptionProcess.ProcessWithResume(ex);
                return(null);
            }
        }
Beispiel #4
0
        /// <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>
 ///
 /// </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> >());
 }
 /// <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);
     }
 }
 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="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="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="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="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.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="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="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> >());
 }
 /// <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>
        /// 根据<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;
                }
            })));
        }
Beispiel #22
0
        /// <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()));
            }
        }