From e6c9c8027d220672d89f34768c298b1123d71965 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=A8=E9=B1=BC=28iFish=29?= Date: Sun, 14 Dec 2014 23:17:15 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TrainInfomationProviderService/Program.cs | 2 +- .../StationInfo/SameStationManager.cs | 2 +- .../Web/Controllers/TransitController.cs | 8 +++ Web12306/TrainSuggestion.cs | 64 ++++++++++++++++--- Web12306/Web.config | 20 ++++-- Web12306/Web12306.csproj | 38 ++++++----- Web12306/js/data.js | 3 + Web12306/js/otn/trainstationsuggest.js | 7 +- Web12306/js/ui/ui-oncetrainsitquery.js | 2 +- Web12306/packages.config | 6 +- 10 files changed, 116 insertions(+), 36 deletions(-) diff --git a/TrainInfomationProviderService/Program.cs b/TrainInfomationProviderService/Program.cs index c7183af..8ec287c 100644 --- a/TrainInfomationProviderService/Program.cs +++ b/TrainInfomationProviderService/Program.cs @@ -33,7 +33,7 @@ namespace TrainInfomationProviderService if (ConfigurationManager.AppSettings["local_disable_train_provider"] == "1") return; - RouteTable.Routes.MapRoute("traintransit", "tt/{action}/{id}", new { area = "", controller = "Transit", id = UrlParameter.Optional }, new { action = "(keepalive|ls|ss|tor|dt|ls2)" }, new[] { "TrainInfomationProviderService.Web" }); + RouteTable.Routes.MapRoute("traintransit", "tt/{action}/{id}", new { area = "", controller = "Transit", id = UrlParameter.Optional }, new { action = "(keepalive|ls|ss|tor|dt|ls2|ssa)" }, new[] { "TrainInfomationProviderService.Web" }); Task.Run(() => { try diff --git a/TrainInfomationProviderService/StationInfo/SameStationManager.cs b/TrainInfomationProviderService/StationInfo/SameStationManager.cs index b78a8b4..dfef2c5 100644 --- a/TrainInfomationProviderService/StationInfo/SameStationManager.cs +++ b/TrainInfomationProviderService/StationInfo/SameStationManager.cs @@ -18,7 +18,7 @@ namespace TrainInfomationProviderService.StationInfo public static Dictionary> SameStationMap { get; private set; } private static Timer _timer; - private static string _cacheUrl; + internal static string _cacheUrl; public static void Init() { diff --git a/TrainInfomationProviderService/Web/Controllers/TransitController.cs b/TrainInfomationProviderService/Web/Controllers/TransitController.cs index f470f8e..786bce9 100644 --- a/TrainInfomationProviderService/Web/Controllers/TransitController.cs +++ b/TrainInfomationProviderService/Web/Controllers/TransitController.cs @@ -13,6 +13,8 @@ namespace TrainInfomationProviderService.Web.Controllers { using System.IO; + using FSLib.MvcWeb.ActionResults; + public class TransitController : Controller { #region Overrides of Controller @@ -85,6 +87,12 @@ namespace TrainInfomationProviderService.Web.Controllers }, JsonRequestBehavior.AllowGet); } + [OutputCache(Duration = 3600), ActionName("ssa")] + public ActionResult GetSameStationAll() + { + return Content(System.IO.File.ReadAllText(SameStationManager._cacheUrl), "application/json", Encoding.UTF8); + } + public ActionResult KeepAlive() { return Json(new { ret = true, time = DateTime.Now.ToString() }, JsonRequestBehavior.AllowGet); diff --git a/Web12306/TrainSuggestion.cs b/Web12306/TrainSuggestion.cs index 20fd7c1..a75e6ab 100644 --- a/Web12306/TrainSuggestion.cs +++ b/Web12306/TrainSuggestion.cs @@ -11,6 +11,35 @@ using Newtonsoft.Json.Serialization; namespace Web12306 { + using System.IO; + using System.Text; + using System.Web.Hosting; + + public class TrainSuggestionCommonData + { + public static readonly Dictionary FrequencyTrainCodeMap = new Dictionary + { + {"任意车次", ".*"}, + {"任意高铁", "G.*"}, + {"任意动车", "D.*"}, + {"任意城铁", "C.*"}, + {"任意直达", "Z.*"}, + {"任意特快", "T.*"}, + {"任意快车", "K.*"}, + {"任意普客", @"\d*"}, + {"任意临客", "L.*"}, + {"任意G/D/C", "[GDC].*"}, + {"任意直达特快", "[TZ].*"}, + {"动车或高铁或城铁", @"[DGC].*"}, + {"特快或直达", @"[TZ].*"}, + {"快车", @"K.*"}, + {"高铁", @"G.*"}, + {"动车", @"D.*"}, + {"城铁", @"C.*"}, + {"直达", @"Z.*"}, + {"特快", @"T.*"} + }; + } public class TrainSuggestion : IHttpHandler { #region Implementation of IHttpHandler @@ -58,7 +87,7 @@ namespace Web12306 return; } context.Response.ContentType = string.IsNullOrEmpty(callback) ? "application/json" : "application/javascript"; - context.Response.BufferOutput = false; + context.Response.BufferOutput = true; context.Response.StatusCode = 200; try @@ -78,8 +107,21 @@ namespace Web12306 } catch (Exception ex) { - throw ex; - return; + //log error + var sb = new StringBuilder(); + sb.AppendLine(string.Format("请求URL: {0}", context.Request.Url)); + sb.AppendLine("数据:"); + sb.AppendLine(data); + sb.AppendLine(); + + sb.AppendLine("错误信息:"); + sb.AppendLine(ex.ToString()); + + var log = DateTime.Now.Ticks + ".log"; + var path = HostingEnvironment.MapPath("~/errors/tr/"); + path = PathUtility.Combine(path, log); + Directory.CreateDirectory(Path.GetDirectoryName(path)); + File.WriteAllText(path, sb.ToString()); } } @@ -671,7 +713,7 @@ namespace Web12306 /// public bool CheckIllegal() { - if (Key != "stupid360") + if (Key != "stupid360" || Stops == null) return true; if (Stops.Values.Any(s => (s.TrainInfo.code == s.TrainInfo.from.code && s.TrainInfo.to.code == s.TrainInfo.end.code))) return true; @@ -688,7 +730,7 @@ namespace Web12306 //added 2014-9-9 检测非法车次 if (SelectedTrain != null && SelectedTrain.Length > 0) { - var reg = new Regex("^(" + string.Join("|", SelectedTrain) + ")$", RegexOptions.IgnoreCase); + var reg = new Regex("^(" + string.Join("|", SelectedTrain.Select(s => TrainSuggestionCommonData.FrequencyTrainCodeMap.GetValue(s).DefaultForEmpty(s))) + ")$", RegexOptions.IgnoreCase); if (Stops.Keys.Any(s => !reg.IsMatch(s))) return true; } @@ -698,9 +740,16 @@ namespace Web12306 public void PreprocessData() { - foreach (var trainInfoItem in Stops.Values) + foreach (var trainInfoItem in Stops.ToArray()) { - trainInfoItem.PreprocessData(Date); + if (trainInfoItem.Value.StopInfos == null) + { + Stops.Remove(trainInfoItem.Key); + } + else + { + trainInfoItem.Value.PreprocessData(Date); + } } } } @@ -887,7 +936,6 @@ namespace Web12306 public string supportCard { get; set; } public string saleTime { get; set; } public string secureStr { get; set; } - public DateTime? selltime { get; set; } public string date { get; set; } public string limitSellInfo { get; set; } diff --git a/Web12306/Web.config b/Web12306/Web.config index 5b05e58..fd538f6 100644 --- a/Web12306/Web.config +++ b/Web12306/Web.config @@ -56,14 +56,26 @@ - - - - + + + + + + + + + + + + + + + + diff --git a/Web12306/Web12306.csproj b/Web12306/Web12306.csproj index 938961b..bd268ee 100644 --- a/Web12306/Web12306.csproj +++ b/Web12306/Web12306.csproj @@ -24,6 +24,7 @@ ..\ true 1.0 + 16ae31ba true @@ -69,6 +70,7 @@ ..\packages\Microsoft.Net.Http.2.2.28\lib\net45\System.Net.Http.Primitives.dll + True @@ -76,9 +78,9 @@ - - True - ..\packages\Microsoft.AspNet.WebPages.2.0.30506.0\lib\net40\System.Web.Helpers.dll + + False + ..\packages\Microsoft.AspNet.WebPages.3.2.2\lib\net45\System.Web.Helpers.dll False @@ -88,9 +90,9 @@ False ..\packages\Microsoft.AspNet.WebApi.WebHost.5.2.2\lib\net45\System.Web.Http.WebHost.dll - - True - ..\packages\Microsoft.AspNet.Mvc.4.0.40804.0\lib\net40\System.Web.Mvc.dll + + False + ..\packages\Microsoft.AspNet.Mvc.5.2.2\lib\net45\System.Web.Mvc.dll False @@ -100,17 +102,17 @@ False ..\packages\Microsoft.AspNet.Razor.3.2.2\lib\net45\System.Web.Razor.dll - - True - ..\packages\Microsoft.AspNet.WebPages.2.0.30506.0\lib\net40\System.Web.WebPages.dll + + False + ..\packages\Microsoft.AspNet.WebPages.3.2.2\lib\net45\System.Web.WebPages.dll - - True - ..\packages\Microsoft.AspNet.WebPages.2.0.30506.0\lib\net40\System.Web.WebPages.Deployment.dll + + False + ..\packages\Microsoft.AspNet.WebPages.3.2.2\lib\net45\System.Web.WebPages.Deployment.dll - - True - ..\packages\Microsoft.AspNet.WebPages.2.0.30506.0\lib\net40\System.Web.WebPages.Razor.dll + + False + ..\packages\Microsoft.AspNet.WebPages.3.2.2\lib\net45\System.Web.WebPages.Razor.dll @@ -283,6 +285,10 @@ + + {6d4588aa-a0fd-4364-972c-22b0ab7938f9} + FSLib.Extension + {c385d043-316a-4f05-a6b9-e70bf0ed8db6} TrainInfomationProviderService @@ -323,12 +329,14 @@ 这台计算机上缺少此项目引用的 NuGet 程序包。启用“NuGet 程序包还原”可下载这些程序包。有关详细信息,请参阅 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。 + +