/// <summary> /// Connect to node /// </summary> public async Task Connect() { if (!Connected) { UpdateActivity("Connecting"); try { Client = await RenderClient.Connect(Address); Client.OnConnected += (a) => OnConnected?.Invoke(this); Client.OnDisconnected += (a) => OnDisconnected?.Invoke(this); Client.OnPacket += HandlePacket; CheckProtocolResponse protocolResp = null; try { protocolResp = await CheckProtocol(MinumumVersionMajor, MinimumVersionMinor, MinimumVersionPatch, Protocol.Version); } catch (Exception ex) { throw new InvalidOperationException("Outdated protocol, exception during check (" + ex.Message + ")"); } if (protocolResp == null || Protocol.Version != protocolResp.ProtocolVersion) { throw new InvalidOperationException($"Outdated protocol, update node before connecting (Protocol: {Protocol.Version}, Found: {protocolResp?.ProtocolVersion})"); } ComputerInfoResponse compData = await GetComputerInfo(); OS = compData.OS; Cores = compData.Cores; ComputerName = compData.Name; UpdateException(""); OnConnected?.Invoke(this); } catch (Exception ex) { UpdateException(ex.Message); Client = null; throw; } finally { UpdateActivity(""); } } }
public static async Task <RenderClient> Connect(string address) { RenderClient client = new RenderClient(address); if (!await client.Connect()) { return(null); } if (!client.Connected) { return(null); } //ComputerInfoResponse info = await client.GetComputerInfoAsync(); if (!client.Connected) { return(null); } return(client); }