public ActionResult AddAgentInfo(ExtensionAgents extensionAgents) { extensionAgents.SubTime = DateTime.Now; extensionAgents.ModifiedOn = DateTime.Now; extensionAgents.Sort = "0"; extensionAgents.DelFlag = 0; extensionAgents.ExtensionScore = 0; if (extensionAgents.UrlName == null) { return(Content("no")); } string[] temp = extensionAgents.UrlName.Split(','); if (temp.Length != 2) { return(Content("no")); } else { extensionAgents.GUID = Guid.NewGuid().ToString("N"); extensionAgents.RouteStatisticsLinks_ID = int.Parse(temp[0]); extensionAgents.ExtensionUrl = ExtendMethord.ExUrlCreate(extensionAgents.GUID); extensionAgents.ExtensionScore = 0; extensionAgents.UrlName = temp[1]; extensionAgentsService.AddEntity(extensionAgents); Dictionary <string, string> Dic = new Dictionary <string, string> { { extensionAgents.GUID, routeStatisticsLinksService.LoadEntities(c => c.ID == extensionAgents.RouteStatisticsLinks_ID).Select(c => c.Url).FirstOrDefault() } }; if (ExtendMethord.GetUrl().URLMap != null) { ExtendMethord.GetUrl().URLMap = Dic; // 更新内存值,这里的等号相当于添加 } } return(Content("ok")); }
public ActionResult Index(string strQuery) {//strQuery为推广员的ID if (strQuery != null) { string url; try { UrlCache cache = ExtendMethord.GetUrl(); url = cache.URLMap[strQuery]; ExtendMethord.OperateScoreCacheQueue.Enqueue(new OperateScoreCache(strQuery));//增加放到队列里去做 } catch (Exception e) { UrlCache cache = new UrlCache(); url = cache.URLMap[strQuery]; ExtendMethord.OperateScoreCacheQueue.Enqueue(new OperateScoreCache(strQuery));//增加放到队列里去做 } return(Redirect(url)); } else { return(Content("链接错误!")); } }
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 }