/// <summary> /// 根据给出经停点文本内容,获取经停点列表。 /// </summary> /// <param name="str">文本内容</param> /// <returns>经停点列表</returns> public static IEnumerable <TransitPoint> GetTransitPoints(string str) { List <TransitPoint> result = default(List <TransitPoint>); Regex pattern = new Regex(TransitPoint.FormatString); MatchCollection matchCollection = pattern.Matches(str); if (matchCollection.Count > 0) { result = new List <TransitPoint>(); foreach (Match item in matchCollection) { string airportCode = item.Groups["AirportCode"].Value; var arrivalTime = new Time(int.Parse(item.Groups["ArrivalHour"].Value), int.Parse(item.Groups["ArrivalMinute"].Value)); var arrivalAddDays = string.IsNullOrEmpty(item.Groups["ArrivalAddDays"].Value) ? 0 : int.Parse(item.Groups["ArrivalAddDays"].Value); var departureTime = new Time(int.Parse(item.Groups["DepartureHour"].Value), int.Parse(item.Groups["DepartureMinute"].Value)); var departureAddDays = string.IsNullOrEmpty(item.Groups["DepartureAddDays"].Value) ? 0 : int.Parse(item.Groups["DepartureAddDays"].Value); var transitPoint = new TransitPoint( airportCode, arrivalTime, arrivalAddDays, departureTime, departureAddDays ); result.Add(transitPoint); } } return(result); }
private TransitPoint CreateTransitPoint(WebPartManager manager, IConfigurationElement element, IExpressionsManager expressionsManager) { bool valid = false; TransitPoint transitPoint = new TransitPoint(); if (element.Attributes.ContainsKey("id")) { valid = true; transitPoint.Chronicler = (ReflectionServices.FindControlEx(element.GetAttributeReference("id").Value.ToString(), manager) as IChronicler); } if (element.Attributes.ContainsKey("member")) { transitPoint.Member = element.GetAttributeReference("member").Value.ToString(); } if (element.Attributes.ContainsKey("value")) { valid = true; transitPoint.Value = element.GetAttributeReference("value").Value; } if (element.Elements.ContainsKey("expression")) { valid = true; IConfigurationElement expressionElement = element.GetElementReference("expression"); IExpression expression = expressionsManager.Token(expressionElement.GetAttributeReference("type").Value.ToString()) as IExpression; if (null == expression) { throw new InvalidOperationException("Token is not an IExpression"); } expression.Make(expressionElement, expressionsManager); transitPoint.Expression = expression; } if (!valid) { transitPoint = null; } return(transitPoint); }