Skip to content
This repository has been archived by the owner on May 17, 2019. It is now read-only.

Commit

Permalink
Added Stylecop
Browse files Browse the repository at this point in the history
  • Loading branch information
dtillman committed Dec 14, 2017
1 parent ee838e5 commit c46d9c7
Show file tree
Hide file tree
Showing 95 changed files with 1,758 additions and 1,749 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ dotnet: 2.0.0
os:
- linux
- osx
osx_image: xcode8.2
osx_image: xcode8.3
branches:
only:
- master
Expand Down
7 changes: 4 additions & 3 deletions config/versions-dev.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
<PropertyGroup>
<SteeltoeVersion>$(STEELTOE_VERSION)</SteeltoeVersion>
<SteeltoeVersionSuffix>$(STEELTOE_DASH_VERSION_SUFFIX)</SteeltoeVersionSuffix>
<SteeltoeCommonVersion>2.0.0-dev-00024</SteeltoeCommonVersion>
<SteeltoeCommonVersion>2.0.0-dev-00040</SteeltoeCommonVersion>
<AspNetCoreVersion>2.0.0</AspNetCoreVersion>
<AspNetCoreTestVersion>2.0.0</AspNetCoreTestVersion>
<AspNetCoreMvcTestVersion>2.0.0</AspNetCoreMvcTestVersion>
<AspNetCoreDepTestVersion>2.0.0</AspNetCoreDepTestVersion>
<CoreFxVersion>4.4.0</CoreFxVersion>
<JsonNetVersion>10.0.1</JsonNetVersion>
<TestSdkVersion>15.3.0</TestSdkVersion>
<StyleCopVersion>1.0.2</StyleCopVersion>
<JsonNetVersion>10.0.3</JsonNetVersion>
<TestSdkVersion>15.5.0</TestSdkVersion>
<XunitVersion>2.3.1</XunitVersion>
<XunitStudioVersion>2.3.1</XunitStudioVersion>
</PropertyGroup>
Expand Down
7 changes: 4 additions & 3 deletions config/versions-master.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
<SteeltoeVersion>$(STEELTOE_VERSION)</SteeltoeVersion>
<SteeltoeVersionSuffix>$(STEELTOE_DASH_VERSION_SUFFIX)</SteeltoeVersionSuffix>
<AspNetCoreVersion>2.0.0</AspNetCoreVersion>
<SteeltoeCommonVersion>2.0.0-master-00024</SteeltoeCommonVersion>
<SteeltoeCommonVersion>2.0.0-master-00041</SteeltoeCommonVersion>
<AspNetCoreTestVersion>2.0.0</AspNetCoreTestVersion>
<AspNetCoreMvcTestVersion>2.0.0</AspNetCoreMvcTestVersion>
<AspNetCoreDepTestVersion>2.0.0</AspNetCoreDepTestVersion>
<CoreFxVersion>4.4.0</CoreFxVersion>
<JsonNetVersion>10.0.1</JsonNetVersion>
<TestSdkVersion>15.3.0</TestSdkVersion>
<StyleCopVersion>1.0.2</StyleCopVersion>
<JsonNetVersion>10.0.3</JsonNetVersion>
<TestSdkVersion>15.5.0</TestSdkVersion>
<XunitVersion>2.3.1</XunitVersion>
<XunitStudioVersion>2.3.1</XunitStudioVersion>
</PropertyGroup>
Expand Down
3 changes: 2 additions & 1 deletion config/versions-update.props
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
<AspNetCoreMvcTestVersion>1.1.3</AspNetCoreMvcTestVersion>
<AspNetCoreDepTestVersion>1.1.1</AspNetCoreDepTestVersion>
<CoreFxVersion>4.3.0</CoreFxVersion>
<StyleCopVersion>1.0.2</StyleCopVersion>
<JsonNetVersion>9.0.1</JsonNetVersion>
<TestSdkVersion>15.3.0</TestSdkVersion>
<TestSdkVersion>15.5.0</TestSdkVersion>
<XunitVersion>2.3.1</XunitVersion>
<XunitStudioVersion>2.3.1</XunitStudioVersion>
</PropertyGroup>
Expand Down
5 changes: 3 additions & 2 deletions config/versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
<AspNetCoreMvcTestVersion>2.0.0</AspNetCoreMvcTestVersion>
<AspNetCoreDepTestVersion>2.0.0</AspNetCoreDepTestVersion>
<CoreFxVersion>4.4.0</CoreFxVersion>
<JsonNetVersion>10.0.1</JsonNetVersion>
<TestSdkVersion>15.3.0</TestSdkVersion>
<StyleCopVersion>1.0.2</StyleCopVersion>
<JsonNetVersion>10.0.3</JsonNetVersion>
<TestSdkVersion>15.5.0</TestSdkVersion>
<XunitVersion>2.3.1</XunitVersion>
<XunitStudioVersion>2.3.1</XunitStudioVersion>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
using Autofac;
// Copyright 2017 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using Autofac;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Options;
using Steeltoe.Common.Discovery;
using Steeltoe.Common.Options.Autofac;
using Steeltoe.Discovery.Eureka;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace Steeltoe.Discovery.Client
Expand All @@ -22,19 +34,20 @@ public static void RegisterDiscoveryClient(this ContainerBuilder container, Disc
{
throw new ArgumentNullException(nameof(container));
}

if (discoveryOptions == null)
{
throw new ArgumentNullException(nameof(discoveryOptions));
}


if (discoveryOptions.ClientType == DiscoveryClientType.EUREKA)
{
EurekaClientOptions clientOptions = discoveryOptions.ClientOptions as EurekaClientOptions;
if (clientOptions == null)
{
throw new ArgumentException("Missing Client Options");
}

container.RegisterInstance(new OptionsMonitorWrapper<EurekaClientOptions>(clientOptions)).As<IOptionsMonitor<EurekaClientOptions>>().SingleInstance();

var regOptions = discoveryOptions.RegistrationOptions as EurekaInstanceOptions;
Expand All @@ -43,6 +56,7 @@ public static void RegisterDiscoveryClient(this ContainerBuilder container, Disc
clientOptions.ShouldRegisterWithEureka = false;
regOptions = new EurekaInstanceOptions();
}

container.RegisterInstance(new OptionsMonitorWrapper<EurekaInstanceOptions>(regOptions)).As<IOptionsMonitor<EurekaInstanceOptions>>().SingleInstance();

AddEurekaServices(container, lifecycle);
Expand All @@ -51,7 +65,6 @@ public static void RegisterDiscoveryClient(this ContainerBuilder container, Disc
{
throw new ArgumentException("Client type UNKNOWN");
}

}

public static void RegisterDiscoveryClient(this ContainerBuilder container, Action<DiscoveryOptions> setupOptions, IDiscoveryLifecycle lifecycle = null)
Expand All @@ -70,7 +83,6 @@ public static void RegisterDiscoveryClient(this ContainerBuilder container, Acti
setupOptions(options);

container.RegisterDiscoveryClient(options, lifecycle);

}

public static void RegisterDiscoveryClient(this ContainerBuilder container, IConfiguration config, IDiscoveryLifecycle lifecycle = null)
Expand All @@ -86,8 +98,6 @@ public static void RegisterDiscoveryClient(this ContainerBuilder container, ICon
}

AddDiscoveryServices(container, config, lifecycle);


}

public static void StartDiscoveryClient(this IContainer container)
Expand Down Expand Up @@ -121,28 +131,27 @@ private static void AddDiscoveryServices(ContainerBuilder container, IConfigurat
{
throw new ArgumentException("Discovery client type UNKNOWN, check configuration");
}

}

private static void AddEurekaServices(ContainerBuilder container, IDiscoveryLifecycle lifecycle)
{

container.RegisterType<EurekaApplicationInfoManager>().SingleInstance();
container.RegisterType<EurekaDiscoveryManager>().SingleInstance();
container.RegisterType<EurekaDiscoveryClient>().AsSelf().As<IDiscoveryClient>().SingleInstance();

if (lifecycle == null)
{
container.RegisterType<ApplicationLifecycle>().As<IDiscoveryLifecycle>();
} else
}
else
{
container.RegisterInstance(lifecycle).SingleInstance();
}
}

