Пример #1
0
 public Predict(StationForecast stationForecast)
 {
     NumberBus   = stationForecast.Rnum;
     EndStation  = stationForecast.Where;
     TimePredict = stationForecast.Arrt != null
                 ? (((int)stationForecast.Arrt / 60) == 0
                   ? "Прибывает..."
                   : ((int)stationForecast.Arrt / 60).ToString())
                 : "";
     TypeBus = string.Equals(stationForecast.Rtype.ToUpperInvariant(), "Т", new StringComparison())
         ? $"~/../../Content/Images/trolleybus.png"
         : (string.Equals(stationForecast.Rtype.ToUpperInvariant(), "М", new StringComparison())
             ? $"~/../../Content/Images/marshrutka.png"
             : $"~/../../Content/Images/bus.png");
     LowFloor = "";
 }
Пример #2
0
        public IEnumerable <StationForecast> GetStationForecastForR(string stationId)
        {
            var stationForecasts = new List <StationForecast>();

            try
            {
                var json =
                    @"[{""clientIPAddress"":""0.0.0.0"",""initiator"":""serviceVMS"",""password"":""3VJDgDbe8ma0qtMkk3jd2w\u003d\u003d"",""userName"":""serviceVMS""},""" +
                    stationId + @"""]";
                using (var content = CreateHttpContent(json))
                {
                    using (var client = new HttpClient())
                    {
                        var uri = new Uri(
                            "http://185.235.72.98:47201/vms-ws/rest/InformationBoardWS/getTransportsByCheckPointId");
                        if (content == null)
                        {
                            return(new List <StationForecast>());
                        }
                        var response = client.PostAsync(uri, content)
                                       ?.Result;
                        if (response == null)
                        {
                            return(new List <StationForecast>());
                        }
                        var contentBody = response?.Content
                                          ?.ReadAsStringAsync()
                                          ?.Result;
                        try
                        {
                            var jResult = JToken.Parse(contentBody).ToObject <rootObject>();
                            if (jResult == null)
                            {
                                return(new List <StationForecast>());
                            }
                            var forecasts = jResult.arrivalTimes;
                            if (forecasts == null || forecasts?.Count == 0)
                            {
                                return(new List <StationForecast>());
                            }
                            var index = 0;
                            foreach (var item in forecasts)
                            {
                                index++;
                                var element = new StationForecast()
                                {
                                    Arrt  = (int)(CreateArrivalTimeRnis(item.arrivalTime)),
                                    Id    = index,
                                    Rnum  = item?.route?.num ?? "",
                                    Rtype = "M",
                                    Where = item?.route?.name.Replace(item?.route?.num, "")
                                };
                                stationForecasts.Add(element);
                            }
                            return(stationForecasts);
                        }
                        catch (JsonException ex)
                        {
                            Logger.WriteLog("Ошибка десериализации json ответа от РНИС", "GetStationForecastRnis");
                            return(new List <StationForecast>());
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.WriteLog($"{ex.Message} {ex.StackTrace}", "PredictManager");
            }
            return(new List <StationForecast>());
        }