Skip to content

Commit 5f2491b

Browse files
committed
update style cop and enable nullable issue #10
1 parent 4027963 commit 5f2491b

28 files changed

Lines changed: 464 additions & 386 deletions

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ The solution contains the following:
2626
Or
2727

2828
```cmd
29-
dotnet add package CometD.NetCore.Salesforce
29+
dotnet add package CometD.NetCore.Salesforce
3030
```
3131

3232
- To Install Salesforce Cli tool globally run the following command:

build/dependecies.props

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@
6060
<PackageReference Update="xunit.runner.visualstudio" Version="2.4.1" />
6161
</ItemGroup>
6262

63+
<ItemGroup Label="Analyzers">
64+
<PackageReference Include="Bet.CodeAnalyzers" Version="1.0.7" PrivateAssets="All" />
65+
</ItemGroup>
66+
6367
<ItemGroup Label="SourceLink">
6468
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0-beta2-18618-05" PrivateAssets="All" />
6569
</ItemGroup>

build/settings.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<IsPackable>true</IsPackable>
55
<VersionPrefix>2.2.0-preview</VersionPrefix>
66
<LangVersion>latest</LangVersion>
7+
<Nullable>disable</Nullable>
78
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
89
<SuppressNETCoreSdkPreviewMessage>true</SuppressNETCoreSdkPreviewMessage>
910
<NoWarn>$(NoWarn);CS1591</NoWarn>

src/AuthApp/AuthApp.csproj

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,12 @@
1616
<PackageReference Include="Bet.Extensions.Options" />
1717
<PackageReference Include="Colorful.Console" />
1818
<PackageReference Include="McMaster.Extensions.CommandLineUtils" />
19-
<PackageReference Include="Microsoft.AspNetCore.Hosting.Server.Abstractions" />
20-
<PackageReference Include="Microsoft.AspNetCore.Http" />
2119
<PackageReference Include="Microsoft.Extensions.Configuration.CommandLine" />
2220
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" />
2321
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" />
2422
<PackageReference Include="Microsoft.Extensions.Hosting" />
25-
<PackageReference Include="NetCoreForce.Client" />
2623
<PackageReference Include="TextCopy" />
24+
<PackageReference Include="NetCoreForce.Client" />
2725
</ItemGroup>
2826
<ItemGroup>
2927
<Content Include="appsettings*.json" CopyToOutputDirectory="PreserveNewest" />

src/AuthApp/Host/HttpServer.cs

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ namespace AuthApp.Host
1919
{
2020
/// <summary>
2121
/// Web Server OAuth Authentication Flow
22-
/// https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/intro_understanding_web_server_oauth_flow.htm
22+
/// https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/intro_understanding_web_server_oauth_flow.htm.
2323
/// </summary>
2424
internal class HttpServer : BackgroundService
2525
{
@@ -84,6 +84,7 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)
8484
{
8585
Console.WriteLine($"OAuth authorization error: {context.Request.QueryString.Get("error")}.", Color.Red);
8686
}
87+
8788
if (context.Request.QueryString.Get("code") == null)
8889
{
8990
Console.WriteLine($"Malformed authorization response {context.Request.QueryString}", Color.Red);
@@ -102,7 +103,7 @@ await auth.WebServerAsync(
102103
code,
103104
$"{_config.LoginUrl}{_config.OAuthUri}");
104105

105-
Console.WriteLineFormatted("Access_token = {0}",Color.Green, Color.Yellow, auth.AccessInfo.AccessToken);
106+
Console.WriteLineFormatted("Access_token = {0}", Color.Green, Color.Yellow, auth.AccessInfo.AccessToken);
106107

107108
Console.WriteLineFormatted("Refresh_token = {0}", Color.Green, Color.Yellow, auth.AccessInfo.RefreshToken);
108109

@@ -118,10 +119,26 @@ await auth.WebServerAsync(
118119
Console.WriteLine($"{nameof(HttpServer)} is stopping.");
119120
}
120121
}
122+
121123
await Task.Delay(TimeSpan.FromSeconds(5), stoppingToken);
122124
}
123125
}
124126

