Skip to content

Commit

Permalink
Merge pull request #207 from pengweiqhca/main
Browse files Browse the repository at this point in the history
Change Microsoft.AspNet.WebApi.Client => System.Net.Http.Json on netstandard
  • Loading branch information
pengweiqhca authored Sep 26, 2022
2 parents ba08630 + 3d222d2 commit c2baf6b
Show file tree
Hide file tree
Showing 35 changed files with 485 additions and 392 deletions.
3 changes: 2 additions & 1 deletion Apollo.AspNet.Demo/Global.asax.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Com.Ctrip.Framework.Apollo;
using Com.Ctrip.Framework.Apollo.ConfigAdapter;
using Com.Ctrip.Framework.Apollo.Enums;
using Microsoft.Extensions.Configuration;
using System;
using System.Configuration;
using System.Web;
Expand Down Expand Up @@ -29,4 +30,4 @@ protected void Application_Start(object sender, EventArgs e)
.AddDefault()
.Build();
}
}
}
4 changes: 3 additions & 1 deletion Apollo.AspNet.Demo/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using Apollo.AspNet.Demo;
using Microsoft.Owin;
using Owin;
using System;
using System.Configuration;
using System.Threading.Tasks;
Expand Down Expand Up @@ -30,4 +32,4 @@ public void Configuration(IAppBuilder app)
return context.Response.WriteAsync((useLegend ? "ConfigurationManager: " : "Configuration: ") + (value ?? "undefined"));
});
}
}
}
2 changes: 1 addition & 1 deletion Apollo.AspNet.Demo/Web.config
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<!-- Change to the actual app id -->
<add key="Apollo:AppId" value="apollo.net" />
<add key="Apollo:EnablePlaceholder" value="true" />
<add key="Apollo:Secret" value="ffd9d01130ee4329875ac3441c0bedda" />
<add key="Apollo:Secret" value="f55faf3729e14866ac5fc2bed2293643" />
<add key="Apollo:MetaServer" value="http://106.54.227.205:8080/" />
<!-- 上面一行和下面2选1 -->
<add key="Apollo:Env" value="Dev" />
Expand Down
2 changes: 1 addition & 1 deletion Apollo.AspNetCore.Demo/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"commandName": "IISExpress",
"environmentVariables": {
"DOTNET_Apollo:MetaServer": "http://106.54.227.205:8080/",
"DOTNET_Apollo:Secret": "ffd9d01130ee4329875ac3441c0bedda",
"DOTNET_Apollo:Secret": "f55faf3729e14866ac5fc2bed2293643",
"DOTNET_ENVIRONMENT": "Development",
"DOTNET_Apollo:AppId": "apollo.net",
"DOTNET_Apollo:Namespaces:4": "application",
Expand Down
12 changes: 6 additions & 6 deletions Apollo.ConfigAdapter.Yaml.Tests/YamlConfigAdapterTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ public void NullTest()

Assert.Equal(6, properties.GetPropertyNames().Count);

Assert.Empty(properties.GetProperty("environments:dev:url"));
Assert.Empty(properties.GetProperty("environments:dev:url2"));
Assert.Empty(properties.GetProperty("environments:dev:url3"));
Assert.Empty(properties.GetProperty("environments:dev:url4"));
Assert.Empty(properties.GetProperty("environments:dev:url") ?? "null");
Assert.Empty(properties.GetProperty("environments:dev:url2") ?? "null");
Assert.Empty(properties.GetProperty("environments:dev:url3") ?? "null");
Assert.Empty(properties.GetProperty("environments:dev:url4") ?? "null");
Assert.Equal("`", properties.GetProperty("environments:dev:url5"));
Assert.Empty(properties.GetProperty("environments:dev:name"));
Assert.Empty(properties.GetProperty("environments:dev:name") ?? "null");
}

[Fact]
Expand Down Expand Up @@ -103,4 +103,4 @@ public void MergeKeysTest()
Assert.Equal("10", properties.GetProperty("sample2:r"));
Assert.Equal("100", properties.GetProperty("sample3:r"));
}
}
}
2 changes: 1 addition & 1 deletion Apollo.ConfigAdapter.Yaml/Apollo.ConfigAdapter.Yaml.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
$(PackageReleaseNotes)</Description>
<PackageTags>$(PackageTags) yml yaml</PackageTags>
<RootNamespace>Com.Ctrip.Framework.Apollo.ConfigAdapter</RootNamespace>
<TargetFrameworks>net40;net45;netstandard2.0</TargetFrameworks>
<TargetFrameworks>net40;net45;netstandard2.0;netstandard2.1</TargetFrameworks>
<Version>$(ApolloVersion).0</Version>
</PropertyGroup>

