Esempio n. 1
0
        public static void Excute(Action <ContainerBuilder> IocRegisterFun)
        {
            var builder   = new ContainerBuilder();
            var baseType  = typeof(IDependency);
            var assemblys = AppDomain.CurrentDomain.GetAssemblies().ToList().Where(t => { return(t.FullName.Contains("Controllers") | t.FullName.Contains("Filters") | t.FullName.Contains("Models") | t.FullName.Contains("BLL") | t.FullName.Contains("DAL") | t.FullName.Contains("Tmp") | t.FullName.Contains("App_Code")); });

            builder.RegisterControllers(assemblys.ToArray());
            builder.RegisterFilterProvider();
            builder.RegisterGeneric(typeof(EfRepository <>)).As(typeof(IRepository <>)).InstancePerLifetimeScope();
            builder.RegisterAssemblyTypes(assemblys.ToArray()).Where(t => baseType.IsAssignableFrom(t) & t != baseType).AsImplementedInterfaces().InstancePerLifetimeScope();
            IocRegisterFun(builder);

            //注入Cache
            //builder.RegisterGeneric(typeof(HttpContextCacheManager)).As(typeof(IHttpContextCacheManager)).InstancePerLifetimeScope();
            //builder.RegisterGeneric(typeof(HttpContextSessionManager)).As(typeof(IHttpContextSessionManager)).InstancePerLifetimeScope();
            //builder.RegisterGeneric(typeof(HttpContextSessionManager)).As(typeof(IHttpContextCacheManager)).InstancePerLifetimeScope();


            //设置相关全局变量
            IocContainerManager.SetInstance(builder.Build());
            IocObjectManager.SetInstance(new IocObjectManager(new IocLifetimeScope()));
            DependencyResolver.SetResolver(new AutofacDependencyResolver(IocContainerManager.GetInstance()));

            //RazorViewEngine设置
            ViewEngines.Engines.Clear();
            ViewEngines.Engines.Add(new TmpRazorViewEngine());

            AutoMapperConfig();
            RouteConfig();
        }
Esempio n. 2
0
        /// <summary>
        /// Handles the Error event of the PageBase control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected void PageBase_Error(object sender, System.EventArgs e)
        {
            Exception currentError = Server.GetLastError();
            var       bllErrorInfo = IocObjectManager.GetInstance().Resolve <IErrorInfoService>();
            var       errorInfo    = new ErrorInfo();

            //if ((SessionManager.GetUser() != null))
            //{
            //    errorInfo.UID = SessionManager.GetUser().AccountID;
            //}
            errorInfo.ErrorMsg   = currentError.Message.ToString();
            errorInfo.ProgramID  = "0";
            errorInfo.Url        = Request.Url.ToString();
            errorInfo.StackTrace = currentError.ToString();
            StringBuilder sb = new StringBuilder();

            Response.Clear();
            sb.Append("<h2>系统错误:</h2><hr/>系统发生错误,错误编号为:");
            sb.Append(bllErrorInfo.Add(errorInfo));
            sb.Append("。该信息已被系统记录,请稍后重试或与系统管理员联系。<br/>错误地址:");
            sb.Append(Request.Url.ToString());
            sb.Append("<br/>错误信息: <font class='ErrorMessage'>");
            sb.Append(currentError.Message.ToString());
            sb.Append("</font><hr/><b>Stack Trace:</b><br/>");
            sb.Append(currentError.ToString());
            Response.Write(sb.ToString());
            Response.End();
            Server.ClearError();
        }
        //todo
        public static MvcHtmlString DropDownList <TModel>(
            this HtmlHelper <TModel> htmlHelper,
            DropDownListOption option,
            IDictionary <string, object> htmlAttributes)
        {
            var codeTableService = IocObjectManager.GetInstance().Resolve <ICodeTableService>();

            var codeTableList = option.FromWay ==
                                FromWayEnum.FromGeneralTable ? codeTableService.GetGeneralTable(
                new CodeTableDto()
            {
                TableName  = option.RefTable,
                TextField  = option.TextField,
                ValueField = option.ValueField
            }
                ) :
                                codeTableService.GetCodeTable(new CodeTableDto()
            {
                TableName = option.RefTable
            })
            ;

            var list = (from u in codeTableList
                        select new SelectListItem()
            {
                Text = u.text, Value = u.id, Selected = option.SelectValue == u.id ? true : false
            }).ToList();

            return(htmlHelper.DropDownList(htmlAttributes["name"].ToString(), list, option.OptionLabel, htmlAttributes));
        }
        /// 返回codeTable缓存数据
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public List <CodeTableItemDto> GetCodeTable(CodeTableDto model)
        {
            var cacheKey = model.TableName;
            var strSql   = "DECLARE @SQL NVARCHAR(2000) SELECT @SQL = SelectSql FROM tbCOM_CodeTable WHERE Name = @p0; ";

            if (!string.IsNullOrEmpty(model.Where))
            {
                strSql += string.Format(" SELECT @SQL=N'SELECT * FROM ('+@SQL+N') AS temp WHERE  {0}' ", model.Where);
            }

            strSql += " EXEC(@SQL) ";

            SqlParameter[] parameters = { new SqlParameter("@p0", model.TableName) };

            Func <List <CodeTableItemDto> > loadFun = () =>
            {
                var data = DbHelperSql.Query(DbHelperSql.DefaultQueryConn, strSql, parameters);
                return(data != null && data.Tables.Count > 0 ? Conversion.ConvertToList <CodeTableItemDto>(data.Tables[0]) : null);
            };

            if (model.UseCache && string.IsNullOrEmpty(model.Where))
            {
                ICacheManager cacheManager = IocObjectManager.GetInstance().Resolve <IHttpContextCacheManager>();
                return(cacheManager.Get(cacheKey, 60, loadFun, () => { return _versionControlService.GetVersionFlag(cacheKey); }));
            }
            else
            {
                return(loadFun());
            }
        }
