Ejemplo n.º 1
0
 public static VKToken FromUri(Uri source)
 {
     Windows.Foundation.WwwFormUrlDecoder decoder = new Windows.Foundation.WwwFormUrlDecoder(source.Query);
     return new VKToken()
     {
         AccessToken = decoder.GetFirstValueByName(ACCESS_TOKEN),
         UserId = decoder.GetFirstValueByName(USER_ID),
         ExperesIn = Convert.ToInt32(decoder.GetFirstValueByName(EXPIRES_IN)),
         Error = decoder.GetFirstValueByName(ERROR),
         ErrorDescription = decoder.GetFirstValueByName(ERROR_DECRIPTION)
     };
 }
Ejemplo n.º 2
0
        // runs only when not restored from state
        public override async Task OnStartAsync(StartKind startKind, IActivatedEventArgs args)
        {
            await Task.Delay(3500);

            var param = string.Empty;
            var protocolArgs = args as ProtocolActivatedEventArgs;
            if (protocolArgs != null)
            {
                var uri = protocolArgs.Uri;
                var decoder = new Windows.Foundation.WwwFormUrlDecoder(uri.Query);
                param = decoder.GetFirstValueByName("filter");
            }
            NavigationService.Navigate(typeof(Views.MainPage), param);
        }
Ejemplo n.º 3
0
        protected override void OnActivated(IActivatedEventArgs e)
        {
            Frame rootFrame = Window.Current.Content as Frame;
            if (rootFrame == null)
            {
                rootFrame = new Frame();
                Window.Current.Content = rootFrame;
            }
           

            if (e.Kind == ActivationKind.VoiceCommand)
            {
                var commandArgs = e as VoiceCommandActivatedEventArgs;
                SpeechRecognitionResult speechRecognitionResult = commandArgs.Result;
                string voiceCommandName = speechRecognitionResult.RulePath[0];
                if (voiceCommandName == "showMap")
                    rootFrame.Navigate(typeof(MapPage), speechRecognitionResult);
            }

            else if (e.Kind == ActivationKind.Protocol)
            {
                // Extract the launch context.
             
                var commandArgs = e as ProtocolActivatedEventArgs;
                Windows.Foundation.WwwFormUrlDecoder decoder = new Windows.Foundation.WwwFormUrlDecoder(commandArgs.Uri.Query);
                var page = decoder.GetFirstValueByName("LaunchContext");

                rootFrame.Navigate(typeof(MapPage));
            }


            Window.Current.Activate();
            }
        /// <summary>
        /// OnActivated is the entry point for an application when it is launched via
        /// means other normal user interaction. This includes Voice Commands, URI activation,
        /// being used as a share target from another app, etc. Here, we're going to handle the
        /// Voice Command activation from Cortana.
        /// 
        /// Note: Be aware that an older VCD could still be in place for your application if you
        /// modify it and update your app via the store. You should be aware that you could get 
        /// activations that include commands in older versions of your VCD, and you should try
        /// to handle them gracefully.
        /// </summary>
        /// <param name="args">Details about the activation method, including the activation
        /// phrase (for voice commands) and the semantic interpretation, parameters, etc.</param>
        protected override void OnActivated(IActivatedEventArgs args)
        {
            base.OnActivated(args);

            Type navigationToPageType;
            ViewModel.TripVoiceCommand? navigationCommand = null;

            // If the app was launched via a Voice Command, this corresponds to the "show trip to <location>" command. 
            // Protocol activation occurs when a tile is clicked within Cortana (via the background task)
            if (args.Kind == ActivationKind.VoiceCommand)
            {
                // The arguments can represent many different activation types. Cast it so we can get the
                // parameters we care about out.
                var commandArgs = args as VoiceCommandActivatedEventArgs;

                Windows.Media.SpeechRecognition.SpeechRecognitionResult speechRecognitionResult = commandArgs.Result;

                // Get the name of the voice command and the text spoken. See AdventureWorksCommands.xml for
                // the <Command> tags this can be filled with.
                string voiceCommandName = speechRecognitionResult.RulePath[0];
                string textSpoken = speechRecognitionResult.Text;

                // The commandMode is either "voice" or "text", and it indictes how the voice command
                // was entered by the user.
                // Apps should respect "text" mode by providing feedback in silent form.
                string commandMode = this.SemanticInterpretation("commandMode", speechRecognitionResult);
                
                switch (voiceCommandName)
                {
                    case "showTripToDestination":
                        // Access the value of the {destination} phrase in the voice command
                        string destination = this.SemanticInterpretation("destination", speechRecognitionResult);

                        // Create a navigation command object to pass to the page. Any object can be passed in,
                        // here we're using a simple struct.
                        navigationCommand = new ViewModel.TripVoiceCommand(
                            voiceCommandName,
                            commandMode,
                            textSpoken,
                            destination);

                        // Set the page to navigate to for this voice command.
                        navigationToPageType = typeof(View.TripDetails);
                        break;
                    default:
                        // If we can't determine what page to launch, go to the default entry point.
                        navigationToPageType = typeof(View.TripListView);
                        break;
                }
            }
            else if (args.Kind == ActivationKind.Protocol)
            {
                // Extract the launch context. In this case, we're just using the destination from the phrase set (passed
                // along in the background task inside Cortana), which makes no attempt to be unique. A unique id or 
                // identifier is ideal for more complex scenarios. We let the destination page check if the 
                // destination trip still exists, and navigate back to the trip list if it doesn't.
                var commandArgs = args as ProtocolActivatedEventArgs;
                Windows.Foundation.WwwFormUrlDecoder decoder = new Windows.Foundation.WwwFormUrlDecoder(commandArgs.Uri.Query);
                var destination = decoder.GetFirstValueByName("LaunchContext");

                navigationCommand = new ViewModel.TripVoiceCommand(
                                        "protocolLaunch",
                                        "text",
                                        "destination",
                                        destination);

                navigationToPageType = typeof(View.TripDetails);
            }
            else
            {
                // If we were launched via any other mechanism, fall back to the main page view.
                // Otherwise, we'll hang at a splash screen.
                navigationToPageType = typeof(View.TripListView);
            }

            // Re"peat the same basic initialization as OnLaunched() above, taking into account whether
            // or not the app is already active.
            Frame rootFrame = Window.Current.Content as Frame;

            // 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();
                App.NavigationService = new NavigationService(rootFrame);

                rootFrame.NavigationFailed += OnNavigationFailed;

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

            // Since we're expecting to always show a details page, navigate even if 
            // a content frame is in place (unlike OnLaunched).
            // Navigate to either the main trip list page, or if a valid voice command
            // was provided, to the details page for that trip.
            rootFrame.Navigate(navigationToPageType, navigationCommand);

            // Ensure the current window is active
            Window.Current.Activate();
        }