Expand Down
4 changes: 2 additions & 2 deletions Apollo.Configuration.Demo/ConfigurationDemo.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Microsoft.Extensions.Options;
using Newtonsoft.Json;
using System.Text.Json;

namespace Apollo.Configuration.Demo;

Expand Down Expand Up @@ -48,7 +48,7 @@ public string GetConfig(string key)

private static void OnChanged(Value value, string name)
{
Console.WriteLine(name + " has changed: " + JsonConvert.SerializeObject(value));
Console.WriteLine(name + " has changed: " + JsonSerializer.Serialize(value));
}

private class Value
Expand Down
2 changes: 1 addition & 1 deletion Apollo.Configuration.Demo/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"AppId": "apollo.net",
"Cluster": "test",
"MetaServer": "http://localhost:8080/",
"Secret": "ffd9d01130ee4329875ac3441c0bedda",
"Secret": "f55faf3729e14866ac5fc2bed2293643",
"Namespaces": [ "application.xml", "application.json", "application.yml", "application.yaml", "application" ],
"Env": "Dev",
"Meta": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"Apollo:AppId": "apollo.net",
"Apollo:Cluster": "test",
"Apollo:EnablePlaceholder": "true",
"Apollo:Secret": "ffd9d01130ee4329875ac3441c0bedda",
"Apollo:Secret": "f55faf3729e14866ac5fc2bed2293643",
"Apollo:MetaServer": "http://106.54.227.205:8080/"
}
}
Expand Down
2 changes: 1 addition & 1 deletion Apollo.ConfigurationManager.Tests/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<appSettings configBuilders="AppSettingsSectionBuilder">
<add key="Apollo:AppId" value="apollo.net" />
<add key="Apollo:EnablePlaceholder" value="true" />
<add key="Apollo:Secret" value="ffd9d01130ee4329875ac3441c0bedda" />
<add key="Apollo:Secret" value="f55faf3729e14866ac5fc2bed2293643" />
<add key="Apollo:MetaServer" value="http://106.54.227.205:8080/" />
<add key="Apollo:SpecialDelimiter" value="." />
</appSettings>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Http" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Http" Version="3.1.0" />

<ProjectReference Include="..\Apollo.OpenApi\Apollo.OpenApi.csproj" />
</ItemGroup>
Expand Down
3 changes: 1 addition & 2 deletions Apollo.OpenApi.Tests/Apollo.OpenApi.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="2.*" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.*" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.*" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.*" />
<PackageReference Include="xunit" Version="2.*" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.*" />
Expand Down
7 changes: 5 additions & 2 deletions Apollo.OpenApi.Tests/AppClusterTest.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
using Com.Ctrip.Framework.Apollo.Core;
using Com.Ctrip.Framework.Apollo.OpenApi;
using Com.Ctrip.Framework.Apollo.OpenApi.Model;
using Xunit;
using Xunit.Abstractions;

namespace Com.Ctrip.Framework.Apollo;
namespace Apollo.OpenApi.Tests;

public class AppClusterTest : BaseTest
{
Expand All @@ -22,6 +23,8 @@ public async Task GetEnvClusterInfo()

Assert.NotNull(@default);

Assert.NotNull(@default.Clusters);

Assert.Contains(ConfigConsts.ClusterNameDefault, @default.Clusters);
}

Expand Down Expand Up @@ -72,6 +75,6 @@ public async Task GetNamespaces()

Assert.NotNull(result);
Assert.Contains(result, ns => ns.NamespaceName == ConfigConsts.NamespaceApplication);
Assert.NotEmpty(result.First(ns => ns.NamespaceName == ConfigConsts.NamespaceApplication).Items);
Assert.NotEmpty(result.FirstOrDefault(ns => ns.NamespaceName == ConfigConsts.NamespaceApplication)?.Items ?? Array.Empty<Item>());
}
}
2 changes: 1 addition & 1 deletion Apollo.OpenApi.Tests/BaseTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using Newtonsoft.Json;
using Xunit.Abstractions;

namespace Com.Ctrip.Framework.Apollo;
namespace Apollo.OpenApi.Tests;

