コード例 #1
0
        public override void ComponentStateChangeFiring <T>(ComponentStateChange <T> componentStateChange)
        {
            var isApplianceState = typeof(T) != typeof(ThermocoupleState);
            var isServerState    = typeof(T) == typeof(ConnectionState);

            componentStateChange.FromUserName = _applicationConfig.UserName;

            if (_connection.IsConnected()
                &&
                ((isApplianceState && _applicationConfig.IsAppliance()) || (isServerState && _applicationConfig.IsServer()))
                )
            {
                _connection.InvokeAsync("ComponentStateChangeBroadcasted",
                                        componentStateChange.FromUserName,
                                        componentStateChange.GetType().ToString(),
                                        componentStateChange.ToJson());
            }
            base.ComponentStateChangeFiring(componentStateChange);
        }
コード例 #2
0
ファイル: BFHub.cs プロジェクト: mwmichalek/BF
        public override async Task OnConnectedAsync()
        {
            UserHandler.ConnectedIds.Add(Context.ConnectionId);

            var userName = Context.User.Identity.Name;

            if (UserHandler.UserNames.Add(userName))
            {
                var componentStateChange = new ComponentStateChange <ConnectionState> {
                    FromUserName = userName,
                    CurrentState = new ConnectionState {
                        Status = ConnectionStatus.Connected
                    }
                };
                logger.LogInformation($"User connected: {userName} : {UserHandler.UserNames.Count} : {UserHandler.ConnectedIds.Count}");
                await Clients.All.SendAsync("ComponentStateChangeReceived",
                                            userName,
                                            componentStateChange.GetType().ToString(),
                                            componentStateChange.ToJson());
            }
        }