Exemplo n.º 1
0
        private void AddButton_Click(object sender, EventArgs e)
        {
            WeatherForecast.DayWeather dayWeather;
            try
            {
                dayWeather = new WeatherForecast.DayWeather()
                {
                    Day              = dateTimePicker1.Value,
                    Weather          = (WeatherForecast.Weather)weatherListBox.SelectedItem,
                    DayTemperature   = Convert.ToDouble(dayTempTextBox.Text),
                    NightTemperature = Convert.ToDouble(nightTempTextBox.Text)
                };

                _weatherService.AddDayWeather(dayWeather);
            }
            catch (Exception ex)
            {
                MessageBox.Show(MyStrings.AddException + ex.Message);
                return;
            }
            var args = new DayWeatherAddedEventArgs()
            {
                DayWeather = dayWeather
            };

            OnDayWeatherAdded(args);
            MessageBox.Show(MyStrings.AddSuccess);
        }
        static void Main(string[] args)
        {
            //try
            //{
            IUnityContainer       container            = BuildContainer();
            IDayWeatherRepository dayWeatherRepository = (IDayWeatherRepository)container.Resolve <IDayWeatherRepository>();
            IImagePathRepository  imagePathRepository  = (IImagePathRepository)container.Resolve <IImagePathRepository>();
            var weatherService = new WeatherService(imagePathRepository, dayWeatherRepository);
            var dayWeatherList = weatherService.GetDayWeatherList();

            WeatherForecast.DayWeather dayWeather;
            for (int i = 0; i < 500000; i++)
            {
                dayWeather = new WeatherForecast.DayWeather()
                {
                    Day              = new DateTime(i + 1, i % 12 + 1, i % 25 + 1),
                    Weather          = WeatherForecast.Weather.Cloudy,
                    DayTemperature   = i % 60 - 10,
                    NightTemperature = i % 60 - 29
                };
                //Console.WriteLine($"{dayWeather.Day.ToString()}, {dayWeather.Weather}, {dayWeather.DayTemperature}");
                weatherService.AddDayWeather(dayWeather);
            }

            //}
            //catch (Exception ex)
            //{
            //    Console.WriteLine(ex.Message);
            //}
            Console.WriteLine("End");
            Console.ReadKey();
        }