예제 #1
0
        private void timerTick(object sender, EventArgs e)
        {
            clktimer = ++clktimer % settings.getClockRefresh();
            if (clktimer == 0)
            {
                string currentTime = DateTime.Now.ToString("h:mm tt");
                if (lastWrittenTime.CompareTo(currentTime) != 0)
                {
                    lastWrittenTime = currentTime;
                    updateTime(lastWrittenTime);
                    Console.WriteLine("Update clock to " + lastWrittenTime);
                }
                string currentDate = DateTime.Now.ToString("MMMM dd, yyyy", CultureInfo.InvariantCulture);
                if (DateBlock.Text.CompareTo(currentDate) != 0)
                {
                    updateDate(currentDate);
                }
            }

            wxtimer = ++wxtimer % settings.getWeatherRefresh();
            if (wxtimer == 0)
            {
                Weather                      weather     = new Weather();
                Weather.WeatherInfo          weatherInfo = weather.getWeather("https://api.weather.gov/stations/KLAF/observations?limit=1");
                Forecast                     forecast    = new Forecast();
                List <Forecast.ForecastData> data        = forecast.getForecast("https://api.weather.gov/gridpoints/IND/40,70/forecast?units=us");
                updateTemp(weatherInfo.temp);
                updateForecast(data);
                Console.WriteLine("Update weather.");
            }

            imgtimer = ++imgtimer % settings.getImgRefresh();
            if (imgtimer == 0)
            {
                ImageBox.Source = new BitmapImage(new Uri(settings.getImgUrl()));
            }

            newtimer = ++newtimer % settings.getNewsRefresh();
            if (newtimer == 0)
            {
                News     news  = new News();
                string[] list  = new string[5];
                int      count = settings.getNewsCount();

                if (count <= 0)
                {
                }
                else
                {
                    string url = "https://newsapi.org/v2/top-headlines?sources=" + settings.getNewsSource() + "&apiKey=5969a901e08f42c7a532e0d93a039ffa";
                    list = news.getNews(count, url);
                    updateNews(count, list);
                    Console.WriteLine("Update News.");
                }
            }
        }
예제 #2
0
        public bool testInvalidWeather()
        {
            Weather w = new Weather();

            Weather.WeatherInfo info = w.getWeather("https://api.weather.gov/stations/QSBN/observations?limit=1");
            //if one value is null all is null
            //only need to check 1 value to exist
            if (info.temp == -12345)
            {
                return(true);
            }

            return(false);
        }
예제 #3
0
        public bool testEmptyWeather()
        {
            Weather w = new Weather();

            Weather.WeatherInfo info = w.getWeather("");
            //if one value is null all is null
            //only need to check 1 value to exist
            if (info.temp == -12345)
            {
                return(true);
            }

            return(false);
        }
예제 #4
0
        public MainWindow()
        {
            InitializeComponent();
            settings = new Settings();
            Test.runTests();

            clktimer        = 0;
            wxtimer         = 0;
            imgtimer        = 0;
            newtimer        = 0;
            lastWrittenTime = DateTime.Now.ToString("hh:mm tt");


            Weather weather = new Weather();

            Weather.WeatherInfo weatherInfo = weather.getWeather("https://api.weather.gov/stations/KLAF/observations?limit=1");
            updateTemp(weatherInfo.temp);

            //trying to create text boxes for posts
            List <Announcement> announcements = new GetAnnouncements().getAnnouncements("https://kassarl.github.io/corkboardjson/announcements.json");

            TextBlock[] textBoxes = new TextBlock[announcements.Count];

            for (int i = 0; i < announcements.Count; i++)
            {
                PostController post = new PostController();
                post.setBody(announcements[i].getBody());
                post.setTitle(announcements[i].getTitle());
                MainView.Children.Add(post);
            }

            //ImageBox.Source = new BitmapImage(new Uri("../../surprise.PNG", UriKind.Relative));
            ImageBox.Source = new BitmapImage(new Uri(settings.getImgUrl()));
            TimeBlock.Text  = DateTime.Now.ToString("h:mm tt");
            DayBlock.Text   = DateTime.Now.DayOfWeek.ToString();
            DateBlock.Text  = DateTime.Now.ToString("MMMM dd, yyyy", CultureInfo.InvariantCulture);

            updateUI();

            Show();

            timer          = new System.Windows.Forms.Timer();
            timer.Interval = 1000; // 1 second
            timer.Tick    += new System.EventHandler(timerTick);
            timer.Start();
        }
예제 #5
0
        /*
         * This method is solely to be used on startup and when new settings are loaded in
         */
        public void updateUI()
        {
            OuterView.Background = new SolidColorBrush(settings.getOuterColor());
            MainView.Background  = new SolidColorBrush(settings.getInnerColor());
            setOuterTextColor(settings.getOuterTextColor());
            setInnerTextColor(settings.getInnerTextColor());

            if (settings.isWeatherVisible())
            {
                TempBlock.Visibility    = Visibility.Visible;
                ForecastView.Visibility = Visibility.Visible;
                Weather             weather     = new Weather();
                Weather.WeatherInfo weatherInfo = weather.getWeather("https://api.weather.gov/stations/KLAF/observations?limit=1");
                updateTemp(weatherInfo.temp);

                Forecast forecast = new Forecast();
                List <Forecast.ForecastData> data = forecast.getForecast("https://api.weather.gov/gridpoints/IND/40,70/forecast?units=us");
                updateForecast(data);
            }
            else
            {
                TempBlock.Visibility    = Visibility.Collapsed;
                ForecastView.Visibility = Visibility.Collapsed;
            }

            if (settings.isImageVisible())
            {
                ImageBox.Visibility = Visibility.Visible;
                ImageBox.Source     = new BitmapImage(new Uri(settings.getImgUrl()));
            }
            else
            {
                ImageBox.Visibility = Visibility.Collapsed;
            }

            if (settings.isTimeVisible())
            {
                TimeBlock.Visibility = Visibility.Visible;
                TimeBlock.Text       = DateTime.Now.ToString("h:mm tt");
            }
            else
            {
                TimeBlock.Visibility = Visibility.Collapsed;
            }

            if (settings.isDateVisible())
            {
                DayBlock.Visibility  = Visibility.Visible;
                DateBlock.Visibility = Visibility.Visible;
                updateDay(DateTime.Now.DayOfWeek.ToString());
                updateDate(DateTime.Now.ToString("MMMM dd, yyyy", CultureInfo.InvariantCulture));
            }
            else
            {
                DateBlock.Visibility = Visibility.Collapsed;
                DayBlock.Visibility  = Visibility.Collapsed;
            }

            if (settings.isNewsVisible())
            {
                News news  = new News();
                int  count = settings.getNewsCount();
                if (count <= 0)
                {
                }
                else
                {
                    string[] list = new string[count];
                    string   url  = "https://newsapi.org/v2/top-headlines?sources=" + settings.getNewsSource() + "&apiKey=5969a901e08f42c7a532e0d93a039ffa";
                    list = news.getNews(count, url);
                    updateNews(count, list);
                }
            }
        }