コード例 #1
0
        //------ 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());
            }
        }
コード例 #2
0
 /// <summary>
 /// 引发 <see cref="UpdatesFound"/> 事件
 /// </summary>
 protected virtual void OnUpdatesFound()
 {
     UpdatesFound?.Invoke(this, EventArgs.Empty);
     EnsureUpdateStarted();
 }