Esempio n. 1
0
        /// <summary>
        /// Initilizes trains , tracks, stations, speeds, distances etc
        /// </summary>
        private static void InitializeData()
        {
            try
            {
                // Randomly generating different but constant speeds, shipment capacity & track distances.
                Random randomNumberGenerator = new Random();
                for (int i = 0; i < _noOfStations; i++)
                {
                    _distances[i] = randomNumberGenerator.Next(3, 11) * 10;
                }

                for (int i = 0; i < _noOfTrains; i++)
                {
                    _speeds[i] = randomNumberGenerator.Next(3, 25) * 10;
                }

                // Global cache
                var cache = LookupCache.GetInstance();

                // Initilize train tracks & trains
                Dictionary <string, TrainTrack> _dicTracks = new Dictionary <string, TrainTrack>();

                for (int i = 1; i <= _noOfStations; i++)
                {
                    Station station = new Station(i, "Station" + i.ToString());
                    cache.AddStation(station);
                    if (i == _noOfStations)
                    {
                        String     key   = "Station" + i.ToString() + "ToStation" + (i + 1).ToString();
                        TrainTrack track = new TrainTrack(i, 1, _distances[i - 1]);
                        _dicTracks.Add(key, track);
                    }
                    else
                    {
                        String     key   = "Station" + i.ToString() + "To" + "Station1";
                        TrainTrack track = new TrainTrack(i, 1 + i, _distances[i - 1]);
                        _dicTracks.Add(key, track);
                    }
                }

                // adding train tracks to cache
                cache.AddTracks(_dicTracks);

                for (int i = 1; i <= _noOfTrains; i++)
                {
                    Train train = new Train(i, "Train" + i.ToString(), _shipmentCapacity[i - 1], _speeds[i - 1]);
                    cache.AddTrain(train);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Esempio n. 2
0
        private void InitilizeUIComponents()
        {
            // Initialize stations
            if (tvwStations != null)
            {
                var      nodes       = tvwStations.Nodes;
                TreeNode rootNode    = new TreeNode("All Stations");
                var      dicStations = LookupCache.GetInstance().GetStations();
                if (dicStations != null)
                {
                    TreeNode node;
                    foreach (var stationKey in dicStations.Keys)
                    {
                        var station = dicStations[stationKey];
                        node = new TreeNode(station.ToString());
                        rootNode.Nodes.Add(node);
                    }
                }
                nodes.Add(rootNode);
                tvwStations.ExpandAll();
            }

            // Initialize trains
            if (tvwTrains != null)
            {
                var      nodes     = tvwTrains.Nodes;
                TreeNode rootNode  = new TreeNode("All Trains");
                var      lstTrains = LookupCache.GetInstance().GetTrains();
                if (lstTrains != null)
                {
                    TreeNode node;
                    foreach (var train in lstTrains)
                    {
                        node = new TreeNode(train.ToString());
                        rootNode.Nodes.Add(node);
                    }
                }
                nodes.Add(rootNode);
                tvwTrains.ExpandAll();
            }

            // Initialize train tracks
            if (tvwTracks != null)
            {
                var      nodes     = tvwTracks.Nodes;
                TreeNode rootNode  = new TreeNode("All Train Tracks");
                var      dicTracks = LookupCache.GetInstance().GetTracks();
                if (dicTracks != null)
                {
                    TreeNode node;
                    foreach (var key in dicTracks.Keys)
                    {
                        var track = dicTracks[key];
                        node = new TreeNode(track.ToString());
                        rootNode.Nodes.Add(node);
                    }
                }
                nodes.Add(rootNode);
                tvwTracks.ExpandAll();
            }
        }