Пример #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
        /// <summary>
        /// Handle package from client
        /// </summary>
        private void HandlePacket(RenderClient client, BlendFarmMessage p)
        {
            if (p is RenderInfoResponse)
            {
                RenderInfoResponse renderResp = ((RenderInfoResponse)p);

                double progress = Math.Round(((double)renderResp.TilesFinished / renderResp.TilesTotal) * 100, 1);
                if (renderResp.TaskID == CurrentTask)
                {
                    UpdateActivity($"Rendering ({renderResp.TilesFinished}/{renderResp.TilesTotal})", progress);
                }
            }
            if (p is RenderBatchResult)
            {
                RenderBatchResult renderBatchResult = ((RenderBatchResult)p);

                OnBatchResult?.Invoke(this, renderBatchResult);
            }
        }
        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);
        }