// // GET: /Enter/ public ActionResult Index() { ConfigDataCache Cache = EnterPageInitialize.CreateInstance(EnterPageInitialize.ConfigProviderCreate()); #region 动态字段初始化 ViewBag.Title = Cache.Map_ConfigData["Title"]; ViewBag.MenuNameForPhoneSize = Cache.Map_ConfigData["MenuNameForPhoneSize"]; ViewBag.EnterNoticName = Cache.Map_ConfigData["EnterNoticName"]; ViewBag.FirstNav = Cache.Map_ConfigData["FirstNav"]; ViewBag.SecondNav = Cache.Map_ConfigData["SecondNav"]; ViewBag.ThirdNav = Cache.Map_ConfigData["ThirdNav"]; ViewBag.EnterNoticContentTitle = Cache.Map_ConfigData["EnterNoticContentTitle"]; ViewBag.EnterNoticContent = Cache.Map_ConfigData["EnterNoticContent"]; ViewBag.FooterFirstTitle = Cache.Map_ConfigData["FooterFirstTitle"]; ViewBag.FooterFirstContent = Cache.Map_ConfigData["FooterFirstContent"]; ViewBag.TableDownloadContent_left = Cache.Map_ConfigData["TableDownloadContent_left"]; ViewBag.TableDownloadContent_right = Cache.Map_ConfigData["TableDownloadContent_right"]; ViewBag.FirstNav_Title = Cache.Map_ConfigData["FirstNav_Title"]; ViewBag.SecondNav_Title = Cache.Map_ConfigData["SecondNav_Title"]; ViewBag.ThirdNav_Title = Cache.Map_ConfigData["ThirdNav_Title"]; ViewBag.TableDownloadFileName = Cache.Map_ConfigData["TableDownloadFileName"]; ViewBag.TableDownloadLink = Cache.Map_ConfigData["TableDownloadLink"]; ViewBag.FourthNav = Cache.Map_ConfigData["FourthNav"]; #endregion #region portfolios初始化 int portfolioModalSum = Convert.ToInt32(Cache.Map_ConfigData["portfolioModalSum"]); portfolioModal portfolio = new portfolioModal(); portfolioModal[] portfolios = new portfolioModal[portfolioModalSum]; for (int i = 1; i <= portfolioModalSum; i++) { portfolio.Name = "portfolioModal" + i.ToString(); portfolio.ImgSrc = Cache.Map_ConfigData["portfolioImgSrc" + i.ToString()]; portfolio.TitleInside = Cache.Map_ConfigData["portfolioTitleInside" + i.ToString()]; portfolio.ImgSrcInside = Cache.Map_ConfigData["portfolioImgSrcInside" + i.ToString()]; portfolio.paragraphInside = Cache.Map_ConfigData["portfolioparagraphInside" + i.ToString()]; portfolio.LinkNameInside = Cache.Map_ConfigData["portfolioLinkNameInside" + i.ToString()]; portfolio.LinkContentInside = Cache.Map_ConfigData["portfolioLinkContentInside" + i.ToString()]; portfolio.LinkInside = Cache.Map_ConfigData["portfolioLinkInside" + i.ToString()]; portfolios[i - 1] = DeepCopy <portfolioModal>(portfolio);//这里必须深拷贝 } ViewBag.portfolios = portfolios; #endregion #region EnterForm初始化 int EnterFormFieldSum = Convert.ToInt32(Cache.Map_ConfigData["EnterFormFieldSum"]); EnterFormFieldModul EnterFormField = new EnterFormFieldModul(); EnterFormFieldModul[] EnterFormFields = new EnterFormFieldModul[EnterFormFieldSum]; for (int a = 1; a <= EnterFormFieldSum; a++) { EnterFormField.LabelName = "EnterFormField" + a.ToString(); EnterFormField.TypeName = Cache.Map_ConfigData["EnterFormFieldTypeName" + a.ToString()]; EnterFormField.PlaceholderString = Cache.Map_ConfigData["EnterFormFieldPlaceholderString" + a.ToString()]; EnterFormField.Attribute = Cache.Map_ConfigData["EnterFormAttribute" + a.ToString()]; EnterFormField.DisplayName = Cache.Map_ConfigData["EnterFormDisplayName" + a.ToString()]; EnterFormFields[a - 1] = DeepCopy <EnterFormFieldModul>(EnterFormField);//这里必须深拷贝 } ViewBag.EnterFormFields = EnterFormFields; #endregion return(View()); }
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); WebApiConfig.Register(GlobalConfiguration.Configuration); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); DBInitialize.CreatDefaultTableData();//首次启动程序会因为去创建DBContext中的Dynamic模型而费时间,但是启动起来了就OK了。 //这里做一个开关,项目不涉及到的时候关闭,避免影响效率 if (Convert.ToBoolean(ConfigurationManager.AppSettings["DynamicModelSwitch"])) { EnterPageInitialize.CreateInstance(EnterPageInitialize.ConfigProviderCreate());//启动报名页面修改的单例对象,提上同理。 } //ContainerBuilder builder = new ContainerBuilder(); //builder.RegisterControllers(Assembly.GetExecutingAssembly()); //builder.RegisterAssemblyTypes(Assembly.GetExecutingAssembly()).AsImplementedInterfaces(); //var container = builder.Build(); //DependencyResolver.SetResolver(new AutofacDependencyResolver(container)); var builder = new ContainerBuilder(); var assembly = Assembly.GetExecutingAssembly(); var BllService = System.Reflection.Assembly.Load("Yuruisoft.RS.BLL");//类似于RegisterType的形式注册,被注册类型可以不是直接引用,但是必须被加载 //var dbModel = System.Reflection.Assembly.Load("Yuruisoft.RS.Model"); builder.RegisterAssemblyTypes(BllService, BllService).AsImplementedInterfaces(); //builder.RegisterAssemblyTypes(dbModel, dbModel).AsImplementedInterfaces(); builder.RegisterControllers(typeof(MvcApplication).Assembly); var container = builder.Build(); DependencyResolver.SetResolver(new AutofacDependencyResolver(container)); #region 线程与异步管理 log4net.Config.XmlConfigurator.Configure(new System.IO.FileInfo(Server.MapPath("/App_Data/Config/Log4net.Config/log4net.Config.xml")));//读取配置信息 //string fileLogPath = Server.MapPath("App_Data/Log/"); //开启一个线程,扫描日志队列 ThreadPool.QueueUserWorkItem((a) => { while (true) { if (MyExceptionAttribute.exceptonQueue.Count() > 0) //判断是否有数据 { Exception ex = MyExceptionAttribute.exceptonQueue.Dequeue(); //出队 if (ex != null) { //string fileName = DateTime.Now.ToString("yyyy-MM-dd") + ".txt"; //File.AppendAllText(fileLogPath + fileName, ex.ToString(), Encoding.Default);//将异常写到文件中,用追加 ILog logger = LogManager.GetLogger("errorMsg"); logger.Error(ex);//将异常信息写到磁盘上 } else { Thread.Sleep(3000);//如果队列中没有数据,让当前线程休息,避免造成CPU空转 } } else { //这里可以自定义 Thread.Sleep(3000); //如果队列中没有数据,让当前线程休息,避免造成CPU空转 } } }); ThreadPool.QueueUserWorkItem((a) => {//这里是更新键值对的操作 while (true) { if (ExtendMethord.OperateScoreCacheQueue.Count() > 0) { OperateScoreCache op = ExtendMethord.OperateScoreCacheQueue.Dequeue(); if (op != null) { op.ScoreCacheAddOne(); } else { Thread.Sleep(3000); } } else { Thread.Sleep(3000); } } }); ThreadPool.QueueUserWorkItem((a) => {//这里是更新键值对的操作 while (true) { ExtendMethord.UpdateDB(); Thread.Sleep(3000); } }); #endregion }