private void NetworkChange_NetworkAddressChanged(object sender, EventArgs e)
        {
            Application.Current.Dispatcher.Invoke(new Action(() =>
            {
                if (CheckForInternet.Connected())
                {
                    NoInternetWarning.Source = null;

                    ConnectedToInternet = true;

                    if (((MainWindow)Application.Current.MainWindow).AlertTextBody.Text == "You may not be connected to the internet...")
                    {
                        ParseWeatherXML.NWSAlertsInfo();
                    }
                }
                else
                {
                    ConnectedToInternet = false;

                    Thread thread = new Thread(EarlyNetCheck)
                    {
                        IsBackground = true
                    };
                    thread.Start();

                    NoInternetWarning.Source = new BitmapImage(new Uri(@"pack://application:,,,/NWS Alerts;component/Resources/NoInternetWarning.png", UriKind.Absolute));

                    EasyLogger.Info("It appears that you do not have an internet connection. We will retry later.");
                }
            }));
        }
        public void DateTimeSettings()
        {
            timer = new DispatcherTimer(new TimeSpan(0, 0, 1), DispatcherPriority.Normal, delegate
            {
                if (Default.ShowDate)
                {
                    ShowDateCheckBox.IsChecked = true;
                    CurrentDate.Content        = DateTime.Now.ToString(@"dddd, MMM d");

                    ShowDateCheckBox.Checked   += ShowDateCheckBox_Checked;
                    ShowDateCheckBox.Unchecked += ShowDateCheckBox_Unchecked;
                }
                if (Default.ShowTime)
                {
                    ShowTimeCheckBox.IsChecked = true;
                    CurrentTime.Content        = DateTime.Now.ToString(@"h:mm tt");

                    ShowTimeCheckBox.Checked   += ShowTimeCheckBox_Checked;
                    ShowTimeCheckBox.Unchecked += ShowTimeCheckBox_Unchecked;
                }
                if (UpdateTimer.ReturnDateTime(DateTime.Now.AddMinutes(-30), FileTime) && !Updating && ConnectedToInternet)
                {
                    Updating = true;

                    EasyLogger.Info("Downloading new weather info using values: " + Default.LatValue + "," + Default.LongValue);

                    Thread thread = new Thread(() => DesktopWeatherXML(PreWeatherString + Default.LatValue + "," + Default.LongValue, NWSAlertsDirectory + "\\WeatherInfo.xml"))
                    {
                        IsBackground = true
                    };
                    thread.Start();
                }
                if (UpdateTimer.ReturnDateTime(DateTime.Now.AddMinutes(-10), AlertTime))
                {
                    AlertTime = DateTime.Now.AddSeconds(-DateTime.Now.Second);

                    if (CheckForInternet.Connected())
                    {
                        ParseWeatherXML.NWSAlertsInfo();
                    }
                }
            }, Dispatcher);
        }
        public void EarlyNetCheck()
        {
            Thread.Sleep(6000);

            while (true)
            {
                if (CheckForInternet.Connected())
                {
                    Application.Current.Dispatcher.Invoke(new Action(() =>
                    {
                        NoInternetWarning.Source = null;

                        ConnectedToInternet = true;
                    }));

                    break;
                }
                else
                {
                    Thread.Sleep(6000);
                }
            }
        }
示例#4
0
        public MainWindow()
        {
            InitializeComponent();

            EasyLogger.BackupLogs(EasyLogger.LogFile);
            EasyLogger.AddListener(EasyLogger.LogFile);

            ((MainWindow)Application.Current.MainWindow).mainWindow.StateChanged += MainWindow_StateChanged;

            HideThisWindow();

            Closing += MainWindow_Closing;

            if (Default.UpgradeRequired)
            {
                Default.Upgrade();

                Default.UpgradeRequired = false;

                Default.Save();

                Default.Reload();

                if (Default.FirstRun)
                {
                    Default.FirstRun = false;

                    SettingsWindow settingsWindow = new SettingsWindow();
                    settingsWindow.ShowDialog();

                    LocationBox locationBox = new LocationBox();
                    locationBox.ShowDialog();

                    MessageBox.Show("Right click on the Desktop App to change the weather location to your preferred location." + Environment.NewLine + Environment.NewLine + "You will need to find your lattitude and longitude in order for me to find your local weather.", "NWS Alerts", MessageBoxButton.OK, MessageBoxImage.Information);

                    Default.Save();

                    Default.Reload();
                }
            }

            NotifyTray.TrayIconCreate();

            if (Default.MuteToast)
            {
                NotifyTray.MuteMenuItem.Checked = true;
                ParseWeatherXML.MuteAlerts      = true;
            }

            NotificationActivatorBase.RegisterComType(typeof(NotificationActivator), OnActivated);

            NotificationHelper.RegisterComServer(typeof(NotificationActivator), Assembly.GetExecutingAssembly().Location);

            if (CheckForInternet.Connected())
            {
                ParseWeatherXML.NWSAlertsInfo();
            }
            else
            {
                ((MainWindow)Application.Current.MainWindow).AlertTextBody.Text = "You may not be connected to the internet...";
            }

            WeatherApp = new DesktopWeather();
            WeatherApp.Show();
        }
        private void LoadSettings()
        {
            window.Background.Opacity = Default.WindowOpacity;
            windowBackground.Opacity  = Default.WindowOpacity;

            LatTextBox.Text  = Default.LatValue;
            LongTextBox.Text = Default.LongValue;

            if (Default.UseAccentBorder)
            {
                window.BorderBrush = SystemParameters.WindowGlassBrush;

                BorderAccentCheckBox.IsChecked = true;

                SystemParameters.StaticPropertyChanged += WindowGlassBrush_Changed;
            }
            else
            {
                window.BorderThickness = new Thickness(0, 0, 0, 0);
            }

            OpacitySlider.Value = Default.WindowOpacity;

            if (OpacitySlider.Value < 0.95)
            {
                Overlay.Opacity = 0.1;
            }
            else
            {
                Overlay.Opacity = 0.3;
            }

            VersionLabel.Content = "xCONFLiCTiONx  |  Version: " + Assembly.GetExecutingAssembly().GetName().Version.ToString();

            BorderAccentCheckBox.Checked   += BorderAccentCheckBox_Checked;
            BorderAccentCheckBox.Unchecked += BorderAccentCheckBox_Unchecked;

            Grid1.Children.Remove(SettingsPanel);

            if (!CheckForInternet.Connected())
            {
                NoInternetWarning.Source = new BitmapImage(new Uri(@"pack://application:,,,/NWS Alerts;component/Resources/NoInternetWarning.png", UriKind.Absolute));

                ConnectedToInternet = false;

                Thread thread = new Thread(EarlyNetCheck)
                {
                    IsBackground = true
                };
                thread.Start();
            }

            if (File.Exists(NWSAlertsDirectory + "\\WeatherInfo.xml"))
            {
                fileInfo = new FileInfo(NWSAlertsDirectory + "\\WeatherInfo.xml");

                FileTime = fileInfo.LastWriteTime;

                SetWeatherUI();
            }

            DateTimeSettings();

            OpacitySlider.ValueChanged += OpacitySlider_ValueChanged;

            MouseUp += MainWindow_MouseUp;
        }