예제 #1
0
        /// <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("");
                }
            }
        }
예제 #2
0
        //Check Client Data

        /// <summary>
        /// Returns information about this machine
        /// </summary>
        public async Task <ComputerInfoResponse> GetComputerInfo()
        {
            if (!Connected)
            {
                throw new InvalidOperationException("Not connected");
            }

            ComputerInfoResponse resp = await Client.Send <ComputerInfoResponse>(new ComputerInfoRequest(), CancellationToken.None);

            if (resp != null)
            {
                ComputerName = resp.Name;
                Cores        = resp.Cores;
                OS           = resp.OS;
            }

            return(resp);
        }