127+
private static async Task<Stream> ShowBrowserMessage(HttpListenerContext context)
128+
{
129+
var response = context.Response;
130+
var responseString = string.Format(@"
131+
<html>
132+
<body>Please return to the console to retrieve access and refresh tokens.</body>
133+
</html>");
134+
135+
var buffer = Encoding.UTF8.GetBytes(responseString);
136+
response.ContentLength64 = buffer.Length;
137+
var responseOutput = response.OutputStream;
138+
await responseOutput.WriteAsync(buffer, 0, buffer.Length);
139+
return responseOutput;
140+
}
141+
125142
private int GetRandomUnusedPort()
126143
{
127144
var listener = new TcpListener(IPAddress.Loopback, 5050);
@@ -137,20 +154,5 @@ private string GetAuthorizationUrl(string redirectURI)
137154
var url = $"{authEndpoint}?response_type=code&access_type=offline&scope=openid%20profile%20api%20refresh_token%20offline_access&redirect_uri={Uri.EscapeDataString(redirectURI)}&client_id={_config.ClientId}";
138155
return url;
139156
}
140-
141-
private static async Task<Stream> ShowBrowserMessage(HttpListenerContext context)
142-
{
143-
var response = context.Response;
144-
var responseString = string.Format(@"
145-
<html>
146-
<body>Please return to the console to retrieve access and refresh tokens.</body>
147-
</html>");
148-
149-
var buffer = Encoding.UTF8.GetBytes(responseString);
150-
response.ContentLength64 = buffer.Length;
151-
var responseOutput = response.OutputStream;
152-
await responseOutput.WriteAsync(buffer, 0, buffer.Length);
153-
return responseOutput;
154-
}
155157
}
156158
}

src/AuthApp/Host/SfConfig.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,19 @@ namespace AuthApp.Host
55
public class SfConfig
66
{
77
/// <summary>
8-
/// Salesforce Client Id
8+
/// Salesforce Client Id.
99
/// </summary>
1010
[Required]
1111
public string ClientId { get; set; }
1212

1313
/// <summary>
14-
/// Salesforece Secret Id
14+
/// Salesforece Secret Id.
1515
/// </summary>
1616
[Required]
1717
public string ClientSecret { get; set; }
1818

1919
/// <summary>
20-
/// i.e. https://login.salesforce.com
20+
/// i.e. https://login.salesforce.com.
2121
/// </summary>
2222
[Required]
2323
[Url]

src/AuthApp/HostBuilderExtensions.cs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@ internal static IHostBuilder CreateDefaultBuilder(HostBuilderOptions options)
3939
}
4040