Esempio n. 5
0
        public List <PrivilegeDto> GetUrlPermissionItems(string userID, short[] roleIDs)
        {
            var           sessionKey      = "UrlPermission";
            ICacheManager _sessionManager = IocObjectManager.GetInstance().Resolve <IHttpContextSessionManager>();
            var           result          = _sessionManager.Get(sessionKey, 20, () =>
            {
                return((from p in UseRepository.Table
                        join u in _programRepository.Table
                        on p.AccessValue equals u.ProgramID
                        where p.AccessMaster == 1 && p.OperationID == 1
                        //&& ((p.PrivilegeMaster == 1 && p.PrivilegeValue == roleID.ToString()) || (p.PrivilegeMaster == 2 && p.PrivilegeValue == userID)) && p.OperationID == 1
                        select new PrivilegeDto {
                    PrivilegeID = p.PrivilegeID, ValidFrom = p.ValidFrom, ValidUntil = p.ValidUntil, PrivilegeMaster = p.PrivilegeMaster, PrivilegeValue = p.PrivilegeValue, AccessMaster = p.AccessMaster, AccessValue = p.AccessValue, BranchMember = p.BranchMember, OperationID = p.OperationID, IsIdentity = p.IsIdentity, Url = u.Url
                }).Union(
                           from p in UseRepository.Table
                           join u in _programButtonRepository.Table
                           on p.AccessValue equals u.ProgramButtonID
                           where p.AccessMaster == 2 && p.OperationID == 1
                           //&& ((p.PrivilegeMaster == 1 && p.PrivilegeValue == roleID.ToString()) || (p.PrivilegeMaster == 2 && p.PrivilegeValue == userID)) && p.OperationID == 1
                           select new PrivilegeDto {
                    PrivilegeID = p.PrivilegeID, ValidFrom = p.ValidFrom, ValidUntil = p.ValidUntil, PrivilegeMaster = p.PrivilegeMaster, PrivilegeValue = p.PrivilegeValue, AccessMaster = p.AccessMaster, AccessValue = p.AccessValue, BranchMember = p.BranchMember, OperationID = p.OperationID, IsIdentity = p.IsIdentity, Url = u.Url
                }
                           ).ToList());
            }, () =>
            {
                return(_versionControlService.GetVersionFlag(sessionKey));
            });
            var item = result.Where(p => (p.PrivilegeMaster == 1 && roleIDs.Contains(short.Parse(p.PrivilegeValue))) || (p.PrivilegeMaster == 2 && p.PrivilegeValue == userID));

            return(item != null?item.ToList() : null);
        }
Esempio n. 6
0
        /// <summary>
        /// 得到AppSettings中的配置字符串信息
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public static string GetConfigString(string key)
        {
            string CacheKey = "AppSettings-" + key;

            var    cacheManager = IocObjectManager.GetInstance().Resolve <IHttpContextCacheManager>();
            object objModel     = cacheManager.Get <object>(CacheKey, 180, () =>
            {
                return(ConfigurationManager.AppSettings[key]);
            });

            return(objModel.ToString());
        }
