Example #1
0
        public List <string> GetDetails()
        {
            List <string> details = new List <string>();

            details.Add("Name:" + m_Name);
            details.Add("Phone Number:" + m_PhoneNumber);
            details.Add("Status:" + m_Status.ToString());
            details = m_Vehicle.GetVehicleDetails(details);
            return(details);
        }
Example #2
0
        public override string ToString()
        {
            string customer = string.Format(
                "The owner is {0} and his phone number is {1}{2}{3}Vehicle Status is: {4}",
                Name,
                PhoneNumber,
                Environment.NewLine,
                Vehicle.ToString(),
                VehicleStatus.ToString());

            return(customer);
        }
Example #3
0
        public override string ToString()
        {
            string GarageVehicleProfileInfo = string.Format(
                @"Profile of Vehicle in the Garage:
Vehicle Owner name is: {0}
Vehicle Owner Phone is: {1}
Vehicle State on the garage: {2}",
                NameOfOwner,
                PhoneOfOwner,
                VehicleStatus.ToString());

            return(GarageVehicleProfileInfo);
        }
        public override string ToString()
        {
            string details = string.Format(
                @"License Number: {0}
Model: {1}
Power type: {2}. Current power state: {3}
Vehicle status: {4}
Wheel info: {5}
",
                r_LicenseNumber,
                r_ModelName,
                PowerSource.ToString(),
                PowerSource.CurrAmount,
                VehicleStatus.ToString(),
                m_VehicleWheels[0].ToString());

            return(details);
        }
Example #5
0
        public async Task <IEnumerable <Vehicle> > Get(Guid?customerId, VehicleStatus?status)
        {
            _logger.LogInformation($"Request vehicles CustomerId={customerId?.ToString() ?? "All"}, Status={status?.ToString() ?? "All"}");

            var filter = new VehicleFilter
            {
                CustomerId = customerId
            };
            var storageData = await _repository.List(filter);

            _logger.LogTrace($"Found {storageData.Count()} vehicles");

            await _bus.SendSubscribeRequest(new VehicleTrackSubscribeRequest(storageData.Select(x => x.Id)));

            _logger.LogInformation($"Subscribed on {storageData.Count()} vehicles");

            var statuses = await _statusCache.ExtractStatuses(storageData);

            _logger.LogTrace($"Statuses extracted");

            var customers = await _customerService.ExtractCustomers(storageData);

            _logger.LogTrace($"Customers extracted");

            var result = storageData.Select(v => v.ToVehicle(statuses[v.Id], customers[v.CustomerId]));

            if (status != null)
            {
                result = result.Where(v => v.Status == status);
            }

            return(result);
        }
Example #6
0
        // Async method to send simulated telemetry
        private static async Task SendDeviceToCloudMessagesAsync()
        {
            Random rand            = new Random();
            var    routeEnumerator = route.GetEnumerator();

            routeEnumerator.MoveNext();

            while (true)
            {
                if (status == VehicleStatus.onTrip || status == VehicleStatus.pickedUp)
                {
                    // Create JSON message

                    if (requestLock && requestLockContractId.Trim() == contractId.Trim())
                    {
                        status = VehicleStatus.droppedOff; // there will be no telemetry after this.
                        //contractId = String.Empty;
                        requestLock             = false;
                        Console.ForegroundColor = ConsoleColor.Green;
                        Console.WriteLine();
                        Console.WriteLine("Car Locked! - Trip ended!");
                        Console.ResetColor();
                    }

                    var telemetryDataPoint = new
                    {
                        vin                 = myVin,
                        milage              = Math.Round(currentMilage, 4),
                        contractId          = contractId,
                        lat                 = routeEnumerator.Current.lat,
                        lon                 = routeEnumerator.Current.lon,
                        noOfHardBreaks      = rand.Next(1, 100) < hardBreakProbability ? 1 : 0,
                        collisionDetection  = rand.Next(1, 100) < 5 ? 1 : 0, // fixed 5% rate
                        tirePressure        = rand.Next(29, 30).ToString() + ',' + rand.Next(29, 30).ToString() + ',' + rand.Next(30, 32).ToString() + ',' + rand.Next(30, 32).ToString(),
                        fuelConsumptionRate = tripAvgFuelConsumptionRate + rand.Next(-2, 2),
                        speed               = avgMilesPerHour + rand.Next(-5, 5),
                        status              = status.ToString()
                    };

                    var messageString = JsonConvert.SerializeObject(telemetryDataPoint);
                    var message       = new Message(Encoding.ASCII.GetBytes(messageString));
                    message.ContentType = "application/json";

                    // Send the tlemetry message
                    await s_deviceClient.SendEventAsync(message);

                    Console.ForegroundColor = ConsoleColor.Blue;
                    Console.WriteLine(".");
                    Console.ResetColor();

                    if (status == VehicleStatus.pickedUp)
                    {
                        // after one picked-up status subsequent messages will have ontrip status.
                        status = VehicleStatus.onTrip;
                    }

                    var  milesPerSecond = (double)avgMilesPerHour / 3600;
                    bool hasMorePoint   = routeEnumerator.MoveNext();
                    if (!hasMorePoint)
                    {
                        routeEnumerator = route.GetEnumerator();
                        routeEnumerator.MoveNext();
                    }
                    currentMilage = currentMilage + (telemetryInterval / 1000) * milesPerSecond;
                }

                await Task.Delay(telemetryInterval);
            }
        }