Skip to content

Commit 36d37f5

Browse files
committed
issue #2 making a dotnet cli tool refactor
1 parent c93d37d commit 36d37f5

21 files changed

Lines changed: 374 additions & 144 deletions

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ BenchmarkDotNet.Artifacts/
5353
project.lock.json
5454
project.fragment.lock.json
5555
artifacts/
56-
**/Properties/launchSettings.json
56+
#**/Properties/launchSettings.json
5757

5858
# StyleCop
5959
StyleCopReport.xml

CometD.NetCore.Salesforce.sln

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio 15
4-
VisualStudioVersion = 15.0.27703.2042
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.28606.126
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CometD.NetCore.Salesforce", "src\CometD.NetCore.Salesforce\CometD.NetCore.Salesforce.csproj", "{CDF94744-1E4D-41D4-A3AC-C0D1AFA6FD40}"
77
EndProject
@@ -26,6 +26,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{DF67E08B
2626
build\sources.props = build\sources.props
2727
EndProjectSection
2828
EndProject
29+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{F0246231-B425-4C7A-BD19-EF4177AF48C0}"
30+
EndProject
2931
Global
3032
GlobalSection(SolutionConfigurationPlatforms) = preSolution
3133
Debug|Any CPU = Debug|Any CPU
@@ -48,6 +50,11 @@ Global
4850
GlobalSection(SolutionProperties) = preSolution
4951
HideSolutionNode = FALSE
5052
EndGlobalSection
53+
GlobalSection(NestedProjects) = preSolution
54+
{CDF94744-1E4D-41D4-A3AC-C0D1AFA6FD40} = {F0246231-B425-4C7A-BD19-EF4177AF48C0}
55+
{6FACF1B8-5D3D-48BF-B2A9-FA06E195D1B6} = {F0246231-B425-4C7A-BD19-EF4177AF48C0}
56+
{0AC0A8E4-AF3E-4078-A472-0D2DC1392C00} = {F0246231-B425-4C7A-BD19-EF4177AF48C0}
57+
EndGlobalSection
5158
GlobalSection(ExtensibilityGlobals) = postSolution
5259
SolutionGuid = {800A565D-7D93-4523-AD7A-EFA4067997DC}
5360
EndGlobalSection

appveyor.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
version: 1.0.{build}
1+
version: 2.0.{build}
22
branches:
33
only:
44
- master
55
pull_requests:
66
do_not_increment_build_number: true
77
image: Visual Studio 2017
8-
## temporary until 2.1 sdk is installed
8+
## temporary until 3.0.100-preview-010184 sdk is installed
99
install:
10-
- ps: $urlCurrent = "https://dotnetcli.blob.core.windows.net/dotnet/Sdk/2.1.300/dotnet-sdk-2.1.300-win-x64.zip"
10+
- ps: $urlCurrent = "https://dotnetcli.blob.core.windows.net/dotnet/Sdk/3.0.100-preview-010184/dotnet-sdk-3.0.100-preview-010184-win-x64.zip"
1111
- ps: $env:DOTNET_INSTALL_DIR = "$pwd\.dotnetsdk"
1212
- ps: mkdir $env:DOTNET_INSTALL_DIR -Force | Out-Null
1313
- ps: $tempFileCurrent = [System.IO.Path]::GetTempFileName()
@@ -26,7 +26,7 @@ test: off
2626
# - dotnet test tests/XUnitTests.csproj
2727

2828
artifacts:
29-
- path: .\src\CometD.NetCore.Salesforce\bin\Release\**\*.nupkg
29+
- path: /.*\.nupkg/
3030
name: NuGet package
3131

3232
deploy:

build/dependecies.props

Lines changed: 56 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,59 @@
11
<Project>
22

3-
<PropertyGroup>
4-
<NetCoreCommonVersion>2.1.1</NetCoreCommonVersion>
5-
</PropertyGroup>
6-
7-
<PropertyGroup Condition="'$(TargetFramework)' == 'netcoreapp2.1' Or '$(TargetFramework)' == 'netstandard2.0'">
8-
<NetCoreCommonVersion>2.1.1</NetCoreCommonVersion>
9-
</PropertyGroup>
10-
11-
<PropertyGroup Condition="'$(TargetFramework)' == 'netcoreapp2.2'">
12-
<NetCoreCommonVersion>2.2.0</NetCoreCommonVersion>
13-
</PropertyGroup>
14-
15-
<ItemGroup Label="NetCore">
16-
<PackageReference Update="Microsoft.Extensions.Logging.Abstractions" Version="$(NetCoreCommonVersion)" />
17-
<PackageReference Update="Microsoft.Extensions.Logging" Version="$(NetCoreCommonVersion)" />
18-
<PackageReference Update="Microsoft.Extensions.Logging.Configuration" Version="$(NetCoreCommonVersion)" />
19-
<PackageReference Update="Microsoft.Extensions.Logging.Console" Version="$(NetCoreCommonVersion)" />
20-
<PackageReference Update="Microsoft.Extensions.Logging.Debug" Version="$(NetCoreCommonVersion)" />
21-
<PackageReference Update="Microsoft.Extensions.ObjectPool" Version="$(NetCoreCommonVersion)" />
22-
23-
<PackageReference Update="Microsoft.Extensions.Configuration.Binder" Version="$(NetCoreCommonVersion)" />
24-
<PackageReference Update="Microsoft.Extensions.Configuration.CommandLine" Version="$(NetCoreCommonVersion)" />
25-
<PackageReference Update="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="$(NetCoreCommonVersion)" />
26-
<PackageReference Update="Microsoft.Extensions.Configuration.Json" Version="$(NetCoreCommonVersion)" />
27-
<PackageReference Update="Microsoft.Extensions.Hosting" Version="$(NetCoreCommonVersion)" />
28-
<PackageReference Update="Microsoft.Extensions.Hosting.Abstractions" Version="$(NetCoreCommonVersion)" />
29-
30-
<PackageReference Update="Microsoft.Extensions.DependencyInjection" Version="$(NetCoreCommonVersion)" />
31-
<PackageReference Update="Microsoft.Extensions.Options" Version="$(NetCoreCommonVersion)" />
32-
<PackageReference Update="Microsoft.AspNetCore.Hosting.Server.Abstractions" Version="$(NetCoreCommonVersion)" />
33-
<PackageReference Update="Microsoft.AspNetCore.Http" Version="$(NetCoreCommonVersion)" />
34-
<PackageReference Update="Microsoft.Extensions.Configuration.CommandLine" Version="$(NetCoreCommonVersion)" />
35-
<PackageReference Update="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="$(NetCoreCommonVersion)" />
36-
<PackageReference Update="Microsoft.Extensions.Configuration.Json" Version="$(NetCoreCommonVersion)" />
37-
<PackageReference Update="Microsoft.Extensions.Hosting" Version="$(NetCoreCommonVersion)" />
38-
</ItemGroup>
39-
40-
<ItemGroup Label="Shared Libraries">
41-
<PackageReference Update="Bet.AspNetCore" Version="1.0.2" />
42-
<PackageReference Update="CometD.NetCore2" Version="1.0.3" />
43-
<PackageReference Update="KDCLLC.BuildingBlocks.SalesforceEventBus" Version="1.0.2" />
44-
45-
<PackageReference Update="NetCoreForce.Client" Version="2.5.0" />
46-
<PackageReference Update="Polly" Version="7.0.2" />
47-
</ItemGroup>
48-
49-
<ItemGroup Label="SourceLink">
50-
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0-beta2-18618-05" PrivateAssets="All" />
51-
</ItemGroup>
3+
<PropertyGroup>
4+
<NetCoreCommonVersion>2.1.1</NetCoreCommonVersion>
5+
</PropertyGroup>
6+
7+
<PropertyGroup Condition="'$(TargetFramework)' == 'netcoreapp2.1' Or '$(TargetFramework)' == 'netstandard2.0'">
8+
<NetCoreCommonVersion>2.1.1</NetCoreCommonVersion>
9+
</PropertyGroup>
10+
11+
<PropertyGroup Condition="'$(TargetFramework)' == 'netcoreapp2.2'">
12+
<NetCoreCommonVersion>2.2.0</NetCoreCommonVersion>
13+
</PropertyGroup>
14+
15+
<PropertyGroup Condition="'$(TargetFramework)' == 'netcoreapp3.0'">
16+
<NetCoreCommonVersion>3.0.0-preview.19074.2</NetCoreCommonVersion>
17+
</PropertyGroup>
18+
19+
<ItemGroup Label="NetCore">
20+
<PackageReference Update="Microsoft.Extensions.Logging.Abstractions" Version="$(NetCoreCommonVersion)" />
21+
<PackageReference Update="Microsoft.Extensions.Logging" Version="$(NetCoreCommonVersion)" />
22+
<PackageReference Update="Microsoft.Extensions.Logging.Configuration" Version="$(NetCoreCommonVersion)" />
23+
<PackageReference Update="Microsoft.Extensions.Logging.Console" Version="$(NetCoreCommonVersion)" />
24+
<PackageReference Update="Microsoft.Extensions.Logging.Debug" Version="$(NetCoreCommonVersion)" />
25+
<PackageReference Update="Microsoft.Extensions.ObjectPool" Version="$(NetCoreCommonVersion)" />
26+
27+
<PackageReference Update="Microsoft.Extensions.Configuration.Binder" Version="$(NetCoreCommonVersion)" />
28+
<PackageReference Update="Microsoft.Extensions.Configuration.CommandLine" Version="$(NetCoreCommonVersion)" />
29+
<PackageReference Update="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="$(NetCoreCommonVersion)" />
30+
<PackageReference Update="Microsoft.Extensions.Configuration.Json" Version="$(NetCoreCommonVersion)" />
31+
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="$(NetCoreCommonVersion)" />
32+
33+
<PackageReference Update="Microsoft.Extensions.Hosting" Version="$(NetCoreCommonVersion)" />
34+
<PackageReference Update="Microsoft.Extensions.Hosting.Abstractions" Version="$(NetCoreCommonVersion)" />
35+
36+
<PackageReference Update="Microsoft.Extensions.DependencyInjection" Version="$(NetCoreCommonVersion)" />
37+
<PackageReference Update="Microsoft.Extensions.Options" Version="$(NetCoreCommonVersion)" />
38+
<PackageReference Update="Microsoft.AspNetCore.Hosting.Server.Abstractions" Version="$(NetCoreCommonVersion)" />
39+
<PackageReference Update="Microsoft.AspNetCore.Http" Version="$(NetCoreCommonVersion)" />
40+
<PackageReference Update="Microsoft.Extensions.Configuration.CommandLine" Version="$(NetCoreCommonVersion)" />
41+
<PackageReference Update="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="$(NetCoreCommonVersion)" />
42+
<PackageReference Update="Microsoft.Extensions.Configuration.Json" Version="$(NetCoreCommonVersion)" />
43+
<PackageReference Update="Microsoft.Extensions.Hosting" Version="$(NetCoreCommonVersion)" />
44+
</ItemGroup>
45+
46+
<ItemGroup Label="Shared Libraries">
47+
<PackageReference Update="Bet.AspNetCore" Version="1.1.0-pre" />
48+
<PackageReference Update="CometD.NetCore2" Version="2.0.0" />
49+
<PackageReference Update="Bet.BuildingBlocks.SalesforceEventBus" Version="2.1.0-pre" />
50+
<PackageReference Update="McMaster.Extensions.CommandLineUtils" Version="2.3.2"/>
51+
<PackageReference Update="NetCoreForce.Client" Version="2.5.0" />
52+
<PackageReference Update="Polly" Version="7.0.2" />
53+
<PackageReference Update="Colorful.Console" Version="1.2.9" />
54+
</ItemGroup>
55+
56+
<ItemGroup Label="SourceLink">
57+
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0-beta2-18618-05" PrivateAssets="All" />
58+
</ItemGroup>
5259
</Project>

build/settings.props

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

33
<PropertyGroup Label="Basic Settings">
44
<IsPackable>true</IsPackable>
5-
<VersionPrefix>1.0.0-pre</VersionPrefix>
5+
<VersionPrefix>2.1.0-pre</VersionPrefix>
66
<LangVersion>latest</LangVersion>
77
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
88
<SuppressNETCoreSdkPreviewMessage>true</SuppressNETCoreSdkPreviewMessage>

src/AuthApp/AuthApp.csproj

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,28 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFrameworks>netcoreapp2.1;netcoreapp2.2</TargetFrameworks>
6-
<IsPackable>false</IsPackable>
7-
</PropertyGroup>
5+
<TargetFrameworks>netcoreapp2.2;netcoreapp3.0</TargetFrameworks>
6+
<ToolCommandName>salesforce</ToolCommandName>
7+
<PackageId>salesforce</PackageId>
8+
<Description>A command-line tool that enables Salesforce Refresh Token Generation.</Description>
9+
<PackAsTool>True</PackAsTool>
10+
</PropertyGroup>
811

912
<ItemGroup>
10-
<PackageReference Include="Microsoft.AspNetCore.Hosting.Server.Abstractions"/>
11-
<PackageReference Include="Microsoft.AspNetCore.Http"/>
12-
<PackageReference Include="Microsoft.Extensions.Configuration.CommandLine"/>
13-
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables"/>
14-
<PackageReference Include="Microsoft.Extensions.Configuration.Json"/>
15-
<PackageReference Include="Microsoft.Extensions.Hosting"/>
16-
<PackageReference Include="NetCoreForce.Client"/>
13+
<PackageReference Include="Bet.AspNetCore" />
14+
<PackageReference Include="Colorful.Console" />
15+
<PackageReference Include="McMaster.Extensions.CommandLineUtils" />
16+
<PackageReference Include="Microsoft.AspNetCore.Hosting.Server.Abstractions" />
17+
<PackageReference Include="Microsoft.AspNetCore.Http" />
18+
<PackageReference Include="Microsoft.Extensions.Configuration.CommandLine" />
19+
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" />
20+
<PackageReference Include="Microsoft.Extensions.Configuration.Json" />
21+
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" />
22+
<PackageReference Include="Microsoft.Extensions.Hosting" />
23+
<PackageReference Include="NetCoreForce.Client" />
1724
</ItemGroup>
1825
<ItemGroup>
1926
<Content Include="appsettings*.json" CopyToOutputDirectory="PreserveNewest" />
2027
<Content Include="hostsettings*.json" CopyToOutputDirectory="PreserveNewest" />
2128
</ItemGroup>
22-
<ItemGroup>
23-
<None Remove="appsettings.Development.json" />
24-
<None Remove="hostsettings.json" />
25-
</ItemGroup>
26-
<ItemGroup>
27-
<Content Include="hostsettings.json">
28-
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
29-
</Content>
30-
</ItemGroup>
31-
<ItemGroup>
32-
<Content Update="appsettings.Development.json">
33-
<DependentUpon>appsettings.json</DependentUpon>
34-
</Content>
35-
</ItemGroup>
3629
</Project>

src/AuthApp/ConsoleHandler.cs

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,14 @@
11
using System;
22
using System.Diagnostics;
3+
using System.IO;
34
using System.Runtime.InteropServices;
5+
using System.Xml.Linq;
46

57
namespace AuthApp
68
{
7-
public class ConsoleHandler
9+
internal static class ConsoleHandler
810
{
9-
public static void ShowConsole()
10-
{
11-
var console = GetConsoleWindow();
12-
ShowWindow(console, 5);
13-
}
14-
15-
public static void HideConsole()
16-
{
17-
var console = GetConsoleWindow();
18-
ShowWindow(console, 0);
19-
}
20-
21-
#pragma warning disable IDE0040 // Add accessibility modifiers
22-
23-
[DllImport("kernel32.dll")]
24-
static extern IntPtr GetConsoleWindow();
25-
26-
[DllImport("user32.dll")]
27-
static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
28-
29-
#pragma warning restore IDE0040 // Add accessibility modifiers
30-
31-
public static Process OpenBrowser(string url)
11+
internal static Process OpenBrowser(string url)
3212
{
3313
try
3414
{
@@ -56,5 +36,27 @@ public static Process OpenBrowser(string url)
5636
}
5737
}
5838
}
39+
40+
internal static string GetUserSecretsId()
41+
{
42+
var files = Directory.GetFiles("./", "*.csproj");
43+
if (files.Length == 0)
44+
{
45+
throw new Exception("This command must be run in a project directory");
46+
}
47+
48+
var file = XElement.Load(files[0]);
49+
var groups = file.Elements(XName.Get("PropertyGroup"));
50+
foreach (var group in groups)
51+
{
52+
var secret = group.Element("UserSecretsId");
53+
if (secret != null)
54+
{
55+
return secret.Value;
56+
}
57+
}
58+
59+
throw new Exception("The UserSecretsId element was not found in your csproj. Please ensure it has been configured.");
60+
}
5961
}
6062
}

