Exemplo n.º 1
0
        public StatusPageViewModel(IConnectionHandler connectionHandler)
        {
            _connectionHandler    = connectionHandler;
            _wifiObserver         = new WifiObserver();
            _postWifiEventService = new PostWifiEventService();

            ViewEventsCommand = new RelayCommand(OpenEventWindow);
            LogoutCommand     = new EventRelayCommand(OnLogoutClicked);
            ExitCommand       = new EventRelayCommand(OnExitClicked);

            if (_connectionHandler.IsConnected())
            {
                _wifiObserver.WifiStateChanged += WifiStateChanged;
                _wifiObserver.StartListening();
            }
        }
        private async Task GetEventsAsync()
        {
            EventList.Clear();

            if (!_connectionHandler.IsConnected())
            {
                EventList.Add(new WifiEventRow("You are not logged in!"));
                return;
            }

            var session = _connectionHandler.GetSession();
            var events  = await _getWifiEventsService.GetEvents(session, session.ObjectId);

            if (events.ResponseStatus != RestResponseStatus.Ok)
            {
                EventList.Add(new WifiEventRow("Error connecting to the backend services!"));
                return;
            }

            foreach (WifiEvent wifiEvent in events.WifiEvents)
            {
                EventList.Add(new WifiEventRow(wifiEvent.ToString()));
            }
        }
        protected override void OnUpdate()
        {
            if (!connection.IsConnected())
            {
                return;
            }

            var entityType = GetArchetypeChunkEntityType();

            var createEntityType     = GetArchetypeChunkComponentType <WorldCommands.CreateEntity.CommandSender>();
            var deleteEntityType     = GetArchetypeChunkComponentType <WorldCommands.DeleteEntity.CommandSender>();
            var reserveEntityIdsType = GetArchetypeChunkComponentType <WorldCommands.ReserveEntityIds.CommandSender>();
            var entityQueryType      = GetArchetypeChunkComponentType <WorldCommands.EntityQuery.CommandSender>();

            var chunkArray = group.CreateArchetypeChunkArray(Allocator.TempJob);

            foreach (var chunk in chunkArray)
            {
                var entityArray = chunk.GetNativeArray(entityType);

                var createEntitySenders = chunk.GetNativeArray(createEntityType);
                for (var i = 0; i < createEntitySenders.Length; ++i)
                {
                    var requestsToSend = createEntitySenders[i].RequestsToSend;
                    var entity         = entityArray[i];
                    foreach (var req in requestsToSend)
                    {
                        commandSystem.SendCommand(req, entity);
                    }

                    requestsToSend.Clear();
                }

                var deleteEntitySenders = chunk.GetNativeArray(deleteEntityType);
                for (var i = 0; i < deleteEntitySenders.Length; ++i)
                {
                    var requestsToSend = deleteEntitySenders[i].RequestsToSend;
                    var entity         = entityArray[i];
                    foreach (var req in requestsToSend)
                    {
                        commandSystem.SendCommand(req, entity);
                    }

                    requestsToSend.Clear();
                }

                var reserveEntityIdsSenders = chunk.GetNativeArray(reserveEntityIdsType);
                for (var i = 0; i < reserveEntityIdsSenders.Length; ++i)
                {
                    var requestsToSend = reserveEntityIdsSenders[i].RequestsToSend;
                    var entity         = entityArray[i];
                    foreach (var req in requestsToSend)
                    {
                        commandSystem.SendCommand(req, entity);
                    }

                    requestsToSend.Clear();
                }

                var entityQuerySenders = chunk.GetNativeArray(entityQueryType);
                for (var i = 0; i < entityQuerySenders.Length; ++i)
                {
                    var requestsToSend = entityQuerySenders[i].RequestsToSend;
                    var entity         = entityArray[i];
                    foreach (var req in requestsToSend)
                    {
                        commandSystem.SendCommand(req, entity);
                    }

                    requestsToSend.Clear();
                }
            }

            chunkArray.Dispose();
        }
        public byte[] HandleReceivedBytes(byte[] receivedBytes)
        {
            var       requestType0 = receivedBytes[1];
            var       requestType1 = receivedBytes[2];
            var       requestType2 = receivedBytes[3];
            var       requestType3 = receivedBytes[4];
            var       counter      = BitConverter.ToUInt16(receivedBytes, 7);
            IResponse response;

            try
            {
                var request     = _requestParser.Parse(receivedBytes);
                var requestType = (RequestTypeAttribute)request.GetType().GetCustomAttributes(typeof(RequestTypeAttribute), true)[0];
                if (request is IConnectionRequiredRequest connectionRequiredRequest && !_connectionHandler.IsConnected(new[] { connectionRequiredRequest.ConnectionIdentifier0, connectionRequiredRequest.ConnectionIdentifier1, connectionRequiredRequest.ConnectionIdentifier2, connectionRequiredRequest.ConnectionIdentifier3 }))
                {
                    response = new CommonErrorResponse(CommonResponseCode.NotConnected, counter, requestType0, requestType1, requestType2, requestType3);
                }
                else if (!_requestHandlerTypes.TryGetValue(requestType, out var requestHandlerType))
                {
                    response = new CommonErrorResponse(CommonResponseCode.UnknownCommand, counter, requestType0, requestType1, requestType2, requestType3);
                }
                else
                {
                    var requestHandler = (IRequestHandler)_serviceLocator.Locate(requestHandlerType);
                    response = requestHandler.Handle(request);
                }
            }