/// <summary> /// 获取静态资源地址 /// </summary> /// <param name="path">路径</param> /// <returns></returns> public static string GetStaticUrl(string path) { return(StringHelper.FormatDefault( string.Format("{0}{1}?v={2}", SettingConfig.GetValue(KeyModel.Config.Setting.KeyStaticUrl, KeyModel.Config.Setting.GroupWebsite), path, VersionNo))); }
/// <summary> /// 多语言资源文件初始 /// </summary> /// <param name="languages"></param> public static void LanguageResourceInit(List <CultureInfo> languages) { Assembly asm = Assembly.Load("App_GlobalResources"); foreach (var item in StringHelper.ToArray(SettingConfig.GetValue(KeyModel.Config.Setting.KeyResourceScript), new string[] { "," })) { #region 脚本资源文件处理 var itemArr = StringHelper.ToArray(item, new string[] { "|" }); if (!(itemArr != null && itemArr.Length == 2)) { continue; } Type resourceType = asm.GetType(itemArr[0]); ResourceManager resourceMgr = new ResourceManager(itemArr[0], asm); if (VerifyHelper.IsEmpty(resourceType) || VerifyHelper.IsEmpty(resourceMgr)) { continue; } foreach (var culture in languages) { string context = ScriptsHelper.GetJSONStringByList(ResourceHelper.GetList(resourceType, resourceMgr, culture), itemArr[1]); if (!VerifyHelper.IsEmpty(context)) { FileHelper.WriterFile(string.Format("{0}/{1}.{2}.js", HttpContext.Current.Server.MapPath(SettingConfig.GetValue(KeyModel.Config.Setting.KeyCulturePath, KeyModel.Config.Setting.GroupWebsite)), itemArr[1], culture), context); } } #endregion } foreach (var name in StringHelper.ToArray(SettingConfig.GetValue(KeyModel.Config.Setting.KeyResourceCache), new string[] { "," })) { #region 缓存资源文件处理 Type resourceType = asm.GetType(name); ResourceManager resourceMgr = new ResourceManager(name, asm); if (VerifyHelper.IsEmpty(resourceType) || VerifyHelper.IsEmpty(resourceMgr)) { continue; } foreach (var culture in languages) { var list = ResourceHelper.GetList(resourceType, resourceMgr, culture); if (!VerifyHelper.IsEmpty(list)) { CachingHelper.Set(string.Format("_RESOURCE_{0}_{1}", resourceType.FullName, culture), list); } } #endregion } }
/// <summary> /// 获取描述信息(无HTML) /// </summary> /// <param name="content"></param> /// <param name="length"></param> /// <param name="startIndex"></param> /// <returns></returns> public static string GetDescript(string content, int length = 0, int startIndex = 0) { if (VerifyHelper.IsEmpty(content)) { return(""); } if (length == 0) { length = IntHelper.Get(SettingConfig.GetValue(KeyModel.Config.Setting.KeyDescriptLength)); } content = HtmlsHelper.Remove(HtmlsHelper.Decode(content)); return(StringHelper.ToCutString(content, length, startIndex: startIndex)); }
/// <summary> /// 获取会员中心路径 /// </summary> /// <returns></returns> public static string GetMemberPath(bool isRouteFormat = false) { var path = StringHelper.Get(SettingConfig.GetValue(KeyModel.Config.Setting.KeyMemberPath, KeyModel.Config.Setting.GroupWebsite)); while (path.IndexOf("//") > -1) { path = path.Replace("//", "/"); } if (isRouteFormat) { path = path.Replace("/", "|"); } return(path); }
void IDoubleXHosting.OnInit(HttpApplication applaction) { base.OnInit(applaction); //语言资源文件初始 WarmupHelper.LanguageResourceInit(Languages); //初始全局RedisCient RedisHelper.Init(SettingConfig.GetValue(KeyModel.Config.Setting.KeyRedisDefault)); //初始Log4net日志配置 log4net.Config.XmlConfigurator.Configure(); //模块加载(暂默认全部) }
/// <summary> /// 创建IOC容器 /// </summary> /// <returns></returns> protected IContainer CreateContainer() { var builder = new ContainerBuilder(); //启动工作器 builder.RegisterType <DoubleXDefaultHosting>().As <IDoubleXHosting>(); builder.RegisterType <DoubleXMvcHosting>().As <IDoubleXHosting>(); //拦截器 builder.RegisterType <ServiceLogInterceptor>(); //拦截注册示例 //builder.RegisterType<EmployeeService>().As<IEmployeeService>().EnableClassInterceptors().InterceptedBy(typeof(ServiceLogInterceptor)); //EnableInterfaceInterceptors() //EnableClassInterceptors() #region 公共模块 builder.RegisterType <NotificationService>().As <INotificationService>() .EnableInterfaceInterceptors().InterceptedBy(typeof(ServiceLogInterceptor)); #endregion #region 组织机构 //builder.RegisterType<EmployeeService>().As<IEmployeeService>(); //builder.RegisterType<RoleService>().As<IRoleService>(); builder.RegisterType <EmployeeService>().As <IEmployeeService>() .EnableInterfaceInterceptors().InterceptedBy(typeof(ServiceLogInterceptor)); #endregion #region 会员信息 builder.RegisterType <MemberService>().As <IMemberService>() .EnableInterfaceInterceptors().InterceptedBy(typeof(ServiceLogInterceptor)); #endregion #region 流量信息 builder.RegisterType <TrafficService>().As <ITrafficService>() .EnableInterfaceInterceptors().InterceptedBy(typeof(ServiceLogInterceptor)); #endregion #region 付款/费用 builder.RegisterType <RechargeRecordService>().As <IRechargeRecordService>() .EnableInterfaceInterceptors().InterceptedBy(typeof(ServiceLogInterceptor)); builder.RegisterType <CostRecordService>().As <ICostRecordService>() .EnableInterfaceInterceptors().InterceptedBy(typeof(ServiceLogInterceptor)); #endregion #region 项目信息 builder.RegisterType <ProjectService>().As <IProjectService>() .EnableInterfaceInterceptors().InterceptedBy(typeof(ServiceLogInterceptor)); #endregion #region 术语管理 builder.RegisterType <TermService>().As <ITermService>() .EnableInterfaceInterceptors().InterceptedBy(typeof(ServiceLogInterceptor)); #endregion //MVC //builder.RegisterAssemblyTypes(assembly.GetExecutingAssembly()).AsImplementedInterfaces(); builder.RegisterControllers(Assembly.Load(SettingConfig.GetValue(KeyModel.Config.Setting.KeyApplaction, KeyModel.Config.Setting.GroupSystem)));//注册所有的Controller //WebApi //builder.RegisterControllers(Assembly.GetExecutingAssembly()).PropertiesAutowired(); builder.RegisterApiControllers(Assembly.Load(SettingConfig.GetValue(KeyModel.Config.Setting.KeyApplaction, KeyModel.Config.Setting.GroupSystem))).PropertiesAutowired(); var container = builder.Build(); //注册api容器需要使用HttpConfiguration对象 DependencyResolver.SetResolver(new AutofacDependencyResolver(container)); HttpConfiguration config = GlobalConfiguration.Configuration; config.DependencyResolver = new AutofacWebApiDependencyResolver(container); CoreHelper.SetContainer(container); return(container); }
public MongoRepository() : this(SettingConfig.GetValue(KeyModel.Config.Setting.KeyMongoDefault, KeyModel.Config.Setting.GroupDatabase)) { }
void IDoubleXHosting.OnStart(HttpApplication applaction) { base.OnStart(applaction); IRoutePublisher routePublisher = new RoutePublisher(new WebAppTypeFinder()); #region WebApi 默认注册 GlobalConfiguration.Configure(new Action <HttpConfiguration>((HttpConfiguration config) => { config.MapHttpAttributeRoutes(); routePublisher.RegisterApiRoutes(config); config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{action}/{id}", defaults: new { id = RouteParameter.Optional } ); //WebApi自定义请求模型绑定 config.ParameterBindingRules.Insert(0, param => { if (param.ParameterType == typeof(RequestModel)) { return(new ApiRequestBind(param)); } return(null); }); //WebApi自定义返回(Json及Json中时间处理) config.Services.Replace(typeof(IContentNegotiator), new WebApiJSONFormat(new JsonMediaTypeFormatter())); //让路由支持namespace config.Services.Replace(typeof(IHttpControllerSelector), new NamespaceHttpControllerSelector(config)); //WebApi自定义全局过滤器 //(该处注册后,每个action都会执行一次.controller/action不需要重复添加) config.Filters.Add(new ApiActionAttribute()); //处理返回过滤器 config.Filters.Add(new ApiExceptionAttribute()); //异常过滤器 })); #endregion #region Mvc 默认注册 //区域注册 AreaRegistration.RegisterAllAreas(); //过滤器注册 new Action <GlobalFilterCollection>((filters) => { filters.Add(new HandleErrorAttribute()); filters.Add(new MvcActionAttribute()); filters.Add(new MvcExceptionAttribute()); })(GlobalFilters.Filters); //路由注册 new Action <RouteCollection>((routes) => { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routePublisher.RegisterMvcRoutes(routes); //启用特性路由(error/404) routes.MapMvcAttributeRoutes(); routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }, namespaces: new[] { string.Format("{0}.Controllers", SettingConfig.GetValue(KeyModel.Config.Setting.KeyApplaction, KeyModel.Config.Setting.GroupSystem)) } ); })(RouteTable.Routes); //js,css绑定 new Action <BundleCollection>((bundles) => { #region //bundles.Add(new ScriptBundle("~/bundles/jquery").Include( // "~/Scripts/jquery-{version}.js")); //// 使用要用于开发和学习的 Modernizr 的开发版本。然后,当你做好 //// 生产准备时,请使用 http://modernizr.com 上的生成工具来仅选择所需的测试。 //bundles.Add(new ScriptBundle("~/bundles/modernizr").Include( // "~/Scripts/modernizr-*")); //bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include( // "~/Scripts/bootstrap.js", // "~/Scripts/respond.js")); //bundles.Add(new StyleBundle("~/Content/css").Include( // "~/Content/bootstrap.css", // "~/Content/site.css")); #endregion })(BundleTable.Bundles); //FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); //RouteConfig.RegisterRoutes(RouteTable.Routes); //BundleConfig.RegisterBundles(BundleTable.Bundles); //MVC模型绑定 ModelBinderProviders.BinderProviders.Insert(0, new MvcRequestBindProvider()); #endregion }
/// <summary> /// 获取站点Url地址 /// </summary> /// <param name="path">路径</param> /// <returns></returns> public static string GetWebUrl(string path = "/") { var webPath = SettingConfig.GetValue(KeyModel.Config.Setting.KeyWebPath, KeyModel.Config.Setting.GroupWebsite); return(StringHelper.FormatDefault(string.Format("{0}{1}", !VerifyHelper.IsEmpty(webPath) && webPath != "/" ? webPath : "", path))); }