public static Task <FeedCompletedArgs> FeedFacebookAsync(this WebBrowser browser, Uri uri)
        {
            CurrentState = FacebookSDKState.FeedDialog;

            feedTaskCompletionSource = new TaskCompletionSource <FeedCompletedArgs>();

            onFeedCompleted = null;
            onFeedCompleted = (object sender, NavigationEventArgs e) =>
            {
                FeedCompletedArgs result;
                FeedNavigationCallBack(e, out result);
                if (result != null)
                {
                    browser.Navigated -= onFeedCompleted;
                    feedTaskCompletionSource.SetResult(result);
                }
            };

            onFeedFailed = null;
            onFeedFailed = (object sender, NavigationFailedEventArgs e) =>
            {
                browser.NavigationFailed -= onFeedFailed;
                feedTaskCompletionSource.SetResult(new FeedCompletedArgs(false));
            };

            browser.Navigated        += onFeedCompleted;
            browser.NavigationFailed += onFeedFailed;

            browser.Navigate(uri);

            return(feedTaskCompletionSource.Task);
        }
        public static Task <AppRequestsCompletedArgs> AppRequestFacebookAsync(this WebBrowser browser, Uri uri)
        {
            CurrentState = FacebookSDKState.AppRequestDialog;

            appRequestTaskCompletionSource = new TaskCompletionSource <AppRequestsCompletedArgs>();

            onRequestCompleted = null;
            onRequestCompleted = (object sender, NavigationEventArgs e) =>
            {
                AppRequestsCompletedArgs result;
                RequestNavigationCallBack(e, out result);
                if (result != null)
                {
                    browser.Navigated -= onRequestCompleted;
                    appRequestTaskCompletionSource.SetResult(result);
                }
            };

            onRequestFailed = null;
            onRequestFailed = (object sender, NavigationFailedEventArgs e) =>
            {
                browser.NavigationFailed -= onRequestFailed;
                appRequestTaskCompletionSource.SetResult(new AppRequestsCompletedArgs(false));
            };

            browser.Navigated        += onRequestCompleted;
            browser.NavigationFailed += onRequestFailed;

            browser.Navigate(uri);

            return(appRequestTaskCompletionSource.Task);
        }
        public static Task <LoginCompletedArgs> LoginFacebookAsync(this WebBrowser browser, Uri uri, string fbAppId, string extendedPermissions)
        {
            CurrentState = FacebookSDKState.Login;

            loginTaskCompletionSource = new TaskCompletionSource <LoginCompletedArgs>();

            onLoginCompleted = null;
            onLoginCompleted = (object sender, NavigationEventArgs e) =>
            {
                LoginCompletedArgs result;
                LoginNavigationCallBack(e, fbAppId, extendedPermissions, out result);
                if (result != null)
                {
                    browser.Navigated -= onLoginCompleted;
                    loginTaskCompletionSource.SetResult(result);
                }
            };

            onLoginFailed = null;
            onLoginFailed = (object sender, NavigationFailedEventArgs e) =>
            {
                browser.NavigationFailed -= onLoginFailed;
                loginTaskCompletionSource.SetResult(new LoginCompletedArgs(false));
            };

            browser.Navigated        += onLoginCompleted;
            browser.NavigationFailed += onLoginFailed;

            browser.Navigate(uri);

            return(loginTaskCompletionSource.Task);
        }
Exemplo n.º 4
0
        private void AddHandler()
        {
            NavigatedEventHandler        successHandler = null;
            NavigationFailedEventHandler failureHandler = null;
            NavigatingCancelEventHandler beforeHandler  = null;

            successHandler = (s, e) =>
            {
                Frame.Navigated        -= successHandler;
                Frame.NavigationFailed -= failureHandler;

                AfterNavigation(null, e.Content as UserControl);
            };

            failureHandler = (s, e) =>
            {
                Frame.Navigated        -= successHandler;
                Frame.NavigationFailed -= failureHandler;

                AfterNavigation(e.Exception, null);
            };

            beforeHandler = (s, e) =>
            {
                Frame.Navigating -= beforeHandler;

                BeforeNavigation();
            };

            Frame.Navigated        += successHandler;
            Frame.NavigationFailed += failureHandler;
            Frame.Navigating       += beforeHandler;
        }