Esempio n. 7
0
        /// <summary>
        /// 获取列表
        /// </summary>
        /// <param name="strLan"></param>
        /// <returns></returns>
        public List <GlobalResources> GetList(string strLan)
        {
            ICacheManager _cacheManager = IocObjectManager.GetInstance().Resolve <IHttpContextCacheManager>();
            var           resources     = _cacheManager.Get("GlobalResourcesByLan", 60, () =>
            {
                return(_globalResourcesRepository.Table.OrderBy(m => m.Lanuage).ToList().ToDictionaryWithMultipleKey(m => { return m.Lanuage; }, true));
            }, () =>
            {
                return(ServiceExtensions.FromIoc <IVersionControlService>().GetVersionFlag("GlobalResourcesByLan"));
            });

            return(resources[strLan]);
        }
Esempio n. 8
0
        public static T GetCachedModel <T>(this IService <T> service, Predicate <T> match) where T : BaseEntity
        {
            var cacheKey = "GeneralTable_" + service.UseRepository.GetTableName().Replace("dbo.", "");
            var versionControlService = IocObjectManager.GetInstance().Resolve <IVersionControlService>();

            ICacheManager _cacheManager = IocObjectManager.GetInstance().Resolve <IHttpContextCacheManager>();
            List <T>      allItems      = _cacheManager.Get(cacheKey, 60, () =>
            {
                return(service.UseRepository.Table.ToList());
            }, () => { return(versionControlService.GetVersionFlag(cacheKey)); });

            return(allItems.Find(match));
        }
Esempio n. 9
0
        public override void OnException(ExceptionContext filterContext)
        {
            if (!filterContext.ExceptionHandled)
            {
                string controllerName = (string)filterContext.RouteData.Values["controller"];
                string actionName     = (string)filterContext.RouteData.Values["action"];

                if (filterContext.Exception.GetType().Name == "CustomerException")
                {
                    HandleErrorInfo info = new HandleErrorInfo(filterContext.Exception, controllerName, actionName);
                    filterContext.Result = new ViewResult()
                    {
                        ViewName = "~/Views/Shared/Error.cshtml",
                        ViewData = new ViewDataDictionary <HandleErrorInfo>(info)
                    };
                    filterContext.ExceptionHandled = true;
                    filterContext.HttpContext.Response.TrySkipIisCustomErrors = true;
                }


                var bllErrorInfo = IocObjectManager.GetInstance().Resolve <IErrorInfoService>();
                var errorInfo    = new ErrorInfo();
                //if ((SessionManager.GetUser() != null))
                //{
                //    errorInfo.UID = SessionManager.GetUser().AccountID;
                //}
                //else
                //    errorInfo.UID = "";
                errorInfo.RunningTime = DateTime.Now;
                errorInfo.ErrorMsg    = filterContext.Exception.Message;
                errorInfo.ErrorCode   = 0;
                errorInfo.ProgramID   = "0";
                errorInfo.Url         = HttpContext.Current.Request.Url.ToString();
                errorInfo.StackTrace  = filterContext.Exception.StackTrace;
                errorInfo.SolveBy     = "";
                StringBuilder sb = new StringBuilder();
                HttpContext.Current.Response.Clear();
                sb.Append("<h2>系统错误:</h2><hr/>系统发生错误,错误编号为:");
                sb.Append(bllErrorInfo.Add(errorInfo));
                sb.Append("。该信息已被系统记录,请稍后重试或与系统管理员联系。<br/>错误地址:");
                sb.Append(HttpContext.Current.Request.Url.ToString());
                sb.Append("<br/>错误信息: <font class='ErrorMessage'>");
                sb.Append(filterContext.Exception.Message);
                sb.Append("</font><hr/><b>Stack Trace:</b><br/>");
                sb.Append(filterContext.Exception.StackTrace);
                HttpContext.Current.Response.Write(sb.ToString());
                HttpContext.Current.Response.End();
            }
        }