Ejemplo n.º 5
0
        /// <summary>
        /// OnActivated is the entry point for an application when it is launched via
        /// means other normal user interaction. This includes Voice Commands, URI activation,
        /// being used as a share target from another app, etc. Here, we're going to handle the
        /// Voice Command activation from Cortana.
        ///
        /// Note: Be aware that an older VCD could still be in place for your application if you
        /// modify it and update your app via the store. You should be aware that you could get
        /// activations that include commands in older versions of your VCD, and you should try
        /// to handle them gracefully.
        /// </summary>
        /// <param name="args">Details about the activation method, including the activation
        /// phrase (for voice commands) and the semantic interpretation, parameters, etc.</param>
        protected override void OnActivated(IActivatedEventArgs args)
        {
            base.OnActivated(args);

            Type navigationToPageType;

            ViewModel.TripVoiceCommand?navigationCommand = null;

            // If the app was launched via a Voice Command, this corresponds to the "show trip to <location>" command.
            // Protocol activation occurs when a tile is clicked within Cortana (via the background task)
            if (args.Kind == ActivationKind.VoiceCommand)
            {
                // The arguments can represent many different activation types. Cast it so we can get the
                // parameters we care about out.
                var commandArgs = args as VoiceCommandActivatedEventArgs;

                Windows.Media.SpeechRecognition.SpeechRecognitionResult speechRecognitionResult = commandArgs.Result;

                // Get the name of the voice command and the text spoken. See AdventureWorksCommands.xml for
                // the <Command> tags this can be filled with.
                string voiceCommandName = speechRecognitionResult.RulePath[0];
                string textSpoken       = speechRecognitionResult.Text;

                // The commandMode is either "voice" or "text", and it indictes how the voice command
                // was entered by the user.
                // Apps should respect "text" mode by providing feedback in silent form.
                string commandMode = this.SemanticInterpretation("commandMode", speechRecognitionResult);

                switch (voiceCommandName)
                {
                case "showTripToDestination":
                    // Access the value of the {destination} phrase in the voice command
                    string destination = this.SemanticInterpretation("destination", speechRecognitionResult);

                    // Create a navigation command object to pass to the page. Any object can be passed in,
                    // here we're using a simple struct.
                    navigationCommand = new ViewModel.TripVoiceCommand(
                        voiceCommandName,
                        commandMode,
                        textSpoken,
                        destination);

                    // Set the page to navigate to for this voice command.
                    navigationToPageType = typeof(View.TripDetails);
                    break;

                default:
                    // If we can't determine what page to launch, go to the default entry point.
                    navigationToPageType = typeof(View.TripListView);
                    break;
                }
            }
            else if (args.Kind == ActivationKind.Protocol)
            {
                // Extract the launch context. In this case, we're just using the destination from the phrase set (passed
                // along in the background task inside Cortana), which makes no attempt to be unique. A unique id or
                // identifier is ideal for more complex scenarios. We let the destination page check if the
                // destination trip still exists, and navigate back to the trip list if it doesn't.
                var commandArgs = args as ProtocolActivatedEventArgs;
                Windows.Foundation.WwwFormUrlDecoder decoder = new Windows.Foundation.WwwFormUrlDecoder(commandArgs.Uri.Query);
                var destination = decoder.GetFirstValueByName("LaunchContext");

                navigationCommand = new ViewModel.TripVoiceCommand(
                    "protocolLaunch",
                    "text",
                    "destination",
                    destination);

                navigationToPageType = typeof(View.TripDetails);
            }
            else
            {
                // If we were launched via any other mechanism, fall back to the main page view.
                // Otherwise, we'll hang at a splash screen.
                navigationToPageType = typeof(View.TripListView);
            }

            // Re"peat the same basic initialization as OnLaunched() above, taking into account whether
            // or not the app is already active.
            Frame rootFrame = Window.Current.Content as Frame;

            // 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();
                App.NavigationService = new NavigationService(rootFrame);

                rootFrame.NavigationFailed += OnNavigationFailed;

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

            // Since we're expecting to always show a details page, navigate even if
            // a content frame is in place (unlike OnLaunched).
            // Navigate to either the main trip list page, or if a valid voice command
            // was provided, to the details page for that trip.
            rootFrame.Navigate(navigationToPageType, navigationCommand);

            // Ensure the current window is active
            Window.Current.Activate();
        }
