private async Task <BeanTraderServiceClient> GetOrOpenClientAsync() { // If the client does not exist or is in a bad state, re-create it if (client == null || client.State == CommunicationState.Closed || client.State == CommunicationState.Faulted) { try { using (await clientSyncLock.LockAsync()) { if (client == null || client.State == CommunicationState.Closed || client.State == CommunicationState.Faulted) { var newClient = ClientFactory.GetServiceClient(); SetClientCredentials(newClient); newClient.Open(); client = newClient; } } Connected?.Invoke(); } catch (EndpointNotFoundException) { MessageBox.Show("Failed to connect to Bean Trader service. Make sure BeanTraderServer.exe is running"); throw; } } return(client); }
private async Task <BeanTraderServiceClient> GetOrOpenClientAsync() { // If the client does not exist or is in a bad state, re-create it if (client == null || client.State == CommunicationState.Closed || client.State == CommunicationState.Faulted) { using (await clientSyncLock.LockAsync()) { if (client == null || client.State == CommunicationState.Closed || client.State == CommunicationState.Faulted) { var newClient = ClientFactory.GetServiceClient(); await SetClientCredentialsAsync(newClient).ConfigureAwait(false); #if NETCORE await newClient.OpenAsync().ConfigureAwait(false); #else newClient.Open(); #endif // NETCORE client = newClient; } } Connected?.Invoke(); } return(client); }
private async Task <T> SafeServiceCallAsync <T>(Func <Task <T> > action) { try { return(await action().ConfigureAwait(false)); } catch (CommunicationException) { client?.Abort(); client = null; return(default);
private async Task SafeServiceCallAsync(Func <Task> action) { try { await action().ConfigureAwait(false); } catch (CommunicationException) { client?.Abort(); client = null; } }
private static async Task SetClientCredentialsAsync(BeanTraderServiceClient client) { client.ClientCredentials.ClientCertificate.Certificate = await GetCertificateAsync().ConfigureAwait(false); client.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.None; }
public void Initialize(BeanTraderServiceClient proxy) { this.proxy = proxy; }