Example #1
0
        public async Task <IEnumerable <Vehicle> > GetVehiclesInArea([FromUri] string tenantId, [FromUri] double topLatitude, [FromUri] double leftLongitude, [FromUri] double bottomLatitude, [FromUri] double rightLongitude)
        {
            ServiceEventSource.Current.Message("Called GetVehiclesInArea in STATELESS GATEWAY service to return collection of Vehicles in a particular Map's area and for Tenant {0}", tenantId);

            long topLeftGeoQuad    = GeoTileTool.GeoCoordinateToInt64QuadKey(topLatitude, leftLongitude);
            long bottomDownGeoQuad = GeoTileTool.GeoCoordinateToInt64QuadKey(bottomLatitude, rightLongitude);

            List <Vehicle> aggregatedVehiclesList = new List <Vehicle>();

            ServicePartitionList partitions = await _fabricClient.QueryManager.GetPartitionListAsync(_vehiclesStatefulServiceUriInstance);

            //Do for each partition with partition-key (QuadKey) is greater than top-lef-quadkey or smaller than down-bottom-quadkey
            foreach (Partition p in partitions)
            {
                long lowPartitionKey  = (p.PartitionInformation as Int64RangePartitionInformation).LowKey;
                long highPartitionKey = (p.PartitionInformation as Int64RangePartitionInformation).HighKey;

                //If partition-keys are within our boundary, query vehicles in partition
                if (topLeftGeoQuad <= highPartitionKey && bottomDownGeoQuad >= lowPartitionKey)
                {
                    IVehiclesStatefulService vehiclesServiceClient =
                        ServiceProxy.Create <IVehiclesStatefulService>(_vehiclesStatefulServiceUriInstance, new ServicePartitionKey(lowPartitionKey));

                    //Async call aggregating the results
                    IList <Vehicle> currentPartitionResult;
                    if (tenantId == "MASTER")
                    {
                        currentPartitionResult = await vehiclesServiceClient.GetVehiclesInAreaAsync(topLatitude, leftLongitude, bottomLatitude, rightLongitude);
                    }
                    else
                    {
                        currentPartitionResult = await vehiclesServiceClient.GetVehiclesInAreaByTenantAsync(tenantId, topLatitude, leftLongitude, bottomLatitude, rightLongitude);
                    }

                    if (currentPartitionResult.Count > 0)
                    {
                        //Aggregate List from current partition to our global result
                        aggregatedVehiclesList.AddRange(currentPartitionResult);
                    }
                }
            }

            //Show List of vehicles to return
            //foreach (Vehicle vehicle in aggregatedVehiclesList)
            //    System.Diagnostics.Debug.WriteLine($"Returning Existing Car: {vehicle.FullTitle} -- Vehicle-Id: {vehicle.Id} -- TenantId: {vehicle.TenantId} -- Orig-Latitude {vehicle.Latitude}, Orig-Longitude {vehicle.Longitude}, GeoQuadKey {vehicle.GeoQuadKey}, Geohash {vehicle.Geohash}");

            //Return the aggregated list from all the partitions
            return(aggregatedVehiclesList);
        }
Example #2
0
 private void EncodeGeoQuadKey()
 {
     _geoLocationQuadKey = GeoTileTool.GeoCoordinateToInt64QuadKey(Latitude, Longitude);
 }