示例#1
0
        /*private IBackgroundTaskRegistration GetRegisteredTask()
         * {
         *  foreach (var task in BackgroundTaskRegistration.AllTasks.Values)
         *  {
         *      if (task.Name == "UpdateChannel")
         *      {
         *          return task;
         *      }
         *  }
         *  return null;
         * }
         *
         * private async Task<bool> init()
         * {
         *  if (channel == null)
         *  {
         *      var response = await PushHelper.getInstance().OpenChannelAndUpload();
         *      channel = response.Channel;
         *
         *      channel.PushNotificationReceived += OnPushNotificationReceived;
         *  }
         *
         *  if (GetRegisteredTask() == null)
         *  {
         *      BackgroundTaskBuilder taskBuilder = new BackgroundTaskBuilder();
         *      MaintenanceTrigger trigger = new MaintenanceTrigger(24*60, false);
         *      taskBuilder.SetTrigger(trigger);
         *      taskBuilder.TaskEntryPoint = "MaintenanceTask";
         *      taskBuilder.Name = "UpdateChannel";
         *
         *      SystemCondition internetCondition = new SystemCondition(SystemConditionType.InternetAvailable);
         *      taskBuilder.AddCondition(internetCondition);
         *
         *      try
         *      {
         *
         *
         *          taskBuilder.Register();
         *          //rootPage.NotifyUser("Task registered", NotifyType.StatusMessage);
         *      }
         *      catch (Exception ex)
         *      {
         *          //rootPage.NotifyUser("Error registering task: " + ex.Message, NotifyType.ErrorMessage);
         *      }
         *  }
         *  else
         *  {
         *      //rootPage.NotifyUser("Task already registered", NotifyType.ErrorMessage);
         *  }
         *
         *  //var response = await PushHelper.getInstance().OpenChannelAndUpload();
         *
         *  return true;
         * }*/

        /*private void OnPushNotificationReceived(PushNotificationChannel sender, PushNotificationReceivedEventArgs e)
         * {
         *
         *  string typeString = String.Empty;
         *  string notificationContent = String.Empty;
         *  switch (e.NotificationType)
         *  {
         *      case PushNotificationType.Badge:
         *          typeString = "Badge";
         *          notificationContent = e.BadgeNotification.Content.GetXml();
         *          break;
         *      case PushNotificationType.Tile:
         *          notificationContent = e.TileNotification.Content.GetXml();
         *          typeString = "Tile";
         *          break;
         *      case PushNotificationType.Toast:
         *          notificationContent = e.ToastNotification.Content.GetXml();
         *          typeString = "Toast";
         *          // Setting the cancel property prevents the notification from being delivered. It's especially important to do this for toasts:
         *          // if your application is already on the screen, there's no need to display a toast from push notifications.
         *          e.Cancel = true;
         *          break;
         *      case PushNotificationType.Raw:
         *          notificationContent = e.RawNotification.Content;
         *          typeString = "Raw";
         *          break;
         *  }
         *
         *  Debug.WriteLine($"Notification recieved: {typeString}");
         * }*/


        protected override void OnActivated(IActivatedEventArgs args)
        {
            if (args.Kind == ActivationKind.Protocol)
            {
                ProtocolActivatedEventArgs eventArgs = args as ProtocolActivatedEventArgs;

                // TODO: Handle URI activation
                // The received URI is eventArgs.Uri.AbsoluteUri

                var uri = eventArgs.Uri.Query;

                try
                {
                    var test = eventArgs.Uri;
                    WwwFormUrlDecoder decoder = new WwwFormUrlDecoder(uri);
                    var param = decoder.ToDictionary(x => x.Name, x => x.Value);

                    var uuid   = param["uuid"];
                    var pubKey = param["pub_key"];

                    Debug.WriteLine($"UUID: {uuid}, PubKey: {pubKey}");

                    if (uuid.Equals(string.Empty) || pubKey.Equals(string.Empty))
                    {
                    }
                } catch (Exception e)
                {
                    Debug.WriteLine($"Error while parsing protocol uri tsdevice://{uri}");
                }
            }
        }
        public static Note TryToGetNoteFromNavigationArgument(string navigationParameter)
        {
            if (String.IsNullOrEmpty(navigationParameter))
            {
                return(null);
            }

            string noteId;

            try
            {
                WwwFormUrlDecoder           decoder     = new WwwFormUrlDecoder(navigationParameter);
                Dictionary <string, string> queryParams = decoder.ToDictionary(x => x.Name, x => x.Value);

                if (!queryParams.ContainsKey("noteId"))
                {
                    return(null);
                }
                noteId = queryParams["noteId"];
            }
            catch (Exception)
            {
                return(null);
            }

            var note = AppData.TryGetNoteById(noteId);

            if (note == null)
            {
                RemoveTileIfExists(noteId);
            }

            return(note);
        }
示例#3
0
        public static T Parse <T>(string arguments)
            where T : new()
        {
            var splitted = arguments.Split('?');

            if (splitted.Length != 2)
            {
                return(default(T));
            }

            var expectedType = splitted[0];
            var queryString  = splitted[1];

            if (typeof(T).Name != expectedType)
            {
                return(default(T));
            }

            var result  = new T();
            var decoder = new WwwFormUrlDecoder(queryString);

            result.InjectValues(decoder.ToDictionary(f => f.Name, f => (object)f.Value));

            return(result);
        }
        protected override void OnActivated(IActivatedEventArgs args)
        {
            if (args.Kind == ActivationKind.Protocol)
            {
                var    eventArgs   = args as ProtocolActivatedEventArgs;
                string accessToken = null;

                if (eventArgs != null)
                {
                    var uri = eventArgs.Uri;
                    //string accessToken = HttpUtility.ParseQueryString(uri.Query);
                    var decoder = new WwwFormUrlDecoder(uri.Query);
                    var uriDict = decoder.ToDictionary(x => x.Name, x => x.Value);
                    if (uriDict.ContainsKey("access_token"))
                    {
                        accessToken = uriDict["access_token"];
                    }
                }

                _localSettings.Values[Constants.FbAccessTokenName] = accessToken;

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

                    rootFrame.NavigationFailed += OnNavigationFailed;

                    if (args.PreviousExecutionState == ApplicationExecutionState.Terminated)
                    {
                        //TODO: Load state from previously suspended application
                    }

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

                rootFrame.Navigate(Core.IsUserLoggedIn() ? typeof(MapView) : typeof(MainPage), args);
            }
        }
示例#5
0
        internal void HandleUri(Uri uri)
        {
            Dictionary <string, string> query = new Dictionary <string, string>();

            if (uri.Query.Length > 0)
            {
                WwwFormUrlDecoder decoder = new WwwFormUrlDecoder(uri.Query);
                query = decoder.ToDictionary(x => x.Name, x => x.Value);
            }

            switch (uri.Host)
            {
            case "settitle":
                // I'm not entirely sure if this is applicable
                // Sets values like title=Confirmations or title=Chat
                break;

            case "lostauth":
                LogoutButton_Click(null, null);
                break;

            case "steamguard":
                if (query["op"] != "conftag")
                {
                    break;
                }

                account.GenerateConfirmationQueryParams(async response =>
                {
                    string[] args = { "window.SGHandler.update('" + response + "', 'ok');" };
                    await ConfirmationWeb.InvokeScriptAsync("eval", args);
                }, query["arg1"]);

                break;

            default:
                Debug.WriteLine("Unhandled uri: " + uri.AbsoluteUri);
                break;
            }
        }
        internal void HandleUri(Uri uri)
        {
            var query = new Dictionary <string, string>();

            if (uri.Query.Length > 0)
            {
                var decoder = new WwwFormUrlDecoder(uri.Query);
                query = decoder.ToDictionary(x => x.Name, x => x.Value);
            }

            switch (uri.Host)
            {
            case "settitle":
                // I'm not entirely sure if this is applicable
                // Sets values like title=Confirmations or title=Chat
                break;

            case "lostauth":
                // This code had a massive tantrum when run outside the application's thread
                this.account.RefreshSession(this.web, async success =>
                {
                    await this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                    {
                        if (success == Success.Success)
                        {
                            Action <object, RoutedEventArgs> call = this.ChatWeb.Visibility == Visibility.Visible ? this.MessageButton_Click :
                                                                    this.ConfirmationWeb.Visibility == Visibility.Visible ? this.ConfirmationsButton_Click :
                                                                    (Action <object, RoutedEventArgs>) this.SteamGuardButton_Click;

                            call(null, null);
                        }
                        else if (success == Success.Error)
                        {
                            this.SteamGuardButton_Click(null, null);
                        }
                        else
                        {
                            Storage.Logout();
                            this.Frame.Navigate(typeof(LoginPage));
                        }
                    });
                });
                break;

            case "steamguard":
                if (query["op"] != "conftag")
                {
                    break;
                }

                this.account.GenerateConfirmationQueryParams(this.web, query["arg1"], async response =>
                {
                    try
                    {
                        string[] args =
                        {
                            "window.SGHandler.update('" + response + "', 'ok');"
                        };
                        await this.ConfirmationWeb.InvokeScriptAsync("eval", args);
                    }
                    catch (Exception)
                    {
                        // We're probably here because the webview was unloaded
                        // Just reload the view
                        this.ConfirmationsButton_Click(null, null);
                    }
                });

                break;

            default:
                Debug.WriteLine("Unhandled uri: " + uri.AbsoluteUri);
                break;
            }
        }