/// <summary> /// Call <see cref="TContract"/> method. /// </summary> /// <typeparam name="TContract">Contract type.</typeparam> /// <typeparam name="T"></typeparam> /// <param name="wcfClientFactory"></param> /// <param name="action"></param> /// <returns></returns> public static T Use <TContract, T>(this IWcfClientFactory <TContract> wcfClientFactory, Func <TContract, T> action) { using (var wcfClient = wcfClientFactory.Create()) { try { return(action(wcfClient.Service)); } catch (Exception exception) { LogException(exception); throw; } } }
/// <summary> /// Call <see cref="TContract"/> method. /// </summary> /// <typeparam name="TContract">Contract type.</typeparam> /// <param name="wcfClientFactory"></param> /// <param name="action"></param> public static void Use <TContract>(this IWcfClientFactory <TContract> wcfClientFactory, Action <TContract> action) { using (var wcfClient = wcfClientFactory.Create()) { try { action(wcfClient.Service); } catch (Exception exception) { LogException(exception); throw; } } }
private async void OnConnect(object o) { if (string.IsNullOrWhiteSpace(PlayerName)) { ConnectionError = "You name is empty"; return; } await Task.Factory.StartNew( () => { try { using (ConnectionView()) { string sessionId = null; if (_userService.Use(service => service.Login(_playerName, out sessionId))) { SessionId = sessionId; _chessClient = _chessService.Create(_serviceCallback); _chessClient.Service.Ready(sessionId); OpponentView(); } else { ConnectionError = "Login failed"; } } } catch (Exception ex) { ConnectionError = ex.Message; } }); }