Exemplo n.º 1
0
        private void Start_Click(object sender, RoutedEventArgs e)
        {
            Start.Visibility = Visibility.Hidden;
            Stop.Visibility  = Visibility.Visible;

            _cancelTokenSource = new CancellationTokenSource();

            try
            {
                if (CanGetByName.SelectedItem.ToString() == "Open Weather Map")
                {
                    _weatherByName = new OpenWeatherMap(Properties.Settings.Default.TokenOpenWeather, Properties.Settings.Default.RequestOpenWeather);
                }
                else if (CanGetByName.SelectedItem.ToString() == "Dark Sky")
                {
                    _weatherByName = new DarkSky(_translator, Properties.Settings.Default.TokenDarkSky, Properties.Settings.Default.RequestDarkSky);
                }

                if (CanGetByCoordinate.SelectedItem.ToString() == "Dark Sky")
                {
                    _weatherByCoordinate = new DarkSky(_translator, Properties.Settings.Default.TokenDarkSky, Properties.Settings.Default.RequestDarkSky);
                }

                var token = _cancelTokenSource.Token;

                apiWork = new Bot(Properties.Settings.Default.TokenBot, token, _weatherByCoordinate, _weatherByName, _translator, () => new UsersRepository());

                apiWork.BotWork();
            }
            catch (Telegram.Bot.Exceptions.ApiRequestException ex)
            {
                MessageBox.Show(ex.Message);
            }
        }