4141
builder
42-
.UseStartupFilters()
42+
.UseOptionValidation()
4343
.ConfigureAppConfiguration((context, config) =>
4444
{
4545
// appsettings file or others
46-
config.AddJsonFile(Path.Combine(fullPath, $"{(defaultConfigName).Split(".")[0]}.json"), optional: true)
47-
.AddJsonFile(Path.Combine(fullPath, $"{(defaultConfigName).Split(".")[0]}.{options.HostingEnviroment}.json"), optional: true);
46+
config.AddJsonFile(Path.Combine(fullPath, $"{defaultConfigName.Split(".")[0]}.json"), optional: true)
47+
.AddJsonFile(Path.Combine(fullPath, $"{defaultConfigName.Split(".")[0]}.{options.HostingEnviroment}.json"), optional: true);
4848

4949
// add secrets if specified
5050
if (options.UserSecrets)
@@ -53,14 +53,14 @@ internal static IHostBuilder CreateDefaultBuilder(HostBuilderOptions options)
5353
}
5454

5555
// configure Azure Vault from the other settings.
56-
var appAzureVaultUrl = config.Build().Bind<AzureVaultOptions>("AzureVault",enableValidation: false);
56+
var appAzureVaultUrl = config.Build().Bind<AzureVaultOptions>("AzureVault", enableValidation: false);
5757

5858
// build azure key vault from passed in parameter
5959
if (!string.IsNullOrWhiteSpace(options.AzureVault))
6060
{
6161
var dic = new Dictionary<string, string>
6262
{
63-
{"AzureVault:BaseUrl", options.AzureVault }
63+
{ "AzureVault:BaseUrl", options.AzureVault }
6464
};
6565

6666
config.AddInMemoryCollection(dic);
@@ -70,26 +70,26 @@ internal static IHostBuilder CreateDefaultBuilder(HostBuilderOptions options)
7070
if (!string.IsNullOrWhiteSpace(appAzureVaultUrl.BaseUrl)
7171
|| !string.IsNullOrWhiteSpace(options.AzureVault))
7272
{
73-
config.AddAzureKeyVault(hostingEnviromentName:options.HostingEnviroment, options.UseAzureKeyPrefix);
73+
config.AddAzureKeyVault(hostingEnviromentName: options.HostingEnviroment, options.UseAzureKeyPrefix);
7474
}
7575

76-
if(!string.IsNullOrWhiteSpace(options.Settings.ClientId)
76+
if (!string.IsNullOrWhiteSpace(options.Settings.ClientId)
7777
&& !string.IsNullOrWhiteSpace(options.Settings.ClientSecret))
7878
{
7979
var inputValues = new Dictionary<string, string>
8080
{
81-
{$"{options.SectionName}:ClientId", options.Settings.ClientId },
82-
{$"{options.SectionName}:ClientSecret", options.Settings.ClientSecret },
83-
{$"{options.SectionName}:LoginUrl", options.Settings.LoginUrl },
84-
{$"{options.SectionName}:OAuthUri", options.Settings.OAuthUri },
85-
{$"{options.SectionName}:OAuthorizeUri", options.Settings.OAuthorizeUri },
81+
{ $"{options.SectionName}:ClientId", options.Settings.ClientId },
82+
{ $"{options.SectionName}:ClientSecret", options.Settings.ClientSecret },
83+
{ $"{options.SectionName}:LoginUrl", options.Settings.LoginUrl },
84+
{ $"{options.SectionName}:OAuthUri", options.Settings.OAuthUri },
85+
{ $"{options.SectionName}:OAuthorizeUri", options.Settings.OAuthorizeUri },
8686
};
8787

8888
config.AddInMemoryCollection(inputValues);
8989
}
9090

91-
if (options.Verbose && options.Level == LogLevel.Debug
92-
|| options.Level == LogLevel.Trace)
91+
if ((options.Verbose && options.Level == LogLevel.Debug)
92+
|| options.Level == LogLevel.Trace)
9393
{
9494
config.Build().DebugConfigurations();
9595
}

src/AuthApp/HostBuilderOptions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ internal class HostBuilderOptions
1919
/// <summary>
2020
/// TraceLevel if verbose is present.
2121
/// </summary>
22-
public LogLevel Level { get; set; }
22+
public LogLevel Level { get; set; }
2323

2424
/// <summary>
2525
/// Ability to use Web project secrets.
2626
/// </summary>
2727
public bool UserSecrets { get; set; }
2828

2929
/// <summary>
30-
/// Url for the azure key vault i.e. https://{vaultname}.vault.azure.net/
30+
/// Url for the azure key vault i.e. https://{vaultname}.vault.azure.net/.
3131
/// </summary>
3232
public string AzureVault { get; set; }
3333

src/AuthApp/Program.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@ public class Program
1515
{
1616
private static Task<int> Main(string[] args)
1717
{
18-
return CommandLineApplication.ExecuteAsync<Program>(args);
18+
return CommandLineApplication.ExecuteAsync<Program>(args);
19+
}
20+
21+
private static string GetVersion()
22+
{
23+
return typeof(Program).Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>().InformationalVersion;
1924
}
2025

2126
private int OnExecute(CommandLineApplication app, IConsole console)
@@ -26,10 +31,5 @@ private int OnExecute(CommandLineApplication app, IConsole console)
2631
app.ShowHelp();
2732
return 1;
2833
}
29-
30-
private static string GetVersion()
31-
{
32-
return typeof(Program).Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>().InformationalVersion;
33-
}
3434
}
3535
}

src/AuthApp/Properties/launchSettings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
//"commandLineArgs": "get-tokens --key: --secret: --verbose:information --section:Salesforce"
99

10-
"commandLineArgs": "get-tokens --key: --secret: --verbose:information --section:Salesforce"
10+
"commandLineArgs": "get-tokens --key: --secret: --verbose:debug --section:Salesforce"
1111

1212
}
1313
}

0 commit comments

Comments
 (0)