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; 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; // Insert the M2_VoiceActivation snippet here case ActivationKind.VoiceCommand: VoiceCommandActivatedEventArgs voiceArgs = args as VoiceCommandActivatedEventArgs; HandleVoiceCommand(args); break; // Insert the M2_ToastActivation snippet here 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(); }
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; 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; default: break; } // Ensure the current window is active Window.Current.Activate(); }
protected override void OnActivated(IActivatedEventArgs args) { base.OnActivated(args); // 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.Protocol) { var commandArgs = args as ProtocolActivatedEventArgs; Windows.Foundation.WwwFormUrlDecoder decoder = new Windows.Foundation.WwwFormUrlDecoder(commandArgs.Uri.Query); var keyword = decoder.GetFirstValueByName("LaunchContext"); Frame rootFrame = Window.Current.Content as Frame; if (rootFrame == null) { rootFrame = new Frame(); rootFrame.NavigationFailed += OnNavigationFailed; Window.Current.Content = rootFrame; } rootFrame.Navigate(typeof(MainPage), keyword); Window.Current.Activate(); } }
// By default, this handler expects URIs of the format 'wtsapp:sample?secret={value}' protected override async Task HandleInternalAsync(ProtocolActivatedEventArgs args) { if (args.Uri.AbsolutePath.ToLowerInvariant().Equals("sample")) { var secret = "<<I-HAVE-NO-SECRETS>>"; try { if (args.Uri.Query != null) { // The following will extract the secret value and pass it to the page. Alternatively, you could pass all or some of the Uri. var decoder = new Windows.Foundation.WwwFormUrlDecoder(args.Uri.Query); secret = decoder.GetFirstValueByName("secret"); } } catch (Exception) { // NullReferenceException if the URI doesn't contain a query // ArgumentException if the query doesn't contain a param called 'secret' } // It's also possible to have logic here to navigate to different pages. e.g. if you have logic based on the URI used to launch NavigationService.Navigate(typeof(ViewModels.UriSchemeExampleViewModel).FullName, secret); } else if (args.PreviousExecutionState != ApplicationExecutionState.Running) { // If the app isn't running and not navigating to a specific page based on the URI, navigate to the home page NavigationService.Navigate(typeof(ViewModels.OverviewViewModel).FullName); } await Task.CompletedTask; }
protected override Task OnActivateApplicationAsync(IActivatedEventArgs args) { if (args.Kind == ActivationKind.Protocol && ((ProtocolActivatedEventArgs)args)?.Uri == null && args.PreviousExecutionState != ApplicationExecutionState.Running) { var protocolArgs = args as ProtocolActivatedEventArgs; if (protocolArgs.Uri.AbsolutePath.Equals("sample", StringComparison.OrdinalIgnoreCase)) { var secret = "<<I-HAVE-NO-SECRETS>>"; try { if (protocolArgs.Uri.Query != null) { // The following will extract the secret value and pass it to the page. Alternatively, you could pass all or some of the Uri. var decoder = new Windows.Foundation.WwwFormUrlDecoder(protocolArgs.Uri.Query); secret = decoder.GetFirstValueByName("secret"); } } catch (Exception) { // NullReferenceException if the URI doesn't contain a query // ArgumentException if the query doesn't contain a param called 'secret' } // It's also possible to have logic here to navigate to different pages. e.g. if you have logic based on the URI used to launch return(LaunchApplicationAsync(PageTokens.UriSchemePage, secret)); } else { // If the app isn't running and not navigating to a specific page based on the URI, navigate to the home page OnLaunchApplicationAsync(args as LaunchActivatedEventArgs); } } if (args.Kind == ActivationKind.Protocol && ((ProtocolActivatedEventArgs)args)?.Uri?.Host == Host && args.PreviousExecutionState != ApplicationExecutionState.Running) { switch (((ProtocolActivatedEventArgs)args).Uri.AbsolutePath) { // Open the page in app that is equivalent to the section on the website. case Section1: // Use NavigationService to Navigate to MySection1Page break; case Section2: // Use NavigationService to Navigate to MySection2Page break; default: // Launch the application with default page. // Use NavigationService to Navigate to MainPage break; } } return(Task.CompletedTask); }
// By default, this handler expects URIs of the format 'wtsapp:sample?secret={value}' protected override async Task HandleInternalAsync(ProtocolActivatedEventArgs args) { var path = args.Uri.AbsolutePath.ToLowerInvariant(); if (path.Equals("")) { var id = ""; try { if (args.Uri.Query != null) { // The following will extract the secret value and pass it to the page. Alternatively, you could pass all or some of the Uri. var decoder = new Windows.Foundation.WwwFormUrlDecoder(args.Uri.Query); id = decoder.GetFirstValueByName("id"); } } catch (Exception) { NavigationService.Navigate(typeof(Views.MainPage)); return; } // It's also possible to have logic here to navigate to different pages. e.g. if you have logic based on the URI used to launch NavigationService.Navigate(typeof(Views.ContentPage), id); } else if (path == "rome") { var text = ""; try { if (args.Uri.Query != null) { // The following will extract the secret value and pass it to the page. Alternatively, you could pass all or some of the Uri. var decoder = new Windows.Foundation.WwwFormUrlDecoder(args.Uri.Query); text = decoder.GetFirstValueByName("text"); } } catch (Exception) { NavigationService.Navigate(typeof(Views.MainPage)); return; } // It's also possible to have logic here to navigate to different pages. e.g. if you have logic based on the URI used to launch NavigationService.Navigate(typeof(Views.RomePage), text); } else if (args.PreviousExecutionState != ApplicationExecutionState.Running) { // If the app isn't running and not navigating to a specific page based on the URI, navigate to the home page NavigationService.Navigate(typeof(Views.MainPage)); } await Task.CompletedTask; }
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(); }
public static string TryGetValue(this Windows.Foundation.WwwFormUrlDecoder decoder, string name) { try { return(decoder.GetFirstValueByName(name)); } catch (ArgumentException) { return(null); } }
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) }; }
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)); }); }
// 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); }
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)); } ); }
public CatalogVoiceCommand SelectDetail(ProtocolActivatedEventArgs activationArgs) { var commandArgs = activationArgs; var decoder = new Windows.Foundation.WwwFormUrlDecoder(commandArgs.Uri.Query); FilterVoiceCommand = decoder.GetFirstValueByName("LaunchContext"); _catalogVoiceCommand = new CatalogVoiceCommand { VoiceCommand = "protocolLaunch", CommandMode = "text", TextSpoken = "filter", Value = FilterVoiceCommand }; return(_catalogVoiceCommand); }
protected override async void OnActivated(IActivatedEventArgs e) { base.OnActivated(e); //Si activation par l'arrière plan if (e.Kind == ActivationKind.Protocol) { var commandArgs = e as ProtocolActivatedEventArgs; if (commandArgs != null) { Windows.Foundation.WwwFormUrlDecoder decoder = new Windows.Foundation.WwwFormUrlDecoder(commandArgs.Uri.Query); var site = decoder.GetFirstValueByName("LaunchContext"); await LaunchApp(site, null); } else { await LaunchApp(null, null); } } }
/// <summary> /// 处理语音命令 /// </summary> /// <param name="args"></param> private void HandleVoiceCommand(IActivatedEventArgs args) { Type navigationToPageType; if (args.Kind == ActivationKind.VoiceCommand) { var cmdArgs = args as VoiceCommandActivatedEventArgs; var speechRecognitionResult = cmdArgs.Result; string voiceCommandName = speechRecognitionResult.RulePath[0]; string text = speechRecognitionResult.Text; //speech or text string commandMode = this.SemanticInterpretation("commandMode", speechRecognitionResult); switch (voiceCommandName) { case "search": string keyword = this.SemanticInterpretation("keyword", speechRecognitionResult); navigationToPageType = typeof(SearchPage); break; } } // Protocol activation occurs when a card is clicked within Cortana (using a background task). 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"); } else { // If we were launched via any other mechanism, fall back to the main page view. // Otherwise, we'll hang at a splash screen. } }
protected override async Task OnActivateApplicationAsync(IActivatedEventArgs args) { //{[{ if (args.Kind == ActivationKind.Protocol && ((ProtocolActivatedEventArgs)args)?.Uri == null && args.PreviousExecutionState != ApplicationExecutionState.Running) { var protocolArgs = args as ProtocolActivatedEventArgs; if (protocolArgs.Uri.AbsolutePath.Equals("sample", StringComparison.OrdinalIgnoreCase)) { var secret = "<<I-HAVE-NO-SECRETS>>"; try { if (protocolArgs.Uri.Query != null) { // The following will extract the secret value and pass it to the page. Alternatively, you could pass all or some of the Uri. var decoder = new Windows.Foundation.WwwFormUrlDecoder(protocolArgs.Uri.Query); secret = decoder.GetFirstValueByName("secret"); } } catch (Exception) { // NullReferenceException if the URI doesn't contain a query // ArgumentException if the query doesn't contain a param called 'secret' } // It's also possible to have logic here to navigate to different pages. e.g. if you have logic based on the URI used to launch await LaunchApplicationAsync(PageTokens.UriSchemeExamplePage, secret); } else { // If the app isn't running and not navigating to a specific page based on the URI, navigate to the home page await OnLaunchApplicationAsync(args as LaunchActivatedEventArgs); } } //}]} await Task.CompletedTask; }
Boolean parseResponseTopic(string topicName, out string rid, out Int32 status) { var match = this.twinResponseTopicRegex.Match(topicName); if (match.Success) { status = Convert.ToInt32(match.Groups[1].Value); #if WINDOWS_UWP // TODO: verify that WwwFormUrlDecoder does the same as ParseQueryString var decoder = new Windows.Foundation.WwwFormUrlDecoder(match.Groups[2].Value); rid = decoder.GetFirstValueByName("$rid"); #else rid = HttpUtility.ParseQueryString(match.Groups[2].Value).Get("$rid"); #endif return(true); } else { rid = ""; status = 500; return(false); } }
public object Convert(object value, Type targetType, object parameter, string language) { if (value is string) { var url = value as string; var uri = new Uri(url); var decoder = new Windows.Foundation.WwwFormUrlDecoder(uri.Query); var videoId = decoder.GetFirstValueByName("v"); if (string.IsNullOrWhiteSpace(videoId)) { videoId = uri.Segments.Last(); } string html = @"<iframe width=""360"" height=""240"" src=""http://www.youtube.com/embed/" + videoId + @"?rel=0"" frameborder=""0"" allowfullscreen></iframe>"; return(html); } return(null); }
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(); }
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)); }); }
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)); } ); }
protected async override void OnActivated(IActivatedEventArgs args) { base.OnActivated(args); Type navigationToPageType; if (args.Kind == ActivationKind.VoiceCommand) { var commandArgs = args as VoiceCommandActivatedEventArgs; SpeechRecognitionResult speechRecognitionResult = commandArgs.Result; string voiceCommandName = speechRecognitionResult.RulePath[0]; switch (voiceCommandName) { case "starWarsIntro": navigationToPageType = typeof(View.SWIntro); break; case "imperialMarch": navigationToPageType = typeof(View.Imperial); break; case "cf_FaceBook": await CFTWT(); navigationToPageType = null; break; case "cf_Twitter": await CFFB(); navigationToPageType = null; break; case "openPPTpres": await PPoint(); navigationToPageType = null; break; case "redAlert": navigationToPageType = typeof(View.RedAlert); break; case "releaseNight": navigationToPageType = typeof(View.ReleaseNight); break; default: navigationToPageType = typeof(View.RaleighDemo); break; } } else if (args.Kind == ActivationKind.Protocol) { var commandArgs = args as ProtocolActivatedEventArgs; Windows.Foundation.WwwFormUrlDecoder decoder = new Windows.Foundation.WwwFormUrlDecoder(commandArgs.Uri.Query); var destination = decoder.GetFirstValueByName("LaunchContext"); navigationToPageType = typeof(View.RaleighDemo); } else { navigationToPageType = typeof(View.RaleighDemo); } Frame rootFrame = Window.Current.Content as Frame; if (rootFrame == null) { rootFrame = new Frame(); NavigationService = new NavigationService(rootFrame); rootFrame.NavigationFailed += OnNavigationFailed; Window.Current.Content = rootFrame; } if (navigationToPageType != null) { rootFrame.Navigate(navigationToPageType, null); } Window.Current.Activate(); }
protected override Task OnActivateApplicationAsync(IActivatedEventArgs args) { if (args.Kind == ActivationKind.Protocol && args.PreviousExecutionState != ApplicationExecutionState.Running) { var protocolArgs = args as ProtocolActivatedEventArgs; if (protocolArgs.Uri.AbsolutePath.Equals("sample", StringComparison.OrdinalIgnoreCase)) { var secret = "<<I-HAVE-NO-SECRETS>>"; try { if (protocolArgs.Uri.Query != null) { // The following will extract the secret value and pass it to the page. Alternatively, you could pass all or some of the Uri. var decoder = new Windows.Foundation.WwwFormUrlDecoder(protocolArgs.Uri.Query); secret = decoder.GetFirstValueByName("secret"); } } catch (Exception) { // NullReferenceException if the URI doesn't contain a query // ArgumentException if the query doesn't contain a param called 'secret' } // It's also possible to have logic here to navigate to different pages. e.g. if you have logic based on the URI used to launch return(LaunchApplicationAsync(PageTokens.UriSchemePage, secret)); } else if (args.PreviousExecutionState != ApplicationExecutionState.Running) { // If the app isn't running and not navigating to a specific page based on the URI, navigate to the home page OnLaunchApplicationAsync(args as LaunchActivatedEventArgs); } } if (args.Kind == ActivationKind.ToastNotification && args.PreviousExecutionState != ApplicationExecutionState.Running) { // Handle a dev center notification here // Since dev center, toast, and Azure notification hub will all active with an ActivationKind.ToastNotification // you may have to parse the toast data to determine where it came from and what action you want to take // If the app isn't running then launch the app here OnLaunchApplicationAsync(args as LaunchActivatedEventArgs); } if (args.Kind == ActivationKind.ToastNotification && args.PreviousExecutionState != ApplicationExecutionState.Running) { // Handle an Azure hub notification here // Since dev center, toast, and Azure notification hub will all active with an ActivationKind.ToastNotification // you may have to parse the toast data to determine where it came from and what action you want to take // If the app isn't running then launch the app here OnLaunchApplicationAsync(args as LaunchActivatedEventArgs); } if (args.Kind == ActivationKind.ToastNotification && args.PreviousExecutionState != ApplicationExecutionState.Running) { // Handle a toast notification here // Since dev center, toast, and Azure notification hub will all active with an ActivationKind.ToastNotification // you may have to parse the toast data to determine where it came from and what action you want to take // If the app isn't running then launch the app here OnLaunchApplicationAsync(args as LaunchActivatedEventArgs); } return(Task.CompletedTask); }
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(); }
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; } } }
/// <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(); }
/// <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(); }
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(); }
/// <summary> /// Entry point for an application activated by some means other than normal launching. /// This includes voice commands, URI, share target from another app, and so on. /// /// NOTE: /// A previous version of the VCD file might remain in place /// if you modify it and update the app through the store. /// Activations might include commands from older versions of your VCD. /// Try to handle these commands gracefully. /// </summary> /// <param name="args">Details about the activation method.</param> protected override void OnActivated(IActivatedEventArgs args) { base.OnActivated(args); Type navigationToPageType; DSAVoiceCommand navigationCommand = null; // Voice command activation. if (args.Kind == ActivationKind.VoiceCommand) { // Event args can represent many different activation types. // Cast it so we can get the parameters we care about out. var commandArgs = args as VoiceCommandActivatedEventArgs; SpeechRecognitionResult speechRecognitionResult = commandArgs.Result; // Get the name of the voice command and the text spoken. // See VoiceCommands.xml for supported voice commands. string voiceCommandName = speechRecognitionResult.RulePath[0]; string textSpoken = speechRecognitionResult.Text; // commandMode indicates whether the command was entered using speech or text. // Apps should respect text mode by providing silent (text) feedback. string commandMode = this.SemanticInterpretation("commandMode", speechRecognitionResult); switch (voiceCommandName) { case "openHeroDSA": // Access the value of {destination} in the voice command. string eigentschaft1 = this.SemanticInterpretation("eigenschaft1", speechRecognitionResult); string eigentschaft2 = this.SemanticInterpretation("eigenschaft2", speechRecognitionResult); string eigentschaft3 = this.SemanticInterpretation("eigenschaft3", speechRecognitionResult); // Create a navigation command object to pass to the page. navigationCommand = new DSAVoiceCommand( eigentschaft1, eigentschaft2, eigentschaft3); // Set the page to navigate to for this voice command. navigationToPageType = typeof(MainPage); break; case "open": default: // If we can't determine what page to launch, go to the default entry point. navigationToPageType = typeof(MainPage); break; } } // Protocol activation occurs when a card is clicked within Cortana (using a background task). 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 eigentschaften = decoder.GetFirstValueByName("LaunchContext").Split(';'); navigationCommand = new DSAVoiceCommand( eigentschaften[0], eigentschaften[1], eigentschaften[2]); navigationToPageType = typeof(MainPage); } 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(MainPage); } // Repeat 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(); }