Ejemplo n.º 6
0
        public virtual void GetAccessToken(OAuthRequestToken requestToken, string verifier, Action<OAuthAccessToken, TwitterResponse> action)
        {
            var args = new FunctionArguments
            {
                ConsumerKey = _consumerKey,
                ConsumerSecret = _consumerSecret,
                Token = requestToken.Token,
                TokenSecret = requestToken.TokenSecret,
                Verifier = verifier
            };

            var request = _accessTokenQuery.Invoke(args);

           _oauth.BeginRequest(request, (req, resp, state) =>
                               {
                                   Exception exception;
                                   var entity = TryAsyncResponse(() =>
                                   {
                                        if (resp == null || resp.StatusCode != HttpStatusCode.OK)
                                        {
                                            return null;
                                        }

#if WINRT
																				var query = new Windows.Foundation.WwwFormUrlDecoder(resp.Content);
																				var accessToken = new OAuthAccessToken
																				{
																					Token = query.GetFirstValueByName("oauth_token") ?? "?",
																					TokenSecret = query.GetFirstValueByName("oauth_token_secret") ?? "?",
																					UserId = Convert.ToInt64(query.GetFirstValueByName("user_id") ?? "0"),
																					ScreenName = query.GetFirstValueByName("screen_name") ?? "?"
																				};
#else
                                       var query = HttpUtility.ParseQueryString(resp.Content);
                                       var accessToken = new OAuthAccessToken
                                       {
                                           Token = query["oauth_token"] ?? "?",
                                           TokenSecret = query["oauth_token_secret"] ?? "?",
                                           UserId = Convert.ToInt64(query["user_id"] ?? "0"),
                                           ScreenName = query["screen_name"] ?? "?"
                                       };
#endif
                                       return accessToken;
                                   },
                                   out exception);

                                   action(entity, new TwitterResponse(resp, exception));
                               }
               );
        }
