Exemplo n.º 1
0
    private async System.Threading.Tasks.Task Authenticate()
    {
      while (User == null)
      {
        string message = null;
        try
        {
          User = await App.MobileServiceClient
              .LoginAsync(MobileServiceAuthenticationProvider.MicrosoftAccount);
        }
        catch (InvalidOperationException)
        {
          message = "You must log in. Login Required";
        }

        if (!string.IsNullOrEmpty(message))
        {
          var dialog = new MessageDialog(message);
          dialog.Commands.Add(new UICommand("OK"));
          await dialog.ShowAsync();
        }
      }

      var user = new User { UserId = User.UserId };
      var userTable = App.MobileServiceClient.GetTable<User>();
      await userTable.InsertAsync(user);

      var channelOperation = await Windows.Networking.PushNotifications.PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();
      var userDeviceTable = App.MobileServiceClient.GetTable<UserDevice>();
      var userDevice = new UserDevice { UserId = user.id, DeviceUri = channelOperation.Uri };
      await userDeviceTable.InsertAsync(userDevice);

    }
Exemplo n.º 2
0
 async Task InitChannel()
 {
   if (App.MobileServiceClient.LoginInProgress)
   {
     return;
   }
   if (App.CurrentChannel != null)
   {
     var userDeviceTable = App.MobileServiceClient.GetTable<UserDevice>();
     var userDevice = new UserDevice { UserId = TheUser.id };
     App.CurrentChannel.ChannelUriUpdated += async (s, e) =>
     {
       userDevice.DeviceUri = App.CurrentChannel.ChannelUri.ToString();
       await userDeviceTable.InsertAsync(userDevice);
     };
     try
     {
       if (App.CurrentChannel.ChannelUri != null)
       {
         userDevice.DeviceUri = App.CurrentChannel.ChannelUri.ToString();
         await userDeviceTable.InsertAsync(userDevice);
       }
       else
       {
         Debug.WriteLine("Channel is null");
       }
     }
     catch (Exception ex)
     {
       
     }
   }
 }