Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/16/17 07:56:01 (7 years ago)
Author:
gkronber
Message:

#2650: merged r14597:14737 from trunk to branch

Location:
branches/symbreg-factors-2650
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/symbreg-factors-2650

  • branches/symbreg-factors-2650/HeuristicLab.Clients.OKB/3.3/Query/QueryClient.cs

    r14185 r14751  
    2424using System.IO;
    2525using System.Linq;
     26using System.ServiceModel;
    2627using HeuristicLab.Clients.Common;
    2728using HeuristicLab.Common;
     
    3940      }
    4041    }
     42
     43    private int endpointRetries;
     44    private string workingEndpoint;
    4145
    4246    #region Properties
     
    6872    }
    6973    public void RefreshAsync(Action<Exception> exceptionCallback) {
    70       var call = new Func<Exception>(delegate() {
     74      var call = new Func<Exception>(delegate () {
    7175        try {
    7276          Refresh();
     
    7680        return null;
    7781      });
    78       call.BeginInvoke(delegate(IAsyncResult result) {
     82      call.BeginInvoke(delegate (IAsyncResult result) {
    7983        Exception ex = call.EndInvoke(result);
    8084        if (ex != null) exceptionCallback(ex);
     
    156160
    157161    #region Helpers
     162    private QueryServiceClient NewServiceClient() {
     163      if (endpointRetries >= Properties.Settings.Default.MaxEndpointRetries)
     164        return CreateClient(workingEndpoint);
     165
     166      var configurations = Properties.Settings.Default.EndpointConfigurationPriorities;
     167      Exception exception = null;
     168
     169      foreach (var endpointConfigurationName in configurations) {
     170        try {
     171          var cl = CreateClient(endpointConfigurationName);
     172          cl.Open();
     173          workingEndpoint = endpointConfigurationName;
     174          return cl;
     175        } catch (EndpointNotFoundException e) {
     176          exception = e;
     177          ++endpointRetries;
     178        }
     179      }
     180
     181      throw exception ?? new EndpointNotFoundException("No endpoint for Query service found.");
     182    }
     183
     184    private QueryServiceClient CreateClient(string endpointConfigurationName) {
     185      var cl = ClientFactory.CreateClient<QueryServiceClient, IQueryService>(endpointConfigurationName);
     186      return cl;
     187    }
     188
    158189    private T CallQueryService<T>(Func<IQueryService, T> call) {
    159       QueryServiceClient client = ClientFactory.CreateClient<QueryServiceClient, IQueryService>();
     190      QueryServiceClient client = NewServiceClient();
     191
    160192      try {
    161193        return call(client);
Note: See TracChangeset for help on using the changeset viewer.