public class ApplicationLifecycle : IDiscoveryLifecycle
{
CancellationTokenSource source = new CancellationTokenSource();
private CancellationTokenSource source = new CancellationTokenSource();

public ApplicationLifecycle()
{
Expand All @@ -165,10 +174,12 @@ public CancellationToken ApplicationStopping
public class OptionsMonitorWrapper<T> : IOptionsMonitor<T>
{
private T _option;

public OptionsMonitorWrapper(T option)
{
_option = option;
}

public T CurrentValue => _option;

public T Get(string name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
<PackageLicenseUrl>http://www.apache.org/licenses/LICENSE-2.0</PackageLicenseUrl>
</PropertyGroup>

<PropertyGroup>
<NoWarn>SA1101;SA1124;SA1201;SA1309;SA1310;SA1401;SA1600;SA1652;1591</NoWarn>
</PropertyGroup>

<ItemGroup Condition="'$(CI_BUILD)' == ''">
<ProjectReference Include="..\Steeltoe.Discovery.Eureka.Client\Steeltoe.Discovery.Eureka.Client.csproj" />
</ItemGroup>
Expand All @@ -27,7 +31,15 @@
<ItemGroup>
<PackageReference Include="Steeltoe.Common" Version="$(SteeltoeCommonVersion)" />
<PackageReference Include="Steeltoe.Common.Autofac" Version="$(SteeltoeCommonVersion)" />
<PackageReference Include="StyleCop.Analyzers" Version="$(StyleCopVersion)">
<PrivateAssets>All</PrivateAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<AdditionalFiles Include="..\..\stylecop.json">
<Link>stylecop.json</Link>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</AdditionalFiles>
</ItemGroup>

</Project>

Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//
// Copyright 2015 the original author or authors.
// Copyright 2017 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -12,7 +11,6 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
Expand All @@ -22,7 +20,6 @@ namespace Steeltoe.Discovery.Client
{
public static class DiscoveryApplicationBuilderExtensions
{

public static IApplicationBuilder UseDiscoveryClient(this IApplicationBuilder app)
{
var service = app.ApplicationServices.GetRequiredService<IDiscoveryClient>();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//
// Copyright 2017 the original author or authors.
// Copyright 2017 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -12,7 +11,6 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
Expand All @@ -26,7 +24,6 @@

namespace Steeltoe.Discovery.Client
{

public static class DiscoveryServiceCollectionExtensions
{
public const string EUREKA_PREFIX = "eureka";
Expand All @@ -37,12 +34,12 @@ public static IServiceCollection AddDiscoveryClient(this IServiceCollection serv
{
throw new ArgumentNullException(nameof(services));
}

if (discoveryOptions == null)
{
throw new ArgumentNullException(nameof(discoveryOptions));
}


if (discoveryOptions.ClientType == DiscoveryClientType.EUREKA)
{
EurekaClientOptions clientOptions = discoveryOptions.ClientOptions as EurekaClientOptions;
Expand All @@ -54,7 +51,7 @@ public static IServiceCollection AddDiscoveryClient(this IServiceCollection serv
services.AddSingleton<IOptionsMonitor<EurekaClientOptions>>(new OptionsMonitorWrapper<EurekaClientOptions>(clientOptions));

var regOptions = discoveryOptions.RegistrationOptions as EurekaInstanceOptions;
if (regOptions == null)
if (regOptions == null)
{
clientOptions.ShouldRegisterWithEureka = false;
regOptions = new EurekaInstanceOptions();
Expand Down Expand Up @@ -88,10 +85,8 @@ public static IServiceCollection AddDiscoveryClient(this IServiceCollection serv
setupOptions(options);

return services.AddDiscoveryClient(options);

}


public static IServiceCollection AddDiscoveryClient(this IServiceCollection services, IConfiguration config, IDiscoveryLifecycle lifecycle = null)
{
if (services == null)
Expand All @@ -107,8 +102,8 @@ public static IServiceCollection AddDiscoveryClient(this IServiceCollection serv
AddDiscoveryServices(services, config, lifecycle);

return services;

}

private static void AddDiscoveryServices(IServiceCollection services, IConfiguration config, IDiscoveryLifecycle lifecycle)
{
var clientConfigsection = config.GetSection(EUREKA_PREFIX);
Expand All @@ -130,7 +125,6 @@ private static void AddDiscoveryServices(IServiceCollection services, IConfigura
{
throw new ArgumentException("Discovery client type UNKNOWN, check configuration");
}

}

private static void AddEurekaServices(IServiceCollection services, IDiscoveryLifecycle lifecycle)
Expand All @@ -142,32 +136,34 @@ private static void AddEurekaServices(IServiceCollection services, IDiscoveryLif
if (lifecycle == null)
{
services.AddSingleton<IDiscoveryLifecycle, ApplicationLifecycle>();
} else
}
else
{
services.AddSingleton(lifecycle);
}

services.AddSingleton<IDiscoveryClient>((p) => p.GetService<EurekaDiscoveryClient>());
}

public class ApplicationLifecycle : IDiscoveryLifecycle
{

public ApplicationLifecycle(IApplicationLifetime lifeCycle)
{
ApplicationStopping = lifeCycle.ApplicationStopping;
}

public CancellationToken ApplicationStopping { get; set; }

}

public class OptionsMonitorWrapper<T> : IOptionsMonitor<T>
{
private T _option;

public OptionsMonitorWrapper(T option)
{
_option = option;
}

public T CurrentValue => _option;

public T Get(string name)
Expand Down
16 changes: 15 additions & 1 deletion src/Steeltoe.Discovery.ClientCore/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
using System.Runtime.CompilerServices;
// Copyright 2017 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using System.Runtime.CompilerServices;

[assembly: InternalsVisibleTo("Steeltoe.Discovery.ClientCore.Test")]
[assembly: InternalsVisibleTo("Pivotal.Discovery.ClientCore.Test")]
Loading

0 comments on commit c46d9c7

Please sign in to comment.