public abstract class BaseTest
{
Expand Down
4 changes: 2 additions & 2 deletions Apollo.OpenApi.Tests/NamespaceClientTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using Xunit;
using Xunit.Abstractions;

namespace Com.Ctrip.Framework.Apollo;
namespace Apollo.OpenApi.Tests;

public class NamespaceClientTest : BaseTest
{
Expand Down Expand Up @@ -122,4 +122,4 @@ public async Task ReleaseTest()

await client.Rollback("apollo", 26864).ConfigureAwait(false);
}
}
}
34 changes: 17 additions & 17 deletions Apollo.OpenApi.Tests/OpenApiFactoryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using Microsoft.Extensions.DependencyInjection;
using Xunit;

namespace Com.Ctrip.Framework.Apollo;
namespace Apollo.OpenApi.Tests;

public class OpenApiFactoryTest
{
Expand All @@ -14,10 +14,10 @@ public async Task ExceptionTest()
try
{
await new OpenApiFactory(new()
{
PortalUrl = new("http://106.54.227.205:8070"),
Token = Guid.NewGuid().ToString("N")
})
{
PortalUrl = new("http://106.54.227.205:8070"),
Token = Guid.NewGuid().ToString("N")
})
.CreateAppClusterClient("abc").GetAppInfo()
.ConfigureAwait(false);
}
Expand All @@ -29,10 +29,10 @@ public async Task ExceptionTest()
try
{
await new OpenApiFactory(new()
{
PortalUrl = new("http://106.54.227.205:8070"),
Token = "19419f7d3e5a1b0b0cfe3e238b36e09718fb8e94"
})
{
PortalUrl = new("http://106.54.227.205:8070"),
Token = "19419f7d3e5a1b0b0cfe3e238b36e09718fb8e94"
})
.CreateAppClusterClient("abc").GetAppInfo()
.ConfigureAwait(false);
}
Expand All @@ -44,10 +44,10 @@ public async Task ExceptionTest()
try
{
await new OpenApiFactory(new()
{
PortalUrl = new("http://106.54.227.205:8070"),
Token = "19419f7d3e5a1b0b0cfe3e238b36e09718fb8e94"
})
{
PortalUrl = new("http://106.54.227.205:8070"),
Token = "19419f7d3e5a1b0b0cfe3e238b36e09718fb8e94"
})
.CreateNamespaceClient("apollo.net", "PRO", "test", "test")
.GetNamespaceInfo()
.ConfigureAwait(false);
Expand All @@ -60,10 +60,10 @@ public async Task ExceptionTest()
try
{
await new OpenApiFactory(new()
{
PortalUrl = new("http://106.54.227.205:8070"),
Token = "19419f7d3e5a1b0b0cfe3e238b36e09718fb8e94"
})
{
PortalUrl = new("http://106.54.227.205:8070"),
Token = "19419f7d3e5a1b0b0cfe3e238b36e09718fb8e94"
})
.CreateNamespaceClient("apollo.net", "DEV", "test", "test")
.GetNamespaceInfo()
.ConfigureAwait(false);
Expand Down
15 changes: 13 additions & 2 deletions Apollo/Apollo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ $(PackageReleaseNotes)</Description>
<Compile Update="Resources.Designer.cs">
<DependentUpon>Resources.resx</DependentUpon>
</Compile>

<PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="5.*" Condition="'$(TargetFramework)' != 'net40'" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net40'">
Expand All @@ -65,4 +63,17 @@ $(PackageReleaseNotes)</Description>
<Reference Include="System.Web" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net45'">
<PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="5.*" />

<Reference Include="System.Web" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETStandard'">
<PackageReference Include="System.Net.Http.Json" Version="6.*" />

<Using Include="System.Net.Http.Json" />
<Using Include="System.Text.Json" />
</ItemGroup>

</Project>
6 changes: 3 additions & 3 deletions Apollo/CacheFileProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ public class LocalPlaintextCacheFileProvider : ICacheFileProvider
{
if (!File.Exists(configFile)) return null;

using var reader = new StreamReader(configFile, Encoding.UTF8);
using var reader = new FileStream(configFile, FileMode.Open);

return new (reader);
return new(reader);
}

public void Save(string configFile, Properties properties)
{
using var file = new StreamWriter(configFile, false, Encoding.UTF8);
using var file = new FileStream(configFile, FileMode.Create);

properties.Store(file);
}
Expand Down
Loading

0 comments on commit c2baf6b

Please sign in to comment.