Beispiel #1
0
 protected sealed override void LimitQuery(LimitStatement statement)
 {
     if (statement != null)
     {
         QueryArgs.Add(new EqualQueryArg()
         {
             Variable = "offset", PropertyValue = new PropertyValue(statement.Offset)
         });
         QueryArgs.Add(new EqualQueryArg()
         {
             Variable = "howMany", PropertyValue = new PropertyValue(statement.Count)
         });
     }
 }
        protected override void ValidateArgs()
        {
            base.ValidateArgs();

            if (QueryArgs.ContainsVariable("ident"))
            {
                QueryArgs["ident"].PropertyValue = new PropertyValue(((string)(QueryArgs["ident"].PropertyValue.Value ?? "")).ToUpper());
            }
            else if (QueryArgs.ContainsVariable("faFlightID"))
            {
                var flightid = QueryArgs["faFlightID"];
                QueryArgs.Clear();
                QueryArgs.Add(new EqualQueryArg {
                    Variable = "ident", PropertyValue = new PropertyValue(flightid.PropertyValue.Value)
                });
            }
        }
        protected override void ValidateArgs()
        {
            base.ValidateArgs();

            if (QueryArgs.ContainsVariable("origin"))
            {
                QueryArgs["origin"].PropertyValue = new PropertyValue(((string)(QueryArgs["origin"].PropertyValue.Value ?? "")).ToUpper());
            }

            if (QueryArgs.ContainsVariable("destination"))
            {
                QueryArgs["destination"].PropertyValue = new PropertyValue(((string)(QueryArgs["destination"].PropertyValue.Value ?? "")).ToUpper());
            }

            if (QueryArgs.ContainsVariable("ident"))
            {
                QueryArgs["ident"].PropertyValue = new PropertyValue(((string)(QueryArgs["ident"].PropertyValue.Value ?? "")).ToUpper());
            }

            var departTimeCount = QueryArgs.Args.Where(x => x.Variable == "departuretime").Count();

            if (departTimeCount > 2)
            {
                throw new InvalidOperationException("Can only have 2 departureTime");
            }

            if (QueryArgs.ContainsVariable("ident"))
            {
                var ident = QueryArgs["ident"];
                var match = Regex.Match(ident.PropertyValue.Value.ToString(), @"(\D+)(\d+)", RegexOptions.IgnoreCase);
                if (match.Success)
                {
                    var airline  = match.Groups[1].Value;
                    var flightno = match.Groups[2].Value;
                    QueryArgs.Add(new EqualQueryArg {
                        Variable = "airline", PropertyValue = new PropertyValue(airline)
                    });
                    QueryArgs.Add(new EqualQueryArg {
                        Variable = "flightno", PropertyValue = new PropertyValue(flightno)
                    });
                    QueryArgs.Remove(ident);
                }
            }

            if (departTimeCount == 1)
            {
                var param = QueryArgs["departuretime"];
                if (((param is QueryGreaterThan || param is QueryGreaterThanEqual) && param.LeftProperty) ||
                    ((param is QueryLessThan || param is QueryLessThanEqual) && !param.LeftProperty))
                {
                    param.Variable = "startDate";
                    var startDate = (DateTime)Conversion.ConvertLongToDateTime(param.PropertyValue.Value);
                    var endDate   = startDate.AddDays(7); //no end date we just assume a week forward
                    QueryArgs.Add(new QueryArgs {
                        Variable = "endDate", PropertyValue = new PropertyValue(Conversion.ConvertDateTimeToLong(endDate))
                    });
                }
                else if (((param is QueryLessThan || param is QueryLessThanEqual) && param.LeftProperty) ||
                         ((param is QueryGreaterThan || param is QueryGreaterThanEqual) && !param.LeftProperty))
                {
                    param.Variable = "endDate";
                    var endDate   = (DateTime)Conversion.ConvertLongToDateTime(param.PropertyValue.Value);
                    var startDate = endDate.AddDays(-7); //no end date we just move a week backword
                    QueryArgs.Add(new QueryArgs {
                        Variable = "startDate", PropertyValue = new PropertyValue(Conversion.ConvertDateTimeToLong(startDate))
                    });
                }
                else if (param is EqualQueryArg)
                {
                    param.Variable = "startDate";
                    var startDate = (DateTime)Conversion.ConvertLongToDateTime(param.PropertyValue.Value);
                    var endDate   = startDate.AddMinutes(1);
                    startDate = startDate.AddMinutes(-1);

                    param.PropertyValue = new PropertyValue(Conversion.ConvertDateTimeToLong(startDate));
                    QueryArgs.Add(new EqualQueryArg {
                        Variable = "endDate", PropertyValue = new PropertyValue(Conversion.ConvertDateTimeToLong(endDate))
                    });
                }
            }
            else //two departureTImes
            {
                foreach (var param in QueryArgs.Args.Where(x => x.Variable == "departuretime"))
                {
                    if (((param is QueryGreaterThan || param is QueryGreaterThanEqual) && param.LeftProperty) ||
                        ((param is QueryLessThan || param is QueryLessThanEqual) && !param.LeftProperty))
                    {
                        param.Variable = "startDate";
                    }
                    else if (((param is QueryLessThan || param is QueryLessThanEqual) && param.LeftProperty) ||
                             ((param is QueryGreaterThan || param is QueryGreaterThanEqual) && !param.LeftProperty))
                    {
                        param.Variable = "endDate";
                    }
                }
            }
        }
Beispiel #4
0
 public sealed override void AddArg(QueryArgs args)
 {
     QueryArgs.Add(args);
 }