Ejemplo n.º 1
0
        public List<Station> Process(StationDirection direction)
        {
            var stationDirectionList = new List<List<Station>>();
            var stationsHtmlDocument = GetHtmlDocument();
            var stationsTable = GetStationTables(stationsHtmlDocument);

            if (stationsTable != null && stationsTable.Count > 0)
            {
                foreach (var tbl in stationsTable)
                {
                    var stationsForward = new List<Station>();
                    var rows = GetRows(tbl);
                    if (rows != null && rows.Count > 0)
                    {
                        stationDirectionList.Add(GetStations(rows));
                    }
                }
            }

            switch (direction)
            {
                case StationDirection.Backward:
                    return stationDirectionList.LastOrDefault();

                case StationDirection.Forward:
                default:
                    return stationDirectionList.FirstOrDefault();
            }
        }
        private async void LoadStations(StationDirection direction,string pattern)
        {
            List<StationResponse> loadedStations;
            loadedStations = await LoadStationsFromLocalDb(pattern);
            if (!loadedStations.Any() && pattern.Length>3)
            {
                //грузим с апи
                loadedStations = await LoadStationsFromApi(pattern);
            }

            SetSuggestionList(direction,loadedStations);
            
        }
        private void SetSuggestionList(StationDirection direction, List<StationResponse> stations)
        {
            if (direction == StationDirection.To)
            {
                ToSuggestionStations = stations;
            }

            if (direction == StationDirection.From)
            {
                FromSuggestionStations = stations;
            }
        }