private UpdateDownloaderFake GetDownloaderWithResultCode(OperationResultCode code) { UpdateDownloaderFake downloader = new UpdateDownloaderFake(); downloader.FakeDownloadResult = CommonMocks.GetDownloadResult(code); return(downloader); }
private OperationResultCode DownloadUpdates(CancellationToken cancellationToken) { _eventSource.InfoMessage("Download Started."); if (cancellationToken.IsCancellationRequested) { _eventSource.InfoMessage("Download Aborted."); return(OperationResultCode.orcAborted); } OperationResultCode downloadResult = OperationResultCode.orcNotStarted; long retries = 0; while (!cancellationToken.IsCancellationRequested) { downloadResult = DownloadUpdatesUtil(cancellationToken); if (downloadResult.Equals(OperationResultCode.orcSucceeded) || retries >= this._serviceSettings.WUOperationRetryCount || cancellationToken.IsCancellationRequested) { break; } TimeSpan delayBetweenRetries = TimeSpan.FromMinutes(this._serviceSettings.WUDelayBetweenRetriesInMinutes); this._helper.WaitOnTask(Task.Delay(delayBetweenRetries), cancellationToken); retries++; } _eventSource.Message("Download finished with result : {0}.", downloadResult); return(downloadResult); }
private WindowsUpdateOperationResult FormatOperationResult(OperationResultCode operationResultCode, WUCollectionWrapper updateCollectionWrapper, WindowsUpdateOperationType operationType, string wuQuery, string wuFrequency, DateTime operationStartTime) { bool rebootRequired = false; IList <WindowsUpdateDetail> details = new List <WindowsUpdateDetail>(); if (updateCollectionWrapper != null && updateCollectionWrapper.Collection != null) { foreach (WUUpdateWrapper item in updateCollectionWrapper.Collection.Values) { WindowsUpdateDetail updateDetail = new WindowsUpdateDetail(); updateDetail.UpdateId = item.Update.Identity.UpdateID; updateDetail.Title = item.Update.Title; updateDetail.Description = item.Update.Description; bool operation = operationType.Equals(WindowsUpdateOperationType.Installation) ? item.IsInstalled : item.IsDownloaded; updateDetail.ResultCode = MatchOperationResult(operation); updateDetail.HResult = item.HResult; details.Add(updateDetail); rebootRequired = !rebootRequired ? item.Update.RebootRequired : rebootRequired; } } return(new WindowsUpdateOperationResult(this._nodeName, operationStartTime, DateTime.UtcNow, MatchOperationResult(operationResultCode), details, operationType, wuQuery, wuFrequency, rebootRequired)); }
private string getResultText(IUpdateInstallationResult upd_result) { OperationResultCode resultCode = upd_result.ResultCode; switch ((int)resultCode) { case 0: return("Operation Not Started"); case 1: return("Operation In Progress"); case 2: return("Operation Successful"); case 3: return("Operation Completed with Errors"); case 4: return("Operation Failed"); case 5: return("Operation Aborted"); } return("Nonstandard result code"); }
/// <summary> /// default constructor: initializes all members /// </summary> public UpdateOpInfo() { title = ""; ID = ""; date = DateTime.MinValue; operation = UpdateOperation.uoUninstallation; result = OperationResultCode.orcNotStarted; }
public static IDownloadResult GetDownloadResult(OperationResultCode resultcode, int hresult = 0) { var mock = new Mock <IDownloadResult>(); mock.Setup(m => m.ResultCode).Returns(resultcode); mock.Setup(m => m.HResult).Returns(hresult); mock.Setup(m => m.GetUpdateResult(It.IsAny <int>())).Throws(new NotImplementedException("Not supported by this mock.")); return(mock.Object); }
public Result(OperationResultCode resultCode, string message, string exceptionStack, object obj, bool m_Showstate) { this.resultCode = (int)resultCode; this.message = message; this.exceptionStack = exceptionStack; data = obj; this.m_Showstate = m_Showstate; }
public static ISearchResult GetSearchResult(IUpdateCollection updates, OperationResultCode resultcode = OperationResultCode.orcSucceeded) { var mock = new Mock <ISearchResult>(); mock.Setup(m => m.ResultCode).Returns(resultcode); mock.Setup(m => m.Updates).Returns(((UpdateCollection)updates)); mock.Setup(m => m.RootCategories).Throws(new NotImplementedException("Not supported by this mock.")); mock.Setup(m => m.Warnings).Returns((IUpdateExceptionCollection)null); return(mock.Object); }
public OperationResult(bool success, OperationResultCode code, string message) { Success = success; if (!Success) { Code = code; Message = message; } }
public static IInstallationResult GetInstallationResult(OperationResultCode resultcode, int hresult = 0, bool rebootRequired = false) { var mock = new Mock <IInstallationResult>(); mock.Setup(m => m.ResultCode).Returns(resultcode); mock.Setup(m => m.HResult).Returns(hresult); mock.Setup(m => m.RebootRequired).Returns(rebootRequired); mock.Setup(m => m.GetUpdateResult(It.IsAny <int>())).Throws(new NotImplementedException("Not supported by this mock.")); return(mock.Object); }
public static OperationResult Decode(XdrDataInputStream stream) { OperationResult decodedOperationResult = new OperationResult(); OperationResultCode discriminant = OperationResultCode.Decode(stream); decodedOperationResult.Discriminant = discriminant; switch (decodedOperationResult.Discriminant.InnerValue) { case OperationResultCode.OperationResultCodeEnum.opINNER: decodedOperationResult.Tr = OperationResultTr.Decode(stream); break; } return(decodedOperationResult); }
public static OperationResult Decode(IByteReader stream) { OperationResult decodedOperationResult = new OperationResult(); decodedOperationResult.Discriminant = OperationResultCode.Decode(stream); switch (decodedOperationResult.Discriminant.InnerValue) { case OperationResultCode.OperationResultCodeEnum.opINNER: decodedOperationResult.Tr = OperationResultTr.Decode(stream); break; default: break; } return(decodedOperationResult); }
private WuOperationResult MatchOperationResult(OperationResultCode operationResultCode) { switch (operationResultCode) { case OperationResultCode.orcAborted: return(WuOperationResult.Aborted); case OperationResultCode.orcFailed: return(WuOperationResult.Failed); case OperationResultCode.orcSucceeded: return(WuOperationResult.Succeeded); case OperationResultCode.orcSucceededWithErrors: return(WuOperationResult.SucceededWithErrors); default: return(WuOperationResult.Failed); } }
private static void InstallUpdates(UpdateCollection installableUpdates) { Logger.Write("Trying to install update(s)."); try { UpdateSession uSession = new UpdateSession(); UpdateDownloader uDownloader = uSession.CreateUpdateDownloader(); IUpdateInstaller uInstaller = uSession.CreateUpdateInstaller(); if (installableUpdates.Count != 0) { Logger.Write(installableUpdates.Count + " update(s) to install."); uInstaller.ClientApplicationID = "InstallPendingUpdates"; uInstaller.AllowSourcePrompts = false; uDownloader.ClientApplicationID = "InstallPendingUpdates"; uDownloader.Updates = installableUpdates; Logger.Write("Starting to download update(s)."); uDownloader.Download(); Logger.Write("Download finnish."); uInstaller.Updates = installableUpdates; Logger.Write("Starting to install " + installableUpdates.Count + " update(s)."); IInstallationResult installResult = uInstaller.Install(); OperationResultCode resultCode = installResult.ResultCode; Logger.Write("Finnish to install update(s). Result : " + resultCode.ToString()); } else { Logger.Write("No udpdate to install."); } } catch (Exception ex) { Logger.Write("Problem when installing update(s). " + ex.Message); } }
public static void Encode(IByteWriter stream, OperationResultCode value) { XdrEncoding.EncodeInt32((int)value.InnerValue, stream); }
public BusinessException(OperationResultCode status, string description) : base(description) { Status = status; Description = description; }
public static OperationResult CreateResult(this ConsulCommandLineTool commandTool, OperationResultCode code) { var result = new OperationResult() { Success = false, Code = code, }; switch (code) { case OperationResultCode.Success: result.Message = "Operation completed successfully."; result.Success = true; break; case OperationResultCode.GenericError: result.Message = "An unexpected error has occured."; break; case OperationResultCode.HelpRequested: result.ShowHelp = true; result.HelpText = commandTool.GetUsage(); break; case OperationResultCode.NoArguments: result.Message = "No arguments were provided."; result.ShowHelp = true; result.HelpText = commandTool.GetUsage(); break; case OperationResultCode.ArgumentsParsingError: result.Message = "Encountered an error while parsing the arguments."; result.ShowHelp = true; result.HelpText = commandTool.GetUsage(); break; case OperationResultCode.HostNotReachable: result.Message = string.Format("The specified host could not be reached: {0}", commandTool.Client.Host.ToString()); break; case OperationResultCode.ServiceDefinitionFileNotFound: result.Message = string.Format("The specified service definition file could not be found: {0}", commandTool.Options.Service); break; case OperationResultCode.ServiceDefinitionFileBadFormat: result.Message = string.Format("The specified service definition file is not valid: {0}", commandTool.Options.Service); break; case OperationResultCode.RegisterServiceFailure: result.Message = string.Format("Failed to register the service."); break; case OperationResultCode.UnregisterServiceFailure: result.Message = string.Format("Failed to unregister the service, likely because a service with that id does not exist."); break; case OperationResultCode.MainOptionMissing: result.Message = "Need to specify at least one main option: \n" + "-n --node: node \n" + "-s --svc: service definition \n" + "-k --kv: key/value"; break; case OperationResultCode.MutlipleMainOptions: result.Message = "Detected multiple main options. Specify only one main option: \n" + "-n --node: node \n" + "-s --svc: service definition \n" + "-k --kv: key/value"; break; case OperationResultCode.SubOptionMissing: result.Message = "Need to specify at least one action option: \n" + "-c --create: create the key/value or service\n" + "-r --read: read a key/value or service\n" + "-d --delete: delete a key/value or service\n"; break; case OperationResultCode.MutlipleSubOptions: result.Message = "Detected multiple action options. Specify only one action option: \n" + "-c --create: create the key/value or service\n" + "-r --read: read a key/value or service\n" + "-d --delete: delete a key/value or service\n"; break; case OperationResultCode.InvalidHostUri: result.Message = string.Format("The host uri is not valid: {0}", commandTool.Options.GetHostString()); break; case OperationResultCode.InvalidKey: result.Message = string.Format("The specified key is not valid: {0}", commandTool.Options.Key); break; case OperationResultCode.DeleteKeyFailure: result.Message = string.Format("Failed to delete the key: {0}", commandTool.Options.Key); break; case OperationResultCode.CreateKeyFailure: result.Message = string.Format("Failed to create the key: {0}", commandTool.Options.Key); break; case OperationResultCode.ValueCannotBeNullOrEmpty: result.Message = string.Format("Cannot create a key without a value"); break; case OperationResultCode.DeleteNodeFailure: result.Message = string.Format("Cannot delete the specified node, likely because it does not exist."); break; } return(result); }
public static void UpdateHist(Server server, bool initiated) { try { Type t = Type.GetTypeFromProgID("Microsoft.Update.Session", server.Location); //wcswapp01.intellig.local OH0KLT733D7S2.global.ds.honeywell.com labengdemctl00.labmasoh.local wcbuildapp02.intellig.local UpdateSession session = (UpdateSession)Activator.CreateInstance(t); IUpdateSearcher updateSearcher = session.CreateUpdateSearcher(); int count = updateSearcher.GetTotalHistoryCount(); IUpdateHistoryEntryCollection history = updateSearcher.QueryHistory(0, count); DateTime current = DateTime.Now; for (int i = 0; i < count; ++i) { if (initiated == true) { int hecc = current.Day * (-1); if (history[i].Date >= current.AddMonths(-1).AddDays(hecc)) { Info temp = new Info(); IUpdateIdentity ID = history[i].UpdateIdentity; OperationResultCode operationResult = history[i].ResultCode; string Result = operationResult.ToString(); if (Result == "orcSucceeded") { temp.TestResults = "Succeeded"; temp.UpdateStatus = "Succeeded"; } else { temp.TestResults = "Failed"; temp.UpdateStatus = "Failed"; } temp.TestDate = history[i].Date; temp.updateID = ID.UpdateID; temp.Title = history[i].Title; temp.ICW = server.ICW; temp.Server = server.ServerName; temp.Active = "Yes"; InfoList.Add(temp); } } else { Info temp = new Info(); IUpdateIdentity ID = history[i].UpdateIdentity; OperationResultCode operationResult = history[i].ResultCode; string Result = operationResult.ToString(); if (Result == "orcSucceeded") { temp.TestResults = "Succeeded"; temp.UpdateStatus = "Succeeded"; } else { temp.TestResults = "Failed"; temp.UpdateStatus = "Failed"; } temp.TestDate = history[i].Date; temp.updateID = ID.UpdateID; temp.Title = history[i].Title; temp.ICW = server.ICW; temp.Server = server.ServerName; temp.Active = "Yes"; //### Uncomment to ignore the updates older than 7 months //if (temp.TestDate <= current.AddMonths(-7)) int y = current.Year; DateTime year = new DateTime(y, 1, 1); if (temp.TestDate <= year) { break; } InfoList.Add(temp); } } } catch (Exception ex) { throw ex; } }
public ApiResponse(OperationResultCode status, string message) { Status = status; Message = message; Timestamp = DateTime.UtcNow.ConvertToTimestamp(); }
public ServiceResult(OperationResultCode code, string message = "", T value = default) { Messages = new [] { message }; Code = code; Value = value; }
private bool HandleWUOperationStates(CancellationToken cancellationToken) { TimeSpan utilityTaskTimeOut = TimeSpan.FromMinutes(this._serviceSettings.OperationTimeOutInMinutes); NodeAgentSfUtilityExitCodes wuOperationState = this._nodeAgentSfUtility.GetWuOperationState(utilityTaskTimeOut); _eventSource.InfoMessage("Current WU Operation State : {0}", wuOperationState); bool reschedule = false; switch (wuOperationState) { case NodeAgentSfUtilityExitCodes.None: case NodeAgentSfUtilityExitCodes.OperationCompleted: { OperationResultCode searchResult = SearchUpdates(cancellationToken); reschedule = (searchResult != OperationResultCode.orcSucceeded ? true : reschedule); if (this._wuCollectionWrapper != null) { if (this._wuCollectionWrapper.Collection.Count == 0) { _eventSource.InfoMessage("No Windows Update available. Completing the operation."); //Complete operation. this._nodeAgentSfUtility.UpdateSearchAndDownloadStatus( NodeAgentSfUtilityExitCodes.OperationCompleted, this._operationResultFormatter.CreateSearchAndDownloadDummyResult(), utilityTaskTimeOut ); break; } OperationResultCode downloadResult = DownloadUpdates(cancellationToken); reschedule = (downloadResult != OperationResultCode.orcSucceeded ? true : reschedule); WindowsUpdateOperationResult searchAndDownloadResult = this._operationResultFormatter.FormatSearchAndDownloadResult(downloadResult, this._wuCollectionWrapper); _eventSource.InfoMessage("Search and download result: {0}", searchAndDownloadResult); this._nodeAgentSfUtility.UpdateSearchAndDownloadStatus(NodeAgentSfUtilityExitCodes.DownloadCompleted, searchAndDownloadResult, utilityTaskTimeOut); NodeAgentSfUtilityExitCodes exitCodes = this.WaitForInstallationApproval(cancellationToken); if (exitCodes.Equals(NodeAgentSfUtilityExitCodes.Failure)) { _eventSource.ErrorMessage("Not able to move from DownloadCompleted state to InstallationApproved state."); reschedule = true; break; } this._nodeAgentSfUtility.UpdateInstallationStatus(NodeAgentSfUtilityExitCodes.InstallationInProgress, null, utilityTaskTimeOut); OperationResultCode installResult = InstallUpdates(cancellationToken); reschedule = (installResult != OperationResultCode.orcSucceeded ? true : reschedule); WindowsUpdateOperationResult installationResult = this._operationResultFormatter.FormatInstallationResult(installResult, this._wuCollectionWrapper); _eventSource.InfoMessage("Installation result: {0}", installationResult); this._nodeAgentSfUtility.UpdateInstallationStatus(NodeAgentSfUtilityExitCodes.InstallationCompleted, installationResult, utilityTaskTimeOut); } break; } case NodeAgentSfUtilityExitCodes.DownloadCompleted: case NodeAgentSfUtilityExitCodes.InstallationApproved: { NodeAgentSfUtilityExitCodes exitCodes = this.WaitForInstallationApproval(cancellationToken); if (exitCodes.Equals(NodeAgentSfUtilityExitCodes.Failure)) { _eventSource.ErrorMessage("Not able to move from DownloadCompleted state to InstallationApproved state."); reschedule = true; break; } OperationResultCode searchResult = SearchUpdates(cancellationToken); reschedule = (searchResult != OperationResultCode.orcSucceeded ? true : reschedule); if (this._wuCollectionWrapper != null) { if (this._wuCollectionWrapper.Collection.Count == 0) { string msg = "Current Operation state : InstallationApproved but no updates found to install. Completing the operation."; this._nodeAgentSfUtility.ReportHealth("WindowsUpdateOperationResult", msg, HealthState.Warning, -1, TimeSpan.FromMinutes(this._serviceSettings.OperationTimeOutInMinutes)); _eventSource.WarningMessage(msg); //Complete operation. this._nodeAgentSfUtility.UpdateInstallationStatus( NodeAgentSfUtilityExitCodes.OperationCompleted, this._operationResultFormatter.CreateInstallationDummyResult(), utilityTaskTimeOut ); break; } this._nodeAgentSfUtility.UpdateInstallationStatus(NodeAgentSfUtilityExitCodes.InstallationInProgress, null, utilityTaskTimeOut); OperationResultCode installResult = InstallUpdates(cancellationToken); reschedule = (installResult != OperationResultCode.orcSucceeded ? true : reschedule); WindowsUpdateOperationResult installationResult = this._operationResultFormatter.FormatInstallationResult(installResult, this._wuCollectionWrapper); _eventSource.InfoMessage("Installation result: {0}", installationResult); this._nodeAgentSfUtility.UpdateInstallationStatus(NodeAgentSfUtilityExitCodes.InstallationCompleted, installationResult, utilityTaskTimeOut); } break; } case NodeAgentSfUtilityExitCodes.InstallationInProgress: { OperationResultCode searchResult = SearchUpdates(cancellationToken); reschedule = (searchResult != OperationResultCode.orcSucceeded ? true : reschedule); if (this._wuCollectionWrapper != null) { if (this._wuCollectionWrapper.Collection.Count == 0) { //this is possible when installation is completed but NT service is killed before updating "InstallationCompleted" status. break; } OperationResultCode installResult = InstallUpdates(cancellationToken); reschedule = (installResult != OperationResultCode.orcSucceeded ? true : reschedule); WindowsUpdateOperationResult installationResult = this._operationResultFormatter.FormatInstallationResult(installResult, this._wuCollectionWrapper); _eventSource.InfoMessage("Installation result: {0}", installationResult); this._nodeAgentSfUtility.UpdateInstallationStatus(NodeAgentSfUtilityExitCodes.InstallationCompleted, installationResult, utilityTaskTimeOut); } break; } default: break; } return(reschedule); }
/// <summary> /// Formats search and download operation result. /// </summary> /// <param name="operationResultCode">Operation result code</param> /// <param name="updateCollectionWrapper">Collection from which the formatted result will be created.</param> /// <returns></returns> public WindowsUpdateOperationResult FormatSearchAndDownloadResult(OperationResultCode operationResultCode, WUCollectionWrapper updateCollectionWrapper) { return(FormatOperationResult(operationResultCode, updateCollectionWrapper, WindowsUpdateOperationType.SearchAndDownload, this._serviceSettings.WUQuery, this._serviceSettings.WUFrequency)); }
/// <summary> /// Formats installation operation result. /// </summary> /// <param name="operationResultCode">Operation result code</param> /// <param name="updateCollectionWrapper">Collection from which the formatted result will be created.</param> /// <returns></returns> public WindowsUpdateOperationResult FormatInstallationResult(OperationResultCode operationResultCode, WUCollectionWrapper updateCollectionWrapper, DateTime operationStartTime) { return(FormatOperationResult(operationResultCode, updateCollectionWrapper, WindowsUpdateOperationType.Installation, this._serviceSettings.WUQuery, this._serviceSettings.WUFrequency, operationStartTime)); }
public ServiceResult(OperationResultCode code, IEnumerable <string> messages = default, T value = default) { Messages = messages; Code = code; Value = value; }
private OperationException OperationException(OperationResultCode code) { return(new OperationException(this.CreateResult(code))); }
/// <summary> /// returns a human-readable string to describe the passed /// OperationResultCode value (e.g. "Succeeded", "Failed", etc., /// depending on whether the code indicates success, failure or any /// other update result) /// </summary> /// <param name="orc">WUApiLib.OperationResultCode value</param> /// <returns>string that describes the operation result code value</returns> public static string OperationResultCodeToString(OperationResultCode orc) { switch (orc) { case OperationResultCode.orcAborted: return "Aborted"; case OperationResultCode.orcFailed: return "Failed"; case OperationResultCode.orcInProgress: return "In progress"; case OperationResultCode.orcNotStarted: return "Not started"; case OperationResultCode.orcSucceeded: return "Succeeded"; case OperationResultCode.orcSucceededWithErrors: return "Succeeded with errors"; default: return "unknown"; } //swi }