Ejemplo n.º 7
0
        public virtual void GetRequestToken(string callback, Action<OAuthRequestToken, TwitterResponse> action)
        {
            var args = new FunctionArguments
            {
                ConsumerKey = _consumerKey,
                ConsumerSecret = _consumerSecret
            };

            var request = _requestTokenQuery.Invoke(args);
            if (!callback.IsNullOrBlank())
            {
                request.AddParameter("oauth_callback", callback);
            }

            _oauth.BeginRequest(request,
                (req, resp, state) =>
                {
                    Exception exception;
                    var entity = TryAsyncResponse(() =>
                    {
                        if (resp == null || resp.StatusCode != HttpStatusCode.OK)
                        {
                            return null;
                        }
											
#if WINRT
												var query = new Windows.Foundation.WwwFormUrlDecoder(resp.Content);
												var requestToken = new OAuthRequestToken
												{
													Token = query.GetFirstValueByName("oauth_token") ?? "?",
													TokenSecret = query.GetFirstValueByName("oauth_token_secret") ?? "?",
													OAuthCallbackConfirmed = Convert.ToBoolean(query.GetFirstValueByName("oauth_callback_confirmed") ?? "false")
												};
#else
                        var query = HttpUtility.ParseQueryString(resp.Content);
                        var requestToken = new OAuthRequestToken
                        {
                            Token = query["oauth_token"] ?? "?",
                            TokenSecret = query["oauth_token_secret"] ?? "?",
                            OAuthCallbackConfirmed = Convert.ToBoolean(query["oauth_callback_confirmed"] ?? "false")
                        };
#endif
                        return requestToken;
                    }, 
                    out exception);

                    action(entity, new TwitterResponse(resp, exception));
                });
        }
        protected override void OnActivated(IActivatedEventArgs args)
        {
            base.OnActivated(args);
            MyInit();

            // 
            // Activation Kind is Voice Command?
            // 
            if (args.Kind == ActivationKind.VoiceCommand)
            {
                Frame rootFrame = Window.Current.Content as Frame;
                VoiceCommandActivatedEventArgs commandArgs = args as VoiceCommandActivatedEventArgs;
                App.VoiceCommandActivedArgs = commandArgs;

                SpeechRecognitionResult speechRecognitionResult = commandArgs.Result;

                string voiceCommandName = speechRecognitionResult.RulePath[0];
                string textSpoken = speechRecognitionResult.Text;

                switch (voiceCommandName)
                {
                    case "whoCodedYou":
                        App.PageToLoadAfterStart = typeof(AboutPage);
                        break;

                    default:
                        break;
                }
            } 
            else if (args.Kind == ActivationKind.Protocol)
            {
                var commandArgs = args as ProtocolActivatedEventArgs;
                var urldecoder = new Windows.Foundation.WwwFormUrlDecoder(commandArgs.Uri.Query);
                var launchContext = urldecoder.GetFirstValueByName("LaunchContext");

                #region Split QueryString into a dictionary 

                Dictionary<string, string> paramDic = new Dictionary<string, string>();

                var theParams = launchContext.Split('&');
                foreach(var p in theParams)
                {
                    var help = p.Split('=');
                    paramDic.Add(help[0], help[1]);
                }

                #endregion

                string action = paramDic.ContainsKey("action") ? paramDic["action"] : "";
                string param = paramDic.ContainsKey("param") ? paramDic["param"] : "";

                switch (action)
                {
                    case "tv":
                        App.PageToLoadAfterStart = typeof(TVGuidePage);
                        App.StartupParam = param;
                        break;

                    default:
                        break;
                }
            }
        }
