Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
 private async Task <T> SafeServiceCallAsync <T>(Func <Task <T> > action)
 {
     try
     {
         return(await action().ConfigureAwait(false));
     }
     catch (CommunicationException)
     {
         client?.Abort();
         client = null;
         return(default);
Ejemplo n.º 4
0
 private async Task SafeServiceCallAsync(Func <Task> action)
 {
     try
     {
         await action().ConfigureAwait(false);
     }
     catch (CommunicationException)
     {
         client?.Abort();
         client = null;
     }
 }
Ejemplo n.º 5
0
        private static async Task SetClientCredentialsAsync(BeanTraderServiceClient client)
        {
            client.ClientCredentials.ClientCertificate.Certificate = await GetCertificateAsync().ConfigureAwait(false);

            client.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.None;
        }
Ejemplo n.º 6
0
 public void Initialize(BeanTraderServiceClient proxy)
 {
     this.proxy = proxy;
 }