public SalesforceEventBusHostedService( ILogger <SalesforceEventBusHostedService> logger, IHostApplicationLifetime appLifetime, IOptions <SalesforceConfiguration> options, IEventBus eventBus) { _logger = logger; _appLifetime = appLifetime; _options = options.Value; _eventBus = eventBus; }
/// <summary> /// Initializes a new instance of the <see cref="AuthenticationClientProxy"/> class and authenticates the session. /// </summary> /// <param name="options"><see cref="SalesforceConfiguration"/>.</param> public AuthenticationClientProxy(SalesforceConfiguration options) { _options = options ?? throw new ArgumentNullException(nameof(options)); _policy = Policy .Handle <Exception>() .WaitAndRetryAsync(5, retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt))); _auth = new AuthenticationClient(); // sync call to authenticate on the creation of the instance of this object. Authenticate().Wait(); }
/// <summary> /// Initializes a new instance of the <see cref="ResilientForceClient"/> class. /// </summary> /// <param name="forceClient"></param> /// <param name="options"></param> /// <param name="logger"></param> public ResilientForceClient( Func <AsyncExpiringLazy <ForceClient> > forceClient, IOptions <SalesforceConfiguration> options, ILogger <ResilientForceClient> logger) { if (forceClient == null) { throw new ArgumentNullException(nameof(forceClient)); } _logger = logger ?? throw new ArgumentNullException(nameof(logger)); _forceClient = forceClient(); _options = options.Value; _policy = Policy.WrapAsync(GetAuthenticationRetryPolicy(), GetWaitAndRetryPolicy()); }
public static IServiceCollection AddStreamingClient(this IServiceCollection services) { services.AddSingleton(sp => { var salesforceConfig = new SalesforceConfiguration(); var config = sp.GetRequiredService <IConfiguration>(); config.Bind("Salesforce", salesforceConfig); return(salesforceConfig); }); services.AddSingleton <IAuthenticationClientProxy, AuthenticationClientProxy>(); services.AddSingleton <IForceClientProxy, ForceClientProxy>(); services.AddSingleton <IStreamingClient, StreamingClient>(); return(services); }
/// <summary> /// Initializes a new instance of the <see cref="EventBus"/> class. /// </summary> /// <param name="streamingClient">The instance of <see cref="IStreamingClient"/> with connection to salesforce.</param> /// <param name="logger">The instance of <see cref="ILogger{SalesforceEventBus}"/>.</param> /// <param name="forceClient">The instance of <see cref="ForceClientProxy"/> to provide a publish functionality to the bus.</param> /// <param name="messageListeners"></param> /// <param name="options"></param> public EventBus( IStreamingClient streamingClient, ILogger <EventBus> logger, IResilientForceClient forceClient, IEnumerable <IMessageListener> messageListeners, IOptions <SalesforceConfiguration> options) { _streamingClient = streamingClient ?? throw new ArgumentNullException(nameof(streamingClient)); _logger = logger ?? throw new ArgumentNullException(nameof(logger)); _forceClient = forceClient ?? throw new ArgumentNullException(nameof(forceClient)); _options = options.Value ?? throw new ArgumentNullException(nameof(options)); _messageListerners = messageListeners; _streamingClient.Reconnect += StreamingClient_Reconnect; _streamingClient.Handshake(); }
/// <summary> /// Constructor for <see cref="AuthenticationClientProxy"/> /// that create an instance of <see cref="NetCoreForce.Client.ForceClient"/>. /// </summary> /// <param name="authenticationClient">Instance of <see cref="AuthenticationClientProxy"/> that creates instance of <see cref="AuthenticationClient"/>.</param> /// <param name="logger">Instance of the <see cref="ILogger{IForceClientProxy}"/>.</param> /// <param name="options">Options based on <see cref="SalesforceConfiguration"/></param> public ForceClientProxy( IAuthenticationClientProxy authenticationClient, ILogger <ForceClientProxy> logger, SalesforceConfiguration options) { _options = options ?? throw new ArgumentNullException(nameof(options)); _authenticationClient = authenticationClient ?? throw new ArgumentNullException(nameof(authenticationClient)); _logger = logger ?? throw new ArgumentNullException(nameof(logger)); // creates an instance of the forceclient register as singleton _forceClient = new NetCoreForce.Client.ForceClient( _authenticationClient.AuthenticationClient.AccessInfo.InstanceUrl, _authenticationClient.AuthenticationClient.ApiVersion, _authenticationClient.AuthenticationClient.AccessInfo.AccessToken ); // create retry authentication policy _policy = CreateAuthenticationWaitAndRetry(_options.Retry, nameof(ForceClientProxy), OnWaitAndRetry); }