private async Task EnsureValidConfigurationServiceWcfConnection()
 {
     await
     WcfCommunicationHelper.StartWcfClient <ConfigurationServiceClient, ConfigurationFault, ConfigurationService.IConfigurationService>(this, _configurationServiceClient,
                                                                                                                                        c => new ConfigurationServiceClient(), async c =>
     {
         _configurationServiceClient = c;
         try
         {
             if (_keepAliveConfigurationService != null)
             {
                 _keepAliveConfigurationService.Dispose();
             }
             if (!await c.get_IsInitializedAsync())
             {
                 IsEnabled = false;
                 return;
             }
             _keepAliveConfigurationService = WcfCommunicationHelper.KeepAlive <ConfigurationFault>(c.KeepAliveAsync, _logger);
             IsEnabled = true;
         }
         catch (Exception ex)
         {
             _logger.Error("Error connecting to configuration service.", ex);
             IsEnabled = false;
         }
     });
 }
 private async Task EnsureValidCommonServicesWcfConnection()
 {
     await
     WcfCommunicationHelper.StartWcfClient <CommonServicesClient, CommonServicesFault, ICommonServices>(this, _commonServicesClient, c => new CommonServicesClient(new InstanceContext(this)),
                                                                                                        async c =>
     {
         _commonServicesClient = c;
         try
         {
             if (_keepAliveCommonServices != null)
             {
                 _keepAliveCommonServices.Dispose();
             }
             if (!await c.get_IsAliveAndInitializedAsync())
             {
                 IsEnabled = false;
                 return;
             }
             await c.SubscribeEventsAsync();
             await c.SubscribeModuleStateEventsAsync();
             var result = await _commonServicesClient.RequestStatesAsync();
             UpdateModuleStates(result);
             _keepAliveCommonServices = WcfCommunicationHelper.KeepAlive <CommonServicesFault>(c.get_IsAliveAndInitializedAsync, _logger);
             IsEnabled = true;
         }
         catch (Exception ex)
         {
             _logger.Error("Error connecting to common services.", ex);
             IsEnabled = false;
         }
     });
 }
Esempio n. 3
0
 /// <summary>
 /// Starts a WCF connection.
 /// </summary>
 /// <typeparam name="TClient">The WCF client type to be used.</typeparam>
 /// <typeparam name="TFault">The WCF fault type that can be thrown by the client.</typeparam>
 /// <typeparam name="TChannel">The WCF channel.</typeparam>
 /// <param name="screen">The screen to which this extension method is valid for.</param>
 /// <param name="client">The WCF client that's currently exicsting and should be closed before a new one is created. Provide null if this doesn't exist.</param>
 /// <param name="createFunc">A function to create a WCF client.</param>
 /// <param name="logger">The logger to log errors.</param>
 /// <param name="postStartFunc">A method that is called after the client has been created to do custom initialization, such as starting a KeepAlive schedule.</param>
 /// <returns>A task that, when completed, returns the newly created WCF client.</returns>
 public static async Task <TClient> StartWcfClient <TClient, TFault, TChannel>(this ModuleControlScreen screen, TClient client,
                                                                               Func <InstanceContext, TClient> createFunc, ILogger logger, Func <TClient, Task> postStartFunc)
     where TChannel : class
     where TClient : ClientBase <TChannel>
 {
     return(await WcfCommunicationHelper.StartWcfClient <TClient, TFault, TChannel>(screen, client, createFunc, postStartFunc));
 }