Example #1
0
        public static Token FromRedirectUrl( string url ) {
            const string accessTokenPn = @"access_token";
            const string signPn = @"secret";
            const string useridPn = @"user_id";
            const string errorPn = @"error";
            const string errorRPn = @"error_reason";
            const string errorDescPn = @"error_description";
            var query =new Uri(url)
                .Fragment
                .TrimStart('#')
                .Split( '&' )
                .Select(a => a.Split('='))
                .Where(a => a.Length == 2)
                .GroupBy(a => a[ 0 ])
                .ToDictionary(a => a.Key, a => a.First()[1]);
            if ( query.ContainsKey( accessTokenPn ) )
                return new Token(
                    query[ accessTokenPn ],
                    query.ContainsKey( signPn )
                        ? query[ signPn ]
                        : "",
                    int.Parse( query[ useridPn ] )
                );
            if ( query.ContainsKey(errorPn))
#if !PORTABLE
                throw new AuthenticationException(
#else
                throw new VkException(
#endif
                $"Error: {query[errorPn]}\r\nType:{query[errorRPn]}\r\nMessage:{query[errorDescPn].Replace('+', ' ')}"
                    );
            throw new FormatException("Can't parse VK response from URL");
        }
Example #2
0
        public static YaToken FromRedirectUri( string url ) {
            const string accessTokenPn = @"access_token";
            const string expiresIn = @"expires_in";
            const string errorPn = @"error";
            var query = new Uri( url ).Fragment.TrimStart( '#' )
                              .Split( '&' )
                              .Select( a => a.Split( '=' ) )
                              .Where( a => a.Length == 2 )
                              .GroupBy( a => a[ 0 ] )
                              .ToDictionary( a => a.Key, a => a.First()[ 1 ] );
            if ( query.ContainsKey( errorPn ) ) throw new AuthenticationException( $"Error: {query[ errorPn ]}" );

            string token;
            if ( !query.TryGetValue( accessTokenPn, out token ) ) throw new FormatException( "Can't parse Ya response from URL" );

            long expiresv;
            {
                string expires;
                query.TryGetValue( expiresIn, out expires );
                if ( !long.TryParse( expires, out expiresv ) ) expiresv = -1;
            }
            return new YaToken( token, expiresv );
        }
Example #3
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 void OnLaunched(LaunchActivatedEventArgs e)
        {
#if DEBUG
            if (Debugger.IsAttached)
            {
                DebugSettings.EnableFrameRateCounter = true;
            }
#endif
            Messenger.Default.Send(new NotificationMessage(Constants.Messages.RefreshPinMsg));
            var rootFrame = Window.Current.Content as Frame;

            //var themeManager = Current.Resources["ThemeManager"];
            StartServices().ConfigureAwait(false);

            // 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();

                rootFrame.CacheSize = 3;

                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)
            {
#if WINDOWS_PHONE_APP
                // Removes the turnstile navigation for startup.
                if (rootFrame.ContentTransitions != null)
                {
                    _transitions = new TransitionCollection();
                    foreach (var c in rootFrame.ContentTransitions)
                    {
                        _transitions.Add(c);
                    }
                }

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

                // When the navigation stack isn't restored navigate to the first page,
                // configuring the new page by passing required information as a navigation
                // parameter
                if (!rootFrame.Navigate(typeof(MainPage), e.Arguments))
                {
                    throw new Exception("Failed to create initial page");
                }
            }

            if (!string.IsNullOrEmpty(e.Arguments))
            {
                var query = new Uri(e.Arguments).QueryDictionary();
                if (query.ContainsKey("source"))
                {
                    var source = query["source"];
                    var type = Type.GetType($"Speader.Views.Sources.{source}View");
                    rootFrame.Navigate(type, new NavigationParameters { ShowHomeButton = true });
                }
            }

            // Ensure the current window is active
            Window.Current.Activate();
        }
Example #4
0
        /// <summary>
        /// Retrieves the podcast action.
        /// </summary>
        /// <param name="uri">The URI.</param>
        /// <returns>The deserialised podcast action</returns>
        public static PodcastAction RetrievePodcastAction(Uri uri)
        {
            string podcastUri = string.Empty;
            if (uri.ToString().Contains(PodcastScheme))
                podcastUri = uri.ToString();
            else
            {
                podcastUri = uri.ToString().Replace("/Protocol?encodedLaunchUri=", string.Empty);
                podcastUri = Uri.UnescapeDataString(podcastUri);
            }

            var commandString = new Uri(podcastUri, UriKind.Absolute).CommandString();
            var queryString = new Uri(podcastUri, UriKind.Absolute).QueryString();

            PodcastCommand command = (PodcastCommand)Enum.Parse(typeof(PodcastCommand), commandString, true);

            var playMode = queryString.ContainsKey(PlayModeArgument) ? (PlayMode)Enum.Parse(typeof(PlayMode), queryString[PlayModeArgument], true) : PlayMode.None;
            var uiMode = queryString.ContainsKey(UiModeArgument) ? (UiMode)Enum.Parse(typeof(UiMode), queryString[UiModeArgument], true) : UiMode.Standard;
            var callbackUri = queryString.ContainsKey(CallbackUriArgument) ? queryString[CallbackUriArgument] : string.Empty;
            var callbackName = queryString.ContainsKey(CallbackNameArgument) ? queryString[CallbackNameArgument] : string.Empty;
            var feedUrl = queryString.ContainsKey(FeedUrlArgument) ? new Uri(Uri.UnescapeDataString(queryString[FeedUrlArgument]), UriKind.RelativeOrAbsolute) : null;

            PodcastAction action = new PodcastAction
            {
                Command = command,
                PlayMode = playMode,
                UiMode = uiMode,
                FeedUrl = feedUrl,
                CallbackUri = callbackUri,
                CallbackName = callbackName
            };

            return action;
        }