2020using System ;
2121using System . Threading . Tasks ;
2222
23+ #nullable enable
24+
2325namespace OpenQA . Selenium . Remote
2426{
2527 /// <summary>
2628 /// Provides a mechanism to execute commands on the browser
2729 /// </summary>
2830 public class DriverServiceCommandExecutor : ICommandExecutor
2931 {
30- private DriverService service ;
31- private HttpCommandExecutor internalExecutor ;
32+ private readonly DriverService service ;
3233 private bool isDisposed ;
3334
3435 /// <summary>
3536 /// Initializes a new instance of the <see cref="DriverServiceCommandExecutor"/> class.
3637 /// </summary>
3738 /// <param name="driverService">The <see cref="DriverService"/> that drives the browser.</param>
3839 /// <param name="commandTimeout">The maximum amount of time to wait for each command.</param>
40+ /// <exception cref="ArgumentNullException">If <paramref name="driverService"/> is <see langword="null"/>.</exception>
3941 public DriverServiceCommandExecutor ( DriverService driverService , TimeSpan commandTimeout )
4042 : this ( driverService , commandTimeout , true )
4143 {
@@ -48,10 +50,11 @@ public DriverServiceCommandExecutor(DriverService driverService, TimeSpan comman
4850 /// <param name="commandTimeout">The maximum amount of time to wait for each command.</param>
4951 /// <param name="enableKeepAlive"><see langword="true"/> if the KeepAlive header should be sent
5052 /// with HTTP requests; otherwise, <see langword="false"/>.</param>
53+ /// <exception cref="ArgumentNullException">If <paramref name="driverService"/> is <see langword="null"/>.</exception>
5154 public DriverServiceCommandExecutor ( DriverService driverService , TimeSpan commandTimeout , bool enableKeepAlive )
5255 {
53- this . service = driverService ;
54- this . internalExecutor = new HttpCommandExecutor ( driverService . ServiceUrl , commandTimeout , enableKeepAlive ) ;
56+ this . service = driverService ?? throw new ArgumentNullException ( nameof ( driverService ) ) ;
57+ this . HttpExecutor = new HttpCommandExecutor ( driverService . ServiceUrl , commandTimeout , enableKeepAlive ) ;
5558 }
5659
5760 /// <summary>
@@ -60,33 +63,31 @@ public DriverServiceCommandExecutor(DriverService driverService, TimeSpan comman
6063 /// <param name="service">The <see cref="DriverService"/> that drives the browser.</param>
6164 /// <param name="commandExecutor">The <see cref="HttpCommandExecutor"/> object used to execute commands,
6265 /// communicating with the service via HTTP.</param>
66+ /// <exception cref="ArgumentNullException">If <paramref name="service"/> or <paramref name="commandExecutor"/> are <see langword="null"/>.</exception>
6367 public DriverServiceCommandExecutor ( DriverService service , HttpCommandExecutor commandExecutor )
6468 {
65- this . service = service ;
66- this . internalExecutor = commandExecutor ;
69+ this . service = service ?? throw new ArgumentNullException ( nameof ( service ) ) ;
70+ this . HttpExecutor = commandExecutor ?? throw new ArgumentNullException ( nameof ( commandExecutor ) ) ;
6771 }
6872
6973 /// <summary>
7074 /// Gets the <see cref="CommandInfoRepository"/> object associated with this executor.
7175 /// </summary>
7276 //public CommandInfoRepository CommandInfoRepository
7377 //{
74- // get { return this.internalExecutor .CommandInfoRepository; }
78+ // get { return this.HttpExecutor .CommandInfoRepository; }
7579 //}
7680
7781 public bool TryAddCommand ( string commandName , CommandInfo info )
7882 {
79- return this . internalExecutor . TryAddCommand ( commandName , info ) ;
83+ return this . HttpExecutor . TryAddCommand ( commandName , info ) ;
8084 }
8185
8286 /// <summary>
8387 /// Gets the <see cref="HttpCommandExecutor"/> that sends commands to the remote
8488 /// end WebDriver implementation.
8589 /// </summary>
86- public HttpCommandExecutor HttpExecutor
87- {
88- get { return this . internalExecutor ; }
89- }
90+ public HttpCommandExecutor HttpExecutor { get ; }
9091
9192 /// <summary>
9293 /// Executes a command
@@ -110,7 +111,7 @@ public async Task<Response> ExecuteAsync(Command commandToExecute)
110111 throw new ArgumentNullException ( nameof ( commandToExecute ) , "Command to execute cannot be null" ) ;
111112 }
112113
113- Response toReturn = null ;
114+ Response toReturn ;
114115 if ( commandToExecute . Name == DriverCommand . NewSession )
115116 {
116117 this . service . Start ( ) ;
@@ -120,7 +121,7 @@ public async Task<Response> ExecuteAsync(Command commandToExecute)
120121 // command, so that we can get the finally block.
121122 try
122123 {
123- toReturn = await this . internalExecutor . ExecuteAsync ( commandToExecute ) . ConfigureAwait ( false ) ;
124+ toReturn = await this . HttpExecutor . ExecuteAsync ( commandToExecute ) . ConfigureAwait ( false ) ;
124125 }
125126 finally
126127 {
@@ -139,6 +140,7 @@ public async Task<Response> ExecuteAsync(Command commandToExecute)
139140 public void Dispose ( )
140141 {
141142 this . Dispose ( true ) ;
143+ GC . SuppressFinalize ( this ) ;
142144 }
143145
144146 /// <summary>
@@ -153,7 +155,7 @@ protected virtual void Dispose(bool disposing)
153155 {
154156 if ( disposing )
155157 {
156- this . internalExecutor . Dispose ( ) ;
158+ this . HttpExecutor . Dispose ( ) ;
157159 this . service . Dispose ( ) ;
158160 }
159161
0 commit comments