private void initEvent() { connection.Closed += async(error) => { await Task.Delay(5000); if (!isExit) { try { await connection.StartAsync(); } catch (Exception ex) { CncErrorEvent?.Invoke(ex.Message); } } }; connection.On <string>(SinglarCNCHubConsts.CNCErrorAction, (message) => { CncErrorEvent?.Invoke(message); }); connection.On <HubResultModel>(SinglarCNCHubConsts.CNCDataAction, (data) => { HubRefreshModelEvent?.Invoke(data); }); connection.On <HubReadWriterResultModel>(SinglarCNCHubConsts.GetCNCReaderWriterResultAction, data => { HubReaderWriterResultEvent?.Invoke(data); }); }
public async Task Close() { isExit = true; try { await connection.StopAsync(); } catch (Exception ex) { CncErrorEvent?.Invoke(ex.Message); } }
public void SendCncData(object cncEventDatas) { var json = Newtonsoft.Json.JsonConvert.SerializeObject(cncEventDatas); try { connection.InvokeAsync(SinglarCNCHubConsts.InitRefreshAction, json); } catch (Exception ex) { CncErrorEvent?.Invoke(ex.Message); } }
public async Task Start() { try { await connection.StartAsync(); ConnectId = connection.ConnectionId; } catch (Exception ex) { CncErrorEvent?.Invoke(ex.Message); } }
public async Task Start() { try { await connection.StartAsync(); CncErrorEvent?.Invoke($"服务器{SmartSystemCNCHostConsts.ApiHost}连接成功! {DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}"); } catch (Exception ex) { await Task.Delay(5000); CncErrorEvent?.Invoke(ex.Message + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); await Start(); } }