Ejemplo n.º 9
0
        private void RespondToBackgroundVoiceCommand(ProtocolActivatedEventArgs e, IAppPage page)
        {
            var commandArgs = e as ProtocolActivatedEventArgs;
            Windows.Foundation.WwwFormUrlDecoder decoder = new Windows.Foundation.WwwFormUrlDecoder(commandArgs.Uri.Query);
            var passedArg = decoder.GetFirstValueByName("LaunchContext");

            // Ensure the current window is active.
            Window.Current.Activate();
        }
Ejemplo n.º 10
0
        protected override async void OnActivated(IActivatedEventArgs args)
        {
            SetupShell(args);

            // we need to wait for the shell to load
            while (AppShell.Current == null)
            {
                await Task.Delay(200);
            }



            switch (args.Kind)
            {
            case ActivationKind.Protocol:
                ProtocolActivatedEventArgs protocolArgs = args as ProtocolActivatedEventArgs;

                // Is this a protocol launch from Cortana actions, or from voice command?
                if (protocolArgs.Uri.Scheme == "sights2see")
                {
                    Windows.Foundation.WwwFormUrlDecoder decoder = new Windows.Foundation.WwwFormUrlDecoder(protocolArgs.Uri.Query);
                    var foodpref = decoder.GetFirstValueByName("foodpref");
                    var parameter = new TripNavigationParameter {
                        TripId = AppSettings.LastTripId, ShowPivotName = TripPivots.Eats, CuisinePreferences = foodpref
                    }.GetJson();
                    AppShell.Current.NavigateToPage(typeof(TripDetailPage), parameter);
                }
                else
                {
                    Windows.Foundation.WwwFormUrlDecoder decoder = new Windows.Foundation.WwwFormUrlDecoder(protocolArgs.Uri.Query);
                    var siteId = decoder.GetFirstValueByName("LaunchContext");
                    var parameter = new TripNavigationParameter {
                        TripId = AppSettings.LastTripId, SightId = Guid.ParseExact(siteId, "D")
                    }.GetJson();
                    AppShell.Current.NavigateToPage(typeof(TripDetailPage), parameter);
                }
                break;

            // Voice activation behavior
            case ActivationKind.VoiceCommand:
                VoiceCommandActivatedEventArgs voiceArgs = args as VoiceCommandActivatedEventArgs;
                HandleVoiceCommand(args);
                break;

            case ActivationKind.ToastNotification:
                var toast = args as ToastNotificationActivatedEventArgs;

                var props = toast.Argument.Split(':');
                if (props[0] == "View")
                {
                    var tripParam = new TripNavigationParameter {
                        TripId = AppSettings.LastTripId, SightId = Guid.ParseExact(props[1], "D")
                    }.GetJson();
                    AppShell.Current.NavigateToPage(typeof(TripDetailPage), tripParam);
                }
                else if (props[0] == "Remove")
                {
                    var tripParam = new TripNavigationParameter {
                        TripId = AppSettings.LastTripId, SightId = Guid.ParseExact(props[1], "D"), DeleteSight = true
                    }.GetJson();
                    AppShell.Current.NavigateToPage(typeof(TripDetailPage), tripParam);
                }
                break;

            default:
                break;
            }

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