Esempio n. 10
0
        /// 返回codeTable缓存数据
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public List <CodeTableItemDto> GetCodeTable(CodeTableDto model)
        {
            var cacheKey = "CodeTable_" + model.TableName;
            var strSql   = "";

            List <SqlParameter> parameters = new List <SqlParameter>()
            {
            };

            if (model.SqlParameters != null && model.SqlParameters.Count >= 0)
            {
                model.SqlParameters.ForEach(m => parameters.Add(m));
                strSql = this.GetModel(m => m.TableName == model.TableName).SelectSql;

                if (!string.IsNullOrEmpty(model.Where))
                {
                    strSql = string.Format("SELECT * FROM ({0}) AS temp WHERE  {1} {2}", strSql, model.Where, model.Order);
                }
            }
            else
            {
                strSql = "DECLARE @SQL NVARCHAR(2000) SELECT @SQL = Select_Sql FROM tbCOM_Code_Table WHERE Table_Name = @p1989; ";
                parameters.Add(new SqlParameter("@p1989", model.TableName));

                if (!string.IsNullOrEmpty(model.Where))
                {
                    strSql += string.Format(" SELECT @SQL=N'SELECT * FROM ('+@SQL+N') AS temp WHERE  {0}' " + model.Order, model.Where);
                }

                strSql += " EXEC(@SQL) ";
            }

            Func <List <CodeTableItemDto> > loadFun = () =>
            {
                var data = DbHelperSql.Query(DbHelperSql.CouQuery, strSql, parameters.ToArray());
                return(data != null && data.Tables.Count > 0 ? Conversion.ConvertToList <CodeTableItemDto>(data.Tables[0]) : null);
            };

            if (model.UseCache && string.IsNullOrEmpty(model.Where))
            {
                ICacheManager cacheManager = IocObjectManager.GetInstance().Resolve <IHttpContextCacheManager>();
                return(cacheManager.Get(cacheKey, 60, loadFun, () => { return _versionControlService.GetVersionFlag(cacheKey); }));
            }
            else
            {
                return(loadFun());
            }
        }
Esempio n. 11
0
 /// <summary>
 /// 登出登陆处理需要清理的Session,
 /// </summary>
 /// <remarks></remarks>
 public static void Logout()
 {
     foreach (var item in SessionItems)
     {
         if (item.ClearWhenLogout)
         {
             HttpContext context = HttpContext.Current;
             if ((context != null) & (context.Session != null))
             {
                 context.Session.Remove(item.SessionKey);
             }
         }
     }
     //清空Session CJ
     IocObjectManager.GetInstance().Resolve <IHttpContextSessionManager>().Clear();
 }
Esempio n. 12
0
        public static T GetCachedModel <T>(this IService <T> service, params object[] pkeyValues) where T : BaseEntity
        {
            var cacheKey = service.UseRepository.GetTableName();

            foreach (var i in pkeyValues)
            {
                cacheKey = cacheKey + "_" + i.ToString();
            }

            ICacheManager _cacheManager = IocObjectManager.GetInstance().Resolve <IHttpContextCacheManager>();
            T             item          = _cacheManager.Get(cacheKey, 60, () =>
            {
                return(service.GetModel(pkeyValues));
            });

            return(item);
        }
Esempio n. 13
0
        public int GetVersion(string key)
        {
            ICacheManager cacheManager = IocObjectManager.GetInstance().Resolve <IHttpContextCacheManager>();
            var           result       = cacheManager.Get("VersionList", 1, () =>
            {
                return(UseRepository.Table.ToList());
            });

            var cacheItem = result.Find(t => t.Key == key);

            if (cacheItem == null)
            {
                throw new ArgumentNullException(key + "未插入版本控制表(Version_Control)中");
            }

            return(cacheItem.Version);
        }
Esempio n. 14
0
        public List <string> GetUrlIdentityItems(int privilegeMaster, string privilegeValue)
        {
            var           sessionKey      = "Privilege_Button";
            ICacheManager _sessionManager = IocObjectManager.GetInstance().Resolve <IHttpContextSessionManager>();
            var           result          = _sessionManager.Get(sessionKey, 20, () =>
            {
                return((from privelege in UseRepository.Table
                        join programButton in _programButtonRepository.Table
                        on privelege.AccessValue equals programButton.ProgramButtonID
                        where privelege.AccessMaster == 2
                        //p.IsIdentity == 2 & p.PrivilegeMaster == privilegeMaster & p.PrivilegeValue == privilegeValue
                        select new { privelege, programButton }).ToList());
            }, () =>
            {
                return(_versionControlService.GetVersionFlag(sessionKey));
            });

            return(result.Where(o => o.privelege.IsIdentity == 2 && o.privelege.PrivilegeMaster == privilegeMaster && o.privelege.PrivilegeValue == privilegeValue).Select(o => o.programButton.Url).ToList());
        }
