feature: Implement Dispose for types which have disposable data (#1171)

* Initial set of dispose implementations

Not handled yet:
- Discord.Net.Websocket/Entities/SocketGuild
- Discord.Net.Tests

* Refactor DiscordSocketClient init into ctor

This way we remove an IDisposableAnalyzer warning for not disposing
the client when we set the client variable.

* Dispose of clients when disposing sharded client

* Finish implementing IDisposable where appropriate

I opted to use NoWarn in the Tests project as it wasn't really necessary
considering that our tests only run once

* Tweak samples after feedback
This commit is contained in:
Monica S
2018-11-29 01:18:16 +00:00
committed by Christopher F
parent dca6c33da3
commit 7366cd4361
31 changed files with 406 additions and 154 deletions

View File

@@ -5,6 +5,7 @@
<TargetFramework>netcoreapp1.1</TargetFramework>
<DebugType>portable</DebugType>
<PackageTargetFallback>$(PackageTargetFallback);portable-net45+win8+wp8+wpa81</PackageTargetFallback>
<NoWarn>IDISP001,IDISP002,IDISP004,IDISP005</NoWarn>
</PropertyGroup>
<ItemGroup>
<Content Include="xunit.runner.json">

View File

@@ -43,7 +43,10 @@ namespace Discord.Net
if (!_isDisposed)
{
if (disposing)
{
_blobCache.Dispose();
_cancelTokenSource?.Dispose();
}
_isDisposed = true;
}
}
@@ -70,7 +73,7 @@ namespace Discord.Net
{
if (method != "GET")
throw new InvalidOperationException("This RestClient only supports GET requests.");
string uri = Path.Combine(_baseUrl, endpoint);
var bytes = await _blobCache.DownloadUrl(uri, _headers);
return new RestResponse(HttpStatusCode.OK, _headers, new MemoryStream(bytes));
@@ -84,7 +87,7 @@ namespace Discord.Net
throw new InvalidOperationException("This RestClient does not support multipart requests.");
}
public async Task ClearAsync()
public async Task ClearAsync()
{
await _blobCache.InvalidateAll();
}
@@ -93,7 +96,7 @@ namespace Discord.Net
{
if (Info != null)
return;
bool needsReset = false;
try
{
@@ -117,4 +120,4 @@ namespace Discord.Net
await _blobCache.InsertObject<CacheInfo>("info", Info);
}
}
}
}