public virtual CommandExecutionResult Load(bool force = false) { foreach (GeneratedModule requiredModule in this.RequiredModules) { CommandExecutionResult requiredModuleResult = requiredModule.Load(force: force); if (requiredModuleResult != null && requiredModuleResult.HadErrors) { return(requiredModuleResult); } } ICommandBuilder command = this.runspace.CreateCommand(); command.Command = "Import-Module"; if (!String.IsNullOrEmpty(ModulePath)) { command.AddParameter("Name", this.ModulePath); } if (force) { command.AddParameter("Force", true); } return(command.Invoke()); }
public virtual CommandExecutionResult ProcessRequest(LiveTestRequest request, LiveTestCredentialFactory credentialsFactory) { if (this.Logger != null) { this.Logger.LogAsync("Translating credentials..."); } credentialsFactory.TranslateCredentialsObjects(request); CommandExecutionResult result = null; string operationId = request.OperationId == null ? null : request.OperationId.ToLowerInvariant(); if (this.Logger != null) { this.Logger.LogAsync("Operation ID of message: " + operationId); } if (!String.IsNullOrEmpty(operationId) && this.Operations.ContainsKey(operationId)) { if (this.Logger != null) { this.Logger.LogAsync("Processing operation..."); } OperationData op = this.Operations[operationId]; // Create the command ICommandBuilder command = this.runspace.CreateCommand(); command.Command = op.Command; foreach (string parameterName in op.Parameters.Keys) { if (request.Params != null && request.Params.ContainsKey(parameterName.ToLowerInvariant())) { command.AddParameter(parameterName, request.Params[parameterName.ToLowerInvariant()]); } else { this.Logger.LogAsync("Request missing parameter: " + parameterName); } } // Process credentials IEnumerable <ICredentialProvider> credProviders = credentialsFactory.Create(request, this.Logger); foreach (ICredentialProvider credProvider in credProviders) { credProvider.Process(command); } // Run the command result = command.Invoke(); // Run post processors, if any foreach (ICommandPostProcessor postProcessor in op.PostProcessors) { result = postProcessor.Process(result); } } else { // error if (this.Logger != null) { this.Logger.LogError("Operation ID was not found in module under test."); } } return(result); }