Esempio n. 15
0
        public bool GetVersionFlag(string key)
        {
            ICacheManager cacheManager = IocObjectManager.GetInstance().Resolve <IHttpContextCacheManager>();
            var           result       = cacheManager.Get("VersionList", 1, () =>
            {
                return(UseRepository.Table.ToList());
            });

            if (versionList == null)
            {
                versionList = result;
                return(false);
            }

            var cacheItem = result.Find(t => t.Key == key);
            var item      = versionList.Find(t => t.Key == key);

            if (cacheItem == null)
            {
                UseRepository.Insert(new VersionControl()
                {
                    Key        = key,
                    Version    = 1,
                    UpdateDate = System.DateTime.Now
                });
                throw new ArgumentNullException(key + "未插入版本控制表(Version_Control)中");
            }

            if (item == null)
            {
                versionList.Add(cacheItem);
                return(true);
            }

            if (item.Version != cacheItem.Version)
            {
                versionList[versionList.IndexOf(item)].Version = cacheItem.Version;
                return(true);
            }

            return(false);
        }
Esempio n. 16
0
        public bool GetVersionFlag(string key)
        {
            ICacheManager cacheManager = IocObjectManager.GetInstance().Resolve <IHttpContextCacheManager>();
            var           result       = cacheManager.Get("VersionList", 1, () =>
            {
                return(UseRepository.Table.ToList());
            });

            if (versionList == null)
            {
                versionList = result;
                return(false);
            }

            var cacheItem = result.Find(t => t.Key == key);
            var item      = versionList.Find(t => t.Key == key);

            if (cacheItem != null)
            {
                if (cacheItem.Version == -1)
                {
                    return(true);
                }
                if (item == null || item.Version != cacheItem.Version)
                {
                    versionList = result;
                    return(true);
                }
            }
            else
            {
                //UseRepository.Insert(new VersionControl()
                //{
                //    Key = key,
                //    Version = 1
                //});
                throw new ArgumentNullException(key + "未插入版本控制表(Version_Control)中");
            }

            return(false);
        }
Esempio n. 17
0
        public static IHtmlContent DropDownListFor <TModel, TProperty>(
            this IHtmlHelper <TModel> htmlHelper,
            Expression <Func <TModel, TProperty> > expression,
            DropDownListOption option,
            IDictionary <string, object> htmlAttributes)
        {
            var codeTableService = IocObjectManager.GetInstance().Resolve <ICodeTableService>();

            var codeTableList = option.FromWay ==
                                FromWayEnum.FromGeneralTable ?
                                codeTableService.GetGeneralTable(
                new CodeTableDto()
            {
                TableName     = option.RefTable,
                TextField     = option.TextField,
                ValueField    = option.ValueField,
                Where         = option.Where,
                UseCache      = option.UseCache,
                SqlParameters = option.SqlParameters
            }
                ):
                                codeTableService.GetCodeTable(
                new CodeTableDto()
            {
                TableName     = option.RefTable,
                Where         = option.Where,
                UseCache      = option.UseCache,
                SqlParameters = option.SqlParameters
            }
                );

            var list = (from u in codeTableList
                        select new SelectListItem()
            {
                Text = u.text, Value = u.id, Selected = option.SelectValue == u.id ? true : false
            }).ToList();

            return(htmlHelper.DropDownListFor(expression, list, option.OptionLabel, htmlAttributes));
        }
Esempio n. 18
0
 public WebViewPage() : base()
 {
     _globalResourcesService = IocObjectManager.GetInstance().Resolve <IGlobalResourcesService>();
 }
Esempio n. 19
0
 public LoginAuthorizeAttribute()
 {
     _privilegeService = IocObjectManager.GetInstance().Resolve <IPrivilegeService>();
 }
Esempio n. 20
0
        /// <summary>
        /// 获取多语言
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public string L(string name)
        {
            IGlobalResourcesService globalResourcesService = IocObjectManager.GetInstance().Resolve <IGlobalResourcesService>();

            return(globalResourcesService.GetValue(name, Thread.CurrentThread.CurrentUICulture.Name));
        }
Esempio n. 21
0
 public static T FromIoc <T>()
 {
     return(IocObjectManager.GetInstance().Resolve <T>());
 }
Esempio n. 22
0
 static public IRepository <T> Create <T>() where T : BaseEntity
 {
     return(IocObjectManager.GetInstance().Resolve <IRepository <T> >());
 }
Esempio n. 23
0
 public GlobalResourcesService() : this(
         RepositoryFactory.Create <GlobalResources>(),
         IocObjectManager.GetInstance().Resolve <IHttpContextCacheManager>())
 {
 }