From d5b06adc8efbcd59a06749749a0e8e9379701555 Mon Sep 17 00:00:00 2001 From: forest93 Date: Wed, 7 Mar 2018 20:42:57 +0800 Subject: [PATCH] Multi-target WCL to netstandard 11/20. This can eliminate the dependency to System.Reflection.Emit since netstandard20. --- UnitTestProject1/Tests/PageTestsDirty.cs | 4 ++- WikiClientLibrary/Client/WikiClient.cs | 13 +++++++--- .../Infrastructures/HttpContentEx.cs | 26 +++++++++---------- WikiClientLibrary/WikiClientLibrary.csproj | 12 ++++++--- 4 files changed, 33 insertions(+), 22 deletions(-) diff --git a/UnitTestProject1/Tests/PageTestsDirty.cs b/UnitTestProject1/Tests/PageTestsDirty.cs index ad97cd28d..43f702dbc 100644 --- a/UnitTestProject1/Tests/PageTestsDirty.cs +++ b/UnitTestProject1/Tests/PageTestsDirty.cs @@ -126,7 +126,7 @@ public async Task LocalFileUploadRetryTest1() wikiClient.RetryDelay = TimeSpan.FromSeconds(1); wikiClient.MaxRetries = 1; var buffer = new byte[1024 * 1024 * 2]; // 2MB, I think this size is fairly large. - // If your connection speed is too fast then, well, trottle it plz. + // If your connection speed is too fast then, well, throttle it plz. using (var ms = new MemoryStream(buffer)) { await Assert.ThrowsAsync(async () => @@ -136,6 +136,8 @@ await Assert.ThrowsAsync(async () => // Usually we should notify the user, then perform the re-upload ignoring the warning. Assert.Equal(UploadResultCode.Warning, result.ResultCode); }); + // Ensure that the stream has not been disposed in this case. + ms.Seek(0, SeekOrigin.Begin); } } diff --git a/WikiClientLibrary/Client/WikiClient.cs b/WikiClientLibrary/Client/WikiClient.cs index dd144b39b..ef0007ed7 100644 --- a/WikiClientLibrary/Client/WikiClient.cs +++ b/WikiClientLibrary/Client/WikiClient.cs @@ -19,10 +19,17 @@ namespace WikiClientLibrary.Client /// public class WikiClient : IWikiClient, IWikiClientLoggable, IDisposable { + +#if NETSTANDARD1_1 + private const string targetFramework = ".NET Standard 1.1"; +#elif NETSTANDARD2_0 + private const string targetFramework = ".NET Standard 2.0"; +#endif + /// /// The User Agent of Wiki Client Library. /// - public const string WikiClientUserAgent = "WikiClientLibrary/0.6 (.NET Portable; http://github.com/cxuesong/WikiClientLibrary)"; + public const string WikiClientUserAgent = "WikiClientLibrary/0.6 (" + targetFramework + "; http://github.com/cxuesong/WikiClientLibrary)"; public WikiClient() : this(new HttpClientHandler(), true) { @@ -103,7 +110,7 @@ public string ClientUserAgent _ClientUserAgent = value; } } - } + } /// /// Referer. @@ -165,7 +172,7 @@ protected virtual HttpRequestMessage CreateHttpRequestMessage(string endPointUrl var query = message.GetHttpQuery(); if (query != null) url = url + "?" + query; return new HttpRequestMessage(message.GetHttpMethod(), url) - {Content = message.GetHttpContent()}; + { Content = message.GetHttpContent() }; } private async Task SendAsync(string endPointUrl, WikiRequestMessage message, diff --git a/WikiClientLibrary/Infrastructures/HttpContentEx.cs b/WikiClientLibrary/Infrastructures/HttpContentEx.cs index 71499950d..22ecd030e 100644 --- a/WikiClientLibrary/Infrastructures/HttpContentEx.cs +++ b/WikiClientLibrary/Infrastructures/HttpContentEx.cs @@ -41,6 +41,7 @@ private static byte[] GetContentByteArray(IEnumerable disposeImpl - ; // Calls System.Net.Http.HttpContent.Dispose + private static readonly Action disposeImpl; // Calls System.Net.Http.HttpContent.Dispose /// protected override void Dispose(bool disposing) { if (disposing) - { - if (DisposeStream) - base.Dispose(true); - else - disposeImpl(this); // We want to bypass StreamContent::Dispose(true) implementation. - } + disposeImpl(this); // We want to bypass StreamContent::Dispose(true) implementation. else base.Dispose(false); } @@ -97,7 +92,7 @@ protected override void Dispose(bool disposing) static KeepAlivingStreamContent() { var method = new DynamicMethod("$KeepAlivingStreamContent.Dispose()", null, - new[] {typeof(KeepAlivingStreamContent)}, typeof(KeepAlivingStreamContent)); + new[] { typeof(KeepAlivingStreamContent) }, typeof(KeepAlivingStreamContent)); var il = method.GetILGenerator(); il.Emit(OpCodes.Ldarg_0); // this il.Emit(OpCodes.Ldc_I4_1); // disposing @@ -108,7 +103,10 @@ static KeepAlivingStreamContent() null); il.Emit(OpCodes.Ret); disposeImpl = - (Action) method.CreateDelegate(typeof(Action)); + (Action)method.CreateDelegate(typeof(Action)); } + +#endif + } } \ No newline at end of file diff --git a/WikiClientLibrary/WikiClientLibrary.csproj b/WikiClientLibrary/WikiClientLibrary.csproj index 9e4d68fb4..a01a91f3e 100644 --- a/WikiClientLibrary/WikiClientLibrary.csproj +++ b/WikiClientLibrary/WikiClientLibrary.csproj @@ -1,14 +1,15 @@  - netstandard1.1 + netstandard1.1;netstandard2.0 WikiClientLibrary CXuesong.MW.WikiClientLibrary 0.6.0-intX7 0.6.0.17 0.6.0.17 Copyright (C) CXuesong 2017 - Wiki Client Library is a .NET Standard & asynchronous client library for MediaWiki sites. + + Wiki Client Library is a .NET Standard & asynchronous client library for MediaWiki sites. This portable & asynchronous MediaWiki API client provides an easy and asynchronous access to commonly-used MediaWiki API. It has the following features: @@ -19,7 +20,8 @@ * Client code has access to CookieContainer, and have chance to persist it. * Tokens are hidden in the library functions, so that client won't bother to retrieve them over and over again. * Query continuations are hidden by IAsyncEnumerable, which will ease the pain when using page generators. - * Other miscellaneous MediaWiki API, such as OpenSearch, Page parsing, and Patrol. + * Other miscellaneous MediaWiki API, such as OpenSearch, Page parsing, and Patrol. + See https://github.com/CXuesong/WikiClientLibrary/releases . MediaWiki API Client en-us @@ -41,7 +43,9 @@ - + + +