Exemplo n.º 1
0
        public IEnumerable <string> Get()
        {
            //ActorId myActorId = ActorId.NewId();
            int     vehicleId    = 1;
            ActorId actorId      = new ActorId(vehicleId);
            var     vehicleProxy = ActorProxy.Create <ILiveVehicleActor>(actorId, "fabric:/LiveVStatefulApp");

            LiveVehicle tempVehicleData1 = new LiveVehicle();

            tempVehicleData1.VehicleId = vehicleId;
            //Seattle Pike's Place coordinates
            tempVehicleData1.GPSCoordinates.Latitude  = 47.608875;
            tempVehicleData1.GPSCoordinates.Longitude = -122.340098;

            //Here we would find out the ZipCode related to the GPS coordinates.
            //For now, I set the ZipCode directly
            string currentZipCode = "98101";

            tempVehicleData1.CurrentZipCode = currentZipCode;

            //Output TBD --> ("Setting vehicleId {0} to Actor {1}", vehicleId, vehicleProxy.GetActorId() );
            vehicleProxy.SetVehicleLiveDataAsync(tempVehicleData1).Wait();

            string resultDone = "Actor " + vehicleProxy.GetActorId().ToString() + " is External-VehicleID: " + vehicleProxy.GetCurrentVehicleLiveDataAsync().Result.VehicleId.ToString();

            return(new string[] { "TEST: ", resultDone });

            //return new string[] { "TEST: ", "TEST 2" };
        }
Exemplo n.º 2
0
        static void AddVehicles()
        {
            Console.WriteLine("\nCreating and adding vehicles to the Live IoT system");

            string defaultCurrentZipCode = "98101";

            //ADD VEHICLE 1 /////////////////////////////////////////////
            int         vehicleId1       = 1;
            LiveVehicle tempVehicleData1 = new LiveVehicle();

            tempVehicleData1.VehicleId = vehicleId1;
            //Seattle Pike's Place coordinates
            tempVehicleData1.GPSCoordinates.Latitude  = 47.608875;
            tempVehicleData1.GPSCoordinates.Longitude = -122.340098;

            //Here we would find out the ZipCode related to the GPS coordinates.
            //For now, I set the ZipCode directly
            tempVehicleData1.CurrentZipCode = defaultCurrentZipCode;

            //Call Http Service to add vehicle
            AddLiveVehicle(tempVehicleData1);
            /////////////////////////////////////////////////////////////////////////

            //ADD VEHICLE 2 /////////////////////////////////////////////
            int         vehicleId2       = 2;
            LiveVehicle tempVehicleData2 = new LiveVehicle();

            tempVehicleData2.VehicleId = vehicleId2;
            //Seattle STARBUCKS ORIGINAL coordinates 47.610021, -122.342649
            tempVehicleData2.GPSCoordinates.Latitude  = 47.610021;
            tempVehicleData2.GPSCoordinates.Longitude = -122.342649;

            //Here we would find out the ZipCode related to the GPS coordinates.
            //For now, I set the ZipCode directly
            tempVehicleData2.CurrentZipCode = defaultCurrentZipCode;

            //Call Http Service to add vehicle
            AddLiveVehicle(tempVehicleData2);
            /////////////////////////////////////////////////////////////////////////

            //ADD VEHICLE 3 /////////////////////////////////////////////
            int         vehicleId3       = 3;
            LiveVehicle tempVehicleData3 = new LiveVehicle();

            tempVehicleData3.VehicleId = vehicleId3;
            //Seattle CONVENTION CENTER coordinates 47.612283, -122.331918
            tempVehicleData3.GPSCoordinates.Latitude  = 47.612283;
            tempVehicleData3.GPSCoordinates.Longitude = -122.331918;

            //Here we would find out the ZipCode related to the GPS coordinates.
            //For now, I set the ZipCode directly
            tempVehicleData3.CurrentZipCode = defaultCurrentZipCode;

            //Call Http Service to add vehicle
            AddLiveVehicle(tempVehicleData3);
            /////////////////////////////////////////////////////////////////////////

            Console.WriteLine("##### END OF ADDING VEHICLES PROCESS #####");
            Console.WriteLine("##########################################");
        }
