Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[dotnet] Annotate DriverServiceCommandExecutor for nullability #14942

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 17 additions & 15 deletions dotnet/src/webdriver/Remote/DriverServiceCommandExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,24 @@
using System;
using System.Threading.Tasks;

#nullable enable

namespace OpenQA.Selenium.Remote
{
/// <summary>
/// Provides a mechanism to execute commands on the browser
/// </summary>
public class DriverServiceCommandExecutor : ICommandExecutor
{
private DriverService service;
private HttpCommandExecutor internalExecutor;
private readonly DriverService service;
private bool isDisposed;

/// <summary>
/// Initializes a new instance of the <see cref="DriverServiceCommandExecutor"/> class.
/// </summary>
/// <param name="driverService">The <see cref="DriverService"/> that drives the browser.</param>
/// <param name="commandTimeout">The maximum amount of time to wait for each command.</param>
/// <exception cref="ArgumentNullException">If <paramref name="driverService"/> is <see langword="null"/>.</exception>
public DriverServiceCommandExecutor(DriverService driverService, TimeSpan commandTimeout)
: this(driverService, commandTimeout, true)
{
Expand All @@ -48,10 +50,11 @@ public DriverServiceCommandExecutor(DriverService driverService, TimeSpan comman
/// <param name="commandTimeout">The maximum amount of time to wait for each command.</param>
/// <param name="enableKeepAlive"><see langword="true"/> if the KeepAlive header should be sent
/// with HTTP requests; otherwise, <see langword="false"/>.</param>
/// <exception cref="ArgumentNullException">If <paramref name="driverService"/> is <see langword="null"/>.</exception>
public DriverServiceCommandExecutor(DriverService driverService, TimeSpan commandTimeout, bool enableKeepAlive)
{
this.service = driverService;
this.internalExecutor = new HttpCommandExecutor(driverService.ServiceUrl, commandTimeout, enableKeepAlive);
this.service = driverService ?? throw new ArgumentNullException(nameof(driverService));
this.HttpExecutor = new HttpCommandExecutor(driverService.ServiceUrl, commandTimeout, enableKeepAlive);
}

/// <summary>
Expand All @@ -60,33 +63,31 @@ public DriverServiceCommandExecutor(DriverService driverService, TimeSpan comman
/// <param name="service">The <see cref="DriverService"/> that drives the browser.</param>
/// <param name="commandExecutor">The <see cref="HttpCommandExecutor"/> object used to execute commands,
/// communicating with the service via HTTP.</param>
/// <exception cref="ArgumentNullException">If <paramref name="service"/> or <paramref name="commandExecutor"/> are <see langword="null"/>.</exception>
public DriverServiceCommandExecutor(DriverService service, HttpCommandExecutor commandExecutor)
{
this.service = service;
this.internalExecutor = commandExecutor;
this.service = service ?? throw new ArgumentNullException(nameof(service));
this.HttpExecutor = commandExecutor ?? throw new ArgumentNullException(nameof(commandExecutor));
}

/// <summary>
/// Gets the <see cref="CommandInfoRepository"/> object associated with this executor.
/// </summary>
//public CommandInfoRepository CommandInfoRepository
//{
// get { return this.internalExecutor.CommandInfoRepository; }
// get { return this.HttpExecutor.CommandInfoRepository; }
//}

public bool TryAddCommand(string commandName, CommandInfo info)
{
return this.internalExecutor.TryAddCommand(commandName, info);
return this.HttpExecutor.TryAddCommand(commandName, info);
}

/// <summary>
/// Gets the <see cref="HttpCommandExecutor"/> that sends commands to the remote
/// end WebDriver implementation.
/// </summary>
public HttpCommandExecutor HttpExecutor
{
get { return this.internalExecutor; }
}
public HttpCommandExecutor HttpExecutor { get; }

/// <summary>
/// Executes a command
Expand All @@ -110,7 +111,7 @@ public async Task<Response> ExecuteAsync(Command commandToExecute)
throw new ArgumentNullException(nameof(commandToExecute), "Command to execute cannot be null");
}

Response toReturn = null;
Response toReturn;
if (commandToExecute.Name == DriverCommand.NewSession)
{
this.service.Start();
Expand All @@ -120,7 +121,7 @@ public async Task<Response> ExecuteAsync(Command commandToExecute)
// command, so that we can get the finally block.
try
{
toReturn = await this.internalExecutor.ExecuteAsync(commandToExecute).ConfigureAwait(false);
toReturn = await this.HttpExecutor.ExecuteAsync(commandToExecute).ConfigureAwait(false);
}
finally
{
Expand All @@ -139,6 +140,7 @@ public async Task<Response> ExecuteAsync(Command commandToExecute)
public void Dispose()
{
this.Dispose(true);
GC.SuppressFinalize(this);
}

/// <summary>
Expand All @@ -153,7 +155,7 @@ protected virtual void Dispose(bool disposing)
{
if (disposing)
{
this.internalExecutor.Dispose();
this.HttpExecutor.Dispose();
this.service.Dispose();
}

Expand Down
2 changes: 2 additions & 0 deletions dotnet/src/webdriver/Remote/ICommandServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

using System;

#nullable enable

namespace OpenQA.Selenium.Remote
{
/// <summary>
Expand Down
Loading