namespace Web12306.Servers.TrainSuggestion { using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; using Newtonsoft.Json; public class RequestInfo { public string Key { get; set; } public string From { get; set; } public string To { get; set; } public DateTime Date { get; set; } [JsonProperty("tt")] public string[] SelectedTrain { get; set; } [JsonProperty("ts")] public string[] SelectedSeats { get; set; } public Dictionary Stops { get; set; } /// /// 检测是否有非法请求,有则返回true /// /// public bool CheckIllegal() { 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; //add 2014年9月4日 - 检测非法席别 if (SelectedSeats == null) return true; if (SelectedSeats.Length > 0) { if (Stops.Values.Any(s => !SelectedSeats.Any(x => s.TrainInfo.ticketMap.ContainsKey(x[0])))) return true; } //added 2014-9-9 检测非法车次 if (SelectedTrain != null && SelectedTrain.Length > 0) { 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; } return false; } public void PreprocessData() { foreach (var trainInfoItem in Stops.ToArray()) { if (trainInfoItem.Value.StopInfos == null) { Stops.Remove(trainInfoItem.Key); } else { trainInfoItem.Value.PreprocessData(Date); } } } } }