public List <Trip> GetTripWithRange(QueryBuilder filterTrip, LocationRange departureLocRange) { tripDatabaseLock.EnterReadLock(); try { tripDatabase = XDocument.Load(tripDatabasePath); var baseQuery = (from t in tripDatabase.Descendants("Trip") where departureLocRange.contains(new Location(Convert.ToDouble(t.Element("DepartureLatitude").Value), Convert.ToDouble(t.Element("DepartureLongitude").Value))) select new Trip() { ID = Convert.ToInt32(t.Element("ID").Value), Owner = t.Element("Owner").Value, DepartureName = t.Element("DepartureName").Value, DepartureDateTime = Convert.ToDateTime(t.Element("DepartureDateTime").Value), ArrivalName = t.Element("ArrivalName").Value, ArrivalDateTime = Convert.ToDateTime(t.Element("ArrivalDateTime").Value), Smoke = Convert.ToBoolean(t.Element("Smoke").Value), Music = Convert.ToBoolean(t.Element("Music").Value), Cost = Convert.ToDouble(t.Element("Cost").Value), FreeSits = Convert.ToInt32(t.Element("FreeSits").Value), Notes = t.Element("Notes").Value, Modifiable = Convert.ToBoolean(t.Element("Modifiable").Value) }); IEnumerable <Trip> filteredQuery = FilterQuery(filterTrip, baseQuery); return(filteredQuery.ToList()); } finally { tripDatabaseLock.ExitReadLock(); } }
public string FormatTextAtLine(LocationRange range) { var(line, _, _, column, _, columnLength, _) = range; var output = FormatTextPreludeAt(line); var padding = new string(' ', Utilities.GetNumberOfDigits(line + 100) // the space the line number takes + 3 // the space for " | " + (column - 1) // the space before the character's column ); var actualLine = GetPrettyLineAt(line); if (actualLine == "") { output += "EOF"; return(output); } output += actualLine + "\n\t"; // the tab is to adjust for the source code padding output += padding + new string('^', columnLength) + " right here\n"; return(output + FormatTextEpilogueAt(line)); }
public string FormatTextAtLines(LocationRange range) { var(firstLine, lastLine, lineLength, firstColumn, _, _, _) = range; var output = FormatTextPreludeAt(firstLine); var padding = new string(' ', Utilities.GetNumberOfDigits(lastLine + 100) // the space the line number takes + 3 // the space for " > " + (firstColumn - 1) // the space before the character's column ); output += "\t" + padding + "v error starts here\n"; for (int i = 0; i < lineLength; i++) { var actualLine = GetPrettyLineAt( lineNumber: firstLine + i, separator: ">" ); if (actualLine == "") { output += "EOF"; return(output); } output += actualLine + '\n'; } return(output + FormatTextEpilogueAt(lastLine)); }
protected GraphqlParseException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext streamingContext) : base(info, streamingContext) { LocationRange = new LocationRange( start: new Location(info.GetInt32("StartLine"), info.GetInt32("StartColumn")), stop: new Location(info.GetInt32("StopLine"), info.GetInt32("StopColumn")) ); }
}//End SearchTrip #endregion private string[] NeighbourNodesInRange(LocationRange departureLocRange) { List <string> targetNeighbours = new List <string>(); foreach (ServiceNode neighbour in Neighbours) { /** The neighbour is within the range. */ if (departureLocRange.contains(neighbour.Location)) { targetNeighbours.Add(baseForwardAddress + neighbour.NodeName); } } return(targetNeighbours.ToArray()); }
public OperationTypeDefinition(OperationType operationType, TypeName typeName, LocationRange location) : base(location) { OperationType = operationType; TypeName = typeName; }
public GraphqlParseException(string message, LocationRange locationRange, Exception innerException) : base(message, innerException) { LocationRange = locationRange; }
public VariableDefinition(Variable variable, ITypeNode graphQLType, IValueNode?defaultValue, LocationRange location) : base(location) { this.Variable = variable; this.GraphQLType = graphQLType; this.DefaultValue = defaultValue; }
public TypeCondition(TypeName typeName, LocationRange location) : base(location) { TypeName = typeName; }
public NonNullType(ITypeNode baseType, LocationRange location) : base(location) { BaseType = baseType; }
public Argument(string name, IValueNode value, LocationRange location) : base(location) { Name = name; Value = value; }
public Result SearchTrip(QueryBuilder queryTrip) { // Error! Search range cannot be a negative number! if (queryTrip.Range < 0) { SearchTripError error = new SearchTripError(); error.Comment = "Search range must be a non-negative number!"; return(error); } /** Check if the current node is the nearest node to the departure location. */ string targetNode = NearestNodeToDeparture(queryTrip.DepartureName); if (!targetNode.Equals(NodeName)) { Console.WriteLine("Decision: sending SearchTripCommand to : {0}", targetNode); ForwardRequiredResult forwardRequest = new ForwardRequiredResult(); forwardRequest.RequestID = serviceImpl.generateGUID(); forwardRequest.Destination = baseForwardAddress + targetNode; return(forwardRequest); } // The Search has no range criteria. We can perform a simple search or // a simple forward request. if (queryTrip.Range == 0) { Console.WriteLine("Testing Range 0"); List <Trip> matchingTrip = GetTripZeroRange(queryTrip); SearchTripResult searchResult = new SearchTripResult(matchingTrip); searchResult.OriginalQueryID = queryTrip.ID; Console.WriteLine("{0} {1} Trip(s) were found in {2}", serviceImpl.LogTimestamp, matchingTrip.Count, NodeName); return(searchResult); } // The client specified a range for search: we need to do a more complex search // and potentially a multiple forwarding. else { Location departureLoc = GMapsAPI.addressToLocation(queryTrip.DepartureName); LocationRange departureLocRange = new LocationRange(departureLoc.Latitude, departureLoc.Longitude, queryTrip.Range); List <Trip> matchingTrip = GetTripWithRange(queryTrip, departureLocRange); SearchTripResult searchResult = new SearchTripResult(matchingTrip); searchResult.OriginalQueryID = queryTrip.ID; Console.WriteLine("{0} {1} Trip(s) were found in {2}", serviceImpl.LogTimestamp, matchingTrip.Count, NodeName); /** Check if there are other neighbour nodes within the range of search. */ string[] targetNeighbours = NeighbourNodesInRange(departureLocRange); if (targetNeighbours.Length > 0) { foreach (string n in targetNeighbours) { Console.WriteLine("{0} is in range.", n); } return(new NullResult()); } else { //Console.WriteLine("No neighbour is in range."); return(searchResult); } } }//End SearchTrip