Skip to content

Commit a08b47e

Browse files
committed
initial addition of the IResilientForceClient
1 parent a296989 commit a08b47e

22 files changed

Lines changed: 894 additions & 126 deletions

CometD.NetCore.Salesforce.sln

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{F0246231-B42
2828
EndProject
2929
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CometD.NetCore.Salesforce", "src\CometD.NetCore.Salesforce\CometD.NetCore.Salesforce.csproj", "{03FD9019-E9BC-4ADE-9BFF-F6FD459CD579}"
3030
EndProject
31+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CometD.UnitTest", "test\CometD.UnitTest\CometD.UnitTest.csproj", "{62A83077-E672-4D88-81AC-08667FE898E3}"
32+
EndProject
33+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{1F013CA3-FD86-46BC-A162-B50DF96DE262}"
34+
EndProject
35+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestApp", "src\TestApp\TestApp.csproj", "{5C96EB67-EC27-4C3B-ABFB-94B8B559CD6B}"
36+
EndProject
3137
Global
3238
GlobalSection(SolutionConfigurationPlatforms) = preSolution
3339
Debug|Any CPU = Debug|Any CPU
@@ -42,13 +48,23 @@ Global
4248
{03FD9019-E9BC-4ADE-9BFF-F6FD459CD579}.Debug|Any CPU.Build.0 = Debug|Any CPU
4349
{03FD9019-E9BC-4ADE-9BFF-F6FD459CD579}.Release|Any CPU.ActiveCfg = Release|Any CPU
4450
{03FD9019-E9BC-4ADE-9BFF-F6FD459CD579}.Release|Any CPU.Build.0 = Release|Any CPU
51+
{62A83077-E672-4D88-81AC-08667FE898E3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
52+
{62A83077-E672-4D88-81AC-08667FE898E3}.Debug|Any CPU.Build.0 = Debug|Any CPU
53+
{62A83077-E672-4D88-81AC-08667FE898E3}.Release|Any CPU.ActiveCfg = Release|Any CPU
54+
{62A83077-E672-4D88-81AC-08667FE898E3}.Release|Any CPU.Build.0 = Release|Any CPU
55+
{5C96EB67-EC27-4C3B-ABFB-94B8B559CD6B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
56+
{5C96EB67-EC27-4C3B-ABFB-94B8B559CD6B}.Debug|Any CPU.Build.0 = Debug|Any CPU
57+
{5C96EB67-EC27-4C3B-ABFB-94B8B559CD6B}.Release|Any CPU.ActiveCfg = Release|Any CPU
58+
{5C96EB67-EC27-4C3B-ABFB-94B8B559CD6B}.Release|Any CPU.Build.0 = Release|Any CPU
4559
EndGlobalSection
4660
GlobalSection(SolutionProperties) = preSolution
4761
HideSolutionNode = FALSE
4862
EndGlobalSection
4963
GlobalSection(NestedProjects) = preSolution
5064
{0AC0A8E4-AF3E-4078-A472-0D2DC1392C00} = {F0246231-B425-4C7A-BD19-EF4177AF48C0}
5165
{03FD9019-E9BC-4ADE-9BFF-F6FD459CD579} = {F0246231-B425-4C7A-BD19-EF4177AF48C0}
66+
{62A83077-E672-4D88-81AC-08667FE898E3} = {1F013CA3-FD86-46BC-A162-B50DF96DE262}
67+
{5C96EB67-EC27-4C3B-ABFB-94B8B559CD6B} = {F0246231-B425-4C7A-BD19-EF4177AF48C0}
5268
EndGlobalSection
5369
GlobalSection(ExtensibilityGlobals) = postSolution
5470
SolutionGuid = {800A565D-7D93-4523-AD7A-EFA4067997DC}

build/dependecies.props

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@
4848
</ItemGroup>
4949

5050
<ItemGroup Label="Shared Libraries">
51-
<PackageReference Update="CometD.NetCore2" Version="2.0.0" />
51+
<PackageReference Update="Bet.Extensions" Version="1.1.19" />
52+
<PackageReference Update="CometD.NetCore2" Version="2.0.1" />
5253
<PackageReference Update="Bet.BuildingBlocks.SalesforceEventBus" Version="2.0.0" />
5354
<PackageReference Update="McMaster.Extensions.CommandLineUtils" Version="2.3.2"/>
5455
<PackageReference Update="NetCoreForce.Client" Version="2.5.0" />

src/AuthApp/Program.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ public class Program
1515
{
1616
private static Task<int> Main(string[] args)
1717
{
18-
1918
return CommandLineApplication.ExecuteAsync<Program>(args);
2019
}
2120

src/CometD.NetCore.Salesforce/CometD.NetCore.Salesforce.csproj

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66
</PropertyGroup>
77

88
<ItemGroup>
9-
<PackageReference Include="CometD.NetCore2"/>
10-
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions"/>
11-
<PackageReference Include="Microsoft.Extensions.DependencyInjection"/>
9+
<PackageReference Include="Bet.Extensions" />
10+
<PackageReference Include="CometD.NetCore2" />
11+
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" />
12+
<PackageReference Include="Microsoft.Extensions.DependencyInjection" />
1213
<PackageReference Include="Microsoft.Extensions.Options" />
13-
<PackageReference Include="NetCoreForce.Client"/>
14-
<PackageReference Include="Polly"/>
14+
<PackageReference Include="NetCoreForce.Client" />
15+
<PackageReference Include="Polly" />
1516
</ItemGroup>
1617

1718
</Project>

src/CometD.NetCore.Salesforce/ForceClient/ForceClientProxy.cs

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,16 @@ public class ForceClientProxy : IForceClientProxy
2828
/// <param name="authenticationClient">Instance of <see cref="AuthenticationClientProxy"/> that creates instance of <see cref="AuthenticationClient"/>.</param>
2929
/// <param name="logger">Instance of the <see cref="ILogger{IForceClientProxy}"/>.</param>
3030
/// <param name="options">Options based on <see cref="SalesforceConfiguration"/></param>
31-
public ForceClientProxy(IAuthenticationClientProxy authenticationClient,
31+
public ForceClientProxy(
32+
IAuthenticationClientProxy authenticationClient,
3233
ILogger<ForceClientProxy> logger,
3334
SalesforceConfiguration options)
3435
{
35-
#region ArgumentException and ArgumentNullException
36-
3736
_options = options ?? throw new ArgumentNullException(nameof(options));
3837

39-
_authenticationClient = authenticationClient ??
40-
throw new ArgumentNullException(nameof(authenticationClient));
38+
_authenticationClient = authenticationClient ?? throw new ArgumentNullException(nameof(authenticationClient));
39+
4140
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
42-
#endregion
4341

4442
// creates an instance of the forceclient register as singleton
4543
_forceClient = new NetCoreForce.Client.ForceClient(
@@ -53,9 +51,6 @@ public ForceClientProxy(IAuthenticationClientProxy authenticationClient,
5351
nameof(ForceClientProxy), OnWaitAndRetry);
5452
}
5553

56-
57-
#region Private
58-
5954
private async Task RefreshAuthorization()
6055
{
6156
await _authenticationClient.Authenticate();
@@ -69,24 +64,27 @@ private async Task RefreshAuthorization()
6964
_logger.LogDebug($"Salesforce Authentication Successful!");
7065
}
7166

72-
private async Task OnWaitAndRetry(Exception ex, int count, Context context)
67+
private async Task OnWaitAndRetry(
68+
Exception ex,
69+
int count,
70+
Context context)
7371
{
7472
_logger.LogWarning($"Trying to {nameof(RefreshAuthorization)}");
7573
_logger.LogWarning($"Retry {context.Count}:{count} of {context.PolicyKey}, due to {ex.Message}.");
7674
await RefreshAuthorization();
7775
}
7876

79-
private IAsyncPolicy CreateAuthenticationWaitAndRetry(int retryAuthorization,
80-
string name,
81-
Func<Exception, int, Context, Task> retryHook)
77+
private IAsyncPolicy CreateAuthenticationWaitAndRetry(
78+
int retryAuthorization,
79+
string name,
80+
Func<Exception, int, Context, Task> retryHook)
8281
{
8382
return Policy
8483
.Handle<ForceApiException>(x => x.Message.Contains("ErrorCode INVALID_SESSION_ID"))
85-
.RetryAsync(retryCount: retryAuthorization,
86-
onRetryAsync: retryHook)
87-
.WithPolicyKey($"{name}Retry");
84+
.RetryAsync(
85+
retryCount: retryAuthorization,
86+
onRetryAsync: retryHook).WithPolicyKey($"{name}Retry");
8887
}
89-
#endregion
9088

9189
/// <summary>
9290
/// Retrieves a Salesforce object by its Id
@@ -96,8 +94,11 @@ private IAsyncPolicy CreateAuthenticationWaitAndRetry(int retryAuthorization,
9694
/// <param name="objectId">Id of the object to retrieve</param>
9795
/// <param name="token">Token to cancel operation</param>
9896
/// <param name="fields">List of fields to return.</param>
99-
/// <returns>The retrieved object from salesforce.</returns>
100-
public async Task<T> GetObjectById<T>(string sObjectTypeName, string objectId, CancellationToken token,
97+
/// <returns>The retrieved object from Salesforce.</returns>
98+
public async Task<T> GetObjectById<T>(
99+
string sObjectTypeName,
100+
string objectId,
101+
CancellationToken token,
101102
List<string> fields = null)
102103
{
103104
return await _policy.ExecuteAsync(ctx => _forceClient.GetObjectById<T>(sObjectTypeName, objectId, fields), token);
@@ -111,7 +112,9 @@ public async Task<T> GetObjectById<T>(string sObjectTypeName, string objectId, C
111112
/// <param name="instance">Object to create</param>
112113
/// <param name="headers">Optional request headers.</param>
113114
/// <returns>A <see cref="CreateResponse"/> representing the operation result.</returns>
114-
public async Task<CreateResponse> CreateRecord<T>(string sObjectTypeName, T instance,
115+
public async Task<CreateResponse> CreateRecord<T>(
116+
string sObjectTypeName,
117+
T instance,
115118
Dictionary<string, string> headers = null)
116119
{
117120
return await _policy.ExecuteAsync(() => _forceClient.CreateRecord(sObjectTypeName, instance, headers));
@@ -126,8 +129,11 @@ public async Task<CreateResponse> CreateRecord<T>(string sObjectTypeName, T inst
126129
/// <param name="token">Token to cancel operation</param>
127130
/// <param name="headers">Optional request headers.</param>
128131
/// <returns>A <see cref="CreateResponse"/> representing the operation result.</returns>
129-
public async Task<CreateResponse> CreateRecord<T>(string sObjectTypeName, T instance,
130-
CancellationToken token, Dictionary<string, string> headers = null)
132+
public async Task<CreateResponse> CreateRecord<T>(
133+
string sObjectTypeName,
134+
T instance,
135+
CancellationToken token,
136+
Dictionary<string, string> headers = null)
131137
{
132138
return await _policy.ExecuteAsync(ctx => _forceClient.CreateRecord(sObjectTypeName, instance, headers), token);
133139
}

src/CometD.NetCore.Salesforce/ForceClient/IForceClientProxy.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1-
using System.Collections.Generic;
1+
using System;
2+
using System.Collections.Generic;
23
using System.Threading;
34
using System.Threading.Tasks;
5+
using CometD.NetCore.Salesforce.Resilience;
46
using NetCoreForce.Client.Models;
57

68
namespace CometD.NetCore.Salesforce.ForceClient
79
{
810
/// <summary>
911
/// A Proxy interface around <see cref="NetCoreForce.Client.ForceClient"/>.
1012
/// </summary>
13+
[Obsolete("Use " + nameof(IResilientForceClient) + "instead.")]
1114
public interface IForceClientProxy
1215
{
1316
/// <summary>

src/CometD.NetCore.Salesforce/IStreamingClient.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ public interface IStreamingClient : IDisposable
3030
void Handshake(int timeout);
3131

3232
/// <summary>
33-
/// Disconnect salesforce subscription to the platform events.
33+
/// Disconnect Salesforce subscription to the platform events.
3434
/// </summary>
3535
void Disconnect();
3636

3737
/// <summary>
38-
/// Disconnect salesforce subscription to the platform events.
38+
/// Disconnect Salesforce subscription to the platform events.
3939
/// </summary>
4040
/// <param name="timeout"></param>
4141
void Disconnect(int timeout);

src/CometD.NetCore.Salesforce/Messaging/MessageData.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
namespace CometD.NetCore.Salesforce.Messaging
22
{
33
/// <summary>
4-
/// Data from the salesforce platform event reply.
4+
/// Data from the Salesforce platform event reply.
55
/// </summary>
66
/// <typeparam name="TPayload"></typeparam>
77
public class MessageData<TPayload> where TPayload : MessagePayload

0 commit comments

Comments
 (0)