You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

287 lines
11 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using log4net;
using DSWeb.Areas;
using System.Threading;
using System.Timers;
using DSWeb.Areas.Mobile.DAL;
using System.Net;
using System.IO;
using AutoMapper;
using DSWeb.Areas.Dispatch.DB;
using DSWeb.Areas.Dispatch.Models;
using DSWeb.Areas.MvcShipping.DB;
using DSWeb.Areas.MvcShipping.Models.MsOpRule;
using DSWeb.Areas.MvcShipping.Models.MsOpSeaeRunBill;
using DSWeb.Areas.MvcShipping.Comm;
using BookingWeb.DB.Model;
namespace DSWeb
{
public class Global : System.Web.HttpApplication
{
public static void RegisterRoutes(RouteCollection routes)
{
string ls = System.Configuration.ConfigurationSettings.AppSettings["isly"].ToString();
if (ls == "1")
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.IgnoreRoute("{resource}.aspx/{*pathInfo}");
routes.MapRoute(
"Default", //适用于虚拟主机,ext可以为ashx,aspx,ascx,asmx
"{controller}.{ext}/{action}/{id}",
new { controller = "Home", action = "Index", id = "" },
new[] { "DSWeb.Controllers" });
routes.MapRoute(
"Default2", //适用可以设置IIS或IIS版本为7.0以上
"{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = "" },
new[] { "DSWeb.Controllers" });
}
}
protected void Application_Start(object sender, EventArgs e)
{
string ls = System.Configuration.ConfigurationSettings.AppSettings["isly"].ToString();
if (ls == "1")
{
AreaRegistration.RegisterAllAreas();
RegisterRoutes(RouteTable.Routes);
}
System.Timers.Timer evtTimer = new System.Timers.Timer(150000);
evtTimer.Elapsed += new System.Timers.ElapsedEventHandler(OnEvtTimer);
evtTimer.Interval = 150000;
evtTimer.Enabled = true;
//HomeService.HomeService.StoreMemcachedForCount();
//log4j日志记录
log4net.Config.XmlConfigurator.Configure();//读取了配置文件中关于Log4Net配置信息.
//开启一个线程,扫描异常信息队列。
string filePath = Server.MapPath("/Log/");
ThreadPool.QueueUserWorkItem((a) =>
{
while (true)
{
//判断一下队列中是否有数据
if (ExceptionAttribute.ExecptionQueue.Count() > 0)
{
Exception ex = ExceptionAttribute.ExecptionQueue.Dequeue();
if (ex != null)
{
//将异常信息写到日志文件中。
//string fileName = DateTime.Now.ToString("yyyy-MM-dd");
//File.AppendAllText(filePath+fileName+".txt",ex.ToString(),System.Text.Encoding.UTF8);
ILog logger = LogManager.GetLogger("errorMsg");
logger.Error(ex.ToString());
}
else
{
//如果队列中没有数据,休息
Thread.Sleep(3000);
}
}
else
{
//如果队列中没有数据,休息
Thread.Sleep(3000);
}
}
}, filePath);
var appid = ConfigurationManager.AppSettings["appid"];
if (appid != null && appid.ToString() != "")
{
//每隔5个小时刷新微信的AccessToken
System.Timers.Timer myTimer = new System.Timers.Timer(1000 * 60 * 60 * 5);
myTimer.Elapsed += new ElapsedEventHandler(myTimer_Elapsed);
myTimer.Enabled = true;
myTimer.AutoReset = true;
}
InitMapper();
JobScheduler.Start();
}
private static void OnEvtTimer(object sender, System.Timers.ElapsedEventArgs e)
{
//定时运行服务
//c#让webservice定时执行
/*HomeService.HomeService.StoreMemcachedForCount("");
HomeService.HomeService.StoreMemcachedForList("");*/
// HomeService.NavigationService.StoreMemcached();
}
protected void Session_Start(object sender, EventArgs e)
{
}
protected void Application_BeginRequest(object sender, EventArgs e)
{
if (Context.Request.FilePath == "/") Context.RewritePath("Default.aspx");
}
protected void Application_AuthenticateRequest(object sender, EventArgs e)
{
}
protected void Application_Error(object sender, EventArgs e)
{
Exception lastError = Server.GetLastError();
ExceptionAttribute.AddException(lastError);
//Server.Transfer("~/Error/FriendError.aspx");
}
protected void Session_End(object sender, EventArgs e)
{
}
protected void Application_End(object sender, EventArgs e)
{
#region 微信刷新AccessToken定时器关联
//下面的代码是关键可解决IIS应用程序池自动回收的问题
Thread.Sleep(1000);
//这里设置你的web地址可以随便指向你的任意一个aspx页面甚至不存在的页面目的是要激发Application_Start
string url = "http://www.baidu.com";
HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
Stream receiveStream = myHttpWebResponse.GetResponseStream();//得到回写的字节流
#endregion
}
void myTimer_Elapsed(object source, ElapsedEventArgs e)
{
try
{
DBLog.Log(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + ":AutoTask is Working!");
TokenTask();
}
catch (Exception ee)
{
DBLog.Log(ee.ToString());
}
}
void TokenTask()
{
AccessTokenDAL.RefrashAccessToken();
}
void InitMapper()
{
Mapper.Initialize(cfg =>
{
cfg.CreateMap<Areas.Dispatch.DB.InfoClient, InfoClientLoginViewModel>();
cfg.CreateMap<Areas.Dispatch.DB.InfoClient, InfoClientTruckViewModel>();
cfg.CreateMap<DriverRegistViewModel, DriverInfo>();
cfg.CreateMap<DriverInfo, DriverRegistViewModel>();
cfg.CreateMap<DriverInfo, DriverAuditViewModel>()
.ForMember(x => x.AuditStatsName, m =>
{
m.MapFrom(d => d.IsAudit ? "已审核" : "未审核");
});
cfg.CreateMap<OpStatusInfo, OpStatusViewModel>()
.ForMember(x => x.COMPTIME, m =>
{
m.MapFrom(d => d.COMPTIME.HasValue ? d.COMPTIME.Value.ToString("yyyy-MM-dd HH:mm:ss") : "");
})
.ForMember(x => x.COMPTIME_DATE, m =>
{
m.MapFrom(d => d.COMPTIME.HasValue ? d.COMPTIME.Value.ToString("yyyy-MM-dd") : "");
})
.ForMember(x => x.COMPTIME_TIME, m =>
{
m.MapFrom(d => d.COMPTIME.HasValue ? d.COMPTIME.Value.ToString("HH:mm:ss") : "");
});
cfg.CreateMap<OpRule, OpRuleListViewModel>()
.ForMember(x => x.EnableDisableTime, m =>
{
m.MapFrom(d => d.EnableDisableTime.HasValue ? d.EnableDisableTime.Value.ToString("yyyy/MM/dd HH:mm:ss") : "");
});
cfg.CreateMap<OpRule, OpRuleEditViewModel>();
cfg.CreateMap<OpRuleEditViewModel, OpRule>();
cfg.CreateMap<OpRuleItemEditViewModel, OpRuleItem>();
cfg.CreateMap<OpRule, OpRuleCheckListViewModel>();
cfg.CreateMap<OpRuleItem, OpRuleItemCheckListViewModel>();
cfg.CreateMap<OpSeaeRunBill, RunBillEditViewModel>()
.ForMember(x => x.RUNTIME, m =>
{
m.MapFrom(d => d.RUNTIME.HasValue ? d.RUNTIME.Value.ToString("yyyy-MM-dd HH:mm:ss") : "");
});
cfg.CreateMap<RunBillEditViewModel, OpSeaeRunBill>();
cfg.CreateMap<OpSeaeRunBill, RunBillListViewModel>()
.ForMember(x => x.RUNTIME, m =>
{
m.MapFrom(d => d.RUNTIME.HasValue ? d.RUNTIME.Value.ToString("yyyy-MM-dd HH:mm:ss") : "");
})
.ForMember(x => x.STATUS, m =>
{
m.MapFrom(d => EnumExt.GetDescription((OpSeaeRunBillStatus)Enum.Parse(typeof(OpSeaeRunBillStatus), d.STATUS), true));
})
.ForMember(x => x.CREATETIME, m =>
{
m.MapFrom(d => d.CREATETIME.HasValue ? d.CREATETIME.Value.ToString("yyyy-MM-dd HH:mm:ss") : "");
});
cfg.CreateMap<DispInfoClient, DispInfoClientRegistViewModel>();
cfg.CreateMap<DispInfoClientRegistViewModel, DispInfoClient>();
cfg.CreateMap<DispInfoClient, DispInfoClientAuditViewModel>()
.ForMember(x => x.AuditStatsName, m =>
{
m.MapFrom(d => d.IsAudit ? "已审核" : "未审核");
});
cfg.CreateMap<BookingUser, BookingUserViewModel>()
.ForMember(x => x.IDENTIFICATION_STATE_STR, m =>
{
m.MapFrom(d => d.IDENTIFICATION_STATE == "NotIndent" ? "未提交" : (d.IDENTIFICATION_STATE == "Identifying" ? "待审核" : (d.IDENTIFICATION_STATE == "Indentified" ? "已通过" : "已驳回")));
})
.ForMember(x => x.STATUS_STR, m =>
{
m.MapFrom(d => d.STATUS == "Active" ? "激活" : "禁用");
})
.ForMember(x => x.REG_TIME, m =>
{
m.MapFrom(d => d.REG_TIME.ToString("yyyy-MM-dd HH:mm:ss"));
});
cfg.CreateMap<OP_SEAE_ORDER, OrderEditViewModel>()
.ForMember(x => x.ISCONTAINERSOC, map => map.MapFrom(t => t.ISCONTAINERSOC == "1" ? true : false))
.ForMember(x => x.ETD, map => map.MapFrom(t => t.ETD.HasValue ? t.ETD.Value.ToString("yyyy-MM-dd") : ""))
.ForMember(x => x.MODIFYTIME, map => map.MapFrom(t => t.MODIFYTIME.HasValue ? t.MODIFYTIME.Value.Ticks : 0))
;
});
}
}
}