private void BtInstall_Click(object sender, RoutedEventArgs e) { BtInstall.IsEnabled = false; BtSchedule.IsEnabled = false; TpPicker.IsEnabled = false; SqlCe.UpdateSupData("STD", string.Empty); if (_isReschedule) { SqlCe.SetEnforcedFlag(_scheduleId); } SqlCe.SetUpdatesInstallStatusFlag(true); CcmUtils.ExecuteInstallUpdates(true); SetStatus(ScheduleStatus.Green); StatusText.Text = "Installation has been initiated."; }
private void CheckForSups() { if (_supCheckBlocked || SqlCe.GetAutoEnforceFlag()) { return; } try { var sups = CcmUtils.Updates; if (sups.Count() == 0) { _lastFoundSups = null; Globals.Log.Information("No updates available at this time"); return; } _lastFoundSups = _lastFoundSups ?? DateTime.Now; if (_lastFoundSups > DateTime.Now.AddMinutes(-5)) { return; } var jsonSups = JsonConvert.SerializeObject(sups); SqlCe.UpdateSupData("STD", jsonSups); Globals.Log.Information($"Found {sups.Count()} updates available for scheduling"); var nextSchedule = SqlCe.GetNextSupSchedule(); var supdeadline = sups.OrderBy(y => y.Deadline).First().Deadline; var nextServiceCycle = SqlCe.GetServiceSchedule(); if (nextSchedule.Id != 0) { Globals.Log.Information($"Next update enforcement time '{nextSchedule.EnforcementTime}' deadline for available updates = '{supdeadline}', 'toasting' user - reschedule necessary"); if (nextSchedule.EnforcementTime <= supdeadline) { Globals.Log.Information($"Next update enforcement time '{nextSchedule.EnforcementTime}' deadline for available updates = '{supdeadline}', skipping 'toast'"); return; } else { SqlCe.SetEnforcedFlag(nextSchedule.Id); } } var dtNextServiceCycle = CommonUtils.GetNextServiceCycleAsDateTime(); if (dtNextServiceCycle != null) { if (dtNextServiceCycle <= supdeadline) { Globals.Log.Information($"Detected an upcoming service cycle, a Toast notification was suppressed."); return; } } if (UnsafeNativeMethods.IsUserLoggedOn() && !RegistryMethods.GetIpuIsRunning()) { if (!UnsafeNativeMethods.IsSessionLocked()) { UnsafeNativeMethods.Run(_userApp, $"/ToastSup", false); } else { Globals.Log.Information($"Detected a locked or non existing user session, a Toast notification was suppressed."); } } } catch (Exception ex) { Globals.Log.Error(ex.Message); } }
private void SetStatus(CMApplication app) { Dispatcher.Invoke(() => { StatusRed.Visibility = Visibility.Hidden; StatusGreen.Visibility = Visibility.Hidden; StatusOrange.Visibility = Visibility.Hidden; StatusBlue.Visibility = Visibility.Hidden; StatusRed.ToolTip = app.EvaluationStateText; StatusGreen.ToolTip = app.EvaluationStateText; StatusOrange.ToolTip = app.EvaluationStateText; StatusBlue.ToolTip = app.EvaluationStateText; if (app.InstallState.Equals("Installed") && app.EvaluationState == 1 && !_isReschedule) { StatusGreen.Visibility = Visibility.Visible; StatusText.Text = _availableAppsSettings.AppIsInstalledStatusText; return; } switch (app.EvaluationState) { case 1: case 3: if (_isReschedule) { StatusGreen.Visibility = Visibility.Visible; StatusText.Text = _availableAppsSettings.InstallationHasBeenScheduledStatusText; } else { StatusBlue.Visibility = Visibility.Visible; StatusText.Text = _availableAppsSettings.AppCanBeInstalledStatusText; } break; case 4: case 16: case 24: case 25: StatusRed.Visibility = Visibility.Visible; StatusText.Text = _availableAppsSettings.AppIsInErrorStateStatusText; break; default: StatusOrange.Visibility = Visibility.Visible; StatusText.Text = app.EvaluationState == 13 ? "Reboot pending." : _availableAppsSettings.AppIsBeingEnforcedStatusText; ProgressbarEnforcement.Visibility = Visibility.Visible; TpPicker.IsEnabled = false; BtInstall.IsEnabled = false; BtRepair.IsEnabled = false; BtSchedule.IsEnabled = false; if (_isReschedule) { if (SqlCe.IsAppScheduled(app.Id, app.Revision, out var id)) { SqlCe.SetEnforcedFlag(id); } _isReschedule = false; } break; } }); }
private void EnforcePump() { Task.Run(() => { while (true) { try { var scheduledobject = _objectsToEnforce.Take(); _allowFastReboot = scheduledobject.IsAutoSchedule; SqlCe.SetEnforcedFlag(scheduledobject.Id); if (scheduledobject.EnforcementType.Equals("APP")) { var cmapp = CcmUtils.GetSpecificApp(scheduledobject); if (cmapp == null) { Globals.Log.Warning($"A scheduled enforcement '{scheduledobject.ObjectId}/{scheduledobject.Revision}' could not be performed. Deployment has been removed or changed?"); continue; } if (scheduledobject.Action.Equals("I")) { if (cmapp.IsIpuApplication && _settings.IpuApplication.ShowDialog1 && UnsafeNativeMethods.IsUserLoggedOn()) { if (UnsafeNativeMethods.Run(_userApp, "/ShowIpuDialog1", true) == 0) { //RegistryMethods.SetIpuIsRunning(); //CcmUtils.InstallApplication(cmapp); InstallIpuApplication(cmapp); Globals.Log.Information($"User pressed 'Install' feature updated '{cmapp.Name}'"); } else { SqlCe.DeleteAppSchedule(cmapp.Id, cmapp.Revision); Globals.Log.Warning($"User aborted a scheduled Windows feature upgrade '{cmapp.Name}'"); } } else if (cmapp.IsIpuApplication) { //RegistryMethods.SetIpuIsRunning(); InstallIpuApplication(cmapp); //CcmUtils.InstallApplication(cmapp); } else { CcmUtils.InstallApplication(cmapp); } } else if (scheduledobject.Action.Equals("R")) { CcmUtils.RepairApplication(cmapp); } else { CcmUtils.UninstallApplication(cmapp); } } else if (scheduledobject.EnforcementType.Equals("SUP")) { Globals.Log.Information("Installing updates, disabling component servicing reboot detection until rebooted."); _rebootServicingCheck = false; Set_SupCheckBlocked(); SqlCe.UpdateSupData("STD", string.Empty); CcmUtils.ExecuteInstallUpdates(true); } } catch (Exception ex) { Globals.Log.Error(ex.Message); } } }); }