Exemplo n.º 3
0
        private static void AddLiveVehicle(LiveVehicle vehicle)
        {
            Uri            serviceAddress = new Uri(SeatMapGatewayServiceUrl + "LiveVehicle");
            HttpWebRequest req            = WebRequest.CreateHttp(serviceAddress);

            string data = JsonConvert.SerializeObject(vehicle);
            //This gives you the byte array.

            var dataToSend = Encoding.UTF8.GetBytes(data);

            req.ContentType   = "application/json";
            req.ContentLength = dataToSend.Length;
            req.Method        = "POST";

            req.GetRequestStream().Write(dataToSend, 0, dataToSend.Length);

            var          response   = req.GetResponse();
            Stream       dataStream = response.GetResponseStream();
            StreamReader reader     = new StreamReader(dataStream);
            // Read the content.
            string responseFromServer = reader.ReadToEnd();

            //Console.WriteLine("********************************");
            Console.WriteLine(responseFromServer);
            //Console.WriteLine(" ");
        }
Exemplo n.º 4
0
        public Task SetVehicleLiveDataAsync(LiveVehicle vehicleData)
        {
            ActorEventSource.Current.ActorMessage(this, "Setting current live data to VehicleId to {0}", vehicleData.VehicleId);
            this.State.CurrentVehicleLiveData = vehicleData;

            return(Task.FromResult(true));
        }
Exemplo n.º 5
0
        public LiveVehicle Get(int id)
        {
            ActorId vehicleActorId = new ActorId(id);

            var vehicleProxy = ActorProxy.Create <ILiveVehicleActor>(vehicleActorId, "fabric:/LiveVStatefulApp");

            LiveVehicle retVehicle = vehicleProxy.GetCurrentVehicleLiveDataAsync().Result;

            return(retVehicle);
        }
Exemplo n.º 6
0
        public GPSCoordinates GetVehicleGPSCoordinates(int id)
        {
            LiveVehicle vehicle = this.Get(id);

            //ActorId vehicleActorId = new ActorId(id);
            //var vehicleProxy = ActorProxy.Create<ILiveVehicleActor>(vehicleActorId, "fabric:/LiveVStatefulApp");
            //LiveVehicle vehicle = vehicleProxy.GetCurrentVehicleLiveDataAsync().Result;

            return(vehicle.GPSCoordinates);
        }
Exemplo n.º 7
0
        public IActionResult Post([FromBody] LiveVehicle vehicle)
        {
            //Add vehicle as new vehicle Actor and add it to the VehicleLocator collection
            //Check first that it doesn't exist!

            //Here we would find out the ZipCode related to the GPS coordinates provided by the vehicle data.
            //For now, I set the ZipCode directly
            vehicle.CurrentZipCode = "98101";

            //Add (if not exists to List of vehicles per ZipCode in VehiclesLocatorActor Service)

            //Create a VehicleLocator proxy to check if the vehicle already exists in our system
            //I use ZipCode as ID for the VehiclesList locator actor ID service
            ActorId vehiclesLocatorActorId = new ActorId(vehicle.CurrentZipCode);
            var     vehicleLocatorProxy    = ActorProxy.Create <IVehiclesLocatorActor>(vehiclesLocatorActorId, "fabric:/LiveVStatefulApp");

            bool vehicleExist = false;

            vehicleExist = vehicleLocatorProxy.IsVehicleInZipCodeAreaAsync(vehicle.VehicleId).Result;

            string detailedResponse;

            if (!vehicleExist)
            {
                //Add vehicle to ZipCode Area Actor Manager
                vehicleLocatorProxy.AddVehicleToZipAreaAsync(vehicle.VehicleId);

                //Create and update the vehicle actor just in case it didn't exist
                ActorId vehicleActorId = new ActorId(vehicle.VehicleId);
                var     vehicleProxy   = ActorProxy.Create <ILiveVehicleActor>(vehicleActorId, "fabric:/LiveVStatefulApp");

                //Add/Update data to Vehicle Actor
                vehicleProxy.SetVehicleLiveDataAsync(vehicle).Wait();

                detailedResponse = "Vehicle ID " + vehicle.VehicleId.ToString() + "added to ZipCode area " + vehicle.CurrentZipCode;
            }
            else
            {
                detailedResponse = "Vehicle already in ZipCode area. Nothing is added";
            }

            // Get the response.
            //(The response could be improved by adding the Partition where the Actor has been created, etc.)
            // --> (CDLTLL) --> System.Fabric.FabricRuntime.GetNodeContext().NodeName

            //string message = "Vehicle added to MyShuttle Live IoT system";
            //String.Format("{0} added to partition {1} at {2}", seatMap.Name, client.ResolvedServicePartition.Info.Id, serviceAddress),
            //Encoding.UTF8,
            //"text/html");

            return(new HttpStatusCodeResult(201)); //201 Created
        }