예제 #1
0
        private void OnAuthentication(string data)
        {
            if (Context.IsSecureConnection == false)
            {
                //decode data
            }

            try {
                var authData = JSON.ToObject <stAuthData>(data);
                var UserID   = DBManager.login.GetUserId(authData.Login, authData.Hash);
                if (UserID == 0)
                {
                    SendData(JSON.ToJSON(new stAuthRespose {
                        status   = AuthStatus.FAIL,
                        response = "Invalid auth data!"
                    }));
                    Disconnect(CloseStatusCode.InvalidData, "Invalid auth data!");
                }
                else
                {
                    this.UserID = UserID;
                    IsAuth      = true;
                    ClientType  = authData.client_type;
                    SendData(JSON.ToJSON(new stAuthRespose {
                        status = AuthStatus.OK, response = ""
                    }));
                    onClientConnect?.Invoke(this);
                }
            }
            catch (Exception ex) {
                /*Logger : $"Exception from {ex.Source}: {ex.Message}\nIncoming data:{data}\nStack trace:\n{ex.StackTrace}" */
            }
        }
예제 #2
0
        void INovaAlertService.UnSubscribe(int clientId, eClientType type)
        {
            var existClient = _resources.Clients.FirstOrDefault(c => c.Type == type && c.Id == clientId);

            if (existClient != null)
            {
                _resources.Actions.Add(existClient, eAction.Unsubscribe);
                OnClientDisconnected(existClient);
                AddLog(existClient, "Ngắt kết nối");
            }
        }
예제 #3
0
 void INovaAlertService.UnSubscribe(int clientId, eClientType type)
 {
     try
     {
         if (CheckConnection() == false)
         {
             throw new ServiceException();
         }
         _realProxy.UnSubscribe(clientId, type);
     }
     catch (Exception ex)
     {
         OnException(ex);
     }
 }
예제 #4
0
        void INovaAlertService.Subscribe(int clientId, eClientType type)
        {
            // Check if exist then unsubscribe
            ((INovaAlertService)this).UnSubscribe(clientId, type);

            // Register new client
            INovaAlertServiceCallback callback = OperationContext.Current.GetCallbackChannel <INovaAlertServiceCallback>();
            var client = new Client(clientId)
            {
                Type = type, Callback = callback, LastAction = DateTime.Now
            };

            _resources.Clients.Add(client);
            _resources.Actions.Add(client, eAction.Subscribe);

            client.PropertyChanged += client_PropertyChanged;

            AddLog(client, "Kết nối");
        }