Exemplo n.º 1
0
        private void ReadNetwork_OnClick(object sender, RoutedEventArgs e)
        {
            var filename = GetPathFromDialog();

            try
            {
                _network = _networkInfoRetriever.Read(filename) as Network;

                ReasignNetwork();

                MessageBox.Show("File loaded!", "OK", MessageBoxButton.OK, MessageBoxImage.Information,
                                MessageBoxResult.OK,
                                MessageBoxOptions.None);

                _headerUpdater?.Stop();

                _headerUpdater = null;

                _backgroundWorker?.Stop();

                _backgroundWorker = null;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error,
                                MessageBoxResult.OK,
                                MessageBoxOptions.None);
            }
        }
Exemplo n.º 2
0
        private void Start_OnClick(object sender, RoutedEventArgs e)
        {
            _headerUpdater?.Stop();

            _headerUpdater = null;

            _backgroundWorker?.Stop();

            _backgroundWorker = null;

            _network.ClearMessages();
            _network.Reset();

            var simulationOptionsDialog = new SimulationOptionsDialog(InitializeAllServices);

            simulationOptionsDialog.Show();
        }
Exemplo n.º 3
0
        private void Stop_OnClick(object sender, RoutedEventArgs e)
        {
            if (_backgroundWorker != null)
            {
                _headerUpdater?.Stop();

                _headerUpdater = null;

                _backgroundWorker.Stop();

                _backgroundWorker = null;

                var statistic = _messagesStatisticCounter.Count();

                var messageStatisticWindow = new MessagesStatisticWindow(statistic);

                messageStatisticWindow.Show();
            }
        }
Exemplo n.º 4
0
        private void InitializeAllServices(double messageGenerateChance, int tableUpdatePeriod,
                                           bool isPackageMode, bool isRouterStupid, int messagesSize)
        {
            if (isRouterStupid)
            {
                _messageRouter = new IndependentMessageRouter(_network);
            }
            else
            {
                _messageRouter = new MessageRouter(_network);
            }


            if (isPackageMode)
            {
                _messageCreator = new PackageMessageCreator(_network, _messageRouter);
            }
            else
            {
                _messageCreator = new RequestMessageCreator(_network, _messageRouter);
            }

            _positiveResponseMessageCreator = new PositiveResponseCreator(_network, _messageRouter);
            _negativeResponseMessageCreator = new NegativeResponseCreator(_network, _messageRouter);

            _messageHandler   = new MessageHandler(_network, _messageCreator, _positiveResponseMessageCreator);
            _messageReceiver  = new MessageReceiver(_messageHandler, _negativeResponseMessageCreator);
            _messageExchanger = new MessageExchanger(_network, _messageReceiver);

            if (messagesSize > 0)
            {
                _messageGenerator = new SpecifiedSizeMessageGenerator(_network, _messageCreator, messageGenerateChance,
                                                                      messagesSize);
            }
            else
            {
                _messageGenerator = new MessageGenerator(_network, _messageCreator, messageGenerateChance);
            }


            _messageRepository  = new MessageRepository(_network);
            _messageViewUpdater = new MessageViewUpdater(_messageRepository, Messages);

            _messageRegistrator = new MessageRegistrator(_messageRepository);

            _messagesStatisticCounter = new MessagesStatisticCounter(_messageRegistrator, _messageRepository);

            _backgroundWorker = new Background.BackgroundWorker(_messageExchanger, _messageGenerator,
                                                                _networkDrawer, _messageCreator, _messageRegistrator, _messageViewUpdater, tableUpdatePeriod);

            _messageCreator.UpdateTables();

            FiltrationModeSelect_OnSelectionChanged(FiltrationModeSelect, null);

            _backgroundWorker.Run();

            _backgroundWorker.Interval = IntervalSlider.Value;

            _headerUpdater = new DispatcherTimer
            {
                Interval = TimeSpan.FromMilliseconds(IntervalSlider.Value)
            };

            _headerUpdater.Tick += (sender, args) => Title = $"Coursework (time: {_backgroundWorker.Ticks})";

            _headerUpdater.Start();
        }