コード例 #1
0
        public async Task <IActionResult> Index(string id, string mode)
        {
            if (mode == "creategame")
            {
                Uri serviceName  = GameWeb.GetGameDataServiceName(_serviceContext);
                Uri proxyAddress = this.GetProxyAddress(serviceName);

                string proxyUrl =
                    $"{proxyAddress}/api/GamesData/{id}?PartitionKey={GetPartition(id)}&PartitionKind=Int64Range";

                using (HttpResponseMessage response = await _httpClient.PostAsync(proxyUrl, new StringContent("")))
                {
                    if (response.StatusCode == System.Net.HttpStatusCode.BadRequest)
                    {
                        return(BadRequest());
                    }

                    return(Redirect($"Games/{id}"));
                }
            }
            else if (mode == "signin")
            {
                Response.Cookies.Append("userid", id, new Microsoft.AspNetCore.Http.CookieOptions {
                    Expires = DateTime.Now.AddDays(1),
                });

                return(Redirect($"/"));
            }
            else
            {
                return(BadRequest());
            }
        }
コード例 #2
0
        public async Task <IActionResult> GetState(string id)
        {
            Uri serviceName  = GameWeb.GetGameDataServiceName(_serviceContext);
            Uri proxyAddress = this.GetProxyAddress(serviceName);

            string proxyUrl =
                $"{proxyAddress}/api/GamesData/{id}?PartitionKey={GetPartition(id)}&PartitionKind=Int64Range";

            using (HttpResponseMessage response = await _httpClient.GetAsync(proxyUrl))
            {
                if (response.StatusCode != System.Net.HttpStatusCode.OK)
                {
                    return(NotFound());
                }

                return(Ok(await response.Content.ReadAsStringAsync()));
            }
        }
コード例 #3
0
        public async Task <IActionResult> Put(string id, int idx)
        {
            var userId = Request.Cookies["userid"];

            Uri serviceName  = GameWeb.GetGameDataServiceName(_serviceContext);
            Uri proxyAddress = this.GetProxyAddress(serviceName);

            string proxyUrl =
                $"{proxyAddress}/api/GamesData/{id}?PartitionKey={GetPartition(id)}&PartitionKind=Int64Range";

            using (HttpResponseMessage response = await _httpClient.PutAsJsonAsync(proxyUrl, new { player = userId, idx }))
            {
                if (response.StatusCode != System.Net.HttpStatusCode.OK)
                {
                    return(BadRequest(response.ReasonPhrase));
                }

                string[] result = JsonConvert.DeserializeObject <string[]>(await response.Content.ReadAsStringAsync());
                return(Json(result));
            }
        }
コード例 #4
0
        public async Task <IActionResult> Index()
        {
            var userId = Request.Cookies["userid"];

            ViewBag.IsLoggedIn = userId != null;

            List <string> result = new List <string>();

            Uri serviceName  = GameWeb.GetGameDataServiceName(_serviceContext);
            Uri proxyAddress = this.GetProxyAddress(serviceName);

            try
            {
                ServicePartitionList partitions = await _fabricClient.QueryManager.GetPartitionListAsync(serviceName);

                foreach (Partition partition in partitions)
                {
                    string proxyUrl =
                        $"{proxyAddress}/api/GamesData?PartitionKey={((Int64RangePartitionInformation)partition.PartitionInformation).LowKey}&PartitionKind=Int64Range";

                    using (HttpResponseMessage response = await _httpClient.GetAsync(proxyUrl))
                    {
                        if (response.StatusCode != System.Net.HttpStatusCode.OK)
                        {
                            continue;
                        }

                        result.AddRange(JsonConvert.DeserializeObject <IEnumerable <string> >(await response.Content.ReadAsStringAsync()));
                    }
                }
            }
            catch
            {
            }

            return(View(result.ToArray()));
        }
コード例 #5
0
        public async Task <IActionResult> Index(string id)
        {
            var userId = Request.Cookies["userid"];

            Uri serviceName  = GameWeb.GetGameDataServiceName(_serviceContext);
            Uri proxyAddress = this.GetProxyAddress(serviceName);

            string proxyUrl =
                $"{proxyAddress}/api/GamesData/AddPlayer/{id}?PartitionKey={GetPartition(id)}&PartitionKind=Int64Range";

            using (HttpResponseMessage response = await _httpClient.PutAsJsonAsync(proxyUrl, new { player = userId }))
            {
                if (response.StatusCode == System.Net.HttpStatusCode.OK)
                {
                    ViewBag.Role = JsonConvert.DeserializeObject <string>(await response.Content.ReadAsStringAsync());
                }
                else
                {
                    ViewBag.Role = "Spectator";
                }
            }

            proxyUrl =
                $"{proxyAddress}/api/GamesData/{id}?PartitionKey={GetPartition(id)}&PartitionKind=Int64Range";

            using (HttpResponseMessage response = await _httpClient.GetAsync(proxyUrl))
            {
                if (response.StatusCode != System.Net.HttpStatusCode.OK)
                {
                    return(NotFound());
                }

                string[] gameState = JsonConvert.DeserializeObject <string[]>(await response.Content.ReadAsStringAsync());
                return(View(gameState));
            }
        }