예제 #1
0
        public async Task HEADER(WorkerHeader header)
        {
            Term.Success($"Connected new worker: {header.RuntimeVersion}, {header.InstanceUID}, Ver: {header.Version}");
            await Groups.AddToGroupAsync(Context.ConnectionId, header.InstanceUID.ToString());

            await this.Clients.Caller.SendAsync("ACTION", RequestAction.ONLINE);

            workers.Add(Context.ConnectionId, header);
        }
예제 #2
0
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            if (!_state.IsSupported())
            {
                _state.DumpError($"Current OS is not supported.", true);
            }



            Url           = Setting.SignalR.OrDefault("http://localhost:6666/signal/hub");
            SigConnection = new HubConnectionBuilder()
                            .WithUrl(Url)
                            .AddNewtonsoftJsonProtocol()
                            .Build();
            SigConnection.Closed += OnClosed;

            SigConnection.On <RequestAction>("ACTION", async(z) =>
            {
                switch (z)
                {
                case RequestAction.OFFLINE:
                    _state.SwitchDNS(true);
                    break;

                case RequestAction.ONLINE:
                    _state.SwitchDNS("127.0.0.1");
                    await SigConnection.SendAsync("WAIT", 1000, stoppingToken);
                    break;

                case RequestAction.RESTART:
                    _state.Restart();
                    break;
                }
            });

            await SigConnection.StartAsync(stoppingToken).ContinueWith(async x =>
            {
                if (x.Exception != null)
                {
                    await OnClosed(x.Exception);
                }
            }, stoppingToken);

            await SigConnection.SendAsync("HEADER",
                                          WorkerHeader.Collect(_state.InstanceUID), stoppingToken);
        }