src/AuthApp/Host/HttpServer.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,21 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)
3434

3535
var authUrl = GetAuthorizationUrl(redirectURI);
3636
Console.WriteLine($"Opening a browser window with Url: {authUrl}");
37-
ConsoleHandler.HideConsole();
3837

3938
var process = ConsoleHandler.OpenBrowser(authUrl);
4039
var context = await http.GetContextAsync();
4140

4241
while (!stoppingToken.IsCancellationRequested || isCompleted )
4342
{
43+
if (isCompleted)
44+
{
45+
return;
46+
}
47+
4448
Console.WriteLine($"{nameof(HttpServer)} is running");
4549

4650
if (context != null)
4751
{
48-
ConsoleHandler.ShowConsole();
49-
5052
var responseOutput = await ShowBrowserMessage(context);
5153

5254
responseOutput.Close();
@@ -70,7 +72,7 @@ await auth.WebServerAsync(_config.ClientId,
7072
redirectURI,
7173
code,
7274
$"{_config.LoginUrl}/services/oauth2/token");
73-
75+
7476

7577
Console.WriteLine($"Your access_token is {auth.AccessInfo.AccessToken}");
7678
Console.WriteLine($"Your refresh_token is {auth.AccessInfo.RefreshToken}");

src/AuthApp/Host/SfConfig.cs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,26 @@
1-
namespace AuthApp.Host
1+
using System.ComponentModel.DataAnnotations;
2+
3+
namespace AuthApp.Host
24
{
35
public class SfConfig
46
{
7+
/// <summary>
8+
/// Salesforce Client Id
9+
/// </summary>
10+
[Required]
511
public string ClientId { get; set; }
12+
13+
/// <summary>
14+
/// Salesforece Secret Id
15+
/// </summary>
16+
[Required]
617
public string ClientSecret { get; set; }
7-
public string LoginUrl { get; set; } = @"https://test.salesforce.com";
18+
19+
/// <summary>
20+
/// i.e. https://login.salesforce.com
21+
/// </summary>
22+
[Required]
23+
[Url]
24+
public string LoginUrl { get; set; }
825
}
926
}

0 commit comments

Comments
 (0)