private async void LoadGames()
        {
            var client   = new RestClient("https://cecs475-boardamges.herokuapp.com/");
            var request  = new RestRequest("api/games", Method.GET);
            var task     = client.ExecuteTaskAsync(request);
            var response = await task;

            if (response.StatusCode == System.Net.HttpStatusCode.NotFound)
            {
                MessageBox.Show("No games found");
            }
            else
            {
                JArray games = JArray.Parse(response.Content);
                foreach (var game in games)
                {
                    WebClient webClient = new WebClient();
                    Uri       uri       = new Uri(game["Files"][0]["Url"].ToString());
                    string    filePath  = "games/" + game["Files"][0]["FileName"].ToString();
                    await webClient.DownloadFileTaskAsync(uri, filePath);

                    uri      = new Uri(game["Files"][1]["Url"].ToString());
                    filePath = "games/" + game["Files"][1]["FileName"].ToString();
                    await webClient.DownloadFileTaskAsync(uri, filePath);
                }

                GameChoiceWindow gameChoiceWindow = new GameChoiceWindow();
                this.Close();
                gameChoiceWindow.Show();
            }
        }
示例#2
0
        async void OnLoad(object sender, RoutedEventArgs e)
        {
            var temp             = downloadFile();
            var temp2            = await temp;
            GameChoiceWindow gcw = new GameChoiceWindow();

            gcw.Show();
            this.Close();
        }
        async void OnLoad(object sender, RoutedEventArgs e)
        {
            var webAPI = new WebClient();
            await webAPI.ProcessGames();

            var gameChoiceWindow = new GameChoiceWindow();

            this.Close();
            gameChoiceWindow.Show();
        }
        private async void mLoaded(object sender, RoutedEventArgs e)
        {
            var client   = new RestClient("https://cecs475-boardamges.herokuapp.com/");
            var request  = new RestRequest("api/games", Method.GET);
            var response = await client.ExecuteTaskAsync(request);

            string r = response.Content;

            r = r.Substring(1);
            r = r.Substring(0, r.Length - 1);
            var           games   = JObject.Parse(r);
            JToken        results = games.Last.First;
            List <string> strList = new List <string>();
            List <JToken> things  = new List <JToken>()
            {
                results.First, results.Last
            };

            foreach (JToken t in things)
            {
                JToken token = t.First;
                do
                {
                    strList.Add(token.First.ToObject <string>());
                    token = token.Next;
                }while (token != null);
            }
            for (int i = 0; i < strList.Count(); i++)
            {
                string val = strList.ElementAt(i);
                if (val.Contains("https"))
                {
                    var web = new WebClient();
                    await web.DownloadFileTaskAsync(val, "games/" + strList.ElementAt(i - 1));
                }
            }


            GameChoiceWindow cgw = new GameChoiceWindow();

            cgw.Show();
            this.Close();
        }
        private async void Window_Loaded(object sender, RoutedEventArgs e)
        {
            var client  = new RestClient("https://cecs475-boardamges.herokuapp.com");
            var request = new RestRequest("/api/games", Method.GET);

            var response = client.Execute(request);

            if (response.StatusCode == System.Net.HttpStatusCode.NotFound)
            {
                MessageBox.Show("Failed to Connect");
            }
            else
            {
                dynamic b = JsonConvert.DeserializeObject(response.Content);
                await DownloadFileTaskAsync(b);
            }
            int milliseconds = 2000;

            var gamewindow = new GameChoiceWindow();
        }
示例#6
0
        public async void OnLoad(object sender, RoutedEventArgs e)
        {
            var client   = new RestClient("https://cecs475-boardamges.herokuapp.com/api/games");
            var request  = new RestRequest(Method.GET);
            var response = await client.ExecuteAsync(request);

            var games = JsonConvert.DeserializeObject <List <Game> >(response.Content);

            foreach (Game game in games)
            {
                WebClient webClient = new WebClient();
                foreach (Info file in game.Files)
                {
                    await webClient.DownloadFileTaskAsync(file.URL, "..\\Debug\\games\\" + file.FileName);
                }
            }

            GameChoiceWindow gameChoiceWindow = new GameChoiceWindow();

            gameChoiceWindow.Show();
            this.Close();
        }