Example #1
0
        private async static void CompleteUserProfile()
        {
            try
            {
                UserEntityProfileCompletion result = await App.MobileService.InvokeApiAsync <UserEntityProfileCompletion>(ApplicationConstants.COMPLETE_USER_PROFILE_METHOD, HttpMethod.Get, null);

                if (result != null)
                {
                    App.CurrentUser.Name              = result.Name;
                    App.CurrentUser.Picture           = result.Picture;
                    App.CurrentUser.AccessToken       = result.AccessToken;
                    App.CurrentUser.AccessTokenSecret = result.AccessTokenSecret;
                    ApplicationDataManager.StoreValue(ApplicationConstants.UserKey, App.CurrentUser);
                }
            }
            catch (Exception ex)
            {
                HandleInsertChannelException(ex);
            }
        }
Example #2
0
        public async static void RegisterWithMobileServices(string provider)
        {
            try
            {
                App.CurrentUser.Id               = Guid.NewGuid().ToString();
                App.CurrentUser.ProviderIdLong   = App.MobileServicesUser.UserId;
                App.CurrentUser.ProviderIdShort  = IdentityProviderParser.GetShortProvider(App.CurrentUser.ProviderIdLong);
                App.CurrentUser.Token            = App.MobileServicesUser.MobileServiceAuthenticationToken;
                App.CurrentUser.IdentityProvider = IdentityProviderConverter.GetProvider(provider);

                App.Channel = HttpNotificationChannel.Find("MyPushChannel");

                if (App.Channel == null)
                {
                    App.Channel = new HttpNotificationChannel("MyPushChannel");
                    App.Channel.Open();
                }

                if (App.Channel.ConnectionStatus == ChannelConnectionStatus.Disconnected)
                {
                    App.Channel.Open();
                }

                if (!App.Channel.IsShellToastBound)
                {
                    App.Channel.BindToShellToast();
                }
                if (!App.Channel.IsShellToastBound)
                {
                    App.Channel.BindToShellTile();
                }
                App.Channel.ShellToastNotificationReceived += ToastReceived;
                App.Channel.ChannelUriUpdated       += ChannelUriUpdated;
                App.Channel.ConnectionStatusChanged += ConnectionStatusChanged;
            }
            catch (Exception ex)
            {
                HandleInsertChannelException(ex);
            }
            try
            {
                CurrentChannel.Id             = Guid.NewGuid().ToString();
                CurrentChannel.DeviceType     = Enums.DeviceType.WindowsPhone8;
                CurrentChannel.UserId         = CurrentUser.ProviderIdLong;
                CurrentChannel.RegistrationId = String.Empty;
            }
            catch (Exception ex)
            {
                ex.ToString();
            }
            try
            {
                ApplicationDataManager.StoreValue(ApplicationConstants.UserKey, App.CurrentUser);
                await UsersTable.InsertAsync(App.CurrentUser);
            }
            catch (Exception ex)
            {
                ex.ToString();
            }
            try
            {
                if (App.Channel != null && App.Channel.ChannelUri != null)
                {
                    CurrentChannel.ChannelUri = App.Channel.ChannelUri.AbsoluteUri;
                }
                else
                {
                    int x = 0;
                    x++;
                }
                await ChannelsTable.InsertAsync(App.CurrentChannel);
            }
            catch (Exception ex)
            {
                ex.ToString();
            }
            try
            {
                UserEntityProfileCompletion result = await App.MobileService.InvokeApiAsync <UserEntityProfileCompletion>(ApplicationConstants.COMPLETE_USER_PROFILE_METHOD, HttpMethod.Get, null);

                if (result != null)
                {
                    App.CurrentUser.Name              = result.Name;
                    App.CurrentUser.Picture           = result.Picture;
                    App.CurrentUser.AccessToken       = result.AccessToken;
                    App.CurrentUser.AccessTokenSecret = result.AccessTokenSecret;
                    ApplicationDataManager.StoreValue(ApplicationConstants.UserKey, App.CurrentUser);
                }
            }
            catch (Exception ex)
            {
                ex.ToString();
            }
            try
            {
                Dictionary <String, String> query = new Dictionary <string, string>();
                query.Add("userId", CurrentUser.ProviderIdLong);
                List <Friend> friends = await App.MobileService.InvokeApiAsync <List <Friend> >(ApplicationConstants.GET_USERS_METHOD, HttpMethod.Get, query);

                if (friends != null)
                {
                    ChatPageViewModel chatPageViewModel = ServiceLocator.Current.GetInstance <ChatPageViewModel>();
                    chatPageViewModel.FriendsViewModel = new ObservableCollection <Friend>(friends);
                    chatPageViewModel.SelectedFriend   = friends[0];
                }
            }
            catch (Exception ex)
            {
                ex.ToString();
            }
        }