예제 #1
0
        public void AddPassage(Passage passage)
        {
            if (passage == null)
            {
                throw new System.ArgumentNullException("Passage is equal to null while trying to add to the train {0}", Name);
            }

            Passages.Add(passage);
        }
예제 #2
0
        static async Task RunAsync()
        {
            Trains trains = await GetStations(GlobalVar.FROM, GlobalVar.TO, GlobalVar.DATE, GlobalVar.TIME);



            foreach (var train in trains.GetTrains())
            {
                //var tasksPassages = new List<Task<bool>>();
                //for (var i = 0; i < train.Stations.Count - 1; i++)
                //{
                //	tasksPassages.Add(ContigentCheckPassage(train.Stations[i].Name, train.Stations[i + 1].Name,
                //		GlobalVar.DATE, train.Stations[i].DepartureTime, trains.JSFViewState, train.ID));
                //}
                //var listPassages = await Task.WhenAll(tasksPassages);

                //for (var i = 0; i < train.Stations.Count - 1; i++)
                //{
                //	train.AddPassage(new Passage(train.Stations[i].Name, train.Stations[i + 1].Name, listPassages[i]));
                //}

                for (var i = 0; i < train.Stations.Count - 1; i++)
                {
                    var isFree = await ContigentCheckPassage(train.Stations[i].Name, train.Stations[i + 1].Name,
                                                             GlobalVar.DATE, train.Stations[i].DepartureTime, trains.JSFViewState, train.ID);

                    train.AddPassage(new Passage(train.Stations[i].Name, train.Stations[i + 1].Name, isFree));
                }
            }

            foreach (var train in trains.GetTrains())
            {
                List <Passage> passages = new List <Passage>();
                int            i        = 0;
                while (i < train.Passages.Count)
                {
                    int j = i + 1;
                    while ((train.Passages[j].IsFree == train.Passages[i].IsFree) && (j < train.Passages.Count - 1))
                    {
                        j++;
                    }
                    Passage passage = new Passage(train.Passages[i].From, train.Passages[j].To, train.Passages[i].IsFree);
                    i = j + 1;

                    passages.Add(passage);
                }

                Console.WriteLine("Train {0} has following passages:", train.Name);
                foreach (var passage in passages)
                {
                    Console.WriteLine("Passage from {0} to {1} is {2}", passage.From, passage.To, (passage.IsFree ? "free" : "paid"));
                }
            }
            Console.WriteLine("END");
        }