public async Task <UserAccountEntity.User> GetUserEntity(UserAccountEntity userAccountEntity)
        {
            try
            {
                var authenticationManager = new AuthenticationManager();
                if (userAccountEntity.GetAccessToken().Equals("refresh"))
                {
                    await authenticationManager.RefreshAccessToken(userAccountEntity);
                }
                string url           = "https://vl.api.np.km.playstation.net/vl/api/v1/mobile/users/me/info";
                var    theAuthClient = new HttpClient();
                var    request       = new HttpRequestMessage(HttpMethod.Get, url);
                request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", userAccountEntity.GetAccessToken());
                HttpResponseMessage response = await theAuthClient.SendAsync(request);

                string responseContent = await response.Content.ReadAsStringAsync();

                if (string.IsNullOrEmpty(responseContent))
                {
                    return(null);
                }
                UserAccountEntity.User user = UserAccountEntity.ParseUser(responseContent);
                return(user);
            }
            catch (Exception)
            {
                return(null);
            }
        }
        public async Task <UserAccountEntity.User> GetUserEntity(UserAccountEntity userAccountEntity)
        {
            try
            {
                var authenticationManager = new AuthenticationManager();
                if (userAccountEntity.GetAccessToken().Equals("refresh"))
                {
                    await authenticationManager.RefreshAccessToken(userAccountEntity);
                }
                var theAuthClient = new HttpClient();
                var request       = new HttpRequestMessage(HttpMethod.Get, UrlConstants.VerifyUser);
                request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", userAccountEntity.GetAccessToken());
                HttpResponseMessage response = await theAuthClient.SendAsync(request);

                string responseContent = await response.Content.ReadAsStringAsync();

                if (string.IsNullOrEmpty(responseContent))
                {
                    return(null);
                }
                UserAccountEntity.User user = UserAccountEntity.ParseUser(responseContent);
                return(user);
            }
            catch (Exception)
            {
                return(null);
            }
        }
Esempio n. 3
0
 public MainPivotView()
 {
     InitializeComponent();
     BuildLocalizedApplicationBar();
     _user = App.UserAccountEntity.GetUserEntity();
     FilterListPicker.ItemsSource       = BuildFilterItemEntities();
     FilterListPicker.SelectionChanged += FilterListPicker_OnSelectionChanged;
     //Get online friends list by default.
 }
Esempio n. 4
0
        protected async override void OnInvoke(Microsoft.Phone.Scheduler.ScheduledTask task)
        {
            var  userAccountEntity = new UserAccountEntity();
            var  authManager       = new AuthenticationManager();
            bool loginTest         = await authManager.RefreshAccessToken(userAccountEntity);

            if (loginTest)
            {
                UserAccountEntity.User user = await authManager.GetUserEntity(userAccountEntity);

                if (user == null)
                {
                    return;
                }
                userAccountEntity.SetUserEntity(user);
                NotificationEntity notificationEntity = await GetNotifications(userAccountEntity);

                if (notificationEntity == null)
                {
                    return;
                }
                if (notificationEntity.Notifications == null)
                {
                    return;
                }
                var notificationList = notificationEntity.Notifications.Where(o => o.SeenFlag == false);
                NotificationEntity.Notification firstNotification = notificationList.FirstOrDefault();
                ShellTile appTile = ShellTile.ActiveTiles.First();
                if (firstNotification != null)
                {
                    var toastMessage = firstNotification.Message;
                    var toast        = new ShellToast {
                        Title = "FoulPlay", Content = toastMessage
                    };
                    toast.Show();
                    if (appTile != null)
                    {
                        var tileData = new FlipTileData
                        {
                            Title           = "FoulPlay",
                            BackTitle       = "FoulPlay",
                            BackContent     = firstNotification.Message,
                            WideBackContent = firstNotification.Message,
                            Count           = notificationList.Count()
                        };
                        appTile.Update(tileData);
                    }
                    await NotificationManager.ClearNotification(firstNotification, userAccountEntity);
                }
            }
#if DEBUG_AGENT
            ScheduledActionService.LaunchForTest(task.Name, TimeSpan.FromSeconds(60));
#endif
            NotifyComplete();
        }
