diff --git a/build/Clients.Common.targets b/build/Clients.Common.targets index 617330f2799..a4e4ec2461b 100644 --- a/build/Clients.Common.targets +++ b/build/Clients.Common.targets @@ -5,14 +5,7 @@ 0.0.0-bad 0.0.0 0.0.0.0 - - 1 - - - + $(CurrentVersion) $(CurrentVersion) @@ -21,15 +14,17 @@ $(CurrentAssemblyFileVersion) - true - $(MSBuildThisFileDirectory)\keys\keypair.snk - true + true + $(MSBuildThisFileDirectory)\keys\keypair.snk + true 1591,1572,1571,1573,1587,1570 false - $(DefineConstants);DOTNETCORE - embedded - full + true + embedded + + $(BaseIntermediateOutputPath)\sl-$(MsBuildProjectName)-$(TargetFramework).json + https://raw.githubusercontent.com/elastic/elasticsearch-net diff --git a/build/Elasticsearch.Net.Connections.HttpWebRequestConnection.nuspec b/build/Elasticsearch.Net.Connections.HttpWebRequestConnection.nuspec new file mode 100644 index 00000000000..7aa0a083607 --- /dev/null +++ b/build/Elasticsearch.Net.Connections.HttpWebRequestConnection.nuspec @@ -0,0 +1,28 @@ + + + + Elasticsearch.Net.Connections.HttpWebRequestConnection + $version$ + Elasticsearch.Net HttpWebRequestConnection - Legacy IConnection implementation + Elastic and contributors + Elastic + https://github.com/elastic/elasticsearch-net/blob/master/license.txt + https://github.com/elastic/elasticsearch-net + https://raw.githubusercontent.com/elastic/elasticsearch-net/master/build/nuget-icon.png + false + Elasticsearch.Net + An IConnection implemenation for Elasticsearch.Net and NEST that still utilizes HttpWebRequest and ServicePoints to call Elasticsearch + See https://github.com/elastic/elasticsearch-net/releases/tag/$version$ + 2014-$year$ Elasticsearch BV + elasticsearch,elastic,search,lucene,nest + + + + + + + + + + + diff --git a/build/Elasticsearch.Net.nuspec b/build/Elasticsearch.Net.nuspec index c79e36792dc..a1265482f61 100644 --- a/build/Elasticsearch.Net.nuspec +++ b/build/Elasticsearch.Net.nuspec @@ -16,8 +16,6 @@ 2014-$year$ Elasticsearch BV elasticsearch,elastic,search,lucene,nest - - @@ -30,12 +28,6 @@ - - - - - - diff --git a/build/NEST.JsonNetSerializer.nuspec b/build/NEST.JsonNetSerializer.nuspec index 6c6c0420597..5c537203611 100644 --- a/build/NEST.JsonNetSerializer.nuspec +++ b/build/NEST.JsonNetSerializer.nuspec @@ -16,14 +16,6 @@ 2017-$year$ Elasticsearch BV elasticsearch,elastic,search,lucene,nest,serializer,json - - - - - - - - @@ -32,12 +24,6 @@ - - - - - - diff --git a/build/NEST.nuspec b/build/NEST.nuspec index 1dfdc9c76f5..e3dd7754c8c 100644 --- a/build/NEST.nuspec +++ b/build/NEST.nuspec @@ -16,12 +16,6 @@ 2014-$year$ Elasticsearch BV elasticsearch,elastic,search,lucene,nest - - - - - - @@ -38,12 +32,6 @@ - - - - - - diff --git a/build/profiling/JetBrains.Profiler.Windows.SelfApi.dll b/build/profiling/JetBrains.Profiler.Windows.SelfApi.dll deleted file mode 100644 index 17f67655c78..00000000000 Binary files a/build/profiling/JetBrains.Profiler.Windows.SelfApi.dll and /dev/null differ diff --git a/build/scripts/Benchmarking.fsx b/build/scripts/Benchmarking.fsx index 10812de39cc..d8cdef7d6c1 100644 --- a/build/scripts/Benchmarking.fsx +++ b/build/scripts/Benchmarking.fsx @@ -143,12 +143,12 @@ module Benchmarker = DotNetCli.RunCommand(fun p -> { p with WorkingDir = testsProjectDirectory - }) "run -f net46 -c Release Benchmark" + }) "run -f netcoreapp2.0 -c Release Benchmark" else DotNetCli.RunCommand(fun p -> { p with WorkingDir = testsProjectDirectory - }) "run -f net46 -c Release Benchmark non-interactive" + }) "run -f netcoreapp2.0 -c Release Benchmark non-interactive" finally // running benchmarks can timeout so clean up any generated benchmark files let benchmarkOutputFiles = diff --git a/build/scripts/Building.fsx b/build/scripts/Building.fsx index b01477b50a7..7329cfd9252 100644 --- a/build/scripts/Building.fsx +++ b/build/scripts/Building.fsx @@ -29,16 +29,15 @@ module Build = type private GlobalJson = JsonProvider<"../../global.json"> let private pinnedSdkVersion = GlobalJson.GetSample().Sdk.Version if isMono then setProcessEnvironVar "TRAVIS" "true" - let private buildingOnTravis = getEnvironmentVarAsBool "TRAVIS" - let private sln = sprintf "src/Elasticsearch%s.sln" (if buildingOnTravis then ".DotNetCoreOnly" else "") + let private sln = "src/Elasticsearch.sln" let private compileCore incremental = if not (DotNetCli.isInstalled()) then failwith "You need to install the dotnet command line SDK to build for .NET Core" let runningSdkVersion = DotNetCli.getVersion() if (runningSdkVersion <> pinnedSdkVersion) then failwithf "Attempting to run with dotnet.exe with %s but global.json mandates %s" runningSdkVersion pinnedSdkVersion - let incrementalFramework = DotNetFramework.Net45 + let incrementalFramework = DotNetFramework.NetStandard1_3 let sourceLink = if not incremental && not isMono && runningRelease then "1" else "" let props = [ @@ -46,7 +45,7 @@ module Build = "CurrentAssemblyVersion", (Versioning.CurrentAssemblyVersion.ToString()); "CurrentAssemblyFileVersion", (Versioning.CurrentAssemblyFileVersion.ToString()); "DoSourceLink", sourceLink; - "DotNetCoreOnly", if buildingOnTravis then "1" else ""; + "FakeBuild", "1"; "OutputPathBaseDir", Path.GetFullPath Paths.BuildOutput; ] |> List.map (fun (p,v) -> sprintf "%s=%s" p v) @@ -153,7 +152,7 @@ module Build = trace "Finished rewriting namespaces" let private ilRepackInternal() = - let fw = if isMono then [DotNetFramework.NetStandard1_3] else DotNetFramework.All + let fw = DotNetFramework.All for f in fw do let nest = Project Project.Nest let folder = Paths.ProjectOutputFolder nest f diff --git a/build/scripts/Commandline.fsx b/build/scripts/Commandline.fsx index 4070e1962ca..2f1e13d0ae5 100644 --- a/build/scripts/Commandline.fsx +++ b/build/scripts/Commandline.fsx @@ -34,8 +34,10 @@ NOTE: both the `test` and `integrate` targets can be suffixed with `-all` to for Execution hints can be provided anywhere on the command line - skiptests : skip running tests as part of the target chain -- source_serialization : force tests to use a client with custom source serialization +- skipdocs : skip generating documentation - seed: : provide a seed to run the tests with. +- random:<:B> : sets random K to bool B if if B is ommitted will default to true + K can be: sourceserializer, typedkeys or oldconnection (only valid on windows) """ module Commandline = @@ -44,7 +46,7 @@ module Commandline = let private args = getBuildParamOrDefault "cmdline" "build" |> split ' ' let skipTests = args |> List.exists (fun x -> x = "skiptests") - let skipDocs = args |> List.exists (fun x -> x = "skipdocs") || isMono + let skipDocs = args |> List.exists (fun x -> x = "skipdocs") let seed = match args |> List.tryFind (fun x -> x.StartsWith("seed:")) with | Some t -> t.Replace("seed:", "") @@ -59,17 +61,17 @@ module Commandline = args |> List.filter ( fun x -> - x <> "skiptests" && x <> "skipdocs" && x <> "source_serialization" && not (x.StartsWith("seed:")) && not (x.StartsWith("random:")) + x <> "skiptests" && x <> "skipdocs" && not (x.StartsWith("seed:")) && not (x.StartsWith("random:")) ) let multiTarget = match (filteredArgs |> List.tryHead) with - | Some t when t.EndsWith("-all") -> MultiTarget.All - | _ -> MultiTarget.One + | Some t when t.EndsWith("-one") -> MultiTarget.One + | _ -> MultiTarget.All let target = match (filteredArgs |> List.tryHead) with - | Some t -> t.Replace("-all", "") + | Some t -> t.Replace("-one", "") | _ -> "build" let validMonoTarget = @@ -203,6 +205,7 @@ module Commandline = setBuildParam "first" firstVersionOrPath setBuildParam "second" secondVersionOrPath + | ["touch"; ] -> ignore() | ["temp"; ] -> ignore() | ["canary"; ] -> ignore() | ["canary"; apiKey ] -> diff --git a/build/scripts/Documentation.fsx b/build/scripts/Documentation.fsx index 49f63a20d79..e087c540df3 100644 --- a/build/scripts/Documentation.fsx +++ b/build/scripts/Documentation.fsx @@ -16,12 +16,13 @@ module Documentation = let Generate() = let docGenerator = PrivateProject(DocGenerator) - let path = Paths.ProjectOutputFolder docGenerator DotNetFramework.Net46 - let generator = sprintf "%s/%s.exe" path docGenerator.Name - ExecProcess (fun p -> - p.WorkingDirectory <- Paths.Source("CodeGeneration") @@ docGenerator.Name - p.FileName <- generator - ) (TimeSpan.FromMinutes 3.) |> ignore + let path = Paths.ProjectOutputFolder docGenerator DotNetFramework.NetCoreApp2_0 + let generator = sprintf "%s.dll" docGenerator.Name + + DotNetCli.RunCommand(fun p -> + { p with + WorkingDir = path + }) generator // TODO: hook documentation validation into the process let Validate() = diff --git a/build/scripts/Paths.fsx b/build/scripts/Paths.fsx index 08a13d8801d..dc04fa45b49 100644 --- a/build/scripts/Paths.fsx +++ b/build/scripts/Paths.fsx @@ -39,6 +39,7 @@ module Paths = match project with | Project p -> match p with + | ElasticsearchNetHttpWebRequestConnection -> sprintf "%s/Connections/%s/%s.csproj" SourceFolder project.Name project.Name | NestJsonNetSerializer -> sprintf "%s/Serializers/%s/%s.csproj" SourceFolder project.Name project.Name | _ -> sprintf "%s/%s/%s.csproj" SourceFolder project.Name project.Name | PrivateProject p -> diff --git a/build/scripts/Projects.fsx b/build/scripts/Projects.fsx index 3e3384a4a4c..0d6a48a4d7b 100644 --- a/build/scripts/Projects.fsx +++ b/build/scripts/Projects.fsx @@ -14,22 +14,21 @@ module Projects = type DotNetFrameworkIdentifier = { MSBuild: string; Nuget: string; DefineConstants: string; } type DotNetFramework = - | Net45 | Net46 | NetStandard1_3 - | NetCoreApp1_1 - static member All = [Net45; Net46; NetStandard1_3] + | NetCoreApp2_0 + static member All = [NetStandard1_3] member this.Identifier = match this with - | Net45 -> { MSBuild = "v4.5"; Nuget = "net45"; DefineConstants = if not isMono then "TRACE;NET45" else "NET45"; } - | Net46 -> { MSBuild = "v4.6"; Nuget = "net46"; DefineConstants = if not isMono then "TRACE;NET46" else "NET46"; } - | NetStandard1_3 -> { MSBuild = "netstandard1.3"; Nuget = "netstandard1.3"; DefineConstants = if not isMono then "TRACE;DOTNETCORE" else "DOTNETCORE"; } - | NetCoreApp1_1 -> { MSBuild = "netcoreapp1.1"; Nuget = "netcoreapp1.1"; DefineConstants = if not isMono then "TRACE;DOTNETCORE" else "DOTNETCORE"; } + | Net46 -> { MSBuild = "v4.6"; Nuget = "net46"; DefineConstants = ""; } + | NetStandard1_3 -> { MSBuild = "netstandard1.3"; Nuget = "netstandard1.3"; DefineConstants = ""; } + | NetCoreApp2_0 -> { MSBuild = "netcoreapp2.0"; Nuget = "netcoreapp2.0"; DefineConstants = ""; } type Project = | Nest | ElasticsearchNet | NestJsonNetSerializer + | ElasticsearchNetHttpWebRequestConnection type PrivateProject = | Tests @@ -43,11 +42,18 @@ module Projects = seq [ Project Project.ElasticsearchNet; Project Project.Nest; + Project Project.NestJsonNetSerializer; + Project ElasticsearchNetHttpWebRequestConnection; PrivateProject PrivateProject.Tests ] static member AllPublishable = - seq [Project Project.ElasticsearchNet; Project Project.Nest; Project Project.NestJsonNetSerializer;] + seq [ + Project Project.ElasticsearchNet; + Project Project.Nest; + Project Project.NestJsonNetSerializer; + Project ElasticsearchNetHttpWebRequestConnection; + ] static member Tests = seq [PrivateProject PrivateProject.Tests;] member this.Name = @@ -57,6 +63,7 @@ module Projects = | Nest -> "Nest" | ElasticsearchNet -> "Elasticsearch.Net" | NestJsonNetSerializer -> "Nest.JsonNetSerializer" + | ElasticsearchNetHttpWebRequestConnection -> "Elasticsearch.Net.Connections.HttpWebRequestConnection" | PrivateProject p -> match p with | Tests -> "Tests" diff --git a/build/scripts/Targets.fsx b/build/scripts/Targets.fsx index ddceaf177e7..4b4c5888144 100644 --- a/build/scripts/Targets.fsx +++ b/build/scripts/Targets.fsx @@ -34,6 +34,7 @@ open Differ.Differ Commandline.parse() +Target "Touch" <| fun _ -> traceHeader "Touching build" Target "Build" <| fun _ -> traceHeader "STARTING BUILD" Target "Start" <| fun _ -> match (isMono, Commandline.validMonoTarget) with @@ -78,7 +79,10 @@ Target "Release" <| fun _ -> StrongName.ValidateDllsInNugetPackage() Target "TestNugetPackage" <| fun _ -> - Tests.RunReleaseUnitTests() + //RunReleaseUnitTests restores the canary nugetpackages in tests, since these end up being cached + //its too evasive to run on development machines or TC, Run only on AppVeyor containers. + if buildServer <> AppVeyor then Tests.RunUnitTests() + else Tests.RunReleaseUnitTests() Target "Canary" <| fun _ -> trace "Running canary build" @@ -101,7 +105,7 @@ Target "Diff" <| fun _ -> =?> ("Version", hasBuildParam "version") ==> "Restore" =?> ("FullBuild", Commandline.needsFullBuild) - =?> ("Test", (not Commandline.skipTests)) + =?> ("Test", (not Commandline.skipTests && Commandline.target <> "canary")) =?> ("InternalizeDependencies", (not isMono)) ==> "InheritDoc" =?> ("Documentation", (not Commandline.skipDocs)) @@ -119,7 +123,7 @@ Target "Diff" <| fun _ -> "Version" ==> "Release" - =?> ("TestNugetPackage", (not isMono)) + =?> ("TestNugetPackage", (not isMono && not Commandline.skipTests)) ==> "Canary" "Start" @@ -131,6 +135,7 @@ Target "Diff" <| fun _ -> "Build" ==> "Release" +"Touch" "Start" ==> "Clean" ==> "Diff" diff --git a/build/scripts/Testing.fsx b/build/scripts/Testing.fsx index a565d4c9d33..7ed40056121 100644 --- a/build/scripts/Testing.fsx +++ b/build/scripts/Testing.fsx @@ -42,8 +42,9 @@ module Tests = let command = let p = ["xunit"; "-parallel"; "all"; "-xml"; "../.." @@ Paths.Output("TestResults-Desktop-Clr.xml")] match (target, buildingOnTravis) with + //make sure we don't test against net46 on mono or travis systems | (_, true) - | (Commandline.MultiTarget.One, _) -> ["-framework"; "netcoreapp1.1"] |> List.append p + | (Commandline.MultiTarget.One, _) -> ["-framework"; "netcoreapp2.0"] |> List.append p | _ -> p let dotnet = Tooling.BuildTooling("dotnet") diff --git a/build/scripts/Tooling.fsx b/build/scripts/Tooling.fsx index 945b7df4c0b..af532a58ce0 100644 --- a/build/scripts/Tooling.fsx +++ b/build/scripts/Tooling.fsx @@ -109,12 +109,12 @@ module Tooling = let jetBrainsTools = [{ DotTraceTool.Name = "JetBrains DotTrace Self-Profile API"; - Download = "https://download-cf.jetbrains.com/resharper/JetBrains.Profiler.SelfSdk.2016.3.2.zip"; + Download = "https://download-cf.jetbrains.com/resharper/JetBrains.Profiler.SelfSdk.2017.3.2.zip"; TargetDir = "dottrace-selfprofile"; }; { DotTraceTool.Name = "JetBrains DotTrace Commandline Tools"; - Download = "https://download-cf.jetbrains.com/resharper/JetBrains.dotTrace.CommandLineTools.2016.3.20170126.121657.zip"; + Download = "https://download-cf.jetbrains.com/resharper/JetBrains.dotTrace.CommandLineTools.2017.3.2.zip"; TargetDir = "dottrace-commandline"; }] @@ -139,7 +139,6 @@ module Tooling = let toolPath = commandLineTool @@ path member this.Exec arguments = execAt Environment.CurrentDirectory toolPath arguments - let DotTraceProfiler = new ProfilerTooling("ConsoleProfiler.exe") let DotTraceReporter = new ProfilerTooling("Reporter.exe") let DotTraceSnapshotStats = new ProfilerTooling("SnapshotStat.exe") @@ -165,5 +164,5 @@ module Tooling = let result = execProcessWithTimeout toolPath arguments (TimeSpan.FromMinutes 5.) "." if result <> 0 then failwith (sprintf "Failed to run diff tooling for %s args: %A" exe arguments) - let JustAssembly = DiffTooling("JustAssembly.CommandLineTool.exe") + let JustAssembly = DiffTooling("JustAssembly.CommandLineTool.exe") \ No newline at end of file diff --git a/src/CodeGeneration/ApiGenerator/ApiGenerator.csproj b/src/CodeGeneration/ApiGenerator/ApiGenerator.csproj index 3e0a321da30..974192a820a 100644 --- a/src/CodeGeneration/ApiGenerator/ApiGenerator.csproj +++ b/src/CodeGeneration/ApiGenerator/ApiGenerator.csproj @@ -2,14 +2,14 @@ Exe - net46 + netcoreapp2.0 6.0.0 alpha + NU1701 - diff --git a/src/CodeGeneration/ApiGenerator/Views/Enums.Generated.cshtml b/src/CodeGeneration/ApiGenerator/Views/Enums.Generated.cshtml index 15589671c1c..dd51bbf2d5d 100644 --- a/src/CodeGeneration/ApiGenerator/Views/Enums.Generated.cshtml +++ b/src/CodeGeneration/ApiGenerator/Views/Enums.Generated.cshtml @@ -125,21 +125,13 @@ namespace Elasticsearch.Net for (int index = 0; index < values.Length; index++) { var value = values.GetValue(index); -#if DOTNETCORE var info = type.GetTypeInfo().GetDeclaredField(value.ToString()); -#else - var info = type.GetField(value.ToString()); -#endif var da = (EnumMemberAttribute[])info.GetCustomAttributes(typeof(EnumMemberAttribute), false); var stringValue = da.Length > 0 ? da[0].Value : Enum.GetName(type, value); dictionary.Add((Enum)value, stringValue); } -#if DOTNETCORE var isFlag = type.GetTypeInfo().GetCustomAttributes(typeof(FlagsAttribute), false).Any(); -#else - var isFlag = type.GetCustomAttributes(typeof(FlagsAttribute), false).Length > 0; -#endif return (e) => { diff --git a/src/CodeGeneration/DocGenerator/AsciiDoc/GeneratedAsciidocVisitor.cs b/src/CodeGeneration/DocGenerator/AsciiDoc/GeneratedAsciidocVisitor.cs index 8fc9b008c95..0a0c7ee5875 100644 --- a/src/CodeGeneration/DocGenerator/AsciiDoc/GeneratedAsciidocVisitor.cs +++ b/src/CodeGeneration/DocGenerator/AsciiDoc/GeneratedAsciidocVisitor.cs @@ -29,12 +29,12 @@ namespace DocGenerator.AsciiDoc /// public class GeneratedAsciidocVisitor : NoopVisitor { - private static readonly Dictionary Ids = new Dictionary(); + private static readonly Dictionary Ids = new Dictionary(); private readonly FileInfo _source; private readonly FileInfo _destination; - private readonly Dictionary _projects; - private int _topSectionTitleLevel; + private readonly Dictionary _projects; + private int _topSectionTitleLevel; private Document _document; private Document _newDocument; private bool _topLevel = true; @@ -43,7 +43,7 @@ public GeneratedAsciidocVisitor(FileInfo source, FileInfo destination, Dictionar { _source = source; _destination = destination; - _projects = projects; + _projects = projects; } public Document Convert(Document document) @@ -76,7 +76,8 @@ public override void Visit(Document document) if (document.Attributes.All(a => a.Name != "ref_current")) { - _newDocument.Attributes.Add(new AttributeEntry("ref_current", "https://www.elastic.co/guide/en/elasticsearch/reference/6.1")); + _newDocument.Attributes.Add(new AttributeEntry("ref_current", + "https://www.elastic.co/guide/en/elasticsearch/reference/6.1")); } var github = "https://github.com/elastic/elasticsearch-net"; @@ -90,18 +91,19 @@ public override void Visit(Document document) _newDocument.Attributes.Add(new AttributeEntry("nuget", "https://www.nuget.org/packages")); } - var originalFile = Regex.Replace(_source.FullName.Replace("\\", "/"), @"^(.*Tests/)", $"{github}/tree/master/src/Tests/"); + var originalFile = Regex.Replace(_source.FullName.Replace("\\", "/"), @"^(.*Tests/)", + $"{github}/tree/master/src/Tests/"); _newDocument.Insert(0, new Comment { Style = CommentStyle.MultiLine, Text = $"IMPORTANT NOTE\r\n==============\r\nThis file has been generated from {originalFile}. \r\n" + - "If you wish to submit a PR for any spelling mistakes, typos or grammatical errors for this file,\r\n" + - "please modify the original csharp file found at the link and submit the PR with that change. Thanks!" + "If you wish to submit a PR for any spelling mistakes, typos or grammatical errors for this file,\r\n" + + "please modify the original csharp file found at the link and submit the PR with that change. Thanks!" }); _topSectionTitleLevel = _source.Directory.Name.Equals("request", StringComparison.OrdinalIgnoreCase) && - _source.Directory.Parent != null && - _source.Directory.Parent.Name.Equals("search", StringComparison.OrdinalIgnoreCase) + _source.Directory.Parent != null && + _source.Directory.Parent.Name.Equals("search", StringComparison.OrdinalIgnoreCase) ? 2 : 3; @@ -153,9 +155,10 @@ public override void Visit(Container elements) continue; } - // if there is a section title since the last source block, don't add one - var lastSourceBlock = _newDocument.LastOrDefault(e => e is Source); - var lastSectionTitle = _newDocument.OfType().LastOrDefault(e => e.Level == _topSectionTitleLevel + 1); + // if there is a section title since the last source block, don't add one + var lastSourceBlock = _newDocument.LastOrDefault(e => e is Source); + var lastSectionTitle = + _newDocument.OfType().LastOrDefault(e => e.Level == _topSectionTitleLevel + 1); if (lastSourceBlock != null && lastSectionTitle != null) { var lastSectionTitleIndex = _newDocument.IndexOf(lastSectionTitle); @@ -177,18 +180,19 @@ public override void Visit(Container elements) } _newDocument.Add(source); - break; + break; case "initializer": - case "queryinitializer": - _newDocument.Add(CreateSubsectionTitle("Object Initializer syntax example")); + case "queryinitializer": + _newDocument.Add(CreateSubsectionTitle("Object Initializer syntax example")); _newDocument.Add(source); - break; + break; case "expectresponse": // Don't add the Handlng Response section title if it was the last title (it might be defined in the doc already) if (!LastSectionTitleMatches(text => text.Equals("Handling responses", StringComparison.OrdinalIgnoreCase))) { _newDocument.Add(CreateSubsectionTitle("Handling Responses")); } + _newDocument.Add(source); break; default: @@ -231,7 +235,7 @@ public override void Visit(SectionTitle sectionTitle) var builder = new StringBuilder(); using (var writer = new AsciiDocVisitor(new StringWriter(builder))) { - writer.Visit((InlineContainer)sectionTitle); + writer.Visit((InlineContainer) sectionTitle); } var title = builder.ToString().PascalToHyphen(); @@ -253,86 +257,104 @@ public override void Visit(SectionTitle sectionTitle) base.Visit(sectionTitle); } - public override void Visit(AttributeEntry attributeEntry) - { - if (attributeEntry.Name == "xml-docs") - { - var value = attributeEntry.Value; - - if (string.IsNullOrEmpty(value)) - { - base.Visit(attributeEntry); - return; - } - - var parts = value.Split(':'); - var assemblyName = parts[0]; - var typeName = parts[1]; - - string xmlDocsFile; - Assembly assembly; - string assemblyNamespace; - - //TODO: tidy this up - switch (assemblyName.ToLowerInvariant()) - { - case "elasticsearch.net": - xmlDocsFile = Path.GetFullPath(Path.Combine(Program.BuildOutputPath, "Elasticsearch.Net", "net46", "Elasticsearch.Net.XML")); - assembly = typeof(ElasticLowLevelClient).Assembly; - assemblyNamespace = typeof(ElasticLowLevelClient).Namespace; - break; - default: - xmlDocsFile = Path.GetFullPath(Path.Combine(Program.BuildOutputPath, "Nest", "net46", "Nest.XML")); - assembly = typeof(ElasticClient).Assembly; - assemblyNamespace = typeof(ElasticClient).Namespace; - break; - } - - // build xml documentation file on the fly if it doesn't exist - if (!File.Exists(xmlDocsFile)) - { - var project = _projects[assemblyName]; - var compilation = project.GetCompilationAsync().Result; - - using (var peStream = new MemoryStream()) - using (var commentStream = File.Create(xmlDocsFile)) - { - var emitResult = compilation.Emit(peStream, null, commentStream); - - if (!emitResult.Success) - { - var failures = emitResult.Diagnostics.Where(diagnostic => - diagnostic.IsWarningAsError || - diagnostic.Severity == DiagnosticSeverity.Error); - - var builder = new StringBuilder($"Unable to emit compilation for: {assemblyName}"); - foreach (var diagnostic in failures) - { - builder.AppendLine($"{diagnostic.Id}: {diagnostic.GetMessage()}"); - } - builder.AppendLine(new string('-', 30)); - - throw new Exception(builder.ToString()); - } - } - } - - var assemblyMembers = DocReader.Read(assembly, xmlDocsFile); - var type = assembly.GetType(assemblyNamespace + "." + typeName); - var visitor = new XmlDocsVisitor(type); - - visitor.VisitAssembly(assemblyMembers); - if (visitor.LabeledListItems.Any()) - { - var labeledList = new LabeledList(); - foreach (var item in visitor.LabeledListItems.OrderBy(l => l.Label)) - { - labeledList.Items.Add(item); - } - _newDocument.Insert(_newDocument.IndexOf(attributeEntry), labeledList); - } - } - } + public override void Visit(AttributeEntry attributeEntry) + { + if (attributeEntry.Name != "xml-docs") return; + //true when running from the IDE, build/output might have not been created + string configuration = null; + if (Program.BuildOutputPath.Contains("src")) + { + //bin/Debug|Release/netcoreapp2.0 + configuration = new DirectoryInfo(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)).Parent?.Name; + return; + } + + string XmlFile(string project) + { + if (configuration == null) + return Path.Combine(Program.BuildOutputPath, project, "netstandard1.3", $"{project}.XML"); + return Path.Combine(Program.BuildOutputPath, project, "bin", configuration, "netstandard1.3", + $"{project}.XML"); + } + + var value = attributeEntry.Value; + + if (string.IsNullOrEmpty(value)) + { + base.Visit(attributeEntry); + return; + } + + var parts = value.Split(':'); + var assemblyName = parts[0]; + var typeName = parts[1]; + + string xmlDocsFile; + Assembly assembly; + string assemblyNamespace; + + //TODO: tidy this up + switch (assemblyName.ToLowerInvariant()) + { + case "elasticsearch.net": + xmlDocsFile = Path.GetFullPath(XmlFile("Elasticsearch.Net")); + assembly = typeof(ElasticLowLevelClient).Assembly; + assemblyNamespace = typeof(ElasticLowLevelClient).Namespace; + break; + default: + xmlDocsFile = Path.GetFullPath(XmlFile("Nest")); + assembly = typeof(ElasticClient).Assembly; + assemblyNamespace = typeof(ElasticClient).Namespace; + break; + } + + // build xml documentation file on the fly if it doesn't exist + if (!File.Exists(xmlDocsFile)) + { + var project = _projects[assemblyName]; + + var compilation = project.GetCompilationAsync().Result; + + using (var peStream = new MemoryStream()) + using (var commentStream = File.Create(xmlDocsFile)) + { + var emitResult = compilation.Emit(peStream, null, commentStream); + + if (!emitResult.Success) + { + var failures = emitResult.Diagnostics.Where(diagnostic => + diagnostic.IsWarningAsError || + diagnostic.Severity == DiagnosticSeverity.Error); + + var builder = new StringBuilder($"Unable to emit compilation for: {assemblyName}"); + foreach (var diagnostic in failures) + { + builder.AppendLine($"{diagnostic.Id}: {diagnostic.GetMessage()}"); + } + + builder.AppendLine(new string('-', 30)); + + throw new Exception(builder.ToString()); + } + } + } + + var assemblyMembers = DocReader.Read(assembly, xmlDocsFile); + var type = assembly.GetType(assemblyNamespace + "." + typeName); + var visitor = new XmlDocsVisitor(type); + + visitor.VisitAssembly(assemblyMembers); + if (visitor.LabeledListItems.Any()) + { + var labeledList = new LabeledList(); + foreach (var item in visitor.LabeledListItems.OrderBy(l => l.Label)) + { + labeledList.Items.Add(item); + } + + _newDocument.Insert(_newDocument.IndexOf(attributeEntry), labeledList); + } + } private void RemoveDocDirectoryAttribute(Document document) { @@ -351,7 +373,7 @@ private bool LastSectionTitleMatches(Func predicate) var builder = new StringBuilder(); using (var visitor = new AsciiDocVisitor(new StringWriter(builder))) { - visitor.Visit((InlineContainer)lastSectionTitle); + visitor.Visit((InlineContainer) lastSectionTitle); } return predicate(builder.ToString()); @@ -365,8 +387,8 @@ private SectionTitle CreateSubsectionTitle(string title) var level = _topSectionTitleLevel + 1; var sectionTitle = new SectionTitle(title, level); - // levels 1-3 need to be floating so the Elasticsearch docs generation does not - // split into separate file + // levels 1-3 need to be floating so the Elasticsearch docs generation does not + // split into separate file if (level < 4) sectionTitle.IsFloating = true; diff --git a/src/CodeGeneration/DocGenerator/Buildalyzer/AnalyzerManager.cs b/src/CodeGeneration/DocGenerator/Buildalyzer/AnalyzerManager.cs index 21d094be22b..9ac58dbc13e 100644 --- a/src/CodeGeneration/DocGenerator/Buildalyzer/AnalyzerManager.cs +++ b/src/CodeGeneration/DocGenerator/Buildalyzer/AnalyzerManager.cs @@ -47,7 +47,7 @@ public class AnalyzerManager public string SolutionDirectory { get; } public AnalyzerManager(ILoggerFactory loggerFactory = null, LoggerVerbosity loggerVerbosity = LoggerVerbosity.Normal) - : this(null, loggerFactory, loggerVerbosity) + : this(null, null, loggerFactory, loggerVerbosity) { } @@ -56,7 +56,7 @@ public AnalyzerManager(TextWriter logWriter, LoggerVerbosity loggerVerbosity = L { } - public AnalyzerManager(string solutionFilePath, ILoggerFactory loggerFactory = null, LoggerVerbosity loggerVerbosity = LoggerVerbosity.Normal) + public AnalyzerManager(string solutionFilePath, string[] projects, ILoggerFactory loggerFactory = null, LoggerVerbosity loggerVerbosity = LoggerVerbosity.Normal) { LoggerVerbosity = loggerVerbosity; ProjectLogger = loggerFactory?.CreateLogger(); @@ -65,7 +65,7 @@ public AnalyzerManager(string solutionFilePath, ILoggerFactory loggerFactory = n { solutionFilePath = ValidatePath(solutionFilePath, true); SolutionDirectory = Path.GetDirectoryName(solutionFilePath); - GetProjectsInSolution(solutionFilePath); + GetProjectsInSolution(solutionFilePath, projects); } } @@ -87,8 +87,9 @@ public AnalyzerManager(string solutionFilePath, TextWriter logWriter, LoggerVerb } } - private void GetProjectsInSolution(string solutionFilePath) + private void GetProjectsInSolution(string solutionFilePath, string[] projects = null) { + projects = projects ?? new string[] { }; var supportedType = new[] { SolutionProjectType.KnownToBeMSBuildFormat, @@ -98,8 +99,8 @@ private void GetProjectsInSolution(string solutionFilePath) SolutionFile solution = SolutionFile.Parse(solutionFilePath); foreach(ProjectInSolution project in solution.ProjectsInOrder) { - if (!supportedType.Contains(project.ProjectType)) - continue; + if (!supportedType.Contains(project.ProjectType)) continue; + if (projects.Length > 0 && !projects.Contains(project.ProjectName)) continue; GetProject(project.AbsolutePath); } } diff --git a/src/CodeGeneration/DocGenerator/Buildalyzer/ProjectAnalyzer.cs b/src/CodeGeneration/DocGenerator/Buildalyzer/ProjectAnalyzer.cs index 1788286b14c..29e93a73776 100644 --- a/src/CodeGeneration/DocGenerator/Buildalyzer/ProjectAnalyzer.cs +++ b/src/CodeGeneration/DocGenerator/Buildalyzer/ProjectAnalyzer.cs @@ -72,7 +72,8 @@ internal ProjectAnalyzer(AnalyzerManager manager, string projectFilePath, XDocum { Manager = manager; ProjectFilePath = projectFilePath; - _projectDocument = TweakProjectDocument(projectDocument); + var projectFolder = Path.GetDirectoryName(projectFilePath); + _projectDocument = TweakProjectDocument(projectDocument, projectFolder); // Get the paths _buildEnvironment = EnvironmentFactory.GetBuildEnvironment(projectFilePath, _projectDocument); @@ -80,8 +81,8 @@ internal ProjectAnalyzer(AnalyzerManager manager, string projectFilePath, XDocum // Preload/enforce referencing some required asemblies Copy copy = new Copy(); - // Set global properties - string solutionDir = manager.SolutionDirectory ?? Path.GetDirectoryName(projectFilePath); + + string solutionDir = manager.SolutionDirectory ?? projectFolder; _globalProperties = _buildEnvironment.GetGlobalProperties(solutionDir); // Create the logger @@ -119,8 +120,19 @@ public Project Load() } // Tweaks the project file a bit to ensure a succesfull build - private static XDocument TweakProjectDocument(XDocument projectDocument) + private static XDocument TweakProjectDocument(XDocument projectDocument, string projectFolder) { + foreach (XElement import in projectDocument.GetDescendants("Import").ToArray()) + { + var att = import.Attribute("Project"); + if (att == null) continue; + + var project = att.Value; + if (project.EndsWith("Clients.Common.targets")) + att.Value = Path.GetFullPath(Path.Combine(projectFolder, att.Value)); + else if (project.EndsWith("outputpath.props")) + att.Value = Path.GetFullPath(Path.Combine(projectFolder, att.Value)); + } // Add SkipGetTargetFrameworkProperties to every ProjectReference foreach (XElement projectReference in projectDocument.GetDescendants("ProjectReference").ToArray()) { diff --git a/src/CodeGeneration/DocGenerator/DocGenerator.csproj b/src/CodeGeneration/DocGenerator/DocGenerator.csproj index 578cc7830df..d715b4a932a 100644 --- a/src/CodeGeneration/DocGenerator/DocGenerator.csproj +++ b/src/CodeGeneration/DocGenerator/DocGenerator.csproj @@ -1,27 +1,20 @@ - Exe - net46 + netcoreapp2.0 6.0.0 alpha + NU1701,NU1605 - - + - - - - - diff --git a/src/CodeGeneration/DocGenerator/Documentation/Files/DocumentationFile.cs b/src/CodeGeneration/DocGenerator/Documentation/Files/DocumentationFile.cs index e0701757667..7e920e9e567 100644 --- a/src/CodeGeneration/DocGenerator/Documentation/Files/DocumentationFile.cs +++ b/src/CodeGeneration/DocGenerator/Documentation/Files/DocumentationFile.cs @@ -41,9 +41,9 @@ public static DocumentationFile Load(FileInfo fileLocation) protected virtual FileInfo CreateDocumentationLocation() { var testFullPath = this.FileLocation.FullName; - + var p = "\\" + Path.DirectorySeparatorChar.ToString(); var testInDocumentationFolder = - Regex.Replace(testFullPath, @"(^.+\\Tests\\|\" + this.Extension + "$)", "") + Regex.Replace(testFullPath, $@"(^.+{p}Tests{p}|\" + this.Extension + "$)", "") .TrimEnd(".doc") .TrimEnd("Tests") .PascalToHyphen() + ".asciidoc"; diff --git a/src/CodeGeneration/DocGenerator/Documentation/Files/ImageDocumentationFile.cs b/src/CodeGeneration/DocGenerator/Documentation/Files/ImageDocumentationFile.cs index d842de6dd04..f43997f2bae 100644 --- a/src/CodeGeneration/DocGenerator/Documentation/Files/ImageDocumentationFile.cs +++ b/src/CodeGeneration/DocGenerator/Documentation/Files/ImageDocumentationFile.cs @@ -26,7 +26,8 @@ protected override FileInfo CreateDocumentationLocation() { var testFullPath = this.FileLocation.FullName; - var testInDocumenationFolder = Regex.Replace(testFullPath, @"(^.+\\Tests\\|\" + this.Extension + "$)", "") + var p = "\\" + Path.DirectorySeparatorChar.ToString(); + var testInDocumenationFolder = Regex.Replace(testFullPath, $@"(^.+{p}Tests{p}|\" + this.Extension + "$)", "") .PascalToHyphen() + this.Extension; var documentationTargetPath = Path.GetFullPath(Path.Combine(Program.OutputDirPath, testInDocumenationFolder)); diff --git a/src/CodeGeneration/DocGenerator/Documentation/Files/RawDocumentationFile.cs b/src/CodeGeneration/DocGenerator/Documentation/Files/RawDocumentationFile.cs index 6f06e64ae2e..cfd8e960a48 100644 --- a/src/CodeGeneration/DocGenerator/Documentation/Files/RawDocumentationFile.cs +++ b/src/CodeGeneration/DocGenerator/Documentation/Files/RawDocumentationFile.cs @@ -32,7 +32,8 @@ public override Task SaveToDocumentationFolderAsync() protected override FileInfo CreateDocumentationLocation() { var testFullPath = this.FileLocation.FullName; - var testInDocumenationFolder = Regex.Replace(testFullPath, @"(^.+\\Tests\\|\" + this.Extension + "$)", "").PascalToHyphen() + this.Extension; + var p = "\\" + Path.DirectorySeparatorChar.ToString(); + var testInDocumenationFolder = Regex.Replace(testFullPath, $@"(^.+{p}Tests{p}|\" + this.Extension + "$)", "").PascalToHyphen() + this.Extension; var documenationTargetPath = Path.GetFullPath(Path.Combine(Program.OutputDirPath, testInDocumenationFolder)); var fileInfo = new FileInfo(documenationTargetPath); diff --git a/src/CodeGeneration/DocGenerator/LitUp.cs b/src/CodeGeneration/DocGenerator/LitUp.cs index 6acb81ef5a8..a2e5772f05d 100644 --- a/src/CodeGeneration/DocGenerator/LitUp.cs +++ b/src/CodeGeneration/DocGenerator/LitUp.cs @@ -8,19 +8,18 @@ using DocGenerator.Documentation.Files; using Microsoft.Build.Framework; using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.MSBuild; using Microsoft.Extensions.Logging; namespace DocGenerator { public static class LitUp { - private static readonly string[] SkipFolders = { "Debug", "Release" }; + private static readonly string[] SkipFolders = {"Debug", "Release"}; - private static string GetProjectDir(string projectName) => Path.Combine(Program.InputDirPath, projectName); - private static string GetProjectFile(string projectName) => Path.Combine(GetProjectDir(projectName), $"{projectName}.csproj"); + private static string GetProjectDir(string projectName) => Path.Combine(Program.InputDirPath, projectName); + private static string GetProjectFile(string projectName) => Path.Combine(GetProjectDir(projectName), $"{projectName}.csproj"); - public static IEnumerable InputFiles(string path) => + public static IEnumerable InputFiles(string path) => from f in Directory.GetFiles(GetProjectDir("Tests"), $"{path}", SearchOption.AllDirectories) let dir = new DirectoryInfo(f) where dir?.Parent != null && !SkipFolders.Contains(dir.Parent.Name) @@ -28,11 +27,11 @@ from f in Directory.GetFiles(GetProjectDir("Tests"), $"{path}", SearchOption.All public static IEnumerable> GetDocumentFiles(Dictionary projects) { - var testProject = projects["Tests"]; + var testProject = projects["Tests"]; yield return testProject.Documents - .Where(d => d.Name.EndsWith(".doc.cs", StringComparison.OrdinalIgnoreCase)) - .Select(d => new CSharpDocumentationFile(d, projects)); + .Where(d => d.Name.EndsWith(".doc.cs", StringComparison.OrdinalIgnoreCase)) + .Select(d => new CSharpDocumentationFile(d, projects)); yield return testProject.Documents .Where(d => d.Name.EndsWith("UsageTests.cs", StringComparison.OrdinalIgnoreCase)) @@ -44,29 +43,32 @@ public static IEnumerable> GetDocumentFiles(Dicti // process asciidocs last as they may have generated // includes to other output asciidocs yield return InputFiles("*.asciidoc"); - } + } public static async Task GoAsync(string[] args) { //.NET core csprojects are not supported all that well. // https://github.com/dotnet/roslyn/issues/21660 :sadpanda: // Use Buildalyzer to get a workspace from the solution. - var analyzer = new AnalyzerManager(Path.Combine(Program.InputDirPath, "Elasticsearch.DotNetCoreOnly.sln")); + var analyzer = new AnalyzerManager(Path.Combine(Program.InputDirPath, "Elasticsearch.sln"), new[] + { + "Elasticsearch.Net", + "Nest", + "Tests" + }); + var workspace = analyzer.GetWorkspace(); - workspace.WorkspaceFailed += (s, e) => - { - Console.Error.WriteLine(e.Diagnostic.Message); - }; + workspace.WorkspaceFailed += (s, e) => { Console.Error.WriteLine(e.Diagnostic.Message); }; // Buildalyzer, similar to MsBuildWorkspace with the new csproj file format, does // not pick up source documents in the project directory. Manually add them AddDocumentsToWorkspace(workspace); - var projects = workspace.CurrentSolution.Projects - .ToDictionary(p => p.Name, StringComparer.OrdinalIgnoreCase); + var projects = workspace.CurrentSolution.Projects + .ToDictionary(p => p.Name, StringComparer.OrdinalIgnoreCase); - foreach (var file in GetDocumentFiles(projects).SelectMany(s => s)) + foreach (var file in GetDocumentFiles(projects).SelectMany(s => s)) { await file.SaveToDocumentationFolderAsync(); } diff --git a/src/CodeGeneration/DocGenerator/Program.cs b/src/CodeGeneration/DocGenerator/Program.cs index 8244e65a80f..6ebd026e913 100644 --- a/src/CodeGeneration/DocGenerator/Program.cs +++ b/src/CodeGeneration/DocGenerator/Program.cs @@ -7,18 +7,26 @@ public static class Program { static Program() { + string P(string path) + { + return path.Replace(@"\", Path.DirectorySeparatorChar.ToString()); + } + var currentDirectory = new DirectoryInfo(Directory.GetCurrentDirectory()); if (currentDirectory.Name == "DocGenerator" && currentDirectory.Parent.Name == "CodeGeneration") { - InputDirPath = @"..\..\"; - OutputDirPath = @"..\..\..\docs"; - BuildOutputPath = @"..\..\..\build\output"; + Console.WriteLine("IDE: " + currentDirectory); + + InputDirPath = P(@"..\..\"); + OutputDirPath = P(@"..\..\..\docs"); + BuildOutputPath = P(@"..\..\..\src"); } else { - InputDirPath = @"..\..\..\..\..\src"; - OutputDirPath = @"..\..\..\..\..\docs"; - BuildOutputPath = @"..\..\..\..\..\build\output"; + Console.WriteLine("CMD: " + currentDirectory); + InputDirPath = P(@"..\..\..\..\src"); + OutputDirPath = P(@"..\..\..\..\docs"); + BuildOutputPath = P(@"..\..\..\..\build\output"); } } diff --git a/src/CodeGeneration/DocGenerator/StringExtensions.cs b/src/CodeGeneration/DocGenerator/StringExtensions.cs index eef2c1d2ba6..59b82865ca1 100644 --- a/src/CodeGeneration/DocGenerator/StringExtensions.cs +++ b/src/CodeGeneration/DocGenerator/StringExtensions.cs @@ -195,13 +195,25 @@ public string Write() var syntaxTree = CSharpSyntaxTree.ParseText(text); var assemblyName = Path.GetRandomFileName(); - var references = new MetadataReference[] + var references = new List { MetadataReference.CreateFromFile(typeof(object).GetTypeInfo().Assembly.Location), MetadataReference.CreateFromFile(typeof(Enumerable).GetTypeInfo().Assembly.Location), MetadataReference.CreateFromFile(typeof(JsonConvert).GetTypeInfo().Assembly.Location), MetadataReference.CreateFromFile(typeof(ITypedList).GetTypeInfo().Assembly.Location), }; + var systemReferences = new string[] + { + "System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", + "System.ObjectModel, Version=4.0.10.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", + "System.Dynamic.Runtime, Version=4.0.10.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", + "System.Linq.Expressions, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" + }; + foreach (var r in systemReferences) + { + var location = Assembly.Load(r).Location; + references.Add(MetadataReference.CreateFromFile(location)); + } var compilation = CSharpCompilation.Create( diff --git a/src/Connections/Elasticsearch.Net.Connections.HttpWebRequestConnection/Elasticsearch.Net.Connections.HttpWebRequestConnection.csproj b/src/Connections/Elasticsearch.Net.Connections.HttpWebRequestConnection/Elasticsearch.Net.Connections.HttpWebRequestConnection.csproj new file mode 100644 index 00000000000..ab4d2ddd282 --- /dev/null +++ b/src/Connections/Elasticsearch.Net.Connections.HttpWebRequestConnection/Elasticsearch.Net.Connections.HttpWebRequestConnection.csproj @@ -0,0 +1,13 @@ + + + + + net46;netstandard1.3 + netstandard1.3 + $(DefineConstants);FEATURE_HTTPWEBREQUEST + + + + + + \ No newline at end of file diff --git a/src/Elasticsearch.Net/Connection/HttpConnection.cs b/src/Connections/Elasticsearch.Net.Connections.HttpWebRequestConnection/HttpWebRequestConnection.cs similarity index 94% rename from src/Elasticsearch.Net/Connection/HttpConnection.cs rename to src/Connections/Elasticsearch.Net.Connections.HttpWebRequestConnection/HttpWebRequestConnection.cs index d5f9b8925f3..8d84a09dd00 100644 --- a/src/Elasticsearch.Net/Connection/HttpConnection.cs +++ b/src/Connections/Elasticsearch.Net.Connections.HttpWebRequestConnection/HttpWebRequestConnection.cs @@ -1,279 +1,283 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.IO.Compression; -using System.Linq; -using System.Net; -using System.Net.Security; -using System.Text; -using System.Threading; -using System.Threading.Tasks; - -// ReSharper disable VirtualMemberNeverOverriden.Global -#if !DOTNETCORE -namespace Elasticsearch.Net -{ - public class HttpConnection : IConnection - { - internal static bool IsMono { get; } = Type.GetType("Mono.Runtime") != null; - - static HttpConnection() - { - //Not available under mono - if (!IsMono) - HttpWebRequest.DefaultMaximumErrorResponseLength = -1; - } - - protected virtual HttpWebRequest CreateHttpWebRequest(RequestData requestData) - { - var request = this.CreateWebRequest(requestData); - this.SetBasicAuthenticationIfNeeded(request, requestData); - this.SetProxyIfNeeded(request, requestData); - this.SetServerCertificateValidationCallBackIfNeeded(request, requestData); - this.SetClientCertificates(request, requestData); - this.AlterServicePoint(request.ServicePoint, requestData); - return request; - } - - protected virtual void SetClientCertificates(HttpWebRequest request, RequestData requestData) - { - if (requestData.ClientCertificates != null) - request.ClientCertificates.AddRange(requestData.ClientCertificates); - } - - protected virtual void SetServerCertificateValidationCallBackIfNeeded(HttpWebRequest request, RequestData requestData) - { - var callback = requestData?.ConnectionSettings?.ServerCertificateValidationCallback; -#if !__MonoCS__ - //Only assign if one is defined on connection settings and a subclass has not already set one - if (callback != null && request.ServerCertificateValidationCallback == null) - request.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(callback); -#else - if (callback != null) - throw new Exception("Mono misses ServerCertificateValidationCallback on HttpWebRequest"); - #endif - } - - protected virtual HttpWebRequest CreateWebRequest(RequestData requestData) - { - var request = (HttpWebRequest) WebRequest.Create(requestData.Uri); - - request.Accept = requestData.Accept; - request.ContentType = requestData.RequestMimeType; - request.MaximumResponseHeadersLength = -1; - request.Pipelined = requestData.Pipelined; - - if (requestData.HttpCompression) - { - request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate; - request.Headers.Add("Accept-Encoding", "gzip,deflate"); - request.Headers.Add("Content-Encoding", "gzip"); - } - if (!requestData.RunAs.IsNullOrEmpty()) - request.Headers.Add(RequestData.RunAsSecurityHeader, requestData.RunAs); - - if (requestData.Headers != null && requestData.Headers.HasKeys()) - request.Headers.Add(requestData.Headers); - - var timeout = (int) requestData.RequestTimeout.TotalMilliseconds; - request.Timeout = timeout; - request.ReadWriteTimeout = timeout; - - //WebRequest won't send Content-Length: 0 for empty bodies - //which goes against RFC's and might break i.e IIS hen used as a proxy. - //see: https://github.com/elasticsearch/elasticsearch-net/issues/562 - var m = requestData.Method.GetStringValue(); - request.Method = m; - if (m != "HEAD" && m != "GET" && (requestData.PostData == null)) - request.ContentLength = 0; - - return request; - } - - protected virtual void AlterServicePoint(ServicePoint requestServicePoint, RequestData requestData) - { - requestServicePoint.UseNagleAlgorithm = false; - requestServicePoint.Expect100Continue = false; - if (requestData.ConnectionSettings.ConnectionLimit > 0) - requestServicePoint.ConnectionLimit = requestData.ConnectionSettings.ConnectionLimit; - //looking at http://referencesource.microsoft.com/#System/net/System/Net/ServicePoint.cs - //this method only sets internal values and wont actually cause timers and such to be reset - //So it should be idempotent if called with the same parameters - requestServicePoint.SetTcpKeepAlive(true, requestData.KeepAliveTime, requestData.KeepAliveInterval); - } - - protected virtual void SetProxyIfNeeded(HttpWebRequest request, RequestData requestData) - { - if (!requestData.ProxyAddress.IsNullOrEmpty()) - { - var proxy = new WebProxy(); - var uri = new Uri(requestData.ProxyAddress); - var credentials = new NetworkCredential(requestData.ProxyUsername, requestData.ProxyPassword); - proxy.Address = uri; - proxy.Credentials = credentials; - request.Proxy = proxy; - } - - if (requestData.DisableAutomaticProxyDetection) - request.Proxy = null; - } - - protected virtual void SetBasicAuthenticationIfNeeded(HttpWebRequest request, RequestData requestData) - { - // Basic auth credentials take the following precedence (highest -> lowest): - // 1 - Specified on the request (highest precedence) - // 2 - Specified at the global IConnectionSettings level - // 3 - Specified with the URI (lowest precedence) - - var userInfo = Uri.UnescapeDataString(requestData.Uri.UserInfo); - - if (requestData.BasicAuthorizationCredentials != null) - userInfo = requestData.BasicAuthorizationCredentials.ToString(); - - if (!userInfo.IsNullOrEmpty()) - request.Headers["Authorization"] = "Basic " + Convert.ToBase64String(Encoding.UTF8.GetBytes(userInfo)); - } - - public virtual TResponse Request(RequestData requestData) - where TResponse : class, IElasticsearchResponse, new() - { - int? statusCode = null; - IEnumerable warnings = null; - Stream responseStream = null; - Exception ex = null; - string mimeType = null; - try - { - var request = this.CreateHttpWebRequest(requestData); - var data = requestData.PostData; - - if (data != null) - { - using (var stream = request.GetRequestStream()) - { - if (requestData.HttpCompression) - using (var zipStream = new GZipStream(stream, CompressionMode.Compress)) - data.Write(zipStream, requestData.ConnectionSettings); - else - data.Write(stream, requestData.ConnectionSettings); - } - } - requestData.MadeItToResponse = true; - - //http://msdn.microsoft.com/en-us/library/system.net.httpwebresponse.getresponsestream.aspx - //Either the stream or the response object needs to be closed but not both although it won't - //throw any errors if both are closed atleast one of them has to be Closed. - //Since we expose the stream we let closing the stream determining when to close the connection - var response = (HttpWebResponse) request.GetResponse(); - HandleResponse(response, out statusCode, out responseStream, out mimeType); - - if (response.SupportsHeaders && response.Headers.HasKeys() && response.Headers.AllKeys.Contains("Warning")) - warnings = response.Headers.GetValues("Warning"); - } - catch (WebException e) - { - ex = e; - if (e.Response is HttpWebResponse response) - HandleResponse(response, out statusCode, out responseStream, out mimeType); - } - responseStream = responseStream ?? Stream.Null; - return ResponseBuilder.ToResponse(requestData, ex, statusCode, warnings, responseStream, mimeType); - } - - - /// - /// Registers an APM async task cancellation on the threadpool - /// - /// An unregister action that can be used to remove the waithandle prematurely - private static Action RegisterApmTaskTimeout(IAsyncResult result, WebRequest request, RequestData requestData) - { - var waitHandle = result.AsyncWaitHandle; - var registeredWaitHandle = - ThreadPool.RegisterWaitForSingleObject(waitHandle, TimeoutCallback, request, requestData.RequestTimeout, true); - return () => registeredWaitHandle?.Unregister(waitHandle); - } - - private static void TimeoutCallback(object state, bool timedOut) - { - if (!timedOut) return; - (state as WebRequest)?.Abort(); - } - - public virtual async Task RequestAsync(RequestData requestData, - CancellationToken cancellationToken) - where TResponse : class, IElasticsearchResponse, new() - { - Action unregisterWaitHandle = null; - int? statusCode = null; - IEnumerable warnings = null; - Stream responseStream = null; - Exception ex = null; - string mimeType = null; - try - { - var data = requestData.PostData; - var request = this.CreateHttpWebRequest(requestData); - using (cancellationToken.Register(() => request.Abort())) - { - if (data != null) - { - var apmGetRequestStreamTask = Task.Factory.FromAsync(request.BeginGetRequestStream, request.EndGetRequestStream, null); - unregisterWaitHandle = RegisterApmTaskTimeout(apmGetRequestStreamTask, request, requestData); - - using (var stream = await apmGetRequestStreamTask.ConfigureAwait(false)) - { - if (requestData.HttpCompression) - using (var zipStream = new GZipStream(stream, CompressionMode.Compress)) - await data.WriteAsync(zipStream, requestData.ConnectionSettings, cancellationToken).ConfigureAwait(false); - else - await data.WriteAsync(stream, requestData.ConnectionSettings, cancellationToken).ConfigureAwait(false); - } - unregisterWaitHandle?.Invoke(); - } - requestData.MadeItToResponse = true; - //http://msdn.microsoft.com/en-us/library/system.net.httpwebresponse.getresponsestream.aspx - //Either the stream or the response object needs to be closed but not both although it won't - //throw any errors if both are closed atleast one of them has to be Closed. - //Since we expose the stream we let closing the stream determining when to close the connection - - var apmGetResponseTask = Task.Factory.FromAsync(request.BeginGetResponse, request.EndGetResponse, null); - unregisterWaitHandle = RegisterApmTaskTimeout(apmGetResponseTask, request, requestData); - - var response = (HttpWebResponse) (await apmGetResponseTask.ConfigureAwait(false)); - HandleResponse(response, out statusCode, out responseStream, out mimeType); - if (response.SupportsHeaders && response.Headers.HasKeys() && response.Headers.AllKeys.Contains("Warning")) - warnings = response.Headers.GetValues("Warning"); - } - } - catch (WebException e) - { - ex = e; - if (e.Response is HttpWebResponse response) - HandleResponse(response, out statusCode, out responseStream, out mimeType); - } - finally - { - unregisterWaitHandle?.Invoke(); - } - responseStream = responseStream ?? Stream.Null; - return await ResponseBuilder.ToResponseAsync - (requestData, ex, statusCode, warnings, responseStream, mimeType, cancellationToken) - .ConfigureAwait(false); - } - - private static void HandleResponse(HttpWebResponse response, out int? statusCode, out Stream responseStream, out string mimeType) - { - statusCode = (int) response.StatusCode; - responseStream = response.GetResponseStream(); - mimeType = response.ContentType; - // https://github.com/elastic/elasticsearch-net/issues/2311 - // if stream is null call dispose on response instead. - if (responseStream == null || responseStream == Stream.Null) response.Dispose(); - } - - void IDisposable.Dispose() => this.DisposeManagedResources(); - - protected virtual void DisposeManagedResources() { } - } -} -#endif +#if FEATURE_HTTPWEBREQUEST +using System; +using System.Collections.Generic; +using System.IO; +using System.IO.Compression; +using System.Linq; +using System.Net; +using System.Net.Security; +using System.Security.Cryptography.X509Certificates; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +#endif + +namespace Elasticsearch.Net.Connections.HttpWebRequestConnection +{ + +#if !FEATURE_HTTPWEBREQUEST + public class HttpWebRequestConnection : HttpConnection {} +#else + public class HttpWebRequestConnection : IConnection + { + internal static bool IsMono { get; } = Type.GetType("Mono.Runtime") != null; + + static HttpWebRequestConnection() + { + //Not available under mono + if (!IsMono) HttpWebRequest.DefaultMaximumErrorResponseLength = -1; + } + + protected virtual HttpWebRequest CreateHttpWebRequest(RequestData requestData) + { + var request = this.CreateWebRequest(requestData); + this.SetBasicAuthenticationIfNeeded(request, requestData); + this.SetProxyIfNeeded(request, requestData); + this.SetServerCertificateValidationCallBackIfNeeded(request, requestData); + this.SetClientCertificates(request, requestData); + this.AlterServicePoint(request.ServicePoint, requestData); + return request; + } + + protected virtual void SetClientCertificates(HttpWebRequest request, RequestData requestData) + { + if (requestData.ClientCertificates != null) + request.ClientCertificates.AddRange(requestData.ClientCertificates); + } + + protected virtual void SetServerCertificateValidationCallBackIfNeeded(HttpWebRequest request, RequestData requestData) + { + var callback = requestData?.ConnectionSettings?.ServerCertificateValidationCallback; +#if !__MonoCS__ + //Only assign if one is defined on connection settings and a subclass has not already set one + if (callback != null && request.ServerCertificateValidationCallback == null) + request.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(callback); +#else + if (callback != null) + throw new Exception("Mono misses ServerCertificateValidationCallback on HttpWebRequest"); + #endif + } + + protected virtual HttpWebRequest CreateWebRequest(RequestData requestData) + { + var request = (HttpWebRequest) WebRequest.Create(requestData.Uri); + + request.Accept = requestData.Accept; + request.ContentType = requestData.RequestMimeType; + request.MaximumResponseHeadersLength = -1; + request.Pipelined = requestData.Pipelined; + + if (requestData.HttpCompression) + { + request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate; + request.Headers.Add("Accept-Encoding", "gzip,deflate"); + request.Headers.Add("Content-Encoding", "gzip"); + } + if (!string.IsNullOrWhiteSpace(requestData.RunAs)) + request.Headers.Add(RequestData.RunAsSecurityHeader, requestData.RunAs); + + if (requestData.Headers != null && requestData.Headers.HasKeys()) + request.Headers.Add(requestData.Headers); + + var timeout = (int) requestData.RequestTimeout.TotalMilliseconds; + request.Timeout = timeout; + request.ReadWriteTimeout = timeout; + + //WebRequest won't send Content-Length: 0 for empty bodies + //which goes against RFC's and might break i.e IIS hen used as a proxy. + //see: https://github.com/elasticsearch/elasticsearch-net/issues/562 + var m = requestData.Method.GetStringValue(); + request.Method = m; + if (m != "HEAD" && m != "GET" && (requestData.PostData == null)) + request.ContentLength = 0; + + return request; + } + + protected virtual void AlterServicePoint(ServicePoint requestServicePoint, RequestData requestData) + { + requestServicePoint.UseNagleAlgorithm = false; + requestServicePoint.Expect100Continue = false; + if (requestData.ConnectionSettings.ConnectionLimit > 0) + requestServicePoint.ConnectionLimit = requestData.ConnectionSettings.ConnectionLimit; + //looking at http://referencesource.microsoft.com/#System/net/System/Net/ServicePoint.cs + //this method only sets internal values and wont actually cause timers and such to be reset + //So it should be idempotent if called with the same parameters + requestServicePoint.SetTcpKeepAlive(true, requestData.KeepAliveTime, requestData.KeepAliveInterval); + } + + protected virtual void SetProxyIfNeeded(HttpWebRequest request, RequestData requestData) + { + if (!string.IsNullOrWhiteSpace(requestData.ProxyAddress)) + { + var proxy = new WebProxy(); + var uri = new Uri(requestData.ProxyAddress); + var credentials = new NetworkCredential(requestData.ProxyUsername, requestData.ProxyPassword); + proxy.Address = uri; + proxy.Credentials = credentials; + request.Proxy = proxy; + } + + if (requestData.DisableAutomaticProxyDetection) + request.Proxy = null; + } + + protected virtual void SetBasicAuthenticationIfNeeded(HttpWebRequest request, RequestData requestData) + { + // Basic auth credentials take the following precedence (highest -> lowest): + // 1 - Specified on the request (highest precedence) + // 2 - Specified at the global IConnectionSettings level + // 3 - Specified with the URI (lowest precedence) + + var userInfo = Uri.UnescapeDataString(requestData.Uri.UserInfo); + + if (requestData.BasicAuthorizationCredentials != null) + userInfo = requestData.BasicAuthorizationCredentials.ToString(); + + if (!string.IsNullOrWhiteSpace(userInfo)) + request.Headers["Authorization"] = "Basic " + Convert.ToBase64String(Encoding.UTF8.GetBytes(userInfo)); + } + + public virtual TResponse Request(RequestData requestData) + where TResponse : class, IElasticsearchResponse, new() + { + int? statusCode = null; + IEnumerable warnings = null; + Stream responseStream = null; + Exception ex = null; + string mimeType = null; + try + { + var request = this.CreateHttpWebRequest(requestData); + var data = requestData.PostData; + + if (data != null) + { + using (var stream = request.GetRequestStream()) + { + if (requestData.HttpCompression) + using (var zipStream = new GZipStream(stream, CompressionMode.Compress)) + data.Write(zipStream, requestData.ConnectionSettings); + else + data.Write(stream, requestData.ConnectionSettings); + } + } + requestData.MadeItToResponse = true; + + //http://msdn.microsoft.com/en-us/library/system.net.httpwebresponse.getresponsestream.aspx + //Either the stream or the response object needs to be closed but not both although it won't + //throw any errors if both are closed atleast one of them has to be Closed. + //Since we expose the stream we let closing the stream determining when to close the connection + var response = (HttpWebResponse) request.GetResponse(); + HandleResponse(response, out statusCode, out responseStream, out mimeType); + + if (response.SupportsHeaders && response.Headers.HasKeys() && response.Headers.AllKeys.Contains("Warning")) + warnings = response.Headers.GetValues("Warning"); + } + catch (WebException e) + { + ex = e; + if (e.Response is HttpWebResponse response) + HandleResponse(response, out statusCode, out responseStream, out mimeType); + } + responseStream = responseStream ?? Stream.Null; + return ResponseBuilder.ToResponse(requestData, ex, statusCode, warnings, responseStream, mimeType); + } + + + /// + /// Registers an APM async task cancellation on the threadpool + /// + /// An unregister action that can be used to remove the waithandle prematurely + private static Action RegisterApmTaskTimeout(IAsyncResult result, WebRequest request, RequestData requestData) + { + var waitHandle = result.AsyncWaitHandle; + var registeredWaitHandle = + ThreadPool.RegisterWaitForSingleObject(waitHandle, TimeoutCallback, request, requestData.RequestTimeout, true); + return () => registeredWaitHandle?.Unregister(waitHandle); + } + + private static void TimeoutCallback(object state, bool timedOut) + { + if (!timedOut) return; + (state as WebRequest)?.Abort(); + } + + public virtual async Task RequestAsync(RequestData requestData, + CancellationToken cancellationToken) + where TResponse : class, IElasticsearchResponse, new() + { + Action unregisterWaitHandle = null; + int? statusCode = null; + IEnumerable warnings = null; + Stream responseStream = null; + Exception ex = null; + string mimeType = null; + try + { + var data = requestData.PostData; + var request = this.CreateHttpWebRequest(requestData); + using (cancellationToken.Register(() => request.Abort())) + { + if (data != null) + { + var apmGetRequestStreamTask = Task.Factory.FromAsync(request.BeginGetRequestStream, request.EndGetRequestStream, null); + unregisterWaitHandle = RegisterApmTaskTimeout(apmGetRequestStreamTask, request, requestData); + + using (var stream = await apmGetRequestStreamTask.ConfigureAwait(false)) + { + if (requestData.HttpCompression) + using (var zipStream = new GZipStream(stream, CompressionMode.Compress)) + await data.WriteAsync(zipStream, requestData.ConnectionSettings, cancellationToken).ConfigureAwait(false); + else + await data.WriteAsync(stream, requestData.ConnectionSettings, cancellationToken).ConfigureAwait(false); + } + unregisterWaitHandle?.Invoke(); + } + requestData.MadeItToResponse = true; + //http://msdn.microsoft.com/en-us/library/system.net.httpwebresponse.getresponsestream.aspx + //Either the stream or the response object needs to be closed but not both although it won't + //throw any errors if both are closed atleast one of them has to be Closed. + //Since we expose the stream we let closing the stream determining when to close the connection + + var apmGetResponseTask = Task.Factory.FromAsync(request.BeginGetResponse, request.EndGetResponse, null); + unregisterWaitHandle = RegisterApmTaskTimeout(apmGetResponseTask, request, requestData); + + var response = (HttpWebResponse) (await apmGetResponseTask.ConfigureAwait(false)); + HandleResponse(response, out statusCode, out responseStream, out mimeType); + if (response.SupportsHeaders && response.Headers.HasKeys() && response.Headers.AllKeys.Contains("Warning")) + warnings = response.Headers.GetValues("Warning"); + } + } + catch (WebException e) + { + ex = e; + if (e.Response is HttpWebResponse response) + HandleResponse(response, out statusCode, out responseStream, out mimeType); + } + finally + { + unregisterWaitHandle?.Invoke(); + } + responseStream = responseStream ?? Stream.Null; + return await ResponseBuilder.ToResponseAsync + (requestData, ex, statusCode, warnings, responseStream, mimeType, cancellationToken) + .ConfigureAwait(false); + } + + private static void HandleResponse(HttpWebResponse response, out int? statusCode, out Stream responseStream, out string mimeType) + { + statusCode = (int) response.StatusCode; + responseStream = response.GetResponseStream(); + mimeType = response.ContentType; + // https://github.com/elastic/elasticsearch-net/issues/2311 + // if stream is null call dispose on response instead. + if (responseStream == null || responseStream == Stream.Null) response.Dispose(); + } + + void IDisposable.Dispose() => this.DisposeManagedResources(); + + protected virtual void DisposeManagedResources() { } + } +#endif +} diff --git a/src/Elasticsearch.DotNetCoreOnly.sln b/src/Elasticsearch.DotNetCoreOnly.sln deleted file mode 100644 index 276f2aba624..00000000000 --- a/src/Elasticsearch.DotNetCoreOnly.sln +++ /dev/null @@ -1,33 +0,0 @@ -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.26403.7 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Nest", "Nest\Nest.csproj", "{072BA7DA-7B60-407D-8B6E-95E3186BE70C}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Elasticsearch.Net", "Elasticsearch.Net\Elasticsearch.Net.csproj", "{E97CCF40-0BA6-43FE-9F2D-58D454134088}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tests", "Tests\Tests.csproj", "{37164C11-88EF-4428-803A-9AA24FB8B44D}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {072BA7DA-7B60-407D-8B6E-95E3186BE70C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {072BA7DA-7B60-407D-8B6E-95E3186BE70C}.Debug|Any CPU.Build.0 = Debug|Any CPU - {072BA7DA-7B60-407D-8B6E-95E3186BE70C}.Release|Any CPU.ActiveCfg = Release|Any CPU - {072BA7DA-7B60-407D-8B6E-95E3186BE70C}.Release|Any CPU.Build.0 = Release|Any CPU - {E97CCF40-0BA6-43FE-9F2D-58D454134088}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {E97CCF40-0BA6-43FE-9F2D-58D454134088}.Debug|Any CPU.Build.0 = Debug|Any CPU - {E97CCF40-0BA6-43FE-9F2D-58D454134088}.Release|Any CPU.ActiveCfg = Release|Any CPU - {E97CCF40-0BA6-43FE-9F2D-58D454134088}.Release|Any CPU.Build.0 = Release|Any CPU - {37164C11-88EF-4428-803A-9AA24FB8B44D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {37164C11-88EF-4428-803A-9AA24FB8B44D}.Debug|Any CPU.Build.0 = Debug|Any CPU - {37164C11-88EF-4428-803A-9AA24FB8B44D}.Release|Any CPU.ActiveCfg = Release|Any CPU - {37164C11-88EF-4428-803A-9AA24FB8B44D}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal diff --git a/src/Elasticsearch.Net/Configuration/ConnectionConfiguration.cs b/src/Elasticsearch.Net/Configuration/ConnectionConfiguration.cs index 6ee18494c5a..9a8f01559de 100644 --- a/src/Elasticsearch.Net/Configuration/ConnectionConfiguration.cs +++ b/src/Elasticsearch.Net/Configuration/ConnectionConfiguration.cs @@ -4,15 +4,10 @@ using System.Collections.Specialized; using System.ComponentModel; using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Net.Security; using System.Security.Cryptography.X509Certificates; using System.Threading; - -#if DOTNETCORE -using System.Net; using System.Net.Http; -#endif namespace Elasticsearch.Net @@ -23,12 +18,7 @@ namespace Elasticsearch.Net /// public class ConnectionConfiguration : ConnectionConfiguration { - internal static bool IsCurlHandler { get; } = - #if DOTNETCORE - typeof(HttpClientHandler).Assembly().GetType("System.Net.Http.CurlHandler") != null; - #else - false; - #endif + internal static bool IsCurlHandler { get; } = typeof(HttpClientHandler).Assembly().GetType("System.Net.Http.CurlHandler") != null; public static readonly TimeSpan DefaultTimeout = TimeSpan.FromMinutes(1); public static readonly TimeSpan DefaultPingTimeout = TimeSpan.FromSeconds(2); public static readonly TimeSpan DefaultPingTimeoutOnSSL = TimeSpan.FromSeconds(5); diff --git a/src/Elasticsearch.Net/Connection/CertificateValidations.cs b/src/Elasticsearch.Net/Connection/CertificateValidations.cs index 0a6038dcbd3..db4e81b1289 100644 --- a/src/Elasticsearch.Net/Connection/CertificateValidations.cs +++ b/src/Elasticsearch.Net/Connection/CertificateValidations.cs @@ -55,14 +55,7 @@ public static Func Au errors == SslPolicyErrors.None || ValidRootCa(caCertificate, cert, chain, trustRoot, revocationMode); - private static X509Certificate2 to2(X509Certificate certificate) - { - #if DOTNETCORE - return new X509Certificate2(certificate.Export(X509ContentType.Cert)); - #else - return new X509Certificate2(certificate); - #endif - } + private static X509Certificate2 to2(X509Certificate certificate) => new X509Certificate2(certificate.Export(X509ContentType.Cert)); private static bool ValidRootCa(X509Certificate caCertificate, X509Certificate certificate, X509Chain chain, bool trustRoot, X509RevocationMode revocationMode) diff --git a/src/Elasticsearch.Net/Connection/ClientCertificate.cs b/src/Elasticsearch.Net/Connection/ClientCertificate.cs deleted file mode 100644 index 18085ff3139..00000000000 --- a/src/Elasticsearch.Net/Connection/ClientCertificate.cs +++ /dev/null @@ -1,148 +0,0 @@ -// this code contains a refactored version of DecodeRSAPrivateKey() found here http://www.jensign.com/opensslkey/opensslkey.cs -// Its license permits redistribution, the license is included here for reference. - -/* -// -//OpenSSLKey -// .NET 2.0 OpenSSL Public & Private Key Parser -// -/* -Copyright (c) 2000 JavaScience Consulting, Michel Gallant - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -*/ - -using System; -using System.Diagnostics; -using System.IO; -using System.Security.Cryptography; -using System.Security.Cryptography.X509Certificates; - -namespace Elasticsearch.Net -{ -//.NET removed the setter for PrivateKey for X509Certificate, you'll have to manually convert to pfx/p12 or add the key to the machine store -#if !DOTNETCORE - - public class ClientCertificate - { - //https://tls.mbed.org/kb/cryptography/asn1-key-structures-in-der-and-pem - private static RSACryptoServiceProvider DecodeRsaPrivateKey(byte[] privkey) - { - using (var mem = new MemoryStream(privkey)) - using (var binr = new BinaryReader(mem)) - { - var twobytes = binr.ReadUInt16(); - switch (twobytes) - { - case 0x8130: - binr.ReadByte(); //advance 1 byte - break; - case 0x8230: - binr.ReadInt16(); //advance 2 bytes - break; - default: - return null; - } - - twobytes = binr.ReadUInt16(); - if (twobytes != 0x0102) return null; //version number - var bt = binr.ReadByte(); - if (bt != 0x00) return null; - - // We make sure the provider typeString is compatible with RSA - // ---- - // https://msdn.microsoft.com/en-us/library/system.security.cryptography.cspparameters.providertype(v=vs.110).aspx - // https://msdn.microsoft.com/en-us/subscriptions/aa387431.aspx - // https://blogs.msdn.microsoft.com/alejacma/2009/04/30/default-provider-typeString-for-cspparameters-has-changed/ - - var serviceProvider = new RSACryptoServiceProvider(new CspParameters - { - Flags = CspProviderFlags.NoFlags, - KeyContainerName = Guid.NewGuid().ToString(), - ProviderType = 1 - }); - serviceProvider.ImportParameters(new RSAParameters - { - Modulus = ReadNext(binr), - Exponent = ReadNext(binr), - D = ReadNext(binr), - P = ReadNext(binr), - Q = ReadNext(binr), - DP = ReadNext(binr), - DQ = ReadNext(binr), - InverseQ = ReadNext(binr) - }); - return serviceProvider; - } - } - - private static byte[] ReadNext(BinaryReader br) => br.ReadBytes(GetSizeOfIntegerToReadNext(br)); - - private static int GetSizeOfIntegerToReadNext(BinaryReader br) - { - var bt = br.ReadByte(); - if (bt != 0x02) return 0; //expect integer - - var count = 0; - bt = br.ReadByte(); - switch (bt) - { - case 0x81: - count = br.ReadByte(); // data size in next byte - break; - case 0x82: - var highbyte = br.ReadByte(); - var lowbyte = br.ReadByte(); - byte[] modint = {lowbyte, highbyte, 0x00, 0x00}; - count = BitConverter.ToInt32(modint, 0); - break; - default: - count = bt; // we already have the data size - break; - } - while (br.ReadByte() == 0x00) //remove high order zeros in data - count -= 1; - br.BaseStream.Seek(-1, SeekOrigin.Current); //last ReadByte wasn't a removed zero, so back up a byte - return count; - } - - private static byte[] ReadBytesFromPemFile(string fileContents, string typeString) - { - var header = $"-----BEGIN {typeString}-----"; - var footer = $"-----END {typeString}-----"; - var start = fileContents.IndexOf(header, StringComparison.Ordinal) + header.Length; - var end = fileContents.IndexOf(footer, start, StringComparison.Ordinal) - start; - var base64Der = fileContents.Substring(start, end); - return Convert.FromBase64String(base64Der); - } - - public static X509Certificate2 LoadWithPrivateKey(string publicCertificatePath, string privateKeyPath, string password) - { - var publicCert = File.ReadAllText(publicCertificatePath); - var privateKey = File.ReadAllText(privateKeyPath); - var certBuffer = ReadBytesFromPemFile(publicCert, "CERTIFICATE"); - var keyBuffer = ReadBytesFromPemFile(privateKey, "RSA PRIVATE KEY"); - var certificate = !string.IsNullOrEmpty(password) ? new X509Certificate2(certBuffer, password) : new X509Certificate2(certBuffer); - var prov = DecodeRsaPrivateKey(keyBuffer); - certificate.PrivateKey = prov; - return certificate; - } - } -#endif -} diff --git a/src/Elasticsearch.Net/Connection/HttpConnection-CoreFx.cs b/src/Elasticsearch.Net/Connection/HttpConnection-CoreFx.cs index b0a4f1b911b..ba3eb912e00 100644 --- a/src/Elasticsearch.Net/Connection/HttpConnection-CoreFx.cs +++ b/src/Elasticsearch.Net/Connection/HttpConnection-CoreFx.cs @@ -1,5 +1,4 @@ -#if DOTNETCORE -using System; +using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.IO; @@ -7,8 +6,6 @@ using System.Net; using System.Net.Http; using System.Net.Http.Headers; -using System.Net.Security; -using System.Security.Cryptography.X509Certificates; using System.Text; using System.Threading; using System.Threading.Tasks; @@ -307,4 +304,3 @@ protected virtual void DisposeManagedResources() } } } -#endif diff --git a/src/Elasticsearch.Net/ConnectionPool/Node.cs b/src/Elasticsearch.Net/ConnectionPool/Node.cs index d0fb23186be..bef75f36839 100644 --- a/src/Elasticsearch.Net/ConnectionPool/Node.cs +++ b/src/Elasticsearch.Net/ConnectionPool/Node.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; -using Purify; namespace Elasticsearch.Net { @@ -13,7 +12,7 @@ public Node(Uri uri) //http://my-saas-provider.com/instance if (!uri.OriginalString.EndsWith("/", StringComparison.Ordinal)) uri = new Uri(uri.OriginalString + "/"); - this.Uri = uri.Purify(); + this.Uri = uri; this.IsAlive = true; this.HoldsData = true; this.MasterEligible = true; @@ -74,7 +73,7 @@ public void MarkAlive() this.DeadUntil = default(DateTime); } - public Uri CreatePath(string path) => new Uri(this.Uri, path).Purify(); + public Uri CreatePath(string path) => new Uri(this.Uri, path); public Node Clone() => new Node(this.Uri) diff --git a/src/Elasticsearch.Net/CrossPlatform/TypeExtensions.cs b/src/Elasticsearch.Net/CrossPlatform/TypeExtensions.cs index 6a071038273..e16369e02dd 100644 --- a/src/Elasticsearch.Net/CrossPlatform/TypeExtensions.cs +++ b/src/Elasticsearch.Net/CrossPlatform/TypeExtensions.cs @@ -10,45 +10,26 @@ internal static class DotNetCoreTypeExtensions { internal static bool IsGeneric(this Type type) { -#if DOTNETCORE return type.GetTypeInfo().IsGenericType; -#else - return type.IsGenericType; -#endif } internal static bool AssignableFrom(this Type type, Type from) { -#if DOTNETCORE return type.GetTypeInfo().IsAssignableFrom(from.GetTypeInfo()); -#else - return type.IsAssignableFrom(from); -#endif } - + internal static Assembly Assembly(this Type type) { -#if DOTNETCORE return type.GetTypeInfo().Assembly; -#else - return type.Assembly; -#endif } internal static bool IsValue(this Type type) { -#if DOTNETCORE return type.GetTypeInfo().IsValueType; -#else - return type.IsValueType; -#endif } internal static TypeCode GetTypeCode(this Type type) { -#if !DOTNETCORE - return Type.GetTypeCode(type); -#else if (type == null) return TypeCode.Empty; else if (type == typeof(bool)) @@ -85,7 +66,6 @@ internal static TypeCode GetTypeCode(this Type type) return GetTypeCode(Enum.GetUnderlyingType(type)); else return TypeCode.Object; -#endif } } } diff --git a/src/Elasticsearch.Net/Domain/Enums.Generated.cs b/src/Elasticsearch.Net/Domain/Enums.Generated.cs index 94d85dd139e..5a13b211267 100644 --- a/src/Elasticsearch.Net/Domain/Enums.Generated.cs +++ b/src/Elasticsearch.Net/Domain/Enums.Generated.cs @@ -11,7 +11,7 @@ namespace Elasticsearch.Net { - + public enum Refresh { [EnumMember(Value = "true")] @@ -21,7 +21,7 @@ public enum Refresh [EnumMember(Value = "wait_for")] WaitFor } - + public enum Bytes { [EnumMember(Value = "b")] @@ -47,7 +47,7 @@ public enum Bytes [EnumMember(Value = "pb")] Pb } - + public enum Health { [EnumMember(Value = "green")] @@ -57,7 +57,7 @@ public enum Health [EnumMember(Value = "red")] Red } - + public enum Size { [EnumMember(Value = "")] @@ -73,7 +73,7 @@ public enum Size [EnumMember(Value = "p")] P } - + public enum Level { [EnumMember(Value = "cluster")] @@ -83,7 +83,7 @@ public enum Level [EnumMember(Value = "shards")] Shards } - + public enum WaitForEvents { [EnumMember(Value = "immediate")] @@ -99,7 +99,7 @@ public enum WaitForEvents [EnumMember(Value = "languid")] Languid } - + public enum WaitForStatus { [EnumMember(Value = "green")] @@ -109,7 +109,7 @@ public enum WaitForStatus [EnumMember(Value = "red")] Red } - + public enum ExpandWildcards { [EnumMember(Value = "open")] @@ -121,7 +121,7 @@ public enum ExpandWildcards [EnumMember(Value = "all")] All } - + public enum DefaultOperator { [EnumMember(Value = "AND")] @@ -129,7 +129,7 @@ public enum DefaultOperator [EnumMember(Value = "OR")] Or } - + public enum VersionType { [EnumMember(Value = "internal")] @@ -141,7 +141,7 @@ public enum VersionType [EnumMember(Value = "force")] Force } - + public enum Conflicts { [EnumMember(Value = "abort")] @@ -149,7 +149,7 @@ public enum Conflicts [EnumMember(Value = "proceed")] Proceed } - + public enum SearchType { [EnumMember(Value = "query_then_fetch")] @@ -157,7 +157,7 @@ public enum SearchType [EnumMember(Value = "dfs_query_then_fetch")] DfsQueryThenFetch } - + public enum OpType { [EnumMember(Value = "index")] @@ -165,7 +165,7 @@ public enum OpType [EnumMember(Value = "create")] Create } - + public enum Format { [EnumMember(Value = "detailed")] @@ -173,7 +173,7 @@ public enum Format [EnumMember(Value = "text")] Text } - + public enum ThreadType { [EnumMember(Value = "cpu")] @@ -183,7 +183,7 @@ public enum ThreadType [EnumMember(Value = "block")] Block } - + public enum SuggestMode { [EnumMember(Value = "missing")] @@ -193,7 +193,7 @@ public enum SuggestMode [EnumMember(Value = "always")] Always } - + public enum GroupBy { [EnumMember(Value = "nodes")] @@ -201,7 +201,7 @@ public enum GroupBy [EnumMember(Value = "parents")] Parents } - + [Flags]public enum ClusterStateMetric { [EnumMember(Value = "blocks")] @@ -221,7 +221,7 @@ [Flags]public enum ClusterStateMetric [EnumMember(Value = "_all")] All = 1 << 7 } - + [Flags]public enum IndicesStatsMetric { [EnumMember(Value = "completion")] @@ -257,7 +257,7 @@ [Flags]public enum IndicesStatsMetric [EnumMember(Value = "_all")] All = 1 << 15 } - + [Flags]public enum NodesInfoMetric { [EnumMember(Value = "settings")] @@ -279,7 +279,7 @@ [Flags]public enum NodesInfoMetric [EnumMember(Value = "ingest")] Ingest = 1 << 8 } - + [Flags]public enum NodesStatsMetric { [EnumMember(Value = "breaker")] @@ -305,7 +305,7 @@ [Flags]public enum NodesStatsMetric [EnumMember(Value = "_all")] All = 1 << 10 } - + [Flags]public enum NodesStatsIndexMetric { [EnumMember(Value = "completion")] @@ -341,7 +341,7 @@ [Flags]public enum NodesStatsIndexMetric [EnumMember(Value = "_all")] All = 1 << 15 } - + [Flags]public enum NodesUsageMetric { [EnumMember(Value = "rest_actions")] @@ -349,7 +349,7 @@ [Flags]public enum NodesUsageMetric [EnumMember(Value = "_all")] All = 1 << 1 } - + [Flags]public enum WatcherStatsMetric { [EnumMember(Value = "queued_watches")] @@ -361,29 +361,29 @@ [Flags]public enum WatcherStatsMetric } public static class KnownEnums - { + { private class EnumDictionary : Dictionary - { + { public EnumDictionary(int capacity) : base(capacity) {} public Func Resolver { get; set; } - } + } + - public static string GetStringValue(this Refresh enumValue) { - + switch (enumValue) { case Refresh.True: return "true"; case Refresh.False: return "false"; case Refresh.WaitFor: return "wait_for"; } - throw new ArgumentException($"'{enumValue.ToString()}' is not a valid value for enum 'Refresh'"); + throw new ArgumentException($"'{enumValue.ToString()}' is not a valid value for enum 'Refresh'"); } - + public static string GetStringValue(this Bytes enumValue) { - + switch (enumValue) { case Bytes.B: return "b"; @@ -398,24 +398,24 @@ public static string GetStringValue(this Bytes enumValue) case Bytes.P: return "p"; case Bytes.Pb: return "pb"; } - throw new ArgumentException($"'{enumValue.ToString()}' is not a valid value for enum 'Bytes'"); + throw new ArgumentException($"'{enumValue.ToString()}' is not a valid value for enum 'Bytes'"); } - + public static string GetStringValue(this Health enumValue) { - + switch (enumValue) { case Health.Green: return "green"; case Health.Yellow: return "yellow"; case Health.Red: return "red"; } - throw new ArgumentException($"'{enumValue.ToString()}' is not a valid value for enum 'Health'"); + throw new ArgumentException($"'{enumValue.ToString()}' is not a valid value for enum 'Health'"); } - + public static string GetStringValue(this Size enumValue) { - + switch (enumValue) { case Size.Raw: return ""; @@ -425,24 +425,24 @@ public static string GetStringValue(this Size enumValue) case Size.T: return "t"; case Size.P: return "p"; } - throw new ArgumentException($"'{enumValue.ToString()}' is not a valid value for enum 'Size'"); + throw new ArgumentException($"'{enumValue.ToString()}' is not a valid value for enum 'Size'"); } - + public static string GetStringValue(this Level enumValue) { - + switch (enumValue) { case Level.Cluster: return "cluster"; case Level.Indices: return "indices"; case Level.Shards: return "shards"; } - throw new ArgumentException($"'{enumValue.ToString()}' is not a valid value for enum 'Level'"); + throw new ArgumentException($"'{enumValue.ToString()}' is not a valid value for enum 'Level'"); } - + public static string GetStringValue(this WaitForEvents enumValue) { - + switch (enumValue) { case WaitForEvents.Immediate: return "immediate"; @@ -452,24 +452,24 @@ public static string GetStringValue(this WaitForEvents enumValue) case WaitForEvents.Low: return "low"; case WaitForEvents.Languid: return "languid"; } - throw new ArgumentException($"'{enumValue.ToString()}' is not a valid value for enum 'WaitForEvents'"); + throw new ArgumentException($"'{enumValue.ToString()}' is not a valid value for enum 'WaitForEvents'"); } - + public static string GetStringValue(this WaitForStatus enumValue) { - + switch (enumValue) { case WaitForStatus.Green: return "green"; case WaitForStatus.Yellow: return "yellow"; case WaitForStatus.Red: return "red"; } - throw new ArgumentException($"'{enumValue.ToString()}' is not a valid value for enum 'WaitForStatus'"); + throw new ArgumentException($"'{enumValue.ToString()}' is not a valid value for enum 'WaitForStatus'"); } - + public static string GetStringValue(this ExpandWildcards enumValue) { - + switch (enumValue) { case ExpandWildcards.Open: return "open"; @@ -477,23 +477,23 @@ public static string GetStringValue(this ExpandWildcards enumValue) case ExpandWildcards.None: return "none"; case ExpandWildcards.All: return "all"; } - throw new ArgumentException($"'{enumValue.ToString()}' is not a valid value for enum 'ExpandWildcards'"); + throw new ArgumentException($"'{enumValue.ToString()}' is not a valid value for enum 'ExpandWildcards'"); } - + public static string GetStringValue(this DefaultOperator enumValue) { - + switch (enumValue) { case DefaultOperator.And: return "AND"; case DefaultOperator.Or: return "OR"; } - throw new ArgumentException($"'{enumValue.ToString()}' is not a valid value for enum 'DefaultOperator'"); + throw new ArgumentException($"'{enumValue.ToString()}' is not a valid value for enum 'DefaultOperator'"); } - + public static string GetStringValue(this VersionType enumValue) { - + switch (enumValue) { case VersionType.Internal: return "internal"; @@ -501,91 +501,91 @@ public static string GetStringValue(this VersionType enumValue) case VersionType.ExternalGte: return "external_gte"; case VersionType.Force: return "force"; } - throw new ArgumentException($"'{enumValue.ToString()}' is not a valid value for enum 'VersionType'"); + throw new ArgumentException($"'{enumValue.ToString()}' is not a valid value for enum 'VersionType'"); } - + public static string GetStringValue(this Conflicts enumValue) { - + switch (enumValue) { case Conflicts.Abort: return "abort"; case Conflicts.Proceed: return "proceed"; } - throw new ArgumentException($"'{enumValue.ToString()}' is not a valid value for enum 'Conflicts'"); + throw new ArgumentException($"'{enumValue.ToString()}' is not a valid value for enum 'Conflicts'"); } - + public static string GetStringValue(this SearchType enumValue) { - + switch (enumValue) { case SearchType.QueryThenFetch: return "query_then_fetch"; case SearchType.DfsQueryThenFetch: return "dfs_query_then_fetch"; } - throw new ArgumentException($"'{enumValue.ToString()}' is not a valid value for enum 'SearchType'"); + throw new ArgumentException($"'{enumValue.ToString()}' is not a valid value for enum 'SearchType'"); } - + public static string GetStringValue(this OpType enumValue) { - + switch (enumValue) { case OpType.Index: return "index"; case OpType.Create: return "create"; } - throw new ArgumentException($"'{enumValue.ToString()}' is not a valid value for enum 'OpType'"); + throw new ArgumentException($"'{enumValue.ToString()}' is not a valid value for enum 'OpType'"); } - + public static string GetStringValue(this Format enumValue) { - + switch (enumValue) { case Format.Detailed: return "detailed"; case Format.Text: return "text"; } - throw new ArgumentException($"'{enumValue.ToString()}' is not a valid value for enum 'Format'"); + throw new ArgumentException($"'{enumValue.ToString()}' is not a valid value for enum 'Format'"); } - + public static string GetStringValue(this ThreadType enumValue) { - + switch (enumValue) { case ThreadType.Cpu: return "cpu"; case ThreadType.Wait: return "wait"; case ThreadType.Block: return "block"; } - throw new ArgumentException($"'{enumValue.ToString()}' is not a valid value for enum 'ThreadType'"); + throw new ArgumentException($"'{enumValue.ToString()}' is not a valid value for enum 'ThreadType'"); } - + public static string GetStringValue(this SuggestMode enumValue) { - + switch (enumValue) { case SuggestMode.Missing: return "missing"; case SuggestMode.Popular: return "popular"; case SuggestMode.Always: return "always"; } - throw new ArgumentException($"'{enumValue.ToString()}' is not a valid value for enum 'SuggestMode'"); + throw new ArgumentException($"'{enumValue.ToString()}' is not a valid value for enum 'SuggestMode'"); } - + public static string GetStringValue(this GroupBy enumValue) { - + switch (enumValue) { case GroupBy.Nodes: return "nodes"; case GroupBy.Parents: return "parents"; } - throw new ArgumentException($"'{enumValue.ToString()}' is not a valid value for enum 'GroupBy'"); + throw new ArgumentException($"'{enumValue.ToString()}' is not a valid value for enum 'GroupBy'"); } - + public static string GetStringValue(this ClusterStateMetric enumValue) { - + if ((enumValue & ClusterStateMetric.All) != 0) return "_all"; var list = new List(); if ((enumValue & ClusterStateMetric.Blocks) != 0) list.Add("blocks"); @@ -597,10 +597,10 @@ public static string GetStringValue(this ClusterStateMetric enumValue) if ((enumValue & ClusterStateMetric.Version) != 0) list.Add("version"); return string.Join(",", list); } - + public static string GetStringValue(this IndicesStatsMetric enumValue) { - + if ((enumValue & IndicesStatsMetric.All) != 0) return "_all"; var list = new List(); if ((enumValue & IndicesStatsMetric.Completion) != 0) list.Add("completion"); @@ -620,10 +620,10 @@ public static string GetStringValue(this IndicesStatsMetric enumValue) if ((enumValue & IndicesStatsMetric.Suggest) != 0) list.Add("suggest"); return string.Join(",", list); } - + public static string GetStringValue(this NodesInfoMetric enumValue) { - + var list = new List(); if ((enumValue & NodesInfoMetric.Settings) != 0) list.Add("settings"); if ((enumValue & NodesInfoMetric.Os) != 0) list.Add("os"); @@ -636,10 +636,10 @@ public static string GetStringValue(this NodesInfoMetric enumValue) if ((enumValue & NodesInfoMetric.Ingest) != 0) list.Add("ingest"); return string.Join(",", list); } - + public static string GetStringValue(this NodesStatsMetric enumValue) { - + if ((enumValue & NodesStatsMetric.All) != 0) return "_all"; var list = new List(); if ((enumValue & NodesStatsMetric.Breaker) != 0) list.Add("breaker"); @@ -654,10 +654,10 @@ public static string GetStringValue(this NodesStatsMetric enumValue) if ((enumValue & NodesStatsMetric.Discovery) != 0) list.Add("discovery"); return string.Join(",", list); } - + public static string GetStringValue(this NodesStatsIndexMetric enumValue) { - + if ((enumValue & NodesStatsIndexMetric.All) != 0) return "_all"; var list = new List(); if ((enumValue & NodesStatsIndexMetric.Completion) != 0) list.Add("completion"); @@ -677,19 +677,19 @@ public static string GetStringValue(this NodesStatsIndexMetric enumValue) if ((enumValue & NodesStatsIndexMetric.Suggest) != 0) list.Add("suggest"); return string.Join(",", list); } - + public static string GetStringValue(this NodesUsageMetric enumValue) { - + if ((enumValue & NodesUsageMetric.All) != 0) return "_all"; var list = new List(); if ((enumValue & NodesUsageMetric.RestActions) != 0) list.Add("rest_actions"); return string.Join(",", list); } - + public static string GetStringValue(this WatcherStatsMetric enumValue) { - + if ((enumValue & WatcherStatsMetric.All) != 0) return "_all"; var list = new List(); if ((enumValue & WatcherStatsMetric.QueuedWatches) != 0) list.Add("queued_watches"); @@ -730,7 +730,7 @@ static KnownEnums() public static string GetStringValue(this Enum e) { - var type = e.GetType(); + var type = e.GetType(); var resolver = EnumStringResolvers.GetOrAdd(type, GetEnumStringResolver); return resolver(e); } @@ -743,23 +743,15 @@ private static Func GetEnumStringResolver(Type type) for (int index = 0; index < values.Length; index++) { var value = values.GetValue(index); -#if DOTNETCORE var info = type.GetTypeInfo().GetDeclaredField(value.ToString()); -#else - var info = type.GetField(value.ToString()); -#endif var da = (EnumMemberAttribute[])info.GetCustomAttributes(typeof(EnumMemberAttribute), false); var stringValue = da.Length > 0 ? da[0].Value : Enum.GetName(type, value); dictionary.Add((Enum)value, stringValue); } -#if DOTNETCORE var isFlag = type.GetTypeInfo().GetCustomAttributes(typeof(FlagsAttribute), false).Any(); -#else - var isFlag = type.GetCustomAttributes(typeof(FlagsAttribute), false).Length > 0; -#endif - return (e) => + return (e) => { if (isFlag) { @@ -777,4 +769,4 @@ private static Func GetEnumStringResolver(Type type) }; } } -} \ No newline at end of file +} diff --git a/src/Elasticsearch.Net/Elasticsearch.Net.csproj b/src/Elasticsearch.Net/Elasticsearch.Net.csproj index 1dbc0c693d5..39e62fdfbbb 100644 --- a/src/Elasticsearch.Net/Elasticsearch.Net.csproj +++ b/src/Elasticsearch.Net/Elasticsearch.Net.csproj @@ -2,13 +2,9 @@ - net45;net46;netstandard1.3 - netstandard1.3 + netstandard1.3 - - - - + diff --git a/src/Elasticsearch.Net/Extensions/Extensions.cs b/src/Elasticsearch.Net/Extensions/Extensions.cs index 1b601536bba..9e07d3a416f 100644 --- a/src/Elasticsearch.Net/Extensions/Extensions.cs +++ b/src/Elasticsearch.Net/Extensions/Extensions.cs @@ -8,11 +8,7 @@ namespace Elasticsearch.Net { internal static class Extensions { -#if !DOTNETCORE - internal static string Utf8String(this byte[] bytes) => bytes == null ? null : Encoding.UTF8.GetString(bytes); -#else internal static string Utf8String(this byte[] bytes) => bytes == null ? null : Encoding.UTF8.GetString(bytes, 0, bytes.Length); -#endif internal static byte[] Utf8Bytes(this string s) { diff --git a/src/Elasticsearch.Net/Extensions/TypeExtensions.cs b/src/Elasticsearch.Net/Extensions/TypeExtensions.cs index eb730bd8bbb..3e4ea8a78ba 100644 --- a/src/Elasticsearch.Net/Extensions/TypeExtensions.cs +++ b/src/Elasticsearch.Net/Extensions/TypeExtensions.cs @@ -42,11 +42,7 @@ internal static object CreateInstance(this Type t, params object[] args) } internal static bool IsValueType(this Type type) { -#if DOTNETCORE return type.GetTypeInfo().IsValueType; -#else - return type.IsValueType; -#endif } //do not remove this is referenced through GetActivatorMethod diff --git a/src/Elasticsearch.Net/Extensions/X509CertificateExtensions.cs b/src/Elasticsearch.Net/Extensions/X509CertificateExtensions.cs index 2a25c4c0d91..50d4b523283 100644 --- a/src/Elasticsearch.Net/Extensions/X509CertificateExtensions.cs +++ b/src/Elasticsearch.Net/Extensions/X509CertificateExtensions.cs @@ -4,7 +4,6 @@ namespace Elasticsearch.Net { internal static class X509CertificateExtensions { -#if DOTNETCORE // https://referencesource.microsoft.com/#mscorlib/system/security/cryptography/x509certificates/x509certificate.cs,318 internal static string GetCertHashString(this X509Certificate certificate) @@ -14,11 +13,8 @@ internal static string GetCertHashString(this X509Certificate certificate) } // https://referencesource.microsoft.com/#mscorlib/system/security/util/hex.cs,1bfe838f662feef3 - // converts number to hex digit. Does not do any range checks. - private static char HexDigit(int num) { - return (char)((num < 10) ? (num + '0') : (num + ('A' - 10))); - } + private static char HexDigit(int num) => (char)((num < 10) ? (num + '0') : (num + ('A' - 10))); private static string EncodeHexString(byte[] sArray) { @@ -36,8 +32,5 @@ private static string EncodeHexString(byte[] sArray) result = new string(hexOrder); return result; } - -#endif - } } diff --git a/src/Elasticsearch.Net/Purify/Purify.cs b/src/Elasticsearch.Net/Purify/Purify.cs deleted file mode 100644 index 7d14dd3eeea..00000000000 --- a/src/Elasticsearch.Net/Purify/Purify.cs +++ /dev/null @@ -1,207 +0,0 @@ -using System; -using System.Globalization; -using System.Reflection; - -namespace Purify -{ - -#if DOTNETCORE - public static class Purifier - { - public static Uri Purify(this Uri uri) => uri; - } -#else - /// - /// The Uri classes in .NET prior to 4.5 and Mono scrub through your Uris and modify them in order to prevent vulnerabilities, for - /// example escaped slashes are unescaped. This scrubbing however prevents Uris that are inline with RFC 3986. Beyond that it prevents - /// using .NET's HTTP clients (HttpClient and WebClient) to talk to APIs that require accessing resources using escaped - /// slashes unless you are using .NET 4.5. - ///
-	/// This static class allows you to purify a Uri instance so that it remains untouched across all .NET runtime versions
-	/// 
- ///
- public static class Purifier - { - - private static readonly bool hasBrokenDotNetUri; - - private static readonly bool isMono; - - static Purifier() - { - isMono = typeof(Uri).GetField("m_Flags", BindingFlags.Instance | BindingFlags.NonPublic) == null; - if (isMono) - return; - - //ShouldUseLegacyV2Quirks was introduced in .net 4.5 - //Eventhough 4.5 is an inplace update of 4.0 this call will return - //a different value if an application specifically targets 4.0 or 4.5+ - var legacyV2Quirks = typeof(UriParser).GetProperty("ShouldUseLegacyV2Quirks", BindingFlags.Static | BindingFlags.NonPublic); - if (legacyV2Quirks == null) - { - hasBrokenDotNetUri = true; //neither 4.0 or 4.5 - return; - } - var isBrokenUri = (bool)legacyV2Quirks.GetValue(null, null); - if (!isBrokenUri) - return; //application targets 4.5 - - //4.0 uses legacyV2quirks on the UriParser but you can set - // - // - // - // - // - // - // this will fix AbsoluteUri but not ToString() - // - // i.e new Uri("http://google.com/%2F").AbsoluteUri - // will return the url untouched but: - // new Uri("http://google.com/%2F").ToString() - // will still return http://google.com// - // - // so instead of using reflection perform a one off functional test. - - hasBrokenDotNetUri = !new Uri("http://google.com/%2F") - .ToString() - .EndsWith("%2F", StringComparison.InvariantCulture); - } - - /// - /// Will purify the to the unscrubed version. - ///
Calling this will be a NOOP on .NET 4.5 and up.
- ///
- /// The uri to be purified - /// The purified uri - public static Uri Purify(this Uri uri) - { - IPurifier purifier = null; - if (isMono) - purifier = new PurifierMono(); - else if (hasBrokenDotNetUri) - purifier = new PurifierDotNet(); - else return uri; - - return purifier.Purify(uri); - } - - private interface IPurifier - { - /// - /// purifies and returns the passed - /// - Uri Purify(Uri uri); - } - - private class PurifierDotNet : IPurifier - { - private static FieldInfo flagsField; - private static FieldInfo infoField; - private static FieldInfo stringField; - private static FieldInfo infoStringField; - private static FieldInfo moreInfoField; - private static FieldInfo moreInfoAbsoluteUri; - private static FieldInfo moreInfoPath; - private static FieldInfo moreInfoQuery; - - static PurifierDotNet() - { - var uriType = typeof(Uri); - flagsField = uriType.GetField("m_Flags", BindingFlags.NonPublic | BindingFlags.Instance); - stringField = uriType.GetField("m_String", BindingFlags.NonPublic | BindingFlags.Instance); - infoField = uriType.GetField("m_Info", BindingFlags.NonPublic | BindingFlags.Instance); - var infoFieldType = infoField.FieldType; - infoStringField = infoFieldType.GetField("String", BindingFlags.Public | BindingFlags.Instance); - moreInfoField = infoFieldType.GetField("MoreInfo", BindingFlags.Public | BindingFlags.Instance); - var moreInfoType = moreInfoField.FieldType; - moreInfoAbsoluteUri = moreInfoType.GetField("AbsoluteUri", BindingFlags.Public | BindingFlags.Instance); - moreInfoQuery = moreInfoType.GetField("Query", BindingFlags.Public | BindingFlags.Instance); - moreInfoPath = moreInfoType.GetField("Path", BindingFlags.Public | BindingFlags.Instance); - } - - //Code inspired by Rasmus Faber's solution in this post: http://stackoverflow.com/questions/781205/getting-a-url-with-an-url-encoded-slash - public Uri Purify(Uri uri) - { - string paq = uri.PathAndQuery; // need to access PathAndQuery - var abs = uri.AbsoluteUri; //need to access this as well the MoreInfo prop is initialized. - ulong flags = (ulong)flagsField.GetValue(uri); - flags &= ~((ulong)0x30); // Flags.PathNotCanonical|Flags.QueryNotCanonical - flagsField.SetValue(uri, flags); - object info = infoField.GetValue(uri); - var source = (string)stringField.GetValue(uri); - infoStringField.SetValue(info, source); - object moreInfo = moreInfoField.GetValue(info); - moreInfoAbsoluteUri.SetValue(moreInfo, source); - var uriInfo = new UriInfo(uri, source); - moreInfoPath.SetValue(moreInfo, uriInfo.Path); - moreInfoQuery.SetValue(moreInfo, uriInfo.Query); - return uri; - } - } - - private class PurifierMono : IPurifier - { - private static Type uriType = typeof(Uri); - private static FieldInfo mono_sourceField; - private static FieldInfo mono_queryField; - private static FieldInfo mono_pathField; - private static FieldInfo mono_cachedToStringField; - private static FieldInfo mono_cachedAbsoluteUriField; - - static PurifierMono() - { - mono_sourceField = uriType.GetField("source", BindingFlags.NonPublic | BindingFlags.Instance); - mono_queryField = uriType.GetField("query", BindingFlags.NonPublic | BindingFlags.Instance); - mono_pathField = uriType.GetField("path", BindingFlags.NonPublic | BindingFlags.Instance); - mono_cachedToStringField = uriType.GetField("cachedToString", BindingFlags.NonPublic | BindingFlags.Instance); - mono_cachedAbsoluteUriField = uriType.GetField("cachedAbsoluteUri", - BindingFlags.NonPublic | BindingFlags.Instance); - } - - public Uri Purify(Uri uri) - { - var source = (string)mono_sourceField.GetValue(uri); - mono_cachedToStringField.SetValue(uri, source ?? string.Empty); - mono_cachedAbsoluteUriField.SetValue(uri, source ?? string.Empty); - var uriInfo = new UriInfo(uri, source); - mono_pathField.SetValue(uri, uriInfo.Path ?? string.Empty); - mono_queryField.SetValue(uri, uriInfo.Query ?? string.Empty); - return uri; - } - } - - /// - /// Class that breaks a Uri into path and query components given its orignal source - /// - private class UriInfo - { - public string Path { get; private set; } - public string Query { get; private set; } - - public UriInfo(Uri uri, string source) - { - var fragPos = source.IndexOf("#", StringComparison.Ordinal); - var queryPos = source.IndexOf("?", StringComparison.Ordinal); - var start = source.IndexOf(uri.Host, StringComparison.Ordinal) + uri.Host.Length; - var pathEnd = queryPos == -1 ? fragPos : queryPos; - if (pathEnd == -1) - pathEnd = source.Length + 1; - - if (start < pathEnd - 1 && source[start] == ':') - { - var portLength = uri.Port.ToString().Length; - start += portLength + 1; - } - - Path = queryPos > -1 ? source.Substring(start, pathEnd - start) : source.Substring(start); - Query = fragPos > -1 - ? source.Substring(queryPos, fragPos - queryPos) - : queryPos > -1 - ? source.Substring(queryPos, (source.Length - queryPos)) - : null; - } - } - } - -#endif -} diff --git a/src/Elasticsearch.Net/Responses/Dynamic/ElasticsearchDynamicValue.cs b/src/Elasticsearch.Net/Responses/Dynamic/ElasticsearchDynamicValue.cs index da8241a8fb0..3fc2ccce521 100644 --- a/src/Elasticsearch.Net/Responses/Dynamic/ElasticsearchDynamicValue.cs +++ b/src/Elasticsearch.Net/Responses/Dynamic/ElasticsearchDynamicValue.cs @@ -52,7 +52,7 @@ private bool Dispatch(out object result, string name) result = new ElasticsearchDynamicValue(ds[name]); return true; } - + result = new ElasticsearchDynamicValue(this.Value); return true; } @@ -144,7 +144,7 @@ public object Value } /// - /// Attempts to convert the value to type of T, failing to do so will return the defaultValue. + /// Attempts to convert the value to type of T, failing to do so will return the defaultValue. /// /// When no default value is supplied, required to supply the default type /// Optional parameter for default value, if not given it returns default of type T @@ -175,15 +175,7 @@ public object Value else if (stringValue != null) { var converter = TypeDescriptor.GetConverter(TType); - -#if DOTNETCORE return (T)converter.ConvertFromInvariantString(stringValue); -#else - if (converter.IsValid(stringValue)) - { - return (T)converter.ConvertFromInvariantString(stringValue); - } -#endif } else if (TType == typeof(string)) { @@ -214,7 +206,7 @@ public object Value return !(dynamicValue == compareValue); } - + /// /// Indicates whether the current object is equal to another object of the same type. /// @@ -255,7 +247,7 @@ public override bool Equals(object compareValue) } /// - /// Serves as a hash function for a particular type. + /// Serves as a hash function for a particular type. /// /// A hash code for the current instance. public override int GetHashCode() @@ -353,11 +345,7 @@ public override bool TryConvert(ConvertBinder binder, out object result) return false; } } -#if DOTNETCORE result = Convert.ChangeType(value, binderType); -#else - result = Convert.ChangeType(value, typeCode); -#endif return true; } diff --git a/src/Elasticsearch.Net/Serialization/ElasticsearchNetJsonStrategy.cs b/src/Elasticsearch.Net/Serialization/ElasticsearchNetJsonStrategy.cs index 53319f708bf..5dd921b0ad9 100644 --- a/src/Elasticsearch.Net/Serialization/ElasticsearchNetJsonStrategy.cs +++ b/src/Elasticsearch.Net/Serialization/ElasticsearchNetJsonStrategy.cs @@ -39,21 +39,6 @@ private IEnumerable FlattenExceptions(Exception e) private JsonObject ToExceptionJsonObject(Exception e, int depth) { var o = new JsonObject(); -#if !DOTNETCORE - var si = new SerializationInfo(e.GetType(), new FormatterConverter()); - var sc = new StreamingContext(); - e.GetObjectData(si, sc); - //TODO Loop over ISerializable data - - var helpUrl = si.GetString("HelpURL"); - var stackTrace = si.GetString("StackTraceString"); - var remoteStackTrace = si.GetString("RemoteStackTraceString"); - var remoteStackIndex = si.GetInt32("RemoteStackIndex"); - var exceptionMethod = si.GetString("ExceptionMethod"); - var hresult = si.GetInt32("HResult"); - var source = si.GetString("Source"); - var className = si.GetString("ClassName"); -#else var helpUrl = e.HelpLink; var stackTrace = e.StackTrace; var remoteStackTrace = string.Empty; @@ -62,7 +47,6 @@ private JsonObject ToExceptionJsonObject(Exception e, int depth) var hresult = e.HResult; var source = e.Source; var className = string.Empty; -#endif o.Add("Depth", depth); o.Add("ClassName", className); @@ -73,9 +57,8 @@ private JsonObject ToExceptionJsonObject(Exception e, int depth) o.Add("RemoteStackIndex", remoteStackIndex); o.Add("HResult", hresult); o.Add("HelpURL", helpUrl); -#if !DOTNETCORE + //TODO Find out how to get exceptionMethod again WriteStructuredExceptionMethod(o, exceptionMethod); -#endif return o; } diff --git a/src/Elasticsearch.Net/Serialization/SimpleJson.cs b/src/Elasticsearch.Net/Serialization/SimpleJson.cs index 0bf318022d4..eee0f61929a 100644 --- a/src/Elasticsearch.Net/Serialization/SimpleJson.cs +++ b/src/Elasticsearch.Net/Serialization/SimpleJson.cs @@ -46,9 +46,7 @@ // original json parsing code from http://techblog.procurios.nl/k/618/news/view/14605/14863/How-do-I-write-my-own-parser-for-JSON.html -#if NETFX_CORE || DOTNETCORE #define SIMPLE_JSON_TYPEINFO -#endif using System; using System.CodeDom.Compiler; using System.Collections; diff --git a/src/Elasticsearch.Net/Transport/Pipeline/RequestData.cs b/src/Elasticsearch.Net/Transport/Pipeline/RequestData.cs index bb0a2431c75..90b6473e4e7 100644 --- a/src/Elasticsearch.Net/Transport/Pipeline/RequestData.cs +++ b/src/Elasticsearch.Net/Transport/Pipeline/RequestData.cs @@ -5,7 +5,6 @@ using System.Linq; using System.Security.Cryptography.X509Certificates; using System.Text; -using Purify; namespace Elasticsearch.Net { @@ -14,7 +13,7 @@ public class RequestData public const string MimeType = "application/json"; public const string RunAsSecurityHeader = "es-security-runas-user"; - public Uri Uri => this.Node != null ? new Uri(this.Node.Uri, this.PathAndQuery).Purify() : null; + public Uri Uri => this.Node != null ? new Uri(this.Node.Uri, this.PathAndQuery) : null; public HttpMethod Method { get; private set; } public string PathAndQuery { get; } diff --git a/src/Elasticsearch.sln b/src/Elasticsearch.sln index 0a5730b1042..25f3338f911 100644 --- a/src/Elasticsearch.sln +++ b/src/Elasticsearch.sln @@ -22,6 +22,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "_Build", "_Build", "{432D55 ..\paket.bat = ..\paket.bat ..\paket.dependencies = ..\paket.dependencies ..\readme.md = ..\readme.md + outputpath.props = outputpath.props + ..\build\Elasticsearch.Net.Connections.HttpWebRequestConnection.nuspec = ..\build\Elasticsearch.Net.Connections.HttpWebRequestConnection.nuspec EndProjectSection EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "CodeGeneration", "CodeGeneration", "{93331BEE-0AA0-47B7-B1D2-BD5BD31634D1}" @@ -42,6 +44,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DocGenerator", "CodeGenerat EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nest.JsonNetSerializer", "Serializers\Nest.JsonNetSerializer\Nest.JsonNetSerializer.csproj", "{CDC8DEC8-3872-4337-9C40-9CDE5724BBDD}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Connections", "Connections", "{694887B9-6687-4AB1-BE30-2877656DF55D}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Elasticsearch.Net.Connections.HttpWebRequestConnection", "Connections\Elasticsearch.Net.Connections.HttpWebRequestConnection\Elasticsearch.Net.Connections.HttpWebRequestConnection.csproj", "{A44DBED2-D976-4CDE-8E26-DC60B49EF92F}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -74,6 +80,10 @@ Global {CDC8DEC8-3872-4337-9C40-9CDE5724BBDD}.Debug|Any CPU.Build.0 = Debug|Any CPU {CDC8DEC8-3872-4337-9C40-9CDE5724BBDD}.Release|Any CPU.ActiveCfg = Release|Any CPU {CDC8DEC8-3872-4337-9C40-9CDE5724BBDD}.Release|Any CPU.Build.0 = Release|Any CPU + {A44DBED2-D976-4CDE-8E26-DC60B49EF92F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A44DBED2-D976-4CDE-8E26-DC60B49EF92F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A44DBED2-D976-4CDE-8E26-DC60B49EF92F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A44DBED2-D976-4CDE-8E26-DC60B49EF92F}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -83,6 +93,7 @@ Global {D6997ADC-E933-418E-831C-DE1A78897493} = {432D5575-2347-4D3C-BF8C-3E38410C46CA} {98400F59-4BA8-4534-9A78-9C7FA0B42901} = {93331BEE-0AA0-47B7-B1D2-BD5BD31634D1} {CDC8DEC8-3872-4337-9C40-9CDE5724BBDD} = {14241027-0A92-466D-B024-E0063F338915} + {A44DBED2-D976-4CDE-8E26-DC60B49EF92F} = {694887B9-6687-4AB1-BE30-2877656DF55D} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {B3427E39-0C06-4A56-88E2-DCB730B82785} diff --git a/src/Nest/Aggregations/AggregateJsonConverter.cs b/src/Nest/Aggregations/AggregateJsonConverter.cs index f137961a480..9ae25dfdaa9 100644 --- a/src/Nest/Aggregations/AggregateJsonConverter.cs +++ b/src/Nest/Aggregations/AggregateJsonConverter.cs @@ -76,11 +76,7 @@ static AggregateJsonConverter() AllReservedAggregationNames = typeof(Parser) .GetFields(BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public) .Where(f => f.IsLiteral && !f.IsInitOnly) -#if DOTNETCORE .Select(f => (string)f.GetValue(null)) -#else - .Select(f => (string) f.GetRawConstantValue()) -#endif .ToArray(); var allKeys = string.Join(", ", AllReservedAggregationNames); diff --git a/src/Nest/Aggregations/Pipeline/MovingAverage/MovingAverageAggregationJsonConverter.cs b/src/Nest/Aggregations/Pipeline/MovingAverage/MovingAverageAggregationJsonConverter.cs index a588b1f0737..3a1b8a5b381 100644 --- a/src/Nest/Aggregations/Pipeline/MovingAverage/MovingAverageAggregationJsonConverter.cs +++ b/src/Nest/Aggregations/Pipeline/MovingAverage/MovingAverageAggregationJsonConverter.cs @@ -25,27 +25,19 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist Model = GetModel(ps) }; -#if DOTNETCORE - JToken value; - if (ps.TryGetValue("buckets_path", out value) && value != null) - { + if (ps.TryGetValue("buckets_path", out var value) && value != null) aggregation.BucketsPath = new SingleBucketsPath((string)value); - } else - { aggregation.BucketsPath = default(SingleBucketsPath); - } -#else - aggregation.BucketsPath = GetOrDefault("buckets_path", ps); -#endif + //TODO does this work on .NET core? + //aggregation.BucketsPath = GetOrDefault("buckets_path", ps); return aggregation; } public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) { - var movingAvg = value as IMovingAverageAggregation; - if (movingAvg == null) return; + if (!(value is IMovingAverageAggregation movingAvg)) return; writer.WriteStartObject(); writer.WritePropertyName("buckets_path"); serializer.Serialize(writer, movingAvg.BucketsPath); @@ -87,11 +79,9 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s private T GetOrDefault(string key, Dictionary properties) { if (!properties.ContainsKey(key)) return default(T); -#if DOTNETCORE return properties[key].ToObject(); -#else - return (T)Convert.ChangeType(properties[key], typeof(T)); -#endif + //TODO decide if this works too for .NET core, looks like it + //return (T)Convert.ChangeType(properties[key], typeof(T)); } private GapPolicy? GetGapPolicy(Dictionary properties) diff --git a/src/Nest/CommonAbstractions/Extensions/Extensions.cs b/src/Nest/CommonAbstractions/Extensions/Extensions.cs index c94bf02c70d..1c470da587e 100644 --- a/src/Nest/CommonAbstractions/Extensions/Extensions.cs +++ b/src/Nest/CommonAbstractions/Extensions/Extensions.cs @@ -112,11 +112,7 @@ internal static string ToEnumValue(this T enumValue) where T : struct return null; } -#if !DOTNETCORE - internal static string Utf8String(this byte[] bytes) => bytes == null ? null : Encoding.UTF8.GetString(bytes); -#else internal static string Utf8String(this byte[] bytes) => bytes == null ? null : Encoding.UTF8.GetString(bytes, 0, bytes.Length); -#endif internal static byte[] Utf8Bytes(this string s) { @@ -133,11 +129,7 @@ internal static bool IsNullOrEmpty(this IndexName value) } internal static bool IsValueType(this Type type) { -#if DOTNETCORE return type.GetTypeInfo().IsValueType; -#else - return type.IsValueType; -#endif } internal static void ThrowIfNullOrEmpty(this string @object, string parameterName, string when = null) diff --git a/src/Nest/CommonAbstractions/Extensions/TypeExtensions.cs b/src/Nest/CommonAbstractions/Extensions/TypeExtensions.cs index 1a96cb82f1f..b0a10533f05 100644 --- a/src/Nest/CommonAbstractions/Extensions/TypeExtensions.cs +++ b/src/Nest/CommonAbstractions/Extensions/TypeExtensions.cs @@ -160,13 +160,8 @@ private static IEnumerable AllPropertiesNotCached(this Type type) propertiesByName.Add(propertyInfo.Name, propertyInfo); } } -#if DOTNETCORE type = type.GetTypeInfo()?.BaseType; } while (type?.GetTypeInfo()?.BaseType != null); -#else - type = type.BaseType; - } while (type?.BaseType != null); -#endif return propertiesByName.Values; } @@ -175,11 +170,7 @@ private static IEnumerable AllPropertiesNotCached(this Type type) /// private static bool IsHidingMember(PropertyInfo propertyInfo) { -#if DOTNETCORE var baseType = propertyInfo.DeclaringType?.GetTypeInfo()?.BaseType; -#else - var baseType = propertyInfo.DeclaringType?.BaseType; -#endif var baseProperty = baseType?.GetProperty(propertyInfo.Name); if (baseProperty == null) return false; var derivedGetMethod = propertyInfo.GetGetMethod().GetBaseDefinition(); diff --git a/src/Nest/CommonAbstractions/SerializationBehavior/GenericJsonConverters/EnumMemberValueCasingJsonConverter.cs b/src/Nest/CommonAbstractions/SerializationBehavior/GenericJsonConverters/EnumMemberValueCasingJsonConverter.cs index 58268ab53b0..823503e4ddb 100644 --- a/src/Nest/CommonAbstractions/SerializationBehavior/GenericJsonConverters/EnumMemberValueCasingJsonConverter.cs +++ b/src/Nest/CommonAbstractions/SerializationBehavior/GenericJsonConverters/EnumMemberValueCasingJsonConverter.cs @@ -3,9 +3,7 @@ using System.Linq; using System.Runtime.Serialization; using Newtonsoft.Json; -#if DOTNETCORE using System.Reflection; -#endif namespace Nest { @@ -36,11 +34,7 @@ static EnumMemberValueCasingJsonConverter() foreach (var e in enums) { -#if DOTNETCORE var field = enumType.GetTypeInfo().GetDeclaredField(e.ToString()); -#else - var field = enumType.GetField(e.ToString()); -#endif var enumMemberValue = field.GetCustomAttributes(typeof(EnumMemberAttribute), true) .Cast() .Select(a => a.Value) diff --git a/src/Nest/CrossPlatform/SynchronizedCollection.cs b/src/Nest/CrossPlatform/SynchronizedCollection.cs index bba83c9fe7a..af4e1c84dbf 100644 --- a/src/Nest/CrossPlatform/SynchronizedCollection.cs +++ b/src/Nest/CrossPlatform/SynchronizedCollection.cs @@ -1,87 +1,71 @@ -#if DOTNETCORE -using System; -using System.Collections; -using System.Diagnostics; -using Nest; +using Nest; namespace System.Collections.Generic { + //TODO see if we can get rid of this [System.Runtime.InteropServices.ComVisible(false)] public class SynchronizedCollection : IList, IList { - List items; - object sync; + readonly List _items; + readonly object _sync; public SynchronizedCollection() { - this.items = new List(); - this.sync = new Object(); + this._items = new List(); + this._sync = new object(); } public SynchronizedCollection(object syncRoot) { - if (syncRoot == null) - throw new ArgumentNullException("syncRoot"); - - this.items = new List(); - this.sync = syncRoot; + this._sync = syncRoot ?? throw new ArgumentNullException(nameof(syncRoot)); + this._items = new List(); } public SynchronizedCollection(object syncRoot, IEnumerable list) { - if (syncRoot == null) - throw new ArgumentNullException("syncRoot"); - if (list == null) - throw new ArgumentNullException("list"); + if (list == null) throw new ArgumentNullException(nameof(list)); - this.items = new List(list); - this.sync = syncRoot; + this._items = new List(list); + this._sync = syncRoot ?? throw new ArgumentNullException(nameof(syncRoot)); } public SynchronizedCollection(object syncRoot, params T[] list) { if (syncRoot == null) - throw new ArgumentNullException("syncRoot"); + throw new ArgumentNullException(nameof(syncRoot)); if (list == null) - throw new ArgumentNullException("list"); + throw new ArgumentNullException(nameof(list)); - this.items = new List(list.Length); - for (int i = 0; i < list.Length; i++) - this.items.Add(list[i]); + this._items = new List(list.Length); + this._items.AddRange(list); - this.sync = syncRoot; + this._sync = syncRoot; } public int Count { - get { lock (this.sync) { return this.items.Count; } } + get { lock (this._sync) { return this._items.Count; } } } - protected List Items - { - get { return this.items; } - } + protected List Items => this._items; - public object SyncRoot - { - get { return this.sync; } - } + public object SyncRoot => this._sync; public T this[int index] { get { - lock (this.sync) + lock (this._sync) { - return this.items[index]; + return this._items[index]; } } set { - lock (this.sync) + lock (this._sync) { - if (index < 0 || index >= this.items.Count) + if (index < 0 || index >= this._items.Count) throw new ArgumentOutOfRangeException("index", index, $"value {index} must be in range of {this.Items.Count}"); this.SetItem(index, value); @@ -91,16 +75,16 @@ public T this[int index] public void Add(T item) { - lock (this.sync) + lock (this._sync) { - int index = this.items.Count; + var index = this._items.Count; this.InsertItem(index, item); } } public void Clear() { - lock (this.sync) + lock (this._sync) { this.ClearItems(); } @@ -108,31 +92,31 @@ public void Clear() public void CopyTo(T[] array, int index) { - lock (this.sync) + lock (this._sync) { - this.items.CopyTo(array, index); + this._items.CopyTo(array, index); } } public bool Contains(T item) { - lock (this.sync) + lock (this._sync) { - return this.items.Contains(item); + return this._items.Contains(item); } } public IEnumerator GetEnumerator() { - lock (this.sync) + lock (this._sync) { - return this.items.GetEnumerator(); + return this._items.GetEnumerator(); } } public int IndexOf(T item) { - lock (this.sync) + lock (this._sync) { return this.InternalIndexOf(item); } @@ -140,9 +124,9 @@ public int IndexOf(T item) public void Insert(int index, T item) { - lock (this.sync) + lock (this._sync) { - if (index < 0 || index > this.items.Count) + if (index < 0 || index > this._items.Count) throw new ArgumentOutOfRangeException("index", index, $"value {index} must be in range of {this.Items.Count}"); this.InsertItem(index, item); @@ -151,11 +135,11 @@ public void Insert(int index, T item) int InternalIndexOf(T item) { - int count = items.Count; + int count = _items.Count; for (int i = 0; i < count; i++) { - if (object.Equals(items[i], item)) + if (object.Equals(_items[i], item)) { return i; } @@ -165,7 +149,7 @@ int InternalIndexOf(T item) public bool Remove(T item) { - lock (this.sync) + lock (this._sync) { int index = this.InternalIndexOf(item); if (index < 0) @@ -178,9 +162,9 @@ public bool Remove(T item) public void RemoveAt(int index) { - lock (this.sync) + lock (this._sync) { - if (index < 0 || index >= this.items.Count) + if (index < 0 || index >= this._items.Count) throw new ArgumentOutOfRangeException("index", index, $"value {index} must be in range of {this.Items.Count}"); @@ -190,22 +174,22 @@ public void RemoveAt(int index) protected virtual void ClearItems() { - this.items.Clear(); + this._items.Clear(); } protected virtual void InsertItem(int index, T item) { - this.items.Insert(index, item); + this._items.Insert(index, item); } protected virtual void RemoveItem(int index) { - this.items.RemoveAt(index); + this._items.RemoveAt(index); } protected virtual void SetItem(int index, T item) { - this.items[index] = item; + this._items[index] = item; } bool ICollection.IsReadOnly @@ -215,24 +199,18 @@ bool ICollection.IsReadOnly IEnumerator IEnumerable.GetEnumerator() { - return ((IList)this.items).GetEnumerator(); + return ((IList)this._items).GetEnumerator(); } - bool ICollection.IsSynchronized - { - get { return true; } - } + bool ICollection.IsSynchronized => true; - object ICollection.SyncRoot - { - get { return this.sync; } - } + object ICollection.SyncRoot => this._sync; void ICollection.CopyTo(Array array, int index) { - lock (this.sync) + lock (this._sync) { - ((IList)this.items).CopyTo(array, index); + ((IList)this._items).CopyTo(array, index); } } @@ -263,7 +241,7 @@ int IList.Add(object value) { VerifyValueType(value); - lock (this.sync) + lock (this._sync) { this.Add((T)value); return this.Count - 1; @@ -294,7 +272,7 @@ void IList.Remove(object value) this.Remove((T)value); } - static void VerifyValueType(object value) + private static void VerifyValueType(object value) { if (value == null) { @@ -310,4 +288,3 @@ static void VerifyValueType(object value) } } } -#endif diff --git a/src/Nest/CrossPlatform/TypeExtensions.cs b/src/Nest/CrossPlatform/TypeExtensions.cs index 4dc4c718ef7..33f064733c4 100644 --- a/src/Nest/CrossPlatform/TypeExtensions.cs +++ b/src/Nest/CrossPlatform/TypeExtensions.cs @@ -10,20 +10,12 @@ internal static class DotNetCoreTypeExtensions { internal static bool IsGeneric(this Type type) { -#if DOTNETCORE return type.GetTypeInfo().IsGenericType; -#else - return type.IsGenericType; -#endif } internal static Assembly Assembly(this Type type) { -#if DOTNETCORE return type.GetTypeInfo().Assembly; -#else - return type.Assembly; -#endif } internal static bool IsGenericDictionary(this Type type) @@ -53,11 +45,7 @@ internal static bool TryGetGenericDictionaryArguments(this Type type, out Type[] internal static bool IsValue(this Type type) { -#if DOTNETCORE return type.GetTypeInfo().IsValueType; -#else - return type.IsValueType; -#endif } internal static bool IsClass(this Type type) @@ -71,9 +59,6 @@ internal static bool IsClass(this Type type) internal static TypeCode GetTypeCode(this Type type) { -#if !DOTNETCORE - return Type.GetTypeCode(type); -#else if (type == null) return TypeCode.Empty; else if (type == typeof(bool)) @@ -110,37 +95,24 @@ internal static TypeCode GetTypeCode(this Type type) return GetTypeCode(Enum.GetUnderlyingType(type)); else return TypeCode.Object; -#endif } -#if DOTNETCORE internal static bool IsAssignableFrom(this Type t, Type other) => t.GetTypeInfo().IsAssignableFrom(other.GetTypeInfo()); -#endif internal static bool IsEnumType(this Type type) { -#if DOTNETCORE return type.GetTypeInfo().IsEnum; -#else - return type.IsEnum; -#endif } -#if DOTNETCORE internal static IEnumerable GetInterfaces(this Type type) { return type.GetTypeInfo().ImplementedInterfaces; } -#endif internal static IEnumerable GetAttributes(this Type t) where TAttribute : Attribute { -#if !DOTNETCORE - var attributes = Attribute.GetCustomAttributes(t, typeof(TAttribute), true); -#else var attributes = t.GetTypeInfo().GetCustomAttributes(typeof(TAttribute), true); -#endif return attributes.Cast(); } } diff --git a/src/Nest/Nest.csproj b/src/Nest/Nest.csproj index 427e0aaabf0..e60831d0e88 100644 --- a/src/Nest/Nest.csproj +++ b/src/Nest/Nest.csproj @@ -2,19 +2,15 @@ - net45;net46;netstandard1.3 - netstandard1.3 - true + netstandard1.3 + + true - - - - - + diff --git a/src/Serializers/Nest.JsonNetSerializer/Nest.JsonNetSerializer.csproj b/src/Serializers/Nest.JsonNetSerializer/Nest.JsonNetSerializer.csproj index daedcacf11d..fbb71a17da8 100644 --- a/src/Serializers/Nest.JsonNetSerializer/Nest.JsonNetSerializer.csproj +++ b/src/Serializers/Nest.JsonNetSerializer/Nest.JsonNetSerializer.csproj @@ -2,14 +2,8 @@ - net45;net46;netstandard1.3 - netstandard1.3 - true - - - - - 2.0 + netstandard1.3 + diff --git a/src/Tests/ClientConcepts/Certificates/WorkingWithCertificates.doc.cs b/src/Tests/ClientConcepts/Certificates/WorkingWithCertificates.doc.cs index c513b9e276a..24a74ac9616 100644 --- a/src/Tests/ClientConcepts/Certificates/WorkingWithCertificates.doc.cs +++ b/src/Tests/ClientConcepts/Certificates/WorkingWithCertificates.doc.cs @@ -31,13 +31,11 @@ public class WorkingWithCertificates /** Imagine you deploy a web application that talks to Elasticsearch over HTTPS through NEST, and also uses some third party SOAP/WSDL endpoint; * by setting */ -#if !DOTNETCORE public void ServerValidationCallback() { ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, errors) => true; } -#endif /** * validation will not be performed for HTTPS connections to *both* Elasticsearch *and* that external web service. * @@ -171,7 +169,6 @@ protected override void AssertHttpRequestException(HttpRequestException e) * the local CA certificate is part of the chain that was used to generate the servers key. */ -#if !DOTNETCORE /** * ==== Client Certificates * @@ -184,21 +181,13 @@ protected override void AssertHttpRequestException(HttpRequestException e) * as one certificate. The easiest way to do this is to generate a `pfx` or `p12` file from the `.cer` and `.key` * and attach these to requests using `new X509Certificate(pathToPfx)`. * - * If you do not have a way to run `openssl` or `Pvk2Pfx` to do this as part of your deployments the clients ships with a handy helper to generate one - * on the fly by passing the paths to the `.cer` and `.key` files that `certutil` outputs. Sadly, this functonality is not available on .NET Core because - * the `PublicKey` property cannot be set on the crypto service provider that is used to generate the `pfx` file at runtime. + * You can pass a client certificate on `ConnectionSettings` for *all* requests. * - * You can set Client Certificates to use on all connections on `ConnectionSettings` */ public class PkiCluster : CertgenCaCluster { protected override ConnectionSettings Authenticate(ConnectionSettings s) => s // <1> Set the client certificate on `ConnectionSettings` - .ClientCertificate( - ClientCertificate.LoadWithPrivateKey( - this.Node.FileSystem.ClientCertificate, // <2> The path to the `.cer` file - this.Node.FileSystem.ClientPrivateKey, // <3> The path to the `.key` file - "") // <4> The password for the private key - ); + .ClientCertificate(new X509Certificate2(this.Node.FileSystem.ClientCertificate)); //hide protected override string[] AdditionalServerSettings => base.AdditionalServerSettings.Concat(new[] @@ -212,34 +201,24 @@ protected override ConnectionSettings Authenticate(ConnectionSettings s) => s // [IntegrationOnly] public class PkiApiTests : CanConnectTestBase { - public PkiApiTests(PkiCluster cluster, EndpointUsage usage) : base(cluster, usage) - { - } + public PkiApiTests(PkiCluster cluster, EndpointUsage usage) : base(cluster, usage) { } - [I] - public async Task UsedHttps() => await AssertOnAllResponses(r => r.ApiCall.Uri.Scheme.Should().Be("https")); + [I] public async Task UsedHttps() => await AssertOnAllResponses(r => r.ApiCall.Uri.Scheme.Should().Be("https")); } -#endif } -#if !DOTNETCORE /** - * Or per request on `RequestConfiguration` which will take precedence over the ones defined on `ConnectionConfiguration` + * Or on a per request basis on `RequestConfiguration` which will take precedence over the ones defined on `ConnectionConfiguration` */ - public class BadPkiCluster : WorkingWithCertificates.PkiCluster - { - } + public class BadPkiCluster : WorkingWithCertificates.PkiCluster { } [IntegrationOnly] public class BadCustomCertificatePerRequestWinsApiTests : ConnectionErrorTestBase { - public BadCustomCertificatePerRequestWinsApiTests(BadPkiCluster cluster, EndpointUsage usage) : base(cluster, usage) - { - } + public BadCustomCertificatePerRequestWinsApiTests(BadPkiCluster cluster, EndpointUsage usage) : base(cluster, usage) { } // hide - [I] - public async Task UsedHttps() => await AssertOnAllResponses(r => r.ApiCall.Uri.Scheme.Should().Be("https")); + [I] public async Task UsedHttps() => await AssertOnAllResponses(r => r.ApiCall.Uri.Scheme.Should().Be("https")); // a bad certificate // hide @@ -276,5 +255,4 @@ protected override void AssertHttpRequestException(HttpRequestException e) { } } -#endif } diff --git a/src/Tests/ClientConcepts/Connection/ConfigurationOptions.doc.cs b/src/Tests/ClientConcepts/Connection/ConfigurationOptions.doc.cs index e912f4550f6..7619acf528f 100644 --- a/src/Tests/ClientConcepts/Connection/ConfigurationOptions.doc.cs +++ b/src/Tests/ClientConcepts/Connection/ConfigurationOptions.doc.cs @@ -1,13 +1,8 @@ using System; -using System.IO; using Elasticsearch.Net; using Nest; using Tests.Framework.MockData; -#if DOTNETCORE -using System.Net.Http; -#endif - namespace Tests.ClientConcepts.Connection { public class ConfigurationOptions diff --git a/src/Tests/ClientConcepts/Connection/HttpConnectionTests.cs b/src/Tests/ClientConcepts/Connection/HttpConnectionTests.cs index e14e1f8ac4f..6abf2bdfe8e 100644 --- a/src/Tests/ClientConcepts/Connection/HttpConnectionTests.cs +++ b/src/Tests/ClientConcepts/Connection/HttpConnectionTests.cs @@ -1,5 +1,4 @@ -#if DOTNETCORE -using System; +using System; using System.Net.Http; using System.Threading; using System.Threading.Tasks; @@ -144,4 +143,3 @@ [I] public async Task HttpClientUseProxyShouldBeTrueWhenEnabledAutoProxyDetectio } } } -#endif diff --git a/src/Tests/ClientConcepts/Connection/ModifyingDefaultConnection.doc.cs b/src/Tests/ClientConcepts/Connection/ModifyingDefaultConnection.doc.cs index aa0a4cd2d5d..829ea9a5e1b 100644 --- a/src/Tests/ClientConcepts/Connection/ModifyingDefaultConnection.doc.cs +++ b/src/Tests/ClientConcepts/Connection/ModifyingDefaultConnection.doc.cs @@ -106,77 +106,5 @@ public void InMemoryConnectionOverloadedCtor() searchResponse.ShouldBeValid(); searchResponse.Documents.Count.Should().Be(25); } - /** - * ==== Changing HttpConnection - * - * There may be a need to change how the default `HttpConnection` works, for example, to add an X509 certificate - * to the request, change the maximum number of connections allowed to an endpoint, etc. - * - * By deriving from `HttpConnection`, it is possible to change the behaviour of the connection. The following - * provides some examples - * - * [[servicepoint-behaviour]] - * ===== ServicePoint behaviour - * - * If you are running on the Desktop CLR you can override specific properties for the current `ServicePoint` easily - * by overriding `AlterServicePoint` on an `IConnection` implementation deriving from `HttpConnection` - */ -#if !DOTNETCORE - public class MyCustomHttpConnection : HttpConnection - { - protected override void AlterServicePoint(ServicePoint requestServicePoint, RequestData requestData) - { - base.AlterServicePoint(requestServicePoint, requestData); - requestServicePoint.ConnectionLimit = 10000; - requestServicePoint.UseNagleAlgorithm = true; - } - } - - public void UseMyCustomHttpConnection() - { - var connection = new MyCustomHttpConnection(); - var connectionPool = new SingleNodeConnectionPool(new Uri("http://localhost:9200")); - var settings = new ConnectionSettings(connectionPool, connection); - var client = new ElasticClient(settings); - } - /** - * The Connection limit has been increased from the default 80 to much higher and - * https://en.wikipedia.org/wiki/Nagle's_algorithm[nagling] has been enabled, which is disabled by default in the client. - * - * NOTE: The client reuses TCP connections through .NET's internal connection pooling, - * so changing the connection limit to something really high should only be done with careful - * consideration and testing. It's demonstrated here only as an example. - * - * [[x509-certificates]] - * ===== X.509 Certificates - * - * It is possible to add X509 certificates to each request from the client by overriding the `CreateHttpWebRequest` - * method in an `IConnection` implementation deriving from `HttpConnection` - */ - public class X509CertificateHttpConnection : HttpConnection - { - protected override HttpWebRequest CreateHttpWebRequest(RequestData requestData) - { - var request = base.CreateHttpWebRequest(requestData); - request.ClientCertificates.Add(new X509Certificate("file_path_to_cert")); - return request; - } - } - - /** - * As before, a new instance of the custom connection is passed to `ConnectionSettings` in order to - * use - */ - public void UseX509CertificateHttpConnection() - { - var connection = new X509CertificateHttpConnection(); - var connectionPool = new SingleNodeConnectionPool(new Uri("http://localhost:9200")); - var settings = new ConnectionSettings(connectionPool, connection); - var client = new ElasticClient(settings); - } - /** - * See <> for further details. - */ -#endif } } diff --git a/src/Tests/ClientConcepts/ConnectionPooling/Exceptions/UnexpectedExceptions.doc.cs b/src/Tests/ClientConcepts/ConnectionPooling/Exceptions/UnexpectedExceptions.doc.cs index 9d2436fa7c7..20e0f0e6cf5 100644 --- a/src/Tests/ClientConcepts/ConnectionPooling/Exceptions/UnexpectedExceptions.doc.cs +++ b/src/Tests/ClientConcepts/ConnectionPooling/Exceptions/UnexpectedExceptions.doc.cs @@ -68,11 +68,7 @@ [U] public async Task WillFailOverKnowConnectionExceptionButNotUnexpected() { var audit = new Auditor(() => Framework.Cluster .Nodes(10) -#if DOTNETCORE .ClientCalls(r => r.OnPort(9200).FailAlways(new System.Net.Http.HttpRequestException("recover"))) -#else - .ClientCalls(r => r.OnPort(9200).FailAlways(new WebException("recover"))) // <1> calls on 9200 set up to throw a `WebException` -#endif .ClientCalls(r => r.OnPort(9201).FailAlways(new Exception("boom!"))) // <2> calls on 9201 set up to throw an `Exception` .StaticConnectionPool() .Settings(s => s.DisablePing()) diff --git a/src/Tests/ClientConcepts/ConnectionPooling/Sniffing/OnConnectionFailure.doc.cs b/src/Tests/ClientConcepts/ConnectionPooling/Sniffing/OnConnectionFailure.doc.cs index 4fcc7e22f3f..a20615dc69a 100644 --- a/src/Tests/ClientConcepts/ConnectionPooling/Sniffing/OnConnectionFailure.doc.cs +++ b/src/Tests/ClientConcepts/ConnectionPooling/Sniffing/OnConnectionFailure.doc.cs @@ -171,7 +171,7 @@ void SniffUrlAssert(Audit a, string host, int expectedPort) var sniffUri = new UriBuilder(a.Node.Uri) { Path = RequestPipeline.SniffPath, - Query = "?flat_settings=true&timeout=2s" + Query = "flat_settings=true&timeout=2s" }.Uri; sniffUri.PathEquals(a.Path, nameof(SniffUrlAssert)); } diff --git a/src/Tests/ClientConcepts/Exceptions/ExceptionTests.cs b/src/Tests/ClientConcepts/Exceptions/ExceptionTests.cs index d8f391799f3..4e876f0b017 100644 --- a/src/Tests/ClientConcepts/Exceptions/ExceptionTests.cs +++ b/src/Tests/ClientConcepts/Exceptions/ExceptionTests.cs @@ -26,12 +26,8 @@ public void ServerTestWhenThrowExceptionsEnabled() .ThrowExceptions(); var client = new ElasticClient(settings); var exception = Assert.Throws(() => client.GetMapping(s => s.Index("doesntexist"))); -#if DOTNETCORE // HttpClient does not throw on "known error" status codes (i.e. 404) thus the inner exception should not be set exception.InnerException.Should().BeNull(); -#else - exception.InnerException.Should().NotBeNull(); -#endif exception.Response.Should().NotBeNull(); } @@ -43,12 +39,8 @@ public void ClientTestWhenThrowExceptionsEnabled() var client = new ElasticClient(settings); var exception = Assert.Throws(() => client.RootNodeInfo()); var inner = exception.InnerException; -#if DOTNETCORE // HttpClient does not throw on "known error" status codes (i.e. 404) thus OriginalException should not be set inner.Should().BeNull(); -#else - inner.Should().NotBeNull(); -#endif } //[I] @@ -57,12 +49,8 @@ public void ServerTestWhenThrowExceptionsDisabled() var settings = new ConnectionSettings(TestClient.CreateUri(_port)); var client = new ElasticClient(settings); var response = client.GetMapping(s => s.Index("doesntexist")); -#if DOTNETCORE // HttpClient does not throw on "known error" status codes (i.e. 404) thus OriginalException should not be set response.ApiCall.OriginalException.Should().BeNull(); -#else - response.ApiCall.OriginalException.Should().NotBeNull(); -#endif } //[I] @@ -71,12 +59,8 @@ public void ClientTestWhenThrowExceptionsDisabled() var settings = new ConnectionSettings(new Uri("http://doesntexist:9200")); var client = new ElasticClient(settings); var response = client.RootNodeInfo(); -#if DOTNETCORE // HttpClient does not throw on "known error" status codes (i.e. 404) thus OriginalException should not be set response.ApiCall.OriginalException.Should().BeNull(); -#else - response.ApiCall.OriginalException.Should().NotBeNull(); -#endif } //TODO figure out a way to trigger this again diff --git a/src/Tests/CodeStandards/NamingConventions.doc.cs b/src/Tests/CodeStandards/NamingConventions.doc.cs index ce72837ac93..d99f6bfa57a 100644 --- a/src/Tests/CodeStandards/NamingConventions.doc.cs +++ b/src/Tests/CodeStandards/NamingConventions.doc.cs @@ -154,10 +154,8 @@ public void AllNestTypesAreInNestNamespace() { nestAssembly.GetType("System.AssemblyVersionInformation", throwOnError: false), nestAssembly.GetType("System.Runtime.Serialization.Formatters.FormatterAssemblyStyle", throwOnError: false), -#if DOTNETCORE typeof(SynchronizedCollection<>), nestAssembly.GetType("System.ComponentModel.Browsable", throwOnError: false) -#endif }; var types = nestAssembly.GetTypes(); @@ -190,9 +188,7 @@ public void AllElasticsearchNetTypesAreInElasticsearchNetNamespace() elasticsearchNetAssembly.GetType("Purify.Purifier+PurifierDotNet"), elasticsearchNetAssembly.GetType("Purify.Purifier+PurifierMono"), elasticsearchNetAssembly.GetType("Purify.Purifier+UriInfo"), -#if DOTNETCORE elasticsearchNetAssembly.GetType("System.ComponentModel.Browsable") -#endif }; var types = elasticsearchNetAssembly.GetTypes(); @@ -215,11 +211,7 @@ private static bool IsValidTypeNameOrIdentifier(string value, bool isTypeName) for (int index = 0; index < value.Length; ++index) { var character = value[index]; -#if DOTNETCORE var unicodeCategory = CharUnicodeInfo.GetUnicodeCategory(character); -#else - var unicodeCategory = char.GetUnicodeCategory(character); -#endif switch (unicodeCategory) { case UnicodeCategory.UppercaseLetter: diff --git a/src/Tests/Document/Multiple/Bulk/BulkDeserializationBenchmarkTests.cs b/src/Tests/Document/Multiple/Bulk/BulkDeserializationBenchmarkTests.cs index 3f021cecc05..7e50507c119 100644 --- a/src/Tests/Document/Multiple/Bulk/BulkDeserializationBenchmarkTests.cs +++ b/src/Tests/Document/Multiple/Bulk/BulkDeserializationBenchmarkTests.cs @@ -1,9 +1,5 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; using System.IO; using System.Linq; -using System.Reflection; using BenchmarkDotNet.Attributes; using Elasticsearch.Net; using Nest; @@ -12,9 +8,6 @@ using System.Text; using Tests.Framework.Benchmarks; -#if !DOTNETCORE -using System.Buffers; -#endif namespace Tests.Document.Multiple.Bulk { @@ -84,18 +77,6 @@ public BulkResponse HugeResponseWithString() return _jsonSerializer.Deserialize(reader); } -#if !DOTNETCORE - [Benchmark(Description = "deserialize 100,000 items in bulk string response with array pool")] - public BulkResponse HugeResponseWithStringAndArrayPool() - { - using (var reader = new JsonTextReader(new StringReader(Encoding.UTF8.GetString(_hugeResponse)))) - { - reader.ArrayPool = JsonArrayPool.Instance; - return _jsonSerializer.Deserialize(reader); - } - } -#endif - [Benchmark(Description = "Baseline", Baseline = true)] public BulkResponse Baseline() { @@ -140,23 +121,5 @@ private static object ReturnBulkResponse(int numberOfItems) }; } -#if !DOTNETCORE - public class JsonArrayPool : IArrayPool - { - public static readonly JsonArrayPool Instance = new JsonArrayPool(); - - public char[] Rent(int minimumLength) - { - // get char array from System.Buffers shared pool - return ArrayPool.Shared.Rent(minimumLength); - } - - public void Return(char[] array) - { - // return char array to System.Buffers shared pool - ArrayPool.Shared.Return(array); - } - } -#endif } } diff --git a/src/Tests/Document/Multiple/Bulk/BulkProfileTests.cs b/src/Tests/Document/Multiple/Bulk/BulkProfileTests.cs index fbfc804167a..f21297f52cb 100644 --- a/src/Tests/Document/Multiple/Bulk/BulkProfileTests.cs +++ b/src/Tests/Document/Multiple/Bulk/BulkProfileTests.cs @@ -1,8 +1,6 @@ using System; using System.Threading.Tasks; using Nest; -using Tests.Framework.Integration; -using Tests.Framework.ManagedElasticsearch; using Tests.Framework.ManagedElasticsearch.Clusters; using Tests.Framework.MockData; using Tests.Framework.Profiling.Performance; diff --git a/src/Tests/Document/Multiple/ReindexOnServer/ReindexOnServerRemoteApiTests.cs b/src/Tests/Document/Multiple/ReindexOnServer/ReindexOnServerRemoteApiTests.cs index 620ecfb875d..97c65395bc5 100644 --- a/src/Tests/Document/Multiple/ReindexOnServer/ReindexOnServerRemoteApiTests.cs +++ b/src/Tests/Document/Multiple/ReindexOnServer/ReindexOnServerRemoteApiTests.cs @@ -1,16 +1,9 @@ using System; -using System.Collections.Generic; -using System.Linq; using Elasticsearch.Net; -using FluentAssertions; using Nest; -using Purify; using Tests.Framework; using Tests.Framework.Integration; using Tests.Framework.ManagedElasticsearch.Clusters; -using Tests.Framework.MockData; -using Xunit; -using static Nest.Infer; namespace Tests.Document.Multiple.ReindexOnServer { diff --git a/src/Tests/Framework/Benchmarks/BenchmarkConfig.cs b/src/Tests/Framework/Benchmarks/BenchmarkConfig.cs index f565f82ad4c..8d8d4d6dda2 100644 --- a/src/Tests/Framework/Benchmarks/BenchmarkConfig.cs +++ b/src/Tests/Framework/Benchmarks/BenchmarkConfig.cs @@ -12,7 +12,6 @@ namespace Tests.Framework.Benchmarks { -#if NET46 public class CustomJsonExporter : BenchmarkDotNet.Exporters.ExporterBase { protected override string FileExtension => "json"; @@ -55,7 +54,7 @@ public override void ExportToLog(Summary summary, ILogger logger) return data; }); - + logger.WriteLine(JsonConvert.SerializeObject(new Dictionary { { "Title", summary.Title }, @@ -65,7 +64,6 @@ public override void ExportToLog(Summary summary, ILogger logger) })); } } -#endif public class BenchmarkConfigAttribute : Attribute, IConfigSource { public IConfig Config { get; } @@ -74,17 +72,13 @@ public BenchmarkConfigAttribute(int runCount = 1) { var jobs = new[] { Job.Dry.With(Runtime.Core).With(Jit.RyuJit).WithTargetCount(runCount), - Job.Dry.With(Runtime.Clr).With(Jit.RyuJit).WithTargetCount(runCount), + Job.Dry.With(Runtime.Clr).With(Jit.RyuJit).WithTargetCount(runCount), Job.Dry.With(Runtime.Clr).With(Jit.LegacyJit).WithTargetCount(runCount) }; -#if !NET46 - Config = DefaultConfig.Instance.With(jobs).With(JsonExporter.Brief); -#else Config = DefaultConfig.Instance .With(jobs) .With(new CustomJsonExporter()) .With(MemoryDiagnoser.Default); -#endif } } } diff --git a/src/Tests/Framework/Configuration/EnvironmentConfiguration.cs b/src/Tests/Framework/Configuration/EnvironmentConfiguration.cs index 3352684e260..c028bc2453b 100644 --- a/src/Tests/Framework/Configuration/EnvironmentConfiguration.cs +++ b/src/Tests/Framework/Configuration/EnvironmentConfiguration.cs @@ -41,6 +41,11 @@ public EnvironmentConfiguration() { SourceSerializer = RandomBoolConfig("SOURCESERIALIZER", randomizer), TypedKeys = RandomBoolConfig("TYPEDKEYS", randomizer), +#if FEATURE_HTTPWEBREQUEST + OldConnection = RandomBoolConfig("OLDCONNECTION", randomizer), +#else + OldConnection = false +#endif }; } diff --git a/src/Tests/Framework/Configuration/ITestConfiguration.cs b/src/Tests/Framework/Configuration/ITestConfiguration.cs index c2d625379d7..a8f7a172389 100644 --- a/src/Tests/Framework/Configuration/ITestConfiguration.cs +++ b/src/Tests/Framework/Configuration/ITestConfiguration.cs @@ -29,6 +29,7 @@ public class RandomConfiguration { public bool SourceSerializer { get; set; } public bool TypedKeys { get; set; } + public bool OldConnection { get; set; } } } diff --git a/src/Tests/Framework/Configuration/YamlConfiguration.cs b/src/Tests/Framework/Configuration/YamlConfiguration.cs index f2cf5b2b9fa..a5a9eaaaf87 100644 --- a/src/Tests/Framework/Configuration/YamlConfiguration.cs +++ b/src/Tests/Framework/Configuration/YamlConfiguration.cs @@ -39,7 +39,8 @@ public YamlConfiguration(string configurationFile) this.Random = new RandomConfiguration { SourceSerializer = RandomBool("source_serializer", randomizer), - TypedKeys = RandomBool("typed_keys", randomizer) + TypedKeys = RandomBool("typed_keys", randomizer), + OldConnection = RandomBool("old_connection", randomizer) }; } diff --git a/src/Tests/Framework/EndpointTests/ApiIntegrationTestBase.cs b/src/Tests/Framework/EndpointTests/ApiIntegrationTestBase.cs index cce2becda1c..6ba857fa54b 100644 --- a/src/Tests/Framework/EndpointTests/ApiIntegrationTestBase.cs +++ b/src/Tests/Framework/EndpointTests/ApiIntegrationTestBase.cs @@ -52,13 +52,6 @@ protected override Task AssertOnAllResponses(Action assert) }); } - private static bool IsNotRequestExceptionType(Type exceptionType) - { -#if DOTNETCORE - return exceptionType != typeof(System.Net.Http.HttpRequestException); -#else - return exceptionType != typeof(WebException); -#endif - } + private static bool IsNotRequestExceptionType(Type exceptionType) => exceptionType != typeof(System.Net.Http.HttpRequestException); } } diff --git a/src/Tests/Framework/Extensions/TypeExtensions.cs b/src/Tests/Framework/Extensions/TypeExtensions.cs index 6151bdea0b9..752837edc96 100644 --- a/src/Tests/Framework/Extensions/TypeExtensions.cs +++ b/src/Tests/Framework/Extensions/TypeExtensions.cs @@ -8,128 +8,74 @@ namespace Tests.Framework { public static class TypeExtensions { -#if DOTNETCORE internal static InterfaceMapping GetInterfaceMap(this Type t, Type interfaceType) => t.GetTypeInfo().GetRuntimeInterfaceMap(interfaceType); -#endif internal static bool IsInterface(this Type t) { -#if DOTNETCORE return t.GetTypeInfo().IsInterface; -#else - return t.IsInterface; -#endif } internal static bool IsGenericType(this Type type) { -#if DOTNETCORE return type.GetTypeInfo().IsGenericType; -#else - return type.IsGenericType; -#endif } internal static bool IsValueType(this Type type) { -#if DOTNETCORE return type.GetTypeInfo().IsValueType; -#else - return type.IsValueType; -#endif } internal static bool IsEnumType(this Type type) { -#if DOTNETCORE return type.GetTypeInfo().IsEnum; -#else - return type.IsEnum; -#endif } internal static Assembly Assembly(this Type type) { -#if DOTNETCORE return type.GetTypeInfo().Assembly; -#else - return type.Assembly; -#endif } internal static bool IsClass(this Type type) { -#if DOTNETCORE return type.GetTypeInfo().IsClass; -#else - return type.IsClass; -#endif } internal static bool IsAbstract(this Type type) { -#if DOTNETCORE return type.GetTypeInfo().IsAbstract; -#else - return type.IsAbstract; -#endif } internal static Type BaseType(this Type type) { -#if DOTNETCORE return type.GetTypeInfo().BaseType; -#else - return type.BaseType; -#endif } internal static bool IsSealed(this Type type) { -#if DOTNETCORE return type.GetTypeInfo().IsSealed; -#else - return type.IsSealed; -#endif } internal static bool IsVisible(this Type t) { -#if DOTNETCORE return t.GetTypeInfo().IsVisible; -#else - return t.IsVisible; -#endif } internal static bool IsPublic(this Type t) { -#if DOTNETCORE return t.GetTypeInfo().IsPublic; -#else - return t.IsPublic; -#endif } internal static IEnumerable GetAttributes(this Type t) where TAttribute : Attribute { -#if !DOTNETCORE - var attributes = Attribute.GetCustomAttributes(t, typeof(TAttribute), true); -#else var attributes = t.GetTypeInfo().GetCustomAttributes(typeof(TAttribute), true); -#endif return attributes.Cast(); } internal static IEnumerable GetAttributes(this MethodInfo m) where TAttribute : Attribute { -#if !DOTNETCORE - var attributes = Attribute.GetCustomAttributes(m, typeof(TAttribute), true); -#else var attributes = m.GetCustomAttributes(typeof(TAttribute), true); -#endif return attributes.Cast(); } } diff --git a/src/Tests/Framework/Extensions/UriExtensions.cs b/src/Tests/Framework/Extensions/UriExtensions.cs index d7ac339c9a0..f8c0fc46b85 100644 --- a/src/Tests/Framework/Extensions/UriExtensions.cs +++ b/src/Tests/Framework/Extensions/UriExtensions.cs @@ -28,7 +28,8 @@ public static void PathEquals(this Uri actualUri, string pathAndQueryString, str private static Uri CreateUri(Uri baseUri, Dictionary newQueryString) { - var uriBuilder = new UriBuilder(baseUri) {Query = FlattenQueryString(newQueryString)}; + var newQs = FlattenQueryString(newQueryString); + var uriBuilder = new UriBuilder(baseUri) {Query = newQs }; return uriBuilder.Uri; } @@ -97,7 +98,7 @@ private static Uri CreateExpectedUri(Uri u, string pathAndQueryString) private static string FlattenQueryString(Dictionary queryString) { if (queryString == null || queryString.Count == 0) return string.Empty; - return "?" + string.Join("&", queryString.Select(kv => $"{kv.Key}={kv.Value}")); + return string.Join("&", queryString.Select(kv => $"{kv.Key}={kv.Value}")); } private static Dictionary ExplodeQueryString(Uri u) diff --git a/src/Tests/Framework/Extensions/WaitHandleExtensions.cs b/src/Tests/Framework/Extensions/WaitHandleExtensions.cs index aa67b8c8dd5..b3fc3542b46 100644 --- a/src/Tests/Framework/Extensions/WaitHandleExtensions.cs +++ b/src/Tests/Framework/Extensions/WaitHandleExtensions.cs @@ -1,4 +1,3 @@ -#if DOTNETCORE using System; using System.Threading; using System.Diagnostics; @@ -18,4 +17,3 @@ internal static void Close(this Process process) } } } -#endif \ No newline at end of file diff --git a/src/Tests/Framework/Extensions/WebClient-CoreFx.cs b/src/Tests/Framework/Extensions/WebClient-CoreFx.cs index 657325f6481..6a5a55a7bd1 100644 --- a/src/Tests/Framework/Extensions/WebClient-CoreFx.cs +++ b/src/Tests/Framework/Extensions/WebClient-CoreFx.cs @@ -1,4 +1,3 @@ -#if DOTNETCORE using System; using System.IO; using System.Net.Http; @@ -19,4 +18,3 @@ public void DownloadFile(string url, string file) } } } -#endif \ No newline at end of file diff --git a/src/Tests/Framework/ManagedElasticsearch/Nodes/ElasticsearchNode.cs b/src/Tests/Framework/ManagedElasticsearch/Nodes/ElasticsearchNode.cs index 6c755f8b1c2..d09d3003182 100644 --- a/src/Tests/Framework/ManagedElasticsearch/Nodes/ElasticsearchNode.cs +++ b/src/Tests/Framework/ManagedElasticsearch/Nodes/ElasticsearchNode.cs @@ -1,24 +1,15 @@ using System; -using System.Collections.Concurrent; -using System.Collections.Generic; using System.Collections.Specialized; using System.IO; using System.Linq; using System.Reactive.Disposables; using System.Reactive.Linq; -using Bogus; using Elasticsearch.Net; using Nest; -using Newtonsoft.Json; -using Tests.Framework.Configuration; using Tests.Framework.Integration; using Tests.Framework.ManagedElasticsearch.Process; using Tests.Framework.ManagedElasticsearch.SourceSerializers; using Tests.Framework.Versions; -#if !DOTNETCORE -using XplatManualResetEvent = System.Threading.ManualResetEvent; - -#endif namespace Tests.Framework.ManagedElasticsearch.Nodes { diff --git a/src/Tests/Framework/ManagedElasticsearch/Nodes/NodeFileSystem.cs b/src/Tests/Framework/ManagedElasticsearch/Nodes/NodeFileSystem.cs index d196e63fc65..e4caa81c716 100644 --- a/src/Tests/Framework/ManagedElasticsearch/Nodes/NodeFileSystem.cs +++ b/src/Tests/Framework/ManagedElasticsearch/Nodes/NodeFileSystem.cs @@ -59,13 +59,6 @@ public NodeFileSystem(ElasticsearchVersion version, string clusterName, string n this.ElasticsearchHome = Path.Combine(this.RoamingFolder, this._version.FolderInZip); } - private static string GetApplicationDataDirectory() - { -#if DOTNETCORE - return Environment.GetEnvironmentVariable("APPDATA"); -#else - return Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); -#endif - } + private static string GetApplicationDataDirectory() => Environment.GetEnvironmentVariable("APPDATA"); } } diff --git a/src/Tests/Framework/ManagedElasticsearch/Process/XplatManualResetEvent.cs b/src/Tests/Framework/ManagedElasticsearch/Process/XplatManualResetEvent.cs index 90535ab24c5..9ed6024330e 100644 --- a/src/Tests/Framework/ManagedElasticsearch/Process/XplatManualResetEvent.cs +++ b/src/Tests/Framework/ManagedElasticsearch/Process/XplatManualResetEvent.cs @@ -1,4 +1,3 @@ -#if DOTNETCORE using System; using System.Threading; @@ -38,4 +37,3 @@ public bool WaitOne(TimeSpan timeout, bool exitContext) } } } -#endif diff --git a/src/Tests/Framework/ManagedElasticsearch/Tasks/InstallationTasks/EnsureJavaHomeEnvironmentVariableIsSet.cs b/src/Tests/Framework/ManagedElasticsearch/Tasks/InstallationTasks/EnsureJavaHomeEnvironmentVariableIsSet.cs index b4202266f93..472dae8009c 100644 --- a/src/Tests/Framework/ManagedElasticsearch/Tasks/InstallationTasks/EnsureJavaHomeEnvironmentVariableIsSet.cs +++ b/src/Tests/Framework/ManagedElasticsearch/Tasks/InstallationTasks/EnsureJavaHomeEnvironmentVariableIsSet.cs @@ -1,6 +1,4 @@ using System; -using Tests.Framework.Configuration; -using Tests.Framework.Integration; using Tests.Framework.ManagedElasticsearch.Nodes; namespace Tests.Framework.ManagedElasticsearch.Tasks.InstallationTasks @@ -9,12 +7,7 @@ public class EnsureJavaHomeEnvironmentVariableIsSet : InstallationTaskBase { public override void Run(NodeConfiguration config, NodeFileSystem fileSystem) { -#if DOTNETCORE var javaHome = Environment.GetEnvironmentVariable("JAVA_HOME"); -#else - var javaHome = Environment.GetEnvironmentVariable("JAVA_HOME", EnvironmentVariableTarget.Machine) - ?? Environment.GetEnvironmentVariable("JAVA_HOME", EnvironmentVariableTarget.User); -#endif if (string.IsNullOrWhiteSpace(javaHome)) throw new Exception("The elasticsearch bat files are resillient to JAVA_HOME not being set, however the shield tooling is not"); } diff --git a/src/Tests/Framework/ManagedElasticsearch/Tasks/InstallationTasks/InstallationTaskBase.cs b/src/Tests/Framework/ManagedElasticsearch/Tasks/InstallationTasks/InstallationTaskBase.cs index a8d4918dc2d..4a5613c88cc 100644 --- a/src/Tests/Framework/ManagedElasticsearch/Tasks/InstallationTasks/InstallationTaskBase.cs +++ b/src/Tests/Framework/ManagedElasticsearch/Tasks/InstallationTasks/InstallationTaskBase.cs @@ -1,14 +1,9 @@ using System; using System.IO; -using System.Net; using System.Threading.Tasks; -using Tests.Framework.Configuration; using Tests.Framework.Integration; using Tests.Framework.ManagedElasticsearch.Nodes; using Tests.Framework.ManagedElasticsearch.Process; -#if !DOTNETCORE -using XplatManualResetEvent = System.Threading.ManualResetEvent; -#endif namespace Tests.Framework.ManagedElasticsearch.Tasks.InstallationTasks { diff --git a/src/Tests/Framework/ManagedElasticsearch/Tasks/ValidationTasks/ValidateLicenseTask.cs b/src/Tests/Framework/ManagedElasticsearch/Tasks/ValidationTasks/ValidateLicenseTask.cs index ea9878abf94..ad5d8ae4f4b 100644 --- a/src/Tests/Framework/ManagedElasticsearch/Tasks/ValidationTasks/ValidateLicenseTask.cs +++ b/src/Tests/Framework/ManagedElasticsearch/Tasks/ValidationTasks/ValidateLicenseTask.cs @@ -17,11 +17,7 @@ public override void Validate(IElasticClient client, NodeConfiguration configura if (license.IsValid && license.License.Status == LicenseStatus.Active) return; var exceptionMessageStart = "Server has license plugin installed, "; -#if DOTNETCORE var licenseFile = Environment.GetEnvironmentVariable("ES_LICENSE_FILE"); -#else - var licenseFile = Environment.GetEnvironmentVariable("ES_LICENSE_FILE", EnvironmentVariableTarget.Machine); -#endif if (!string.IsNullOrWhiteSpace(licenseFile)) { var putLicense = client.PostLicense(new PostLicenseRequest diff --git a/src/Tests/Framework/Profiling/Memory/MemoryProfile.cs b/src/Tests/Framework/Profiling/Memory/MemoryProfile.cs index c5b525e651c..c8394dd4345 100644 --- a/src/Tests/Framework/Profiling/Memory/MemoryProfile.cs +++ b/src/Tests/Framework/Profiling/Memory/MemoryProfile.cs @@ -1,6 +1,6 @@ -#if !DOTNETCORE using System.IO; using System.Threading; +#if FEATURE_PROFILING using JetBrains.Profiler.Windows.Api; using JetBrains.Profiler.Windows.SelfApi; using JetBrains.Profiler.Windows.SelfApi.Config; diff --git a/src/Tests/Framework/Profiling/Memory/MemoryProfileFactory.cs b/src/Tests/Framework/Profiling/Memory/MemoryProfileFactory.cs index dbf1e7f7833..b9e6af32b40 100644 --- a/src/Tests/Framework/Profiling/Memory/MemoryProfileFactory.cs +++ b/src/Tests/Framework/Profiling/Memory/MemoryProfileFactory.cs @@ -1,4 +1,3 @@ -#if !DOTNETCORE using System; using System.Reflection; using Tests.Framework.Integration; @@ -24,4 +23,3 @@ protected override IDisposable BeginProfiling(string resultsDirectory) } } } -#endif diff --git a/src/Tests/Framework/Profiling/Performance/PerformanceProfile.cs b/src/Tests/Framework/Profiling/Performance/PerformanceProfile.cs index f7012f8e6e8..9b4efd44799 100644 --- a/src/Tests/Framework/Profiling/Performance/PerformanceProfile.cs +++ b/src/Tests/Framework/Profiling/Performance/PerformanceProfile.cs @@ -1,4 +1,3 @@ -#if !DOTNETCORE using System.IO; using System.Threading; using JetBrains.Profiler.Windows.Api; @@ -54,4 +53,3 @@ public override void Dispose() } } } -#endif diff --git a/src/Tests/Framework/Profiling/Performance/PerformanceProfileFactory.cs b/src/Tests/Framework/Profiling/Performance/PerformanceProfileFactory.cs index 357cf791895..4ceb1172cd0 100644 --- a/src/Tests/Framework/Profiling/Performance/PerformanceProfileFactory.cs +++ b/src/Tests/Framework/Profiling/Performance/PerformanceProfileFactory.cs @@ -1,4 +1,3 @@ -#if !DOTNETCORE using System; using System.Reflection; using Tests.Framework.Integration; @@ -24,4 +23,3 @@ protected override IDisposable BeginProfiling(string resultsDirectory) } } } -#endif diff --git a/src/Tests/Framework/Profiling/Profile.cs b/src/Tests/Framework/Profiling/Profile.cs index 8a5e46e6546..2ca4be4ce80 100644 --- a/src/Tests/Framework/Profiling/Profile.cs +++ b/src/Tests/Framework/Profiling/Profile.cs @@ -1,4 +1,3 @@ -#if !DOTNETCORE using System; using System.Collections.Generic; using System.Diagnostics; @@ -65,10 +64,9 @@ protected void WaitForProfilerToAttachToProcess() } else { - throw new ApplicationException($"Could not attach profiler to process after {WaitTime}"); + throw new Exception($"Could not attach profiler to process after {WaitTime}"); } } } } } -#endif diff --git a/src/Tests/Framework/Profiling/Timeline/TimelineProfile.cs b/src/Tests/Framework/Profiling/Timeline/TimelineProfile.cs index ef0250bff8b..e0c44014b1c 100644 --- a/src/Tests/Framework/Profiling/Timeline/TimelineProfile.cs +++ b/src/Tests/Framework/Profiling/Timeline/TimelineProfile.cs @@ -1,4 +1,3 @@ -#if !DOTNETCORE using System.IO; using JetBrains.Profiler.Windows.Api; using JetBrains.Profiler.Windows.SelfApi; @@ -44,4 +43,3 @@ public override void Dispose() } } } -#endif diff --git a/src/Tests/Framework/Profiling/Timeline/TimelineProfileFactory.cs b/src/Tests/Framework/Profiling/Timeline/TimelineProfileFactory.cs index fec43a336bd..1a4a48f9eeb 100644 --- a/src/Tests/Framework/Profiling/Timeline/TimelineProfileFactory.cs +++ b/src/Tests/Framework/Profiling/Timeline/TimelineProfileFactory.cs @@ -1,4 +1,3 @@ -#if !DOTNETCORE using System; using System.Reflection; using Tests.Framework.Integration; @@ -23,4 +22,3 @@ protected override IDisposable BeginProfiling(string resultsDirectory) } } } -#endif diff --git a/src/Tests/Framework/ProfilingMissing.cs b/src/Tests/Framework/ProfilingMissing.cs new file mode 100644 index 00000000000..eb973dfdee4 --- /dev/null +++ b/src/Tests/Framework/ProfilingMissing.cs @@ -0,0 +1,28 @@ +using System; + +#if !FEATURE_PROFILING +namespace Tests.Framework.Profiling.Performance +{ + public class PerformanceAttribute : Attribute + { + public int Iterations { get; set; } + } +} +namespace Tests.Framework.Profiling.Timeline +{ + public class TimelineAttribute : Attribute + { + public int Iterations { get; set; } + } +} + +namespace Tests.Framework.Profiling.Memory +{ + public class MemoryAttribute : Attribute { } +} + +namespace Tests.Framework.Profiling +{ + public class ProfilingSetupAttribute : Attribute { } +} +#endif diff --git a/src/Tests/Framework/TestClient.cs b/src/Tests/Framework/TestClient.cs index a884237c68b..9e3beb46bb9 100644 --- a/src/Tests/Framework/TestClient.cs +++ b/src/Tests/Framework/TestClient.cs @@ -13,6 +13,11 @@ using Tests.Framework.MockData; using Tests.Framework.Versions; +#if FEATURE_HTTPWEBREQUEST +using Elasticsearch.Net.Connections.HttpWebRequestConnection; +#endif + + namespace Tests.Framework { public static class TestClient @@ -44,8 +49,8 @@ private static ITestConfiguration LoadConfiguration() // If running the classic .NET solution, tests run from bin/{config} directory, // but when running DNX solution, tests run from the test project root var yamlConfigurationPath = (directoryInfo.Name == "Tests" - && directoryInfo.Parent != null - && directoryInfo.Parent.Name == "src") + && directoryInfo.Parent != null + && directoryInfo.Parent.Name == "src") ? "." : @"../../../"; @@ -62,8 +67,8 @@ private static ITestConfiguration LoadConfiguration() private static int ConnectionLimitDefault => int.TryParse(Environment.GetEnvironmentVariable("NEST_NUMBER_OF_CONNECTIONS"), out int x) - ? x - : ConnectionConfiguration.DefaultConnectionLimit; + ? x + : ConnectionConfiguration.DefaultConnectionLimit; private static ConnectionSettings DefaultSettings(ConnectionSettings settings) => settings .DefaultIndex("default-index") @@ -101,8 +106,7 @@ private static ConnectionSettings DefaultSettings(ConnectionSettings settings) = //hack to prevent the deprecation warnings from the deprecation response test to be reported if (!string.IsNullOrWhiteSpace(q) && q.Contains("routing=ignoredefaultcompletedhandler")) return; foreach (var d in r.DeprecationWarnings) SeenDeprecations.Add(d); - }) - .OnRequestDataCreated(data => data.Headers.Add("TestMethod", ExpensiveTestNameForIntegrationTests())); + }); public static string PercolatorType => Configuration.ElasticsearchVersion <= ElasticsearchVersion.Create("5.0.0-alpha1") ? ".percolator" @@ -119,7 +123,6 @@ private static bool VersionSatisfiedBy(string range, ElasticsearchVersion versio //anything else fails but we want to know e.g 2.4.5-SNAPSHOT satisfied by <5.0.0; var wholeVersion = $"{version.Major}.{version.Minor}.{version.Patch}"; return versionRange.IsSatisfied(wholeVersion); - } public static bool VersionUnderTestSatisfiedBy(string range) => @@ -143,16 +146,15 @@ public static ConnectionSettings CreateSettings( { if (sourceSerializerFactory != null) return sourceSerializerFactory(builtin, values); - return !Configuration.Random.SourceSerializer - ? null - : new TestSourceSerializerBase(builtin, values); + return !Configuration.Random.SourceSerializer + ? null + : new TestSourceSerializerBase(builtin, values); }, propertyMappingProvider); var defaultSettings = DefaultSettings(s); modifySettings = modifySettings ?? ((m) => { - //only enable debug mode when running in DEBUG mode (always) or optionally wheter we are executing unit tests //during RELEASE builds tests #if !DEBUG @@ -178,7 +180,7 @@ public static IElasticClient GetInMemoryClientWithSourceSerializer( new ElasticClient( CreateSettings(modifySettings, forceInMemory: true, sourceSerializerFactory: sourceSerializerFactory, propertyMappingProvider: propertyMappingProvider) - ); + ); public static IElasticClient GetClient( Func modifySettings = null, @@ -192,14 +194,21 @@ public static IElasticClient GetClient( public static IElasticClient GetClient( Func createPool, Func modifySettings = null, - int port = 9200) => new ElasticClient(CreateSettings(modifySettings, port, forceInMemory: false, createPool: createPool)); public static IConnection CreateConnection(ConnectionSettings settings = null, bool forceInMemory = false) => - Configuration.RunIntegrationTests && !forceInMemory - ? ((IConnection) new HttpConnection()) - : new InMemoryConnection(); + Configuration.RunIntegrationTests && !forceInMemory ? CreateLiveConnection() : new InMemoryConnection(); + + private static IConnection CreateLiveConnection() + { +#if FEATURE_HTTPWEBREQUEST + if (Configuration.Random.OldConnection) return new HttpWebRequestConnection(); + return new HttpConnection(); +#else + return new HttpConnection(); +#endif + } public static IElasticClient GetFixedReturnClient( object response, @@ -222,8 +231,10 @@ public static ConnectionSettings GetFixedReturnSettings( var serializer = Default.RequestResponseSerializer; byte[] fixedResult = null; if (response is string s) fixedResult = Encoding.UTF8.GetBytes(s); - else if (contentType == RequestData.MimeType) fixedResult = serializer.SerializeToBytes(response); - else fixedResult = Encoding.UTF8.GetBytes(response.ToString()); + else if (contentType == RequestData.MimeType) + fixedResult = serializer.SerializeToBytes(response); + else + fixedResult = Encoding.UTF8.GetBytes(response.ToString()); var connection = new InMemoryConnection(fixedResult, statusCode, exception, contentType); var connectionPool = new SingleNodeConnectionPool(new Uri("http://localhost:9200")); @@ -232,35 +243,5 @@ public static ConnectionSettings GetFixedReturnSettings( var settings = (modifySettings != null) ? modifySettings(defaultSettings) : defaultSettings; return settings; } - - private static string ExpensiveTestNameForIntegrationTests() - { - if (!Configuration.RunIntegrationTests) return "ignore"; - -#if DOTNETCORE - return "UNKNOWN"; -#else - var st = new StackTrace(); - var types = GetTypes(st); - var name = types - .LastOrDefault(type => type.FullName.StartsWith("Tests.") && !type.FullName.StartsWith("Tests.Framework.")); - return name?.FullName ?? string.Join(": ", types.Select(n => n.Name)); -#endif - } - -#if !DOTNETCORE - - private static List GetTypes(StackTrace st) - { - var types = (from f in st.GetFrames() - let method = f.GetMethod() - where method != null - let type = method.DeclaringType - where type != null - select type).ToList(); - return types; - } - -#endif } } diff --git a/src/Tests/Framework/VirtualClustering/Rules/ClientCallRule.cs b/src/Tests/Framework/VirtualClustering/Rules/ClientCallRule.cs index fb6713fc099..728e9590191 100644 --- a/src/Tests/Framework/VirtualClustering/Rules/ClientCallRule.cs +++ b/src/Tests/Framework/VirtualClustering/Rules/ClientCallRule.cs @@ -16,12 +16,7 @@ public ClientCallRule Fails(Union times, Union errorState = null) } public ClientCallRule ThrowsAfterSucceeds() { - Self.AfterSucceeds = - #if DOTNETCORE - new System.Net.Http.HttpRequestException(); - #else - new WebException(); - #endif + Self.AfterSucceeds = new System.Net.Http.HttpRequestException(); return this; } diff --git a/src/Tests/Framework/VirtualClustering/VirtualClusterConnection.cs b/src/Tests/Framework/VirtualClustering/VirtualClusterConnection.cs index 33af37c6f42..f9ea3138cef 100644 --- a/src/Tests/Framework/VirtualClustering/VirtualClusterConnection.cs +++ b/src/Tests/Framework/VirtualClustering/VirtualClusterConnection.cs @@ -77,11 +77,7 @@ public override TResponse Request(RequestData requestData) CallResponse ); } -#if DOTNETCORE catch (System.Net.Http.HttpRequestException e) -#else - catch (WebException e) -#endif { return ResponseBuilder.ToResponse(requestData, e, null, null, Stream.Null); } @@ -133,11 +129,7 @@ private TResponse Always(RequestData requestData, TimeSpan tim var time = timeout < rule.Takes.Value ? timeout: rule.Takes.Value; this._dateTimeProvider.ChangeTime(d=> d.Add(time)); if (rule.Takes.Value > requestData.RequestTimeout) -#if DOTNETCORE throw new System.Net.Http.HttpRequestException($"Request timed out after {time} : call configured to take {rule.Takes.Value} while requestTimeout was: {timeout}"); -#else - throw new WebException($"Request timed out after {time} : call configured to take {rule.Takes.Value} while requestTimeout was: {timeout}"); -#endif } return rule.Succeeds @@ -155,11 +147,7 @@ private TResponse Sometimes( var time = timeout < rule.Takes.Value ? timeout : rule.Takes.Value; this._dateTimeProvider.ChangeTime(d=> d.Add(time)); if (rule.Takes.Value > requestData.RequestTimeout) -#if DOTNETCORE throw new System.Net.Http.HttpRequestException($"Request timed out after {time} : call configured to take {rule.Takes.Value} while requestTimeout was: {timeout}"); -#else - throw new WebException($"Request timed out after {time} : call configured to take {rule.Takes.Value} while requestTimeout was: {timeout}"); -#endif } if (rule.Succeeds && times >= state.Successes) @@ -183,11 +171,7 @@ private TResponse Fail(RequestData requestData, TRule rule, Un var ret = returnOverride ?? rule.Return; if (ret == null) -#if DOTNETCORE throw new System.Net.Http.HttpRequestException(); -#else - throw new WebException(); -#endif return ret.Match( (e) => throw e, (statusCode) => this.ReturnConnectionStatus(requestData, CallResponse(rule), diff --git a/src/Tests/Framework/Xunit/NestTestFramework.cs b/src/Tests/Framework/Xunit/NestTestFramework.cs index 24f0824f685..f9acf5d4264 100644 --- a/src/Tests/Framework/Xunit/NestTestFramework.cs +++ b/src/Tests/Framework/Xunit/NestTestFramework.cs @@ -42,6 +42,7 @@ protected override ITestFrameworkExecutor CreateExecutor(AssemblyName assemblyNa WriteLine($" - Random:"); WriteLine($" \t- {nameof(config.Random.SourceSerializer)}: {config.Random.SourceSerializer}"); WriteLine($" \t- {nameof(config.Random.TypedKeys)}: {config.Random.TypedKeys}"); + WriteLine($" \t- {nameof(config.Random.OldConnection)}: {config.Random.OldConnection}"); WriteLine(new string('-', 20)); diff --git a/src/Tests/Framework/Xunit/TestAssemblyRunner.cs b/src/Tests/Framework/Xunit/TestAssemblyRunner.cs index d752ceb3da2..9d0548d472b 100644 --- a/src/Tests/Framework/Xunit/TestAssemblyRunner.cs +++ b/src/Tests/Framework/Xunit/TestAssemblyRunner.cs @@ -202,11 +202,7 @@ private IEnumerable ParseExcludedClusters(string clusterFilter) private static IEnumerable GetAllClustersFromAssembly() { var clusters = -#if DOTNETCORE typeof(ClusterBase).Assembly() -#else - typeof(ClusterBase).Assembly -#endif .GetTypes() .Where(t => typeof(ClusterBase).IsAssignableFrom(t) && t != typeof(ClusterBase)) .Select(c => c.Name.Replace("Cluster", "").ToLowerInvariant()); diff --git a/src/Tests/Framework/Xunit/TestFrameworkExecutor.cs b/src/Tests/Framework/Xunit/TestFrameworkExecutor.cs index 2ca77e2c60b..b3b064a88f6 100644 --- a/src/Tests/Framework/Xunit/TestFrameworkExecutor.cs +++ b/src/Tests/Framework/Xunit/TestFrameworkExecutor.cs @@ -5,6 +5,7 @@ using System.Text; using System.Threading; using Tests.Framework; +using Tests.Framework.Configuration; using Xunit.Abstractions; using Xunit.Sdk; @@ -77,8 +78,11 @@ private static void DumpReproduceFilters(TestAssemblyRunner runner) var sb = new StringBuilder("build ") .Append($"seed:{config.Seed} "); - AppendExplictConfig("SourceSerializer", sb); - AppendExplictConfig("TypedKeys", sb); + AppendExplictConfig(nameof(RandomConfiguration.SourceSerializer), sb); + AppendExplictConfig(nameof(RandomConfiguration.TypedKeys), sb); +#if FEATURE_HTTPWEBREQUEST + AppendExplictConfig(nameof(RandomConfiguration.OldConnection), sb); +#endif if (runningIntegrations) sb.Append("integrate ") diff --git a/src/Tests/Program.cs b/src/Tests/Program.cs index 3753d0d1ed7..dab738b6b90 100644 --- a/src/Tests/Program.cs +++ b/src/Tests/Program.cs @@ -60,8 +60,8 @@ static BenchmarkProgram() private const string SelfProfileSdkDirectory = "dottrace-selfprofile"; - private static string SdkPath { get; } - private static string OutputPath { get; } + private static string SdkPath { get; } + private static string OutputPath { get; } public static void Main(string[] args) { @@ -71,10 +71,7 @@ public static void Main(string[] args) var arguments = args.Skip(1).ToArray(); if (args[0].Equals("Profile", StringComparison.OrdinalIgnoreCase)) { -#if DOTNETCORE - Console.Error.WriteLine("DotTrace Profiling is not currently supported on .NET Core"); - return; -#else +#if FEATURE_PROFILING var configuration = ProfileConfiguration.Parse(arguments); Console.WriteLine("Running Profiling with the following:"); Console.WriteLine($"- SdkPath: {SdkPath}"); @@ -89,6 +86,11 @@ public static void Main(string[] args) profilingFactory.RunAsync(configuration).Wait(); } } +#else + Console.ForegroundColor = ConsoleColor.Red; + Console.WriteLine("Tests.exe is not built with Profiling support"); + Console.ResetColor(); + Environment.Exit(9); #endif } else if (args[0].Equals("Benchmark", StringComparison.OrdinalIgnoreCase)) @@ -110,15 +112,14 @@ public static void Main(string[] args) } } -#if !DOTNETCORE +#if FEATURE_PROFILING private static IEnumerable CreateProfilingFactory(ClusterBase cluster) { - yield return new PerformanceProfileFactory(SdkPath, OutputPath, cluster, Assembly.GetExecutingAssembly(), new ColoredConsoleWriter()); - yield return new TimelineProfileFactory(SdkPath, OutputPath, cluster, Assembly.GetExecutingAssembly(), new ColoredConsoleWriter()); - yield return new MemoryProfileFactory(SdkPath, OutputPath, cluster, Assembly.GetExecutingAssembly(), new ColoredConsoleWriter()); + yield return new PerformanceProfileFactory(SdkPath, OutputPath, cluster, Assembly.GetEntryAssembly(), new ColoredConsoleWriter()); + yield return new TimelineProfileFactory(SdkPath, OutputPath, cluster, Assembly.GetEntryAssembly(), new ColoredConsoleWriter()); + yield return new MemoryProfileFactory(SdkPath, OutputPath, cluster, Assembly.GetEntryAssembly(), new ColoredConsoleWriter()); } #endif - private static Type[] GetBenchmarkTypes() { IEnumerable types; diff --git a/src/Tests/Reproduce/ConnectionReuseAndBalancing.cs b/src/Tests/Reproduce/ConnectionReuseAndBalancing.cs index 513ef3e431a..c58e8b5caa5 100644 --- a/src/Tests/Reproduce/ConnectionReuseAndBalancing.cs +++ b/src/Tests/Reproduce/ConnectionReuseAndBalancing.cs @@ -20,13 +20,8 @@ public class ConnectionReuseCluster : ClusterBase { } public class ConnectionReuseAndBalancing : IClusterFixture { - - private static bool IsCurlHandler { get; } = - #if DOTNETCORE - typeof(HttpClientHandler).Assembly().GetType("System.Net.Http.CurlHandler") != null; - #else - false; - #endif + + private static bool IsCurlHandler { get; } = typeof(HttpClientHandler).Assembly().GetType("System.Net.Http.CurlHandler") != null; private readonly ConnectionReuseCluster _cluster; @@ -78,7 +73,7 @@ private static void AssertHttpStats(IElasticClient c, INodesStatsResponse r, int if (!IsCurlHandler) { - //on non curl connections we expect full connection reuse + //on non curl connections we expect full connection reuse //we allow some leeway on the maxOpened because of connections setup and teared down //during the initial bootstrap procudure from the test framework getting the cluster up. iterationMax = maxCurrent + leeWay; @@ -99,7 +94,7 @@ private static void AssertHttpStats(IElasticClient c, INodesStatsResponse r, int } } - private async Task IndexMockData(IElasticClient c, int requestsPerIteration) + private async Task IndexMockData(IElasticClient c, int requestsPerIteration) { var tokenSource = new CancellationTokenSource(); await c.DeleteIndexAsync(Index(), cancellationToken: tokenSource.Token); diff --git a/src/Tests/Reproduce/GithubIssue2052.cs b/src/Tests/Reproduce/GithubIssue2052.cs index 6f2c48a04cf..070822b89c2 100644 --- a/src/Tests/Reproduce/GithubIssue2052.cs +++ b/src/Tests/Reproduce/GithubIssue2052.cs @@ -72,20 +72,6 @@ private IEnumerable ExceptionJson(Exception e) int maxExceptions = 20; do { -#if !DOTNETCORE - var si = new SerializationInfo(e.GetType(), new FormatterConverter()); - var sc = new StreamingContext(); - e.GetObjectData(si, sc); - - var helpUrl = si.GetString("HelpURL"); - var stackTrace = si.GetString("StackTraceString"); - var remoteStackTrace = si.GetString("RemoteStackTraceString"); - var remoteStackIndex = si.GetInt32("RemoteStackIndex"); - var exceptionMethod = si.GetString("ExceptionMethod"); - var hresult = si.GetInt32("HResult"); - var source = si.GetString("Source"); - var className = si.GetString("ClassName"); -#else var helpUrl = e.HelpLink; var stackTrace = e.StackTrace; var remoteStackTrace = string.Empty; @@ -94,7 +80,6 @@ private IEnumerable ExceptionJson(Exception e) var hresult = e.HResult; var source = e.Source; var className = string.Empty; -#endif yield return new { @@ -107,9 +92,7 @@ private IEnumerable ExceptionJson(Exception e) RemoteStackIndex = remoteStackIndex, HResult = hresult, HelpURL = helpUrl, -#if !DOTNETCORE && !__MonoCS__ - ExceptionMethod = this.WriteStructuredExceptionMethod(exceptionMethod) -#endif + //ExceptionMethod = this.WriteStructuredExceptionMethod(exceptionMethod) }; depth++; e = e.InnerException; diff --git a/src/Tests/Tests.csproj b/src/Tests/Tests.csproj index 32a50620a54..f59ed0b7424 100644 --- a/src/Tests/Tests.csproj +++ b/src/Tests/Tests.csproj @@ -2,31 +2,43 @@ Exe - - - 1 - netcoreapp1.1;net45;net46 - netcoreapp1.1 + netcoreapp2.0;net46 + netcoreapp2.0 6.0.0 alpha - $(DefineConstants);DOTNETCORE Tests.BenchmarkProgram $(NoWarn);xUnit1013 + $(DefineConstants);FEATURE_HTTPWEBREQUEST + $(DefineConstants);FEATURE_PROFILING ../../build/output/_packages;https://api.nuget.org/v3/index.json $(DefineConstants);TESTINGNUGETPACKAGE - - + + + + + - - - + + + + + + + + + + + @@ -38,23 +50,10 @@ - - - - - - - - - - - - - - - + + diff --git a/src/Tests/tests.default.yaml b/src/Tests/tests.default.yaml index c28c0fc98a0..58fa596c747 100644 --- a/src/Tests/tests.default.yaml +++ b/src/Tests/tests.default.yaml @@ -18,4 +18,5 @@ elasticsearch_version: 6.0.0 test_against_already_running_elasticsearch: true #random_source_serializer: true +#random_old_connection: true seed: 69819 diff --git a/src/build/Clients.Common.targets b/src/build/Clients.Common.targets deleted file mode 100644 index a8ad7e34695..00000000000 --- a/src/build/Clients.Common.targets +++ /dev/null @@ -1,46 +0,0 @@ - - - - - 0.0.0-bad - 0.0.0 - 0.0.0.0 - - 1 - - - - - $(CurrentVersion) - $(CurrentVersion) - - $(CurrentAssemblyVersion) - - $(CurrentAssemblyFileVersion) - - true - ..\..\build\keys\keypair.snk - true - 1591,1572,1571,1573,1587,1570 - false - $(DefineConstants);DOTNETCORE - embedded - full - $(BaseIntermediateOutputPath)\sl-$(MsBuildProjectName)-$(TargetFramework).json - https://raw.githubusercontent.com/elastic/elasticsearch-net - - - - - - - - - - - - - diff --git a/src/outputpath.props b/src/outputpath.props index 04e4b70743e..e6c18e04f5e 100644 --- a/src/outputpath.props +++ b/src/outputpath.props @@ -1,4 +1,4 @@ - + $(OutputPathBaseDir)\$(MSBuildProjectName)\