public static void ParseArguments(string arguments) { if (string.IsNullOrEmpty(arguments)) { return; } var decoder = new WwwFormUrlDecoder(arguments); var city = decoder.FirstOrDefault(x => x.Name.Equals("city")); var parkingLot = decoder.FirstOrDefault(x => x.Name.Equals("parkingLot")); if (city != null && parkingLot != null) { Task.Run(async() => { await ServiceLocator.Current.GetInstance <MainViewModel>().TrySelectParkingLotById(city.Value, parkingLot.Value); }); } else if (city != null) { Task.Run(async() => { await ServiceLocator.Current.GetInstance <MainViewModel>().TrySelectCityById(city.Value); }); } }
private void TopicWebView_OnNavigationStarting(WebView sender, WebViewNavigationStartingEventArgs args) { if (args.Uri != null && args.Uri.AbsoluteUri.StartsWith(Strings.LocalUriPrefix)) { args.Cancel = true; if (args.Uri.AbsoluteUri.Contains("quote")) { var decoder = new WwwFormUrlDecoder(args.Uri.Query); var postId = decoder.FirstOrDefault(x => x.Name == "postId")?.Value; if (!string.IsNullOrEmpty(postId)) { Loc.Topic.ShowEditorCommand.Execute(Loc.Topic.CurrentTopic.TopicNewPostUriForm + $"&numrep={postId}"); } } else { Debug.WriteLine("WW " + args.Uri.Query + "-- " + args.Uri + " -- " + args.Uri.AbsoluteUri); string param = args.Uri.Query.Replace("?", ""); if (Loc.Main.ContextMessageCommand.CanExecute(param)) { Loc.Main.ContextMessageCommand.Execute(param); } } } }
public async void NavigateWithConfig(string parameter) { try { var urlDecoder = new WwwFormUrlDecoder(parameter); var pageUrl = urlDecoder.GetFirstValueByName("pageUrl"); await WebViewHelper.NavigateToSpotifyUrl(pageUrl); var autoplayEntry = urlDecoder.FirstOrDefault(x => x.Name == "autoplay"); AutoPlayAction action = AutoPlayAction.None; if (autoplayEntry != null) { action = autoplayEntry.Value == "track" ? AutoPlayAction.Track : AutoPlayAction.Playlist; } if (action != AutoPlayAction.None) { await WebViewHelper.AutoPlay(action); } return; } catch (Exception ex) { logger.Info($"Parsing input parameter {parameter} failed. {ex}"); } }
private async void ThreadWebView_OnNavigationStarting(WebView sender, WebViewNavigationStartingEventArgs args) { if (args.Uri != null && args.Uri.AbsoluteUri.StartsWith(Strings.LocalUriPrefix)) { args.Cancel = true; if (args.Uri.AbsoluteUri.Contains("quote")) { var decoder = new WwwFormUrlDecoder(args.Uri.Query); var postId = decoder.FirstOrDefault(x => x.Name == "postId")?.Value; if (!string.IsNullOrEmpty(postId)) { var package = new EditorPackage(EditorIntent.Quote, Loc.Thread.CurrentThread.ThreadNewPostUriForm + $"&numrep={postId}"); Loc.Thread.ShowEditorCommand.Execute(package); } } else if (args.Uri.AbsoluteUri.Contains("deleteFromMultiQuote")) { var decoder = new WwwFormUrlDecoder(args.Uri.Query); var postId = decoder.FirstOrDefault(x => x.Name == "postId")?.Value; if (!string.IsNullOrEmpty(postId)) { var package = new EditorPackage(EditorIntent.MultiQuote, Loc.Thread.CurrentThread.ThreadNewPostUriForm + $"&numrep={postId}"); await Loc.Editor.RemoveQuoteFromMultiQuote(package); } } else if (args.Uri.AbsoluteUri.Contains("multiQuote")) { var decoder = new WwwFormUrlDecoder(args.Uri.Query); var postId = decoder.FirstOrDefault(x => x.Name == "postId")?.Value; if (!string.IsNullOrEmpty(postId)) { var package = new EditorPackage(EditorIntent.MultiQuote, Loc.Thread.CurrentThread.ThreadNewPostUriForm + $"&numrep={postId}"); Loc.Thread.ShowEditorCommand.Execute(package); } } else if (args.Uri.AbsoluteUri.Contains("edit")) { var decoder = new WwwFormUrlDecoder(args.Uri.Query); var postId = decoder.FirstOrDefault(x => x.Name == "postId")?.Value; if (!string.IsNullOrEmpty(postId)) { var package = new EditorPackage(EditorIntent.Edit, Loc.Thread.CurrentThread.ThreadNewPostUriForm + $"&numreponse={postId}"); Loc.Thread.ShowEditorCommand.Execute(package); } } else { Debug.WriteLine("WW " + args.Uri.Query + "-- " + args.Uri + " -- " + args.Uri.AbsoluteUri); string param = args.Uri.Query.Replace("?", ""); if (Loc.Main.ContextMessageCommand.CanExecute(param)) { Loc.Main.ContextMessageCommand.Execute(param); } } } }
private string GetTargetUrl(NavigationEventArgs e) { var destinationUrl = "https://open.spotify.com"; var parameter = e.Parameter as string; if (!string.IsNullOrEmpty(parameter)) { try { // Launched from a secondary tile var urlDecoder = new WwwFormUrlDecoder(parameter); var pageUrl = urlDecoder.GetFirstValueByName("pageUrl"); var autoplayEntry = urlDecoder.FirstOrDefault(x => x.Name == "autoplay"); if (autoplayEntry != null) { autoPlayAction = autoplayEntry.Value == "track" ? AutoPlayAction.Track : AutoPlayAction.Playlist; } else { autoPlayAction = AutoPlayAction.None; } var sourceEntry = urlDecoder.FirstOrDefault(x => x.Name == "source"); if (sourceEntry != null && sourceEntry.Value == "cortana" && LocalConfiguration.OpenInMiniViewByCortana) { OpenCompactOverlayForAutoPlay(); } destinationUrl = pageUrl; } catch (Exception ex) { logger.Info($"Parsing input parameter {e.Parameter.ToString()} failed. {ex}"); } } return("https://open.spotify.com/static/offline.html?redirectUrl=" + System.Net.WebUtility.UrlEncode(destinationUrl)); }
protected override AuthorizationResponse <string> GetAuthorizationReponseFromResponseData(string responseData) { WwwFormUrlDecoder decoder; try { var responseUrl = new Uri(responseData); decoder = new WwwFormUrlDecoder(responseUrl.Query); } catch (Exception e) { throw new SpotifyAuthorizationException("An invalid URL string has been returned from the Spotify Accounts Service.", e); } var code = decoder.FirstOrDefault(item => item.Name == "code")?.Value; if (string.IsNullOrEmpty(code)) { throw new SpotifyAuthorizationException("An invalid authorization code has been returned from the Spotify Accounts Service."); } return(new AuthorizationResponse <string>(code, decoder.FirstOrDefault(item => item.Name == "state")?.Value)); }
private string GetTileLaunchTargetUrl(string parameter) { if (!string.IsNullOrEmpty(parameter)) { try { // Launched from a secondary tile var urlDecoder = new WwwFormUrlDecoder(parameter); var pageUrl = urlDecoder.GetFirstValueByName("pageUrl"); var autoplayEntry = urlDecoder.FirstOrDefault(x => x.Name == "autoplay"); if (autoplayEntry != null) { xpoWebView.AutoPlayAction = autoplayEntry.Value == "track" ? AutoPlayAction.Track : AutoPlayAction.Playlist; } else { xpoWebView.AutoPlayAction = AutoPlayAction.None; } var sourceEntry = urlDecoder.FirstOrDefault(x => x.Name == "source"); if (sourceEntry != null && sourceEntry.Value == "cortana" && LocalConfiguration.OpenInMiniViewByCortana) { OpenCompactOverlayForAutoPlay(); } return(pageUrl); } catch (Exception ex) { logger.Info($"Parsing input parameter '{parameter}' failed: {ex}"); } } return(null); }
/// <summary> /// [WIP]<para/> /// Parses XMPP IRIs and URIs based on RFC 5122 and returns the result. /// </summary> /// <param name="uri">The URI or IRI that should get parsed.</param> /// <returns>The URI or IRI result or null if an error occurred.</returns> public static IUriAction parse(Uri uri) { if (!string.IsNullOrEmpty(uri?.OriginalString)) { if (string.Equals(uri.Scheme.ToLowerInvariant(), "xmpp")) { string tmp = uri.OriginalString; // 1. remove 'xmpp:' tmp = tmp.Substring(5); // 2. Authority string authority = null; if (tmp.StartsWith("//")) { tmp.Substring(2); int authEnd = tmp.IndexOf('/'); if (authEnd < 0) { authEnd = tmp.IndexOf('?'); if (authEnd < 0) { authEnd = tmp.IndexOf('#'); if (authEnd < 0) { authEnd = tmp.Length <= 0 ? 0 : tmp.Length - 1; } } authority = tmp.Substring(0, authEnd); tmp = tmp.Substring(authEnd + 1); } } if (string.Equals(uri.AbsolutePath, "iot-register")) { WwwFormUrlDecoder query = parseUriQuery(uri); if (query is null) { return(null); } IWwwFormUrlDecoderEntry macEntry = query.FirstOrDefault(x => x.Name.StartsWith("mac")); if (macEntry is null || string.IsNullOrEmpty(macEntry.Value)) { Logger.Error("None or invalid IoT MAC address: " + uri.OriginalString); return(null); } IWwwFormUrlDecoderEntry algoEntry = query.FirstOrDefault(x => x.Name.StartsWith("algo")); if (algoEntry is null || string.IsNullOrEmpty(algoEntry.Value)) { Logger.Error("None or invalid IoT key algorithm: " + uri.OriginalString); return(null); } IWwwFormUrlDecoderEntry keyEntry = query.FirstOrDefault(x => x.Name.StartsWith("key")); if (keyEntry is null || string.IsNullOrEmpty(keyEntry.Value)) { Logger.Error("None or invalid IoT key: " + uri.OriginalString); return(null); } return(new RegisterIoTUriAction(macEntry.Value, algoEntry.Value, keyEntry.Value)); } else { // Check if is OMEMO fingerprint URI: WwwFormUrlDecoder query = parseUriQuery(uri); if (query is null) { return(null); } IWwwFormUrlDecoderEntry entry = query.FirstOrDefault(x => x.Name.StartsWith("omemo-sid-")); if (!(entry is null)) { ECPubKeyModel pubKey = null; try { byte[] fingerprintBytes = SharedUtils.HexStringToByteArray(entry.Value); pubKey = new ECPubKeyModel(fingerprintBytes); } catch (Exception e) { Logger.Error("Failed to parse XMPP URI. Parsing fingerprint failed: " + entry.Value, e); return(null); } if (uint.TryParse(entry.Name.Replace("omemo-sid-", "").Trim(), out uint deviceId)) { OmemoProtocolAddress address = new OmemoProtocolAddress(uri.LocalPath, deviceId); return(new OmemoFingerprintUriAction(new OmemoFingerprint(pubKey, address))); } else { Logger.Warn("Failed to parse XMPP URI. Invalid device ID: " + entry.Name); } } } } else { Logger.Warn("Failed to parse XMPP URI. No 'xmpp' scheme."); } } return(null); }