Exemplo n.º 5
0
        public Task LogoutAsync(Uri logoutUri)
        {
            var frame = new Frame();
            var tcs   = new TaskCompletionSource <bool>();
            LoadCompletedEventHandler    loadCompletedHandler = null;
            NavigationFailedEventHandler failedHandler        = null;
            Action unsubscribe = () =>
            {
                // ReSharper disable AccessToModifiedClosure
                frame.LoadCompleted    -= loadCompletedHandler;
                frame.NavigationFailed -= failedHandler;
                // ReSharper restore AccessToModifiedClosure
            };

            loadCompletedHandler =
                (sender, e) =>
            {
                unsubscribe();
                tcs.SetResult(true);
            };
            failedHandler =
                (sender, e) =>
            {
                unsubscribe();
                tcs.SetException(e.Exception);
            };
            frame.LoadCompleted    += loadCompletedHandler;
            frame.NavigationFailed += failedHandler;
            frame.Navigate(logoutUri);
            return(tcs.Task);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Extends BeginInvoke so that when a state object is not needed, null does not need to be passed.
        /// <example>
        /// navigationfailedeventhandler.BeginInvoke(sender, e, callback);
        /// </example>
        /// </summary>
        public static IAsyncResult BeginInvoke(this NavigationFailedEventHandler navigationfailedeventhandler, Object sender, NavigationFailedEventArgs e, AsyncCallback callback)
        {
            if (navigationfailedeventhandler == null)
            {
                throw new ArgumentNullException("navigationfailedeventhandler");
            }

            return(navigationfailedeventhandler.BeginInvoke(sender, e, callback, null));
        }
Exemplo n.º 7
0
        /// <summary>
        /// Raises the Failed event synchronously.
        /// </summary>
        /// <param name="uri">A URI value representing the navigation content.</param>
        /// <param name="exception">The error that occurred</param>
        /// <returns>true if the the exception should be re-thrown, false if it was handled</returns>
        private bool RaiseNavigationFailed(Uri uri, Exception exception)
        {
            NavigationFailedEventHandler eventHandler = this.NavigationFailed;
            NavigationFailedEventArgs    eventArgs    = new NavigationFailedEventArgs(uri, exception);

            if (eventHandler != null)
            {
                eventHandler(this, eventArgs);
            }

            return(!eventArgs.Handled);
        }
Exemplo n.º 8
0
 public static void Initialize<T>(List<NavMenuItem> list, NavigationFailedEventHandler OnNavigationFailed, LaunchActivatedEventArgs e)
     {
         AppShell shell = Window.Current.Content as AppShell;
         // Do not repeat app initialization when the Window already has content,
         // just ensure that the window is active
         if (shell == null)
         {
             // Create a AppShell to act as the navigation context and navigate to the first page
             shell = new AppShell();
             shell.NavigationList = list;
             try
             {
                 shell.CurrentItem = list.First(i => i.DestPage == typeof(T));
             }
             catch
             {
             }
             // Set the default language
             shell.Language = Windows.Globalization.ApplicationLanguages.Languages[0];
             shell.AppFrame.NavigationFailed += OnNavigationFailed;
             if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
             {
                 //TODO: Load state from previously suspended application
             }
         }
         // Place our app shell in the current Window
         Window.Current.Content = shell;
         if (shell.AppFrame.Content == null)
         {
             // When the navigation stack isn't restored, navigate to the first page
             // suppressing the initial entrance animation.
             shell.AppFrame.Navigate(typeof(T), e.Arguments, new Windows.UI.Xaml.Media.Animation.SuppressNavigationTransitionInfo());
         }
         // Ensure the current window is active
         Window.Current.Activate();
     }
Exemplo n.º 9
0
        private void AddHandler()
        {
            NavigatedEventHandler        successHandler = null;
            NavigationFailedEventHandler failureHandler = null;

            successHandler = (s, e) =>
            {
                Frame.Navigated        -= successHandler;
                Frame.NavigationFailed -= failureHandler;

                AfterNavigation();
            };

            failureHandler = (s, e) =>
            {
                Frame.Navigated        -= successHandler;
                Frame.NavigationFailed -= failureHandler;

                AfterNavigation();
            };

            Frame.Navigated        += successHandler;
            Frame.NavigationFailed += failureHandler;
        }
Exemplo n.º 10
0
        private void AddHandler()
        {
            NavigatedEventHandler        successHandler = null;
            NavigationFailedEventHandler failureHandler = null;

            successHandler = (s, e) =>
            {
                _rootFrame.Navigated        -= successHandler;
                _rootFrame.NavigationFailed -= failureHandler;

                AfterNavigation(null, e.Content as UserControl);
            };

            failureHandler = (s, e) =>
            {
                _rootFrame.Navigated        -= successHandler;
                _rootFrame.NavigationFailed -= failureHandler;

                AfterNavigation(e.Exception, null);
            };

            _rootFrame.Navigated        += successHandler;
            _rootFrame.NavigationFailed += failureHandler;
        }