/// <summary>
        /// Specifies search stop point reference
        /// </summary>
        /// <param name="input"></param>
        /// <param name="stopPointRef">Id of the stop</param>
        /// <returns></returns>
        public static StopEventRequestStructure SearchByStopPointRef(this StopEventRequestStructure input, string stopPointRef)
        {
            input.Location = new LocationContextStructure()
            {
                Item = new LocationRefStructure()
                {
                    Item = new StopPointRefStructure()
                    {
                        Value = stopPointRef
                    }
                }
            };

            return(input);
        }
        public async Task StopEventResponseStructure_Test()
        {
            //Arrange
            string knownStationId = KnownStationId;
            var    serviceClient  = new TriasServiceClient(ConfigHelper.TriasServiceUrl, ConfigHelper.TriasServiceRef);

            var input = new StopEventRequestStructure()
                        .SearchByStopPointRef(knownStationId);
            //Act
            var result = await serviceClient.Request(input);

            //Assert
            Assert.That(result, Is.Not.Null);
            Assert.That(result.ErrorMessage, Is.Null);
            Assert.That(result.StopEventResult, Is.Not.Null);
            Assert.That(result.StopEventResult.Length, Is.GreaterThan(0));
        }
示例#3
0
        /// <inheritdoc cref="ITriasCommunicator" />
        public async Task <StopEventResponse> StopEventRequest(string idStopPoint)
        {
            var stopEventRequest = new StopEventRequestStructure
            {
                Location = new LocationContextStructure
                {
                    Item = new LocationRefStructure {
                        Item = new StopPointRefStructure1 {
                            Value = idStopPoint
                        }
                    },
                    DepArrTime = System.DateTime.Now
                },
                Params = new StopEventParamStructure
                {
                    TimeWindow           = "5", // Include next 5 minutes of stops.
                    StopEventType        = StopEventTypeEnumeration.both,
                    IncludePreviousCalls = true,
                    IncludeOnwardCalls   = true,
                    IncludeRealtimeData  = true,
                }
            };

            var response = await _triasHttpClient.BaseTriasCall <StopEventResponseStructure>(stopEventRequest).ConfigureAwait(false);

            if (!(response.ErrorMessage?.Length > 0))
            {
                return(new StopEventResponse(response, idStopPoint));
            }

            if (response.ErrorMessage.First().Code == "-4030") // STOPEVENT_LOCATIONUNSERVED - Normal because not every stop point has trips in the next 5 minutes.
            {
                return(new StopEventResponse(idStopPoint, new List <StopEventResult>()));
            }

            var errorCodes = response.ErrorMessage?.SelectMany(x => x.Text).Select(x => x.Text) ?? new List <string>();
            var ex         = new StopEventException($"No stop events could be collected. {string.Join('-', errorCodes)}");

            using (_logger.BeginScope(new Dictionary <string, object> {
                { "idStopPoint", idStopPoint }, { "response", response }
            }))
            {
                _logger.LogError(ex, "{IdStopPoint} - No stop events could be collected.", idStopPoint);
            }
            return(new StopEventResponse(idStopPoint, new List <StopEventResult>()));
        }
示例#4
0
 public async Task <StopEventResponseStructure> Request(StopEventRequestStructure input)
 {
     return(await Request <StopEventResponseStructure>(input));
 }