Exemplo n.º 1
0
        public void CreateDummyConnection()
        {
            // check if handler is empty, if so create an instance of it
            if (_handler == null)
            {
                Player player = new Player()
                {
                    name        = "",
                    orderNumber = 1,
                    ready       = true,
                    type        = PlayerType.Host
                };

                // create an instance of the servicebus handler
                _handler = new ServiceBusHandler(player, true);

                // initialise SessionCodeGenerator
                SessionCodeGenerator generator = new SessionCodeGenerator();

                // Generade sessionCode
                string sessionCode = generator.GenerateSessionCode();
                StaticResources.sessionCode = sessionCode;

                //_handler.program.CreateQueueConnection(PlayerType.Host);

                //_handler.program.QueueListner.MessageReceived += OnMessageReceived;
            }


            _handler.program.topic.MessageReceived += OnMessageReceived;
        }
Exemplo n.º 2
0
        private void Start_Host(object sender, RoutedEventArgs e)
        {
            // check if handler is empty, if so create an instance of it
            if (_handler == null)
            {
                // initialise SessionCodeGenerator
                SessionCodeGenerator generator = new SessionCodeGenerator();

                // Generade sessionCode
                string sessionCode = generator.GenerateSessionCode();

                StaticResources.sessionCode = sessionCode;

                // Set player data
                Player player = new Player();
                player.name        = tbName.Text;
                player.type        = PlayerType.Host;
                player.orderNumber = 1;

                // create an instance of the servicebus handler
                _handler = new ServiceBusHandler(player, true);

                _handler.program.CreateQueueListner(PlayerType.Host);

                _handler.program.QueueListner.MessageReceived += OnQueueMessageReceived;
                _handler.program.topic.MessageReceived        += OnTopicMessageReceived;
            }

            lblSession.Content = StaticResources.sessionCode;
            lv.ItemsSource     = StaticResources.PlayerList;
        }
        public async void OnGet()
        {
            TimerHandler.SetTimer();
            TimerHandler.StartTimer();
            if (StaticResources.PlayerList.Count() == 0)
            {
                dummy.SetDummyData();
            }

            StaticResources.field.fieldNumber = StaticResources.user.orderNumber;

            if (ServiceBusHandler.program == null)
            {
                Player player = dummy.GetDummyPlayer();

                //field-id doorgeven
                playerId = player;

                // initialise SessionCodeGenerator
                SessionCodeGenerator generator = new SessionCodeGenerator();

                // Generade sessionCode
                StaticResources.sessionCode = generator.GenerateSessionCode();

                await ServiceBusHandler.InitiateServiceBusHandler(player, true);
            }

            ServiceBusHandler.program.topic.MessageReceived += OnTopicMessageReceived;

            players = StaticResources.PlayerList;

            StaticResources.log.MyTurn = StaticResources.user.orderNumber == 1 ? true : false;
        }
        public IActionResult CreateHost([FromBody] PlayerForUpdateDto player)
        {
            try
            {
                if (player == null)
                {
                    _logger.LogError("Player object sent from client is null.");
                    return(BadRequest("Player object is null"));
                }

                if (!ModelState.IsValid)
                {
                    _logger.LogError("Invalid Player object sent from client.");
                    return(BadRequest("Invalid model object"));
                }

                SessionCodeGenerator generator = new SessionCodeGenerator();
                TopicCreator         creator   = new TopicCreator();

                // create new session

                // start create new session code
                string session_code = "";
                bool   inUse        = true;
                while (inUse)
                {
                    session_code = generator.GenerateSessionCode();

                    inUse = _repository.SessionData.ValidateIfActive(session_code);
                }
                // end create new session code

                // start create new session
                SessionData sessionData = new SessionData();
                sessionData.session_code = session_code;

                _repository.SessionData.CreateSession(sessionData);
                // end create new session

                // start create new topic
                TopicData data = creator.CreateNewTopic(session_code);
                data.sessionCode = session_code;

                _repository.TopicData.CreateTopic(data);
                _repository.Save();
                // end create new topic

                // start create new player
                Player PlayerEntity = _mapper.Map <Player>(player);
                PlayerEntity.orderNumber = 1;
                PlayerEntity.session_id  = sessionData.id;

                _repository.Player.CreatePlayer(PlayerEntity);
                _repository.Save();

                // end create new player

                var            session = _repository.SessionData.GetBySessionCodeWithDetails(session_code);
                SessionDataDto result  = _mapper.Map <SessionDataDto>(session);

                return(Ok(result));
                //return CreatedAtRoute("CategoryById", new { id = createdEntity.id }, createdEntity);
            }
            catch (Exception ex)
            {
                _logger.LogError($"Something went wrong inside CreateArtist action: {ex.Message}");
                return(StatusCode(500, "Internal server error"));
            }
        }