public async void CheckForUpdates(bool online = true) { try { DebugLog("Checking for updates..."); updateSession = new UpdateSession(); updateSearcher = updateSession.CreateUpdateSearcher(); updateSearcher.Online = online; DebugLog("Update searcher params are: " + Dump(updateSearcher)); searchJob_ = updateSearcher.BeginSearch("IsInstalled=0 and IsHidden = 0 and BrowseOnly=0", this, null); } catch (Exception ex) { VMManagementTool.Log.Error("WinUpdatesManager.CheckForUpdates", ex.ToString()); await Task.Yield(); CheckCompleted?.Invoke(false); } }
internal async void CheckForUpdates() { stage = 1; try { await SimualteProgress(""); } catch (Exception) { return; } //dummy updates for (int i = 0; i < 3; i++) { string title = $"A dummy update number {i}"; WinUpdateStatus updateStatus = new WinUpdateStatus(title, new List <string> { "KB" + (DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds.ToString().Substring(0, 6) } ); updateResults.Add(title, updateStatus); } CheckCompleted?.Invoke(true); }
void CheckAll() { // Make sure that issues are checked in correct order. var issues = IssueList.OrderBy(x => x.OrderId).ToArray(); foreach (var issue in issues) { if (IsDisposing) { return; } issue.Check(); if (IsDisposing) { return; } // If issue is critical then... if (issue.IsEnabled && issue.Severity.HasValue && issue.Severity.Value >= IssueSeverity.Critical) { // Skip checking other issues. break; } } // Assign result to property, because results will be read on a different i.e. main Thread. CriticalIssuesCount = IssueList.Count(x => x.IsEnabled && x.Severity.HasValue && x.Severity.Value >= IssueSeverity.Critical); ModerateIssuesCount = IssueList.Count(x => x.IsEnabled && x.Severity.HasValue && x.Severity.Value >= IssueSeverity.Moderate); CheckCompleted?.Invoke(this, new EventArgs()); }
//------ WUA callbacks ---------------------------------------------------- //Search Complete callback //for now this will be our callback //This needs some testing because can be problematic accorting to: //https://docs.microsoft.com/en-us/windows/win32/wua_sdk/guidelines-for-asynchronous-wua-operations void ISearchCompletedCallback.Invoke(ISearchJob searchJob, ISearchCompletedCallbackArgs callbackArgs) { try { var searchResult = updateSearcher.EndSearch(searchJob); if (searchResult.ResultCode != OperationResultCode.orcSucceeded && searchResult.ResultCode != OperationResultCode.orcSucceededWithErrors) { DebugLog($"Update search failed with code: {searchResult.ResultCode}"); CheckCompleted?.Invoke(false); return; } DebugLog($"Found {searchResult.Updates.Count} updates:" + Environment.NewLine); foreach (IUpdate update in searchResult.Updates) { DebugLog(Dump(update)); } DebugLog($"There are {searchResult.RootCategories.Count} cateories:" + Environment.NewLine); foreach (ICategory category in searchResult.RootCategories) { DebugLog(Dump(category)); } if (searchResult.Updates.Count > 0) { updateCollection = searchResult.Updates; foreach (IUpdate update in updateCollection) { List <string> KBs = new List <string>(); foreach (string KB in update.KBArticleIDs) { KBs.Add(KB); } WinUpdateStatus updateStatus = new WinUpdateStatus(update.Title, KBs); updateResults.Add(update.Title, updateStatus); } UpdatesFound?.Invoke(); CheckCompleted?.Invoke(true); } else { CheckCompleted?.Invoke(false); } } catch (Exception ex) { CheckCompleted?.Invoke(false); Log.Error("ISearchCompletedCallback.Invoke", ex.ToString()); } }
public void Check() { if (IsEndOfGame()) { if (IsVictory()) { Victory?.Invoke(this, null); } else { GameOver?.Invoke(this, null); } return; } CheckCompleted?.Invoke(this, null); }
internal async void AbortAll() { //simulate long running abort await Task.Delay(10000); switch (stage) { case 1: CheckCompleted?.Invoke(false); break; case 2: DownloadCompleted?.Invoke(false); break; case 3: InstallationCompleted?.Invoke(false, false); break; } cts?.Cancel(); cts?.Dispose(); }