Esempio n. 5
0
        public async Task <UserAccountEntity> LoginTest(UserAccountEntity userAccountEntity)
        {
            var authManager = new AuthenticationManager();

            UserAccountEntity.User user = await authManager.GetUserEntity(userAccountEntity);

            if (user == null)
            {
                return(null);
            }
            userAccountEntity.SetUserEntity(user);
            return(userAccountEntity);
        }
        /// <summary>
        ///     Populates the page with content passed during navigation. Any saved state is also
        ///     provided when recreating a page from a prior session.
        /// </summary>
        /// <param name="sender">
        ///     The source of the event; typically <see cref="NavigationHelper" />
        /// </param>
        /// <param name="e">
        ///     Event data that provides both the navigation parameter passed to
        ///     <see cref="Frame.Navigate(Type, Object)" /> when this page was initially requested and
        ///     a dictionary of state preserved by this page during an earlier
        ///     session. The state will be null the first time a page is visited.
        /// </param>
        private void navigationHelper_LoadState(object sender, LoadStateEventArgs e)
        {
            _vm = (RecentActivityPageViewModel)DataContext;

            if (e.PageState != null && e.PageState.ContainsKey("userEntity") && App.UserAccountEntity == null)
            {
                string savedStateJson = e.PageState["userAccountEntity"].ToString();
                App.UserAccountEntity = JsonConvert.DeserializeObject <UserAccountEntity>(savedStateJson);
                savedStateJson        = e.PageState["userEntity"].ToString();
                _user = JsonConvert.DeserializeObject <UserAccountEntity.User>(savedStateJson);
                App.UserAccountEntity.SetUserEntity(_user);
            }
            _user = App.UserAccountEntity.GetUserEntity();
            _vm.SetRecentActivityFeed();
        }
        private async Task Update(IBackgroundTaskInstance taskInstance)
        {
            try
            {
                var  userAccountEntity = new UserAccountEntity();
                var  authManager       = new AuthenticationManager();
                bool loginTest         = await authManager.RefreshAccessToken(userAccountEntity);

                if (loginTest)
                {
                    UserAccountEntity.User user = await authManager.GetUserEntity(userAccountEntity);

                    if (user == null)
                    {
                        return;
                    }
                    userAccountEntity.SetUserEntity(user);
                    NotificationEntity notificationEntity = await GetNotifications(userAccountEntity);

                    if (notificationEntity == null)
                    {
                        return;
                    }
                    if (notificationEntity.Notifications == null)
                    {
                        return;
                    }

                    // Debug
                    //NotifyStatusTile.CreateNotificationLiveTile(notificationEntity.Notifications.First());
                    //NotifyStatusTile.CreateToastNotification(notificationEntity.Notifications.First());

                    var notificationList = notificationEntity.Notifications.Where(o => o.SeenFlag == false);
                    foreach (var notification in notificationList)
                    {
                        NotifyStatusTile.CreateNotificationLiveTile(notification);
                        NotifyStatusTile.CreateToastNotification(notification);
                        await NotificationManager.ClearNotification(notification, userAccountEntity);
                    }
                }
            }
            catch (Exception)
            {
                Debug.WriteLine("Failed to show toast/live tile notification");
            }
        }
        /// <summary>
        ///     Populates the page with content passed during navigation.  Any saved state is also
        ///     provided when recreating a page from a prior session.
        /// </summary>
        /// <param name="sender">
        ///     The source of the event; typically <see cref="NavigationHelper" />
        /// </param>
        /// <param name="e">
        ///     Event data that provides both the navigation parameter passed to
        ///     <see cref="Frame.Navigate(Type, Object)" /> when this page was initially requested and
        ///     a dictionary of state preserved by this page during an earlier
        ///     session.  The state will be null the first time a page is visited.
        /// </param>
        private void NavigationHelper_LoadState(object sender, LoadStateEventArgs e)
        {
            _vm = (MessagePageViewModel)DataContext;

            if (e.PageState != null && e.PageState.ContainsKey("userEntity") && App.UserAccountEntity == null)
            {
                string savedStateJson = e.PageState["userAccountEntity"].ToString();
                App.UserAccountEntity = JsonConvert.DeserializeObject <UserAccountEntity>(savedStateJson);
                savedStateJson        = e.PageState["userEntity"].ToString();
                _user = JsonConvert.DeserializeObject <UserAccountEntity.User>(savedStateJson);
                App.UserAccountEntity.SetUserEntity(_user);
            }
            var jsonObjectString = (string)e.NavigationParameter;

            _messageGroup = JsonConvert.DeserializeObject <MessageGroupEntity.MessageGroup>(jsonObjectString);
            _vm.SetMessages(_messageGroup.MessageGroupId, App.UserAccountEntity);
        }
Esempio n. 9
0
        public object Convert(object value, Type targetType, object parameter, string language)
        {
            if (value == null)
            {
                return(null);
            }
            var message = (MessageGroupEntity.MessageGroup)value;

            MessageGroupEntity.MessageGroupDetail messageGroupDetail = message.MessageGroupDetail;
            UserAccountEntity.User user             = App.UserAccountEntity.GetUserEntity();
            List <string>          stringEnumerable =
                messageGroupDetail.Members.Where(member => !member.OnlineId.Equals(user.OnlineId))
                .Select(member => member.OnlineId)
                .ToList();

            return(string.Join <string>(",", stringEnumerable));
        }
Esempio n. 10
0
        protected override async void OnActivated(IActivatedEventArgs args)
        {
            base.OnActivated(args);
            if (args.Kind != ActivationKind.Protocol)
            {
                return;
            }
            var eventArgs = args as ProtocolActivatedEventArgs;

            if (eventArgs == null)
            {
                return;
            }
            IReadOnlyDictionary <string, string> queryString = UriExtensions.ParseQueryString(eventArgs.Uri);

            if (!queryString.ContainsKey("authCode"))
            {
                return;
            }
            var  authManager = new AuthenticationManager();
            bool test        = await authManager.RequestAccessToken(queryString["authCode"]);

            if (!test)
            {
                return;
            }
            bool loginTest = await LoginTest();

            if (!loginTest)
            {
                return;
            }
            UserAccountEntity.User user = await authManager.GetUserEntity(UserAccountEntity);

            if (user == null)
            {
                return;
            }
            UserAccountEntity.SetUserEntity(user);
            var rootFrame = Window.Current.Content as Frame;

            if (rootFrame != null)
            {
                rootFrame.Navigate(typeof(MainPage));
            }
        }
Esempio n. 11
0
        /// <summary>
        /// Checks if the user has an authenication token. If we do, load the user and go to the
        /// main page. If not, load the login screen and redirect them to IE.
        /// </summary>
        private async void LoginTest()
        {
            App.UserAccountEntity = new UserAccountEntity();
            var  authManager = new AuthenticationManager();
            bool loginTest   = await authManager.RefreshAccessToken(App.UserAccountEntity);

            if (loginTest)
            {
                // We have a token! Start the background processing and clear all old notifications.
                StartPeriodicAgent();

                UserAccountEntity.User user = await authManager.GetUserEntity(App.UserAccountEntity);

                if (user == null)
                {
                    MessageBox.Show(AppResources.GenericError);
                    Application.Current.Terminate();
                }
                App.UserAccountEntity.SetUserEntity(user);

                // Clears old notifications and resets the live tile.
                // Note that this ONLY clears normal notifications. Flags on the individual objects (Like friends
                // or new messages) are still there and are cleared when the user activates them.
                NotificationEntity notificationEntity = await GetNotifications(App.UserAccountEntity);

                var notificationList = notificationEntity.Notifications.Where(o => o.SeenFlag == false);
                foreach (var notification in notificationList)
                {
                    await NotificationManager.ClearNotification(notification, App.UserAccountEntity);
                }

                // remove secondary tile
                ShellTile tile = ShellTile.ActiveTiles.FirstOrDefault(x => x.NavigationUri.ToString().Contains("Title=FoulPlay"));
                if (tile != null)
                {
                    tile.Delete();
                }
                NavigationService.Navigate(new Uri("/Views/MainPivotView.xaml", UriKind.Relative));
            }
            else
            {
                // We don't have a token, or something is wrong with their servers :(. Go to the login page...
                NavigationService.Navigate(new Uri("/Views/LoginPage.xaml", UriKind.Relative));
            }
        }
 /// <summary>
 ///     Populates the page with content passed during navigation. Any saved state is also
 ///     provided when recreating a page from a prior session.
 /// </summary>
 /// <param name="sender">
 ///     The source of the event; typically <see cref="NavigationHelper" />
 /// </param>
 /// <param name="e">
 ///     Event data that provides both the navigation parameter passed to
 ///     <see cref="Frame.Navigate(Type, Object)" /> when this page was initially requested and
 ///     a dictionary of state preserved by this page during an earlier
 ///     session. The state will be null the first time a page is visited.
 /// </param>
 private void navigationHelper_LoadState(object sender, LoadStateEventArgs e)
 {
     _vm = (MainPageViewModel)DataContext;
     if (e.PageState != null && e.PageState.ContainsKey("userEntity") && App.UserAccountEntity == null)
     {
         string jsonObjectString = e.PageState["userAccountEntity"].ToString();
         App.UserAccountEntity = JsonConvert.DeserializeObject <UserAccountEntity>(jsonObjectString);
         jsonObjectString      = e.PageState["userEntity"].ToString();
         var user = JsonConvert.DeserializeObject <UserAccountEntity.User>(jsonObjectString);
         App.UserAccountEntity.SetUserEntity(user);
     }
     _user = App.UserAccountEntity.GetUserEntity();
     _vm.SetFriendsList(_user.OnlineId, true, false, false, false, true, false, false);
     _vm.SetRecentActivityFeed(_user.OnlineId);
     _vm.SetMessages(_user.OnlineId, App.UserAccountEntity);
     _vm.SetInviteList();
     CreateBackgroundTask();
 }
Esempio n. 13
0
        /// <summary>
        ///     Invoked when the application is launched normally by the end user.  Other entry points
        ///     will be used such as when the application is launched to open a specific file.
        /// </summary>
        /// <param name="e">Details about the launch request and process.</param>
        protected override async void OnLaunched(LaunchActivatedEventArgs e)
        {
#if DEBUG
            if (Debugger.IsAttached)
            {
                DebugSettings.EnableFrameRateCounter = true;
            }
#endif

            var rootFrame = Window.Current.Content as Frame;
            SettingsPane.GetForCurrentView().CommandsRequested += SettingCharmManager_CommandsRequested;
            // Do not repeat app initialization when the Window already has content,
            // just ensure that the window is active

            // Clear tiles if we have any.
            TileUpdateManager.CreateTileUpdaterForApplication().Clear();
            BadgeUpdateManager.CreateBadgeUpdaterForApplication().Clear();
            TileUpdateManager.CreateTileUpdaterForApplication().EnableNotificationQueue(true);

            if (rootFrame == null)
            {
                // Create a Frame to act as the navigation context and navigate to the first page
                rootFrame = new Frame();
                //Associate the frame with a SuspensionManager key
                SuspensionManager.RegisterFrame(rootFrame, "AppFrame");
                // Set the default language
                rootFrame.Language = ApplicationLanguages.Languages[0];
                //rootFrame.Language = "en-US";
                rootFrame.NavigationFailed += OnNavigationFailed;

                if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
                {
                    // Restore the saved session state only when appropriate
                    try
                    {
                        await SuspensionManager.RestoreAsync();
                    }
                    catch (SuspensionManagerException)
                    {
                        //Something went wrong restoring state.
                        //Assume there is no state and continue
                    }
                }

                // Place the frame in the current Window
                Window.Current.Content = rootFrame;
            }
            if (rootFrame.Content == null)
            {
                // When the navigation stack isn't restored navigate to the first page,
                // configuring the new page by passing required information as a navigation
                // parameter
                bool loginTest = await LoginTest();

                if (loginTest)
                {
                    var authManager             = new AuthenticationManager();
                    UserAccountEntity.User user = await authManager.GetUserEntity(UserAccountEntity);

                    if (user == null)
                    {
                        return;
                    }
                    UserAccountEntity.SetUserEntity(user);
                }
                rootFrame.Navigate(
                    loginTest ? typeof(MainPage) : typeof(LoginPage),
                    e.Arguments);
            }
            // Ensure the current window is active
            Window.Current.Activate();
        }
Esempio n. 14
0
        /// <summary>
        ///     Invoked when the application is launched normally by the end user.  Other entry points
        ///     will be used when the application is launched to open a specific file, to display
        ///     search results, and so forth.
        /// </summary>
        /// <param name="e">Details about the launch request and process.</param>
        protected override async void OnLaunched(LaunchActivatedEventArgs e)
        {
#if DEBUG
            if (System.Diagnostics.Debugger.IsAttached)
            {
                this.DebugSettings.EnableFrameRateCounter = true;
            }
#endif

            var rootFrame = Window.Current.Content as Frame;

            // Clear tiles if we have any.
            //TileUpdateManager.CreateTileUpdaterForApplication().Clear();
            //BadgeUpdateManager.CreateBadgeUpdaterForApplication().Clear();
            //TileUpdateManager.CreateTileUpdaterForApplication().EnableNotificationQueue(true);

            // Do not repeat app initialization when the Window already has content,
            // just ensure that the window is active
            if (rootFrame == null)
            {
                // Create a Frame to act as the navigation context and navigate to the first page
                rootFrame = new Frame();

                // TODO: change this value to a cache size that is appropriate for your application
                rootFrame.CacheSize = 1;

                if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
                {
                    // TODO: Load state from previously suspended application
                }

                // Place the frame in the current Window
                Window.Current.Content = rootFrame;
            }

            if (rootFrame.Content == null)
            {
                // Removes the turnstile navigation for startup.
                if (rootFrame.ContentTransitions != null)
                {
                    transitions = new TransitionCollection();
                    foreach (Transition c in rootFrame.ContentTransitions)
                    {
                        transitions.Add(c);
                    }
                }

                rootFrame.ContentTransitions = null;
                rootFrame.Navigated         += RootFrame_FirstNavigated;

                // When the navigation stack isn't restored navigate to the first page,
                // configuring the new page by passing required information as a navigation
                // parameter
                bool loginTest = await LoginTest();

                if (loginTest)
                {
                    var authManager             = new AuthenticationManager();
                    UserAccountEntity.User user = await authManager.GetUserEntity(UserAccountEntity);

                    if (user == null)
                    {
                        return;
                    }
                    UserAccountEntity.SetUserEntity(user);
                }
                rootFrame.Navigate(
                    loginTest ? typeof(MainPage) : typeof(LoginPage),
                    e.Arguments);
            }

            // Ensure the current window is active
            Window.Current.Activate();
        }