Ejemplo n.º 1
0
        public async Task <IEnumerable <Vehicle> > GetTenantVehicles([FromUri] string tenantId)
        {
            ServiceEventSource.Current.Message("Called GetTenantVehicles in STATELESS GATEWAY service to return collection of Vehicles for Tenant {0}", tenantId);

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

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

            foreach (Partition p in partitions)
            {
                long minKey = (p.PartitionInformation as Int64RangePartitionInformation).LowKey;
                IVehiclesStatefulService vehiclesServiceClient =
                    ServiceProxy.Create <IVehiclesStatefulService>(_vehiclesStatefulServiceUriInstance, new ServicePartitionKey(minKey));

                //Async call aggregating the results
                IList <Vehicle> currentPartitionResult;

                currentPartitionResult = await vehiclesServiceClient.GetTenantVehiclesAsync(tenantId);

                if (currentPartitionResult.Count > 0)
                {
                    //Aggregate List from current partition to our global result
                    aggregatedVehiclesList.AddRange(currentPartitionResult);
                }
            }
            //Return the aggregated list from all the partitions
            return(aggregatedVehiclesList);
        }
Ejemplo n.º 2
0
        public async Task <IEnumerable <Vehicle> > GetAllVehicles()
        {
            ServiceEventSource.Current.Message("Called GetAllVehicles in STATELESS GATEWAY service to return collection of ALL the Vehicles");

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

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

            foreach (Partition p in partitions)
            {
                long minKey = (p.PartitionInformation as Int64RangePartitionInformation).LowKey;
                IVehiclesStatefulService vehiclesServiceClient =
                    ServiceProxy.Create <IVehiclesStatefulService>(_vehiclesStatefulServiceUriInstance, new ServicePartitionKey(minKey));

                //Async call aggregating the results
                IList <Vehicle> currentPartitionResult;

                //(CDLTLL) This method should be substituted by a paginated method (20 vehicles per page or so).
                //No method should return ALL the vehicles as potentially there could be thousands or millions...
                currentPartitionResult = await vehiclesServiceClient.GetAllVehiclesAsync();

                if (currentPartitionResult.Count > 0)
                {
                    //Aggregate List from current partition to our global result
                    aggregatedVehiclesList.AddRange(currentPartitionResult);
                }
            }
            //Return the aggregated list from all the partitions
            return(aggregatedVehiclesList);
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
0
        public string Get()
        {
            //(CDLTLL) baseSFStatefulReliableServiceUrl = FabricRuntime.GetActivationContext().ApplicationName + "/VehiclesStatefulService/";
            baseSFStatefulReliableServiceUri = "fabric:/VehiclesSFApp/VehiclesStatefulService/";

            string serviceUri = baseSFStatefulReliableServiceUri;

            vehiclesStatefulServiceInstance = new Uri(serviceUri);

            ServicePartitionKey      servicePartitionKey = new ServicePartitionKey();
            IVehiclesStatefulService serviceClient       =
                ServiceProxy.Create <IVehiclesStatefulService>(this.vehiclesStatefulServiceInstance, servicePartitionKey);

            //Calling the method in the Stateful service that will be executing in a particular partition/node
            string counter = serviceClient.GetCounter().Result;

            return("Current Counter is: " + counter);
        }
Ejemplo n.º 5
0
        async Task IVehicleActor.SetVehicleAsync(Vehicle vehicle)
        {
            //Create or Update a Vehicle in its related VehicleActor object
            var resultUpdatingActor = this.StateManager.TryAddStateAsync(VehicleEntityPropertyName, vehicle);

            //Create or Update the same Vehicle into Stateful Services
            //like multiple possible "QueryViews" on Stateful Services using Reliable Collections under the covers.
            //These Stateful services could be multiple "Read/query views" like in CQRS architectures with several "Read-sides"
            FabricClient fabricClient = new FabricClient();
            string       vehiclesStatefulServiceUri         = "fabric:/VehiclesSFApp/VehiclesStatefulService";
            Uri          vehiclesStatefulServiceUriInstance = new Uri(vehiclesStatefulServiceUri);

            long vehiclePartitionKey = vehicle.GetPartitionKey();
            IVehiclesStatefulService vehiclesServiceClient =
                ServiceProxy.Create <IVehiclesStatefulService>(vehiclesStatefulServiceUriInstance,
                                                               new ServicePartitionKey(vehiclePartitionKey));

            bool result = await vehiclesServiceClient.AddOrUpdateVehicleAsync(vehicle);

            return;
        }