Skip to content

Commit

Permalink
fix CA1063 (#1470)
Browse files Browse the repository at this point in the history
  • Loading branch information
schulz3000 authored May 7, 2020
1 parent a29f5f4 commit ada6826
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 16 deletions.
2 changes: 1 addition & 1 deletion lib/PuppeteerSharp.ruleset
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
<Rule Id="CA1031" Action="None" /> <!-- Error CA1031: Modify 'SendAsync' to catch a more specific allowed exception type, or rethrow the exception. (CA1031)-->
<Rule Id="CA1032" Action="None" /> <!-- Error CA1032: Add the following constructor to SelectorException: public SelectorException(). (CA1032) -->
<Rule Id="CA1062" Action="None" /> <!-- Error CA1031: Modify 'DeleteAsync' to catch a more specific allowed exception type, or rethrow the exception. (CA1031)-->
<Rule Id="CA1063" Action="None" /> <!-- Error CA1063: Provide an overridable implementation of Dispose(bool) -->
<Rule Id="CA1063" Action="Error" /> <!-- Error CA1063: Provide an overridable implementation of Dispose(bool) -->
<Rule Id="CA1064" Action="None" /> <!-- Error CA1064: Exceptions should be public (CA1064)-->
<Rule Id="CA1001" Action="None" /> <!-- Error CA1001: A class owns a disposable -->
<Rule Id="CA1304" Action="None" /> <!-- Error CA1304: The behavior of 'string.ToLower()' could vary based on the current user's locale settings. Replace this call in 'JSHandle.ToString()' with a call to 'string.ToLower(CultureInfo)'. (CA1304) -->
Expand Down
12 changes: 10 additions & 2 deletions lib/PuppeteerSharp/Browser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -530,11 +530,19 @@ internal static async Task<Browser> CreateAsync(

#region IDisposable

/// <inheritdoc />
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}

/// <summary>
/// Closes <see cref="Connection"/> and any Chromium <see cref="Process"/> that was
/// created by Puppeteer.
/// </summary>
public void Dispose() => _ = CloseAsync();
/// <param name="disposing">Indicates whether disposal was initiated by <see cref="Dispose()"/> operation.</param>
protected virtual void Dispose(bool disposing) => _ = CloseAsync();

#endregion

Expand All @@ -549,4 +557,4 @@ internal static async Task<Browser> CreateAsync(

#endregion
}
}
}
4 changes: 2 additions & 2 deletions lib/PuppeteerSharp/ChromiumProcess.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
Expand Down Expand Up @@ -117,8 +117,8 @@ public ChromiumProcess(string chromiumExecutable, LaunchOptions options, ILogger
/// <inheritdoc />
public void Dispose()
{
GC.SuppressFinalize(this);
Dispose(true);
GC.SuppressFinalize(this);
}

/// <summary>
Expand Down
20 changes: 14 additions & 6 deletions lib/PuppeteerSharp/Connection.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Concurrent;
using System.Linq;
using System.Threading;
Expand Down Expand Up @@ -296,20 +296,28 @@ internal static async Task<Connection> Create(string url, IConnectionOptions con
return new Connection(url, connectionOptions.SlowMo, transport, loggerFactory);
}

/// <inheritdoc />
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}

/// <summary>
/// Releases all resource used by the <see cref="Connection"/> object.
/// It will raise the <see cref="Disconnected"/> event and dispose <see cref="Transport"/>.
/// </summary>
/// <remarks>Call <see cref="Dispose"/> when you are finished using the <see cref="Connection"/>. The
/// <see cref="Dispose"/> method leaves the <see cref="Connection"/> in an unusable state.
/// After calling <see cref="Dispose"/>, you must release all references to the
/// <remarks>Call <see cref="Dispose()"/> when you are finished using the <see cref="Connection"/>. The
/// <see cref="Dispose()"/> method leaves the <see cref="Connection"/> in an unusable state.
/// After calling <see cref="Dispose()"/>, you must release all references to the
/// <see cref="Connection"/> so the garbage collector can reclaim the memory that the
/// <see cref="Connection"/> was occupying.</remarks>
public void Dispose()
/// <param name="disposing">Indicates whether disposal was initiated by <see cref="Dispose()"/> operation.</param>
protected virtual void Dispose(bool disposing)
{
Close("Connection disposed");
Transport.Dispose();
}
#endregion
}
}
}
17 changes: 13 additions & 4 deletions lib/PuppeteerSharp/Page.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2421,14 +2421,23 @@ string SerializeArgument(object arg)
#endregion

#region IDisposable

/// <inheritdoc />
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}

/// <summary>
/// Releases all resource used by the <see cref="Page"/> object by calling the <see cref="CloseAsync"/> method.
/// </summary>
/// <remarks>Call <see cref="Dispose"/> when you are finished using the <see cref="Page"/>. The
/// <see cref="Dispose"/> method leaves the <see cref="Page"/> in an unusable state. After
/// calling <see cref="Dispose"/>, you must release all references to the <see cref="Page"/> so
/// <remarks>Call <see cref="Dispose()"/> when you are finished using the <see cref="Page"/>. The
/// <see cref="Dispose()"/> method leaves the <see cref="Page"/> in an unusable state. After
/// calling <see cref="Dispose()"/>, you must release all references to the <see cref="Page"/> so
/// the garbage collector can reclaim the memory that the <see cref="Page"/> was occupying.</remarks>
public void Dispose() => CloseAsync();
/// <param name="disposing">Indicates whether disposal was initiated by <see cref="Dispose()"/> operation.</param>
protected virtual void Dispose(bool disposing) => _ = CloseAsync();
#endregion

#region IAsyncDisposable
Expand Down
12 changes: 11 additions & 1 deletion lib/PuppeteerSharp/Transport/WebSocketTransport.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Net.WebSockets;
using System.Text;
using System.Threading;
Expand Down Expand Up @@ -138,6 +138,16 @@ public void StopReading()

/// <inheritdoc/>
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}

/// <summary>
/// Close the WebSocketTransport
/// </summary>
/// <param name="disposing">Indicates whether disposal was initiated by <see cref="Dispose()"/> operation.</param>
protected virtual void Dispose(bool disposing)
{
// Make sure any outstanding asynchronous read operation is cancelled.
StopReading();
Expand Down

0 comments on commit ada6826

Please sign in to comment.