Exemple #1
0
 private static void setBaseValues(RoadDetails roadDetails)
 {
     roadDetails.BaseUrl = getAppsettingValue(Constants.AppKeyBaseUrl);
     roadDetails.ApiName = getAppsettingValue(Constants.AppKeyApiName);
     roadDetails.ApiId   = getAppsettingValue(Constants.AppKeyApiId);
     roadDetails.ApiKey  = getAppsettingValue(Constants.AppKeyApiKey);
 }
Exemple #2
0
        public static void Main(string[] args)
        {
            try
            {
                var roadDetails = new RoadDetails();
                for (; ;)
                {
                    Console.WriteLine("Please enter a Road Name");
                    roadDetails.RoadName = Console.ReadLine();

                    if (string.IsNullOrWhiteSpace(roadDetails.RoadName))
                    {
                        Console.WriteLine("Can't enter empty value, Please enter a Road Name");
                        continue;
                    }

                    if (roadDetails.RoadName.ToLower() == "exit")
                    {
                        Exit();
                    }

                    getRoadStatusDetails(roadDetails);
                }
            }
            catch (Exception)
            {
                Console.WriteLine("error processing your request, please reset and restart");
            }
        }
Exemple #3
0
        public async Task <string> GetRoadStatusCall(RoadDetails roadDetails)
        {
            var client = new HttpClient();

            client.BaseAddress = new Uri(roadDetails.FormattedBaseUrl);
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(roadDetails.ApiMediaType));

            var response = await client.GetAsync(roadDetails.FormattedApiKeyDetails);

            var result = await response.Content.ReadAsStringAsync();

            client.Dispose();

            return(result);
        }
        public async Task <RoadStatusInfo> FetchRoadStatus(RoadDetails roadDetails)
        {
            roadDetails.FormattedBaseUrl       = _helperClass.formatAPIAddress(roadDetails);
            roadDetails.FormattedApiKeyDetails = _helperClass.formatAPIKey(roadDetails);
            roadDetails.ApiMediaType           = Constants.ApiMediaType;

            var dataResult = await _dataProcess.GetRoadStatusCall(roadDetails);

            if (dataResult.Contains(Constants.statusCode) &&
                dataResult.Contains(Constants.status))
            {
                return(setUnsuccesData(roadDetails.RoadName));
            }

            var formattedStatus = _helperClass.JsonConverter <RoadStatusInfo>(dataResult);

            return(formattedStatus);
        }
Exemple #5
0
        private static void getRoadStatusDetails(RoadDetails roadDetails)
        {
            ContainerSetUp.Init();
            var initiator = InitiateContainer.Retrieve <ProcessRoadService>();

            setBaseValues(roadDetails);

            var resultSet = initiator.FetchRoadStatusDetails(roadDetails);

            if (string.IsNullOrWhiteSpace(resultSet.Result.httpStatusCode) &&
                resultSet.Result.httpStatusCode != Constants.statusCode &&
                string.IsNullOrWhiteSpace(resultSet.Result.message))
            {
                successMessage(resultSet.Result);
            }
            else
            {
                unsuccessMessage(resultSet.Result);
            }
        }
Exemple #6
0
 public string formatAPIAddress(RoadDetails roadDetails)
 {
     return(string.Format("{0}/{1}/{2}", roadDetails.BaseUrl, roadDetails.ApiName, roadDetails.RoadName));
 }
Exemple #7
0
 public string formatAPIKey(RoadDetails roadDetails)
 {
     return(string.Format("?app_id={0}&app_key={1}", roadDetails.ApiId, roadDetails.ApiKey));
 }
Exemple #8
0
 public async Task <RoadStatusInfo> FetchRoadStatusDetails(RoadDetails roadDetails)
 {
     return(await _roadStatusService.FetchRoadStatus(roadDetails));
 }
        public void Execute(
            DynamicBuffer <AutoLanePoints> autoLanePoints,
            [ReadOnly] ref AutoDetails autoDetails,
            ref AutoPosition autoPosition,
            ref Translation autoTranslation,
            ref Rotation autoRotation)
        {
            if (autoLanePoints.Length == 0)
            {
                /* This is a basic check,
                 * there seems to be a few instances
                 * where the auto does not have points,
                 */
                return;
            }

            var distance = math.distance(autoPosition.Destination, autoTranslation.Value);

            if (distance <= reachedPositionDistance)
            {
                autoPosition.CurrentPositionIndex += 1;

                //If the Auto's current position is at the end of it's list of
                //points, get the next list of points from the road or connection.
                if (autoPosition.CurrentPositionIndex >= autoLanePoints.Length)
                {
                    autoPosition.CurrentPositionIndex = 0;
                    autoLanePoints.Clear();

                    int laneIndex             = 0;
                    int roadIdentity          = 0;
                    int connectionIdentityEnd = 0;


                    for (int i = 0; i < roadEntities.Length; i++)
                    {
                        RoadDetails roadDetails = RoadDetailsFromEntity[roadEntities[i]];

                        if ((roadDetails.RoadIdentity == autoPosition.RoadIdentity) &&
                            (roadDetails.LaneIndex == autoPosition.LaneIndex) &&
                            (roadDetails.ConnectionIdentityStart == autoPosition.ConnectionIdentity) &&
                            (roadDetails.ConnectionIndexStart == autoPosition.ConnectionIndex)
                            )
                        {
                            //Set variables for use to get the next connection
                            laneIndex             = roadDetails.LaneIndex;
                            roadIdentity          = roadDetails.RoadIdentity;
                            connectionIdentityEnd = roadDetails.ConnectionIdentityEnd;

                            var roadLanePointsBuffer = LanePointsFromEntity[roadEntities[i]];
                            var roadLanePoints       = roadLanePointsBuffer.ToNativeArray(Allocator.Temp);
                            var lanePointAuto        = new AutoLanePoints();

                            for (int x = 0; x < roadLanePoints.Length; x++)
                            {
                                lanePointAuto.value = roadLanePoints[x].value;
                                autoLanePoints.Add(lanePointAuto);
                            }
                            break;
                        }
                    }

                    //Get the Connection's Lane's points
                    //First find all options that have the same Idenity and Index.
                    //Then we can randomly select one of the routes through the connection
                    NativeList <Entity> availableConnections = new NativeList <Entity>(Allocator.Temp);

                    for (int i = 0; i < connectionEntities.Length; i++)
                    {
                        var connectionDetails = ConnectionDetailsFromEntity[connectionEntities[i]];

                        if ((connectionDetails.ConnectionIdentity == connectionIdentityEnd) &&
                            (connectionDetails.LaneIndexStart == laneIndex) &&
                            (connectionDetails.RoadIdentityStart == roadIdentity) &&
                            (connectionDetails.ConnectionIndexStart == autoPosition.ConnectionIndex)
                            )
                        {
                            availableConnections.Add(connectionEntities[i]);
                        }
                    }

                    Unity.Mathematics.Random mathRandom = new Unity.Mathematics.Random(randomSeed);
                    int randomValue                = mathRandom.NextInt(0, availableConnections.Length);
                    var connectionDetailsNew       = ConnectionDetailsFromEntity[availableConnections[randomValue]];
                    var connectionLanePointsBuffer = LanePointsFromEntity[availableConnections[randomValue]];
                    var connectionLanePoints       = connectionLanePointsBuffer.ToNativeArray(Allocator.Temp);
                    var lanePoint = new AutoLanePoints();

                    for (int x = 0; x < connectionLanePoints.Length; x++)
                    {
                        lanePoint.value = connectionLanePoints[x].value;
                        autoLanePoints.Add(lanePoint);
                    }

                    //Reset the Auto's variables for the next Road/Connection selection
                    autoPosition.LaneIndex          = connectionDetailsNew.LaneIndexEnd;
                    autoPosition.RoadIdentity       = connectionDetailsNew.RoadIdentityEnd;
                    autoPosition.ConnectionIdentity = connectionDetailsNew.ConnectionIdentity;
                    autoPosition.ConnectionIndex    = connectionDetailsNew.ConnectionIndexEnd;

                    availableConnections.Dispose();
                }

                autoPosition.Destination    = autoLanePoints[autoPosition.CurrentPositionIndex].value;
                autoPosition.Destination.y += autoDetails.yOffset;
            }

            float3 lookVector = autoPosition.Destination - autoTranslation.Value;

            if (!lookVector.Equals(float3.zero))
            {
                Quaternion rotationLookAt = Quaternion.LookRotation(lookVector);
                autoRotation.Value = rotationLookAt;
            }

            float3 smoothedPosition = math.lerp(autoTranslation.Value, autoPosition.Destination, autoDetails.speed * deltaTime);

            autoTranslation.Value = smoothedPosition;
        }