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
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
            services.AddMvc().AddJsonOptions(opcoes =>
            {
                opcoes.SerializerSettings.NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore;
            });

            services.AddSingleton <IProdutoService, ProdutoService>();

            services.AddTransient <IProdutoRepository, ProdutoRepository>();

            //Configuração de propriedades do middleware de compressão
            services.Configure <GzipCompressionProviderOptions>(opcoes =>
            {
                opcoes.Level = CompressionLevel.Optimal;
            });
            services.AddResponseCompression(opcoes =>
            {
                opcoes.Providers.Add <GzipCompressionProvider>();
                opcoes.EnableForHttps = true;
            });

            //AutoMapper
            IMapper mapper = MapperProvider.RegisterMappings().CreateMapper();

            services.AddSingleton(mapper);

            // Service Bus
            services.AddTransient <IServiceBus, ServiceBus>();
            ServiceBusHandler.RegistrarCapturaMensagem(Configuration);
        }
        private void btnJoin_Click(object sender, RoutedEventArgs e)
        {
            // check if handler is empty, if so create an instance of it
            if (_handler == null)
            {
                Player player = new Player();
                player.name = tbName.Text;
                player.type = PlayerType.Guest;

                // get sessin code
                string sessionCode = tbCode.Text;

                StaticResources.sessionCode = sessionCode;

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

                // create Queue connection
                _handler.program.CreateQueueListner(PlayerType.Guest);
                _handler.program.CreateQueueWriter(PlayerType.Guest);

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

            string message = JsonConvert.SerializeObject(StaticResources.user);

            _handler.program.QueueWriter.SendQueueMessage(message, MessageType.JoinRequest, _handler.program.QueueListner.QueueData);
        }
Exemplo n.º 4
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;
        }
Exemplo n.º 5
0
        public async void OnGetJoinHost(string name, string sessionCode)
        {
            // check if handler is empty, if so create an instance of it
            if (ServiceBusHandler.program == null)
            {
                PlayerController playerController = new PlayerController();

                Player player = new Player();
                player.PlayerId = playerController.CreateNewPlayer(name);
                player.name     = name;
                player.type     = PlayerType.Guest;

                StaticResources.sessionCode = sessionCode;

                // create an instance of the servicebus handler
                await ServiceBusHandler.InitiateServiceBusHandler(player);

                await ServiceBusHandler.program.CreateQueueListner(PlayerType.Guest);

                await ServiceBusHandler.program.CreateQueueWriter(PlayerType.Guest);

                ServiceBusHandler.program.QueueListner.MessageReceived += OnQueueMessageReceived;

                string message = JsonConvert.SerializeObject(StaticResources.user);

                await ServiceBusHandler.program.QueueWriter.SendQueueMessageAsync(message, MessageType.JoinRequest, ServiceBusHandler.program.QueueListner.QueueData);

                await ServiceBusHandler.program.QueueWriter.DisconnectFromQueue();

                ServiceBusHandler.program.QueueListner.ConnectToQueue();
            }

            sessionCode = StaticResources.sessionCode;
            players     = 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;
        }
Exemplo n.º 7
0
        public async Task <HttpResponseMessage> PostCustomer(Customer customer)
        {
            HttpResponseMessage response;
            HttpClient          httpClient = new HttpClient();
            string url          = "";
            string authToken    = "";
            string eventbaseurl = "";

            if (ConfigurationManager.AppSettings["IsTestingEnv"].ToString() == "true")
            {
                url          = ConfigurationManager.AppSettings["CutomerAddUrl"].ToString();
                authToken    = ConfigurationManager.AppSettings["authToken"].ToString();
                eventbaseurl = ConfigurationManager.AppSettings["EventApiUrl"].ToString();
            }
            else
            {
                url          = Environment.GetEnvironmentVariable("CutomerAddUrl").ToString();
                authToken    = Environment.GetEnvironmentVariable("authToken");
                eventbaseurl = Environment.GetEnvironmentVariable("EventApiUrl");
            }
            try
            {
                if (Request.Headers.Contains("transactionID"))
                {
                    customer.TransactionID = Request.Headers.GetValues("transactionID").FirstOrDefault();
                }
                if (Request.Headers.Contains("agentID"))
                {
                    customer.AgentId = Request.Headers.GetValues("agentID").FirstOrDefault();
                }
                customer.id = GenerateCustomerId.Generate(9);
                var content       = JsonConvert.SerializeObject(customer);
                var stringContent = new StringContent(content, UnicodeEncoding.UTF8, "application/json");
                var result        = httpClient.PostAsync(url, stringContent);
                response = result.Result;
                if (response.StatusCode == HttpStatusCode.OK)
                {
                    //HttpClient eventHttpClient = new HttpClient();
                    //var eventurl= eventbaseurl+"?customerId=" +customer.id;
                    //eventHttpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", authToken);
                    //var eventresponse=eventHttpClient.GetAsync(eventurl);
                    //eventresponse.Wait();
                    //response = Request.CreateResponse(HttpStatusCode.OK, "Customer details entered succesfully");
                    await ServiceBusHandler.Initialize(JsonConvert.SerializeObject(customer));

                    await CustomerEventRaiser.RaiseNewCustomerEvent(customer.id);
                }
                return(response);
            }
            catch (Exception ex)
            {
                response = Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex);
                return(response);
            }
        }
Exemplo n.º 8
0
        public void OnQueueMessageReceived(string message)
        {
            Transfer transfer = JsonConvert.DeserializeObject <Transfer>(message);

            if (transfer.type == MessageType.Response)
            {
                ServiceBusHandler.HandleQueueMessage(message);
                sessionCode = StaticResources.sessionCode;
                ServiceBusHandler.program.topic.MessageReceived += OnTopicMessageReceived;
            }
        }
Exemplo n.º 9
0
        public void OnTopicMessageReceived(string message)
        {
            Transfer transfer = JsonConvert.DeserializeObject <Transfer>(message);

            if (transfer.type == MessageType.NewPlayer)
            {
                ServiceBusHandler.HandleNewPlayerTopicMessage(message);
                players = StaticResources.PlayerList;
            }

            if (transfer.type == MessageType.StartGame)
            {
                start = true;
            }
        }
Exemplo n.º 10
0
        public async void OnGet()
        {
            if (ServiceBusHandler.program != null)
            {
                if (StaticResources.PlayerList.Count() > 0 && StaticResources.gameCompleted == false)
                {
                    MessageSender messageSender = new MessageSender();
                    messageSender.SendLeaveLobbyMessage();
                }

                TimerHandler.ResetHandler();
                await ServiceBusHandler.ResetData();
            }

            StaticResources.ResetData();
        }
Exemplo n.º 11
0
        public async System.Threading.Tasks.Task <HttpResponseMessage> GetEventAsync(Customer customer)
        {
            HttpResponseMessage response;

            try
            {
                await ServiceBusHandler.Initialize(JsonConvert.SerializeObject(customer));

                response = Request.CreateResponse(HttpStatusCode.OK);
            }
            catch (Exception ex)
            {
                response = Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex);
            }
            return(response);
        }
Exemplo n.º 12
0
 public PlayingField(ServiceBusHandler handler)
 {
     InitializeComponent();
     _handler = handler;
 }
Exemplo n.º 13
0
 public void OnGetRequestNewPlayerList()
 {
     ServiceBusHandler.SendPlayerListRequest();
 }