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; } }); }
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; } }); }
/// <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)); }
private static async Task KeepAliveExec <TFault>(ModuleControlScreen screen, Func <Task> keepAliveFunc, ILogger logger) { if (!await WcfCommunicationHelper.KeepAliveExec <TFault>(keepAliveFunc, logger)) { screen.DisableModule(new Exception("Keep alive ping failed."), logger); } }
public override async Task Shutdown() { _logger.Info("Shutdown() of DemoModuleBViewModel called"); if (_keepAlive != null) { _keepAlive.Dispose(); } await WcfCommunicationHelper.WcfCall <IDemoModuleBServiceFault>(() => _client.UnsubscribeEventsAsync(ModuleInstance), () => Task.FromResult(true), _logger); _client.Close(); }
public override async void Stop() { base.Stop(); await WcfCommunicationHelper.WcfCall <IDemoModuleBServiceFault>(() => _client.StopAsync(), EnsureValidWcfClient, _logger); }
public async Task ResetAlarms(string module) { base.ResetAlarms(); await WcfCommunicationHelper.WcfCall <IDemoModuleBServiceFault>(() => _client.ResetAlarmsAsync(ModuleInstance), EnsureValidWcfClient, _logger); }
public override async void Start() { base.Start(); await WcfCommunicationHelper.WcfCall <IEntryStationServiceFault>(() => _client.StartAsync(), EnsureValidWcfClient, _logger); }
public async void GlobalStop() { await WcfCommunicationHelper.WcfCall <CommonServicesFault>(() => _commonServicesClient.StopAllAsync(), EnsureValidCommonServicesWcfConnection, _logger); }
public override async void Start() { base.Start(); await WcfCommunicationHelper.WcfCall <IDemoModuleCServiceFault>(() => _client.StartAsync(ModuleInstance), EnsureValidWcfClient, _logger); }