コード例 #1
0
 /// <summary>
 /// The "Reboot Now" button was clicked
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void RebootNow_Click(object sender, RoutedEventArgs e)
 {
     if (SystemUpdateManager.State == SystemUpdateManagerState.RebootRequired)
     {
         SystemUpdateManager.RebootToCompleteInstall();
     }
 }
コード例 #2
0
 /// <summary>
 /// The "Check for updates" button was clicked
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void CheckForUpdates_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         if (SystemUpdateManager.State == SystemUpdateManagerState.Idle)
         {
             SystemUpdateManager.StartInstall(SystemUpdateStartInstallAction.UpToReboot);
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine(ex.ToString());
     }
 }
コード例 #3
0
        /// <summary>
        /// When the user clicks "Save" try to save the user active hours
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SaveActiveHours_Click(object sender, RoutedEventArgs e)
        {
            bool succeeded = SystemUpdateManager.TrySetUserActiveHours(StartTime.Time, EndTime.Time);

            if (succeeded)
            {
                ActiveHoursPopup.IsOpen = false;
            }
            else
            {
                // Active hours not set display error message
                string format = GetResourceString("ActiveHoursErrorFormat");
                ActiveHoursErrorText.Text       = String.Format(format, SystemUpdateManager.UserActiveHoursMax);
                ActiveHoursErrorText.Visibility = Visibility.Visible;
            }
        }
コード例 #4
0
        /// <summary>
        /// MainPage constructor
        /// </summary>
        public MainPage()
        {
            this.InitializeComponent();
            _dispatcher = Window.Current.Dispatcher;

            if (!ApiInformation.IsApiContractPresent("Windows.System.SystemManagementContract", 6, 0))
            {
                // SystemUpdateManager was first implemented in SystemManagementContract 6.0
                VisualStateManager.GoToState(this, "NotSupported", false);
                UpdateStateTextBlock.Text = "Windows.System.SystemManagementContract 6.0 not found";
            }
            else if (!SystemUpdateManager.IsSupported())
            {
                // The API must be supported by the current edition of Windows
                // This can also return false if the application doesn't have the systemManagement capability
                VisualStateManager.GoToState(this, "NotSupported", false);
                UpdateStateTextBlock.Text = "System Update not supported (or systemManagement capability missing)";
            }
            else
            {
                // Register for state change notifications
                SystemUpdateManager.StateChanged += SystemUpdateManager_StateChanged;

                // Display update information
                UpdateStateTextBlock.Text = GetResourceString(SystemUpdateManager.State.ToString());
                LastChecked.Text          = SystemUpdateManager.LastUpdateCheckTime.ToString("G");
                LastInstalled.Text        = SystemUpdateManager.LastUpdateInstallTime.ToString("G");

                // Attach ViewModel to ListView
                UpdateItemsListView.ItemsSource = _items;

                // Initialize the visual state
                UpdateVisualState();
                UpdateFlightRing();

                BlockAutoReboot.IsOn = IsAutomaticRebootBlockOn();
            }
        }
コード例 #5
0
        /// <summary>
        /// Handle flight ring selection change
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void FlightRingCombo_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            var oldRing = SystemUpdateManager.GetFlightRing();
            var newRing = e.AddedItems[0].ToString();

            Debug.WriteLine($"newRing={newRing} oldRing={oldRing}");

            if (oldRing != newRing)
            {
                if (newRing == "None")
                {
                    // only set if previous ring was not null or empty
                    if (!String.IsNullOrEmpty(oldRing))
                    {
                        Windows.System.Update.SystemUpdateManager.SetFlightRing(String.Empty);
                    }
                }
                else
                {
                    Windows.System.Update.SystemUpdateManager.SetFlightRing(newRing);
                }
            }
        }
コード例 #6
0
        /// <summary>
        /// Return true if automatic update reboot is blocked.  False otherwise.
        /// </summary>
        /// <returns></returns>
        bool IsAutomaticRebootBlockOn()
        {
            var ids = SystemUpdateManager.GetAutomaticRebootBlockIds();

            return(ids.Count > 0);
        }