Ejemplo n.º 1
0
        private async Task <CommandProcessingResult> ExecuteDemoCommandAsync(DeserializableCommand deserializableCommand)
        {
            var command = deserializableCommand.Command;

            try
            {
                dynamic parameters = WireCommandSchemaHelper.GetParameters(command);
                if (parameters != null)
                {
                    string statusstring = ReflectionHelper.GetNamedPropertyValue(
                        parameters,
                        "data",
                        usesCaseSensitivePropertyNameMatch: true,
                        exceptionThrownIfNoMatch: true);

                    if (statusstring != null &&
                        int.TryParse(statusstring.ToString(), out var count))
                    {
                        await this.commandProcessor.ExecuteCommandAsync("Demo run!");

                        await this.commandProcessor.ExecuteCommandAsync(Commands.DriveForward);

                        await this.commandProcessor.ExecuteCommandAsync(Commands.CameraLedOn);

                        while (count > 0)
                        {
                            count--;
                            await Task.Delay(200);
                        }

                        await this.commandProcessor.ExecuteCommandAsync(Commands.Horn);

                        await this.commandProcessor.ExecuteCommandAsync(Commands.CameraLedOff);

                        await this.commandProcessor.ExecuteCommandAsync(Commands.DriveStop);

                        return(CommandProcessingResult.Success);
                    }

                    // setPointTempDynamic is a null reference.
                    return(CommandProcessingResult.CannotComplete);
                }
                else
                {
                    // parameters is a null reference.
                    return(CommandProcessingResult.CannotComplete);
                }
            }
            catch (Exception)
            {
                return(CommandProcessingResult.RetryLater);
            }
        }
Ejemplo n.º 2
0
        private async Task <CommandProcessingResult> ExecuteSendWaypointsCommandAsync(DeserializableCommand deserializableCommand)
        {
            var command = deserializableCommand.Command;

            try
            {
                dynamic parameters = WireCommandSchemaHelper.GetParameters(command);
                if (parameters != null)
                {
                    string waypointString = ReflectionHelper.GetNamedPropertyValue(
                        parameters,
                        "data",
                        usesCaseSensitivePropertyNameMatch: true,
                        exceptionThrownIfNoMatch: true);
                    if (!string.IsNullOrEmpty(waypointString))
                    {
                        JArray waypointArray = JArray.Parse(waypointString);
                        if (waypointArray != null && waypointArray.Count > 0)
                        {
                            var wayPoints = new List <GeoCoordinate>();
                            foreach (var wayPoint in waypointArray)
                            {
                                if (double.TryParse(wayPoint[0].ToString(), out var lat) &&
                                    double.TryParse(wayPoint[1].ToString(), out var lon))
                                {
                                    var wayPointObject = new GeoCoordinate(lat, lon);
                                    wayPoints.Add(wayPointObject);
                                }
                            }

                            if (wayPoints.Count > 0)
                            {
                                await this.wayPointNavigator.StartWayPointNavigationAsync(wayPoints);
                            }

                            return(CommandProcessingResult.Success);
                        }
                    }
                }

                return(CommandProcessingResult.CannotComplete);
            }
            catch (Exception)
            {
                return(CommandProcessingResult.RetryLater);
            }
        }
Ejemplo n.º 3
0
        private async Task <CommandProcessingResult> ExecuteMoveVehicleCommandAsync(
            DeserializableCommand deserializableCommand)
        {
            var command = deserializableCommand.Command;

            try
            {
                dynamic parameters = WireCommandSchemaHelper.GetParameters(command);
                if (parameters != null)
                {
                    string value = ReflectionHelper.GetNamedPropertyValue(
                        parameters,
                        "data",
                        usesCaseSensitivePropertyNameMatch: true,
                        exceptionThrownIfNoMatch: true);

                    if (!string.IsNullOrEmpty(value) &&
                        Enum.TryParse(
                            typeof(Commands.DrivingDirection),
                            value.Trim(),
                            true,
                            out var direction))
                    {
                        var    cmddir           = (Commands.DrivingDirection)direction;
                        string drivingdirection = Helper.Helpers.MapDrivingDirectionToCommand(cmddir);
                        await this.commandProcessor.ExecuteCommandAsync(drivingdirection);

                        return(CommandProcessingResult.Success);
                    }
                }

                return(CommandProcessingResult.CannotComplete);
            }
            catch (Exception)
            {
                return(CommandProcessingResult.RetryLater);
            }
        }
Ejemplo n.º 4
0
        private async Task <CommandProcessingResult> ExecuteSetLightsCommandAsync(DeserializableCommand deserializableCommand)
        {
            var command = deserializableCommand.Command;

            try
            {
                dynamic parameters = WireCommandSchemaHelper.GetParameters(command);
                if (parameters != null)
                {
                    string value = ReflectionHelper.GetNamedPropertyValue(
                        parameters,
                        "data",
                        usesCaseSensitivePropertyNameMatch: true,
                        exceptionThrownIfNoMatch: true);

                    if (bool.TryParse(value, out var result))
                    {
                        var cmd = result ? Commands.CameraLedOn : Commands.CameraLedOff;
                        await this.commandProcessor.ExecuteCommandAsync(cmd);

                        return(CommandProcessingResult.Success);
                    }

                    // setPointTempDynamic is a null reference.
                    return(CommandProcessingResult.CannotComplete);
                }
                else
                {
                    // parameters is a null reference.
                    return(CommandProcessingResult.CannotComplete);
                }
            }
            catch (Exception)
            {
                return(CommandProcessingResult.RetryLater);
            }
        }