WindowsUpdateProvider.cs- an entry point to the provider that asks you about the metadata of the provider which is shown in the UI. It implements two main methods, BeginRunOperation and EndRunOperation, which is the crux of the provider. The class internally has a private class(SimpleAsyncResult) which implements IAsyncResult to do operations asynchronously.
SimpleAsyncResult stops the server using inbuilt provider StopOperationProvider.
RunOperationOptions options = _operationContext.Server.CreateRunOperationOptions(StopOperationProvider.ProviderName);
_operationContext.Server.BeginRunOperation(_operationContext, options, StopCompleteCallback, null);
If the operation throws then whole operation is short circuited and the exception is thrown to the controller machine. If stopping the server is successful, it calls the custom method (InstallUpdatesRemoteMethod) passing in the arguments (which in this case is null) and the callback method address to call when the operation is complete.
_operationContext.Server.BeginRunRemote(_operationContext,
typeof(InstallUpdatesRemoteMethod),
new object[] { },
InstallUpdatesCompleteCallback,
null);
The operation is executed on the server. If operation on the server throws an exception, the whole process is short circuited, to complete the process and throw the exception. If the operation is completed successful, the callback method passed to the method is called.
_operationContext.Server.BeginRunRemote(_operationContext,
typeof(InstallUpdatesRemoteMethod),
new object[] { },
InstallUpdatesCompleteCallback,
null);
It checks to see if a reboot is required. If a value of true is returned, it calls in the inbuilt reboot provider to reboot the server, also passing in the operation complete callback method.
bool rebootRequired = (bool)_operationContext.Server.EndRunRemote(result);
if (rebootRequired)
{
RunOperationOptions options = _operationContext.Server.CreateRunOperationOptions(RebootOperationProvider.ProviderName);
options.Parameters[0].Value = Resources.RebootRequiredForInstall;
_operationContext.Server.BeginRunOperation(_operationContext,
options,
RebootCompleteCallback,
null);
return;
}