예제 #1
0
        private async void Page_Loaded(object sender, RoutedEventArgs e)
        {
            loadingText.Text = "checking internet connection";
            ConnectionProfile        connectionProfile = NetworkInformation.GetInternetConnectionProfile();
            NetworkConnectivityLevel level             = connectionProfile.GetNetworkConnectivityLevel();

            if (level != NetworkConnectivityLevel.InternetAccess)
            {
                MessageDialog message = new MessageDialog("You are not connected to the internet. Check your connection setings then restart the app.");
                await message.ShowAsync();

                loadingText.Text = "no internet connection found";
                return;
            }

            loadingText.Text = "loading twitch emotes";
            string globalString = await AppConstants.GetWebData(new Uri("http://www.twitchemotes.com/global.json"));

            JObject globalEmotes = JObject.Parse(globalString);

            foreach (KeyValuePair <string, JToken> o in globalEmotes)
            {
                AppConstants.emotes.Add(new Emote((string)o.Key, (string)o.Value["url"], (string)o.Value["description"]));
            }

            string subscriberString = await AppConstants.GetWebData(new Uri("http://www.twitchemotes.com/subscriber.json"));

            JObject subscriberEmotes = JObject.Parse(subscriberString);

            foreach (KeyValuePair <string, JToken> o in subscriberEmotes)
            {
                AppConstants.subscriberEmotes.Add(new SubscriberEmote((string)o.Key, (JObject)o.Value["emotes"], (string)o.Value["_badge"], (long)o.Value["_set"]));
            }

            string setString = await AppConstants.GetWebData(new Uri("http://twitchemotes.com/api/sets"));

            JObject setMap = JObject.Parse(setString);

            foreach (KeyValuePair <string, JToken> o in setMap)
            {
                AppConstants.sets.Add(long.Parse(o.Key), (string)o.Value);
            }

            StorageFolder roamingFolder = ApplicationData.Current.RoamingFolder;

            loadingText.Text = "looking for settings";
            await LoadQualitySettings(roamingFolder);

            loadingText.Text = "looking for users data";
            await LoadUserData(roamingFolder);
        }
예제 #2
0
        private async void Page_Loaded(object sender, RoutedEventArgs e)
        {
            loadingText.Text = "checking internet connection";
            ConnectionProfile        connectionProfile = NetworkInformation.GetInternetConnectionProfile();
            NetworkConnectivityLevel level             = connectionProfile.GetNetworkConnectivityLevel();

            if (level != NetworkConnectivityLevel.InternetAccess)
            {
                MessageDialog message = new MessageDialog("You are not connected to the internet. Check your connection setings then restart the app.");
                await message.ShowAsync();

                loadingText.Text = "no internet connection found";
                return;
            }

            loadingText.Text = "loading twitch emotes";
            string globalString = await AppConstants.GetWebData(new Uri("http://www.twitchemotes.com/global.json"));

            JObject globalEmotes = JObject.Parse(globalString);

            foreach (KeyValuePair <string, JToken> o in globalEmotes)
            {
                AppConstants.emotes.Add(new Emote((string)o.Key, (string)o.Value["url"], (string)o.Value["description"]));
            }

            string subscriberString = await AppConstants.GetWebData(new Uri("http://www.twitchemotes.com/subscriber.json"));

            JObject subscriberEmotes = JObject.Parse(subscriberString);

            foreach (KeyValuePair <string, JToken> o in subscriberEmotes)
            {
                AppConstants.subscriberEmotes.Add(new SubscriberEmote((string)o.Key, (JObject)o.Value["emotes"], (string)o.Value["_badge"], (long)o.Value["_set"]));
            }

            string setString = await AppConstants.GetWebData(new Uri("http://twitchemotes.com/api/sets"));

            JObject setMap = JObject.Parse(setString);

            foreach (KeyValuePair <string, JToken> o in setMap)
            {
                AppConstants.sets.Add(long.Parse(o.Key), (string)o.Value);
            }

            StorageFolder roamingFolder = ApplicationData.Current.RoamingFolder;

            //await localFolder.DeleteAsync();
            loadingText.Text = "looking for users data";
            try
            {
                StorageFile usersFile = await roamingFolder.GetFileAsync("usersFile.json");

                string usersData = await FileIO.ReadTextAsync(usersFile);

                loadingText.Text = "users data found";
                Dictionary <string, string> users = new Dictionary <string, string>();
                loadingText.Text = "reading users data";
                JObject usersO = JObject.Parse(usersData);
                JObject userO  = (JObject)usersO["user"];
                users.Add((string)userO["name"], (string)userO["access_token"]);
                //JArray usersArray = (JArray)usersO["users"];
                //foreach (JObject user in usersArray)
                //{
                //    users.Add((string)user["name"], (string)user["access_token"]);
                //}

                User tempUser = null;
                foreach (KeyValuePair <string, string> user in users)
                {
                    loadingText.Text = "loading " + user.Key.ToString();
                    tempUser         = await AppConstants.twixel.RetrieveUserWithAccessToken(user.Value);

                    if (tempUser == null)
                    {
                        loadingText.Text = user.Value + "'s token invalid";
                        Frame.Navigate(typeof(FirstLaunchInfo));
                        return;
                    }
                }
                AppConstants.ActiveUser = tempUser;
                Frame.Navigate(typeof(HomePage));
            }
            catch (FileNotFoundException ex)
            {
                loadingText.Text = "users data not found";
                Frame.Navigate(typeof(FirstLaunchInfo));
            }
        }