Ejemplo n.º 1
0
        public async Task <InvitesResponse> GetInvitesAsync(CancellationToken cancellationToken) =>
        await Task.Run(async() => {
            if (!CrossConnectivity.Current.IsConnected)
            {
                throw new InvalidOperationException(AppConsts.ERROR_INTERNET_CONNECTION);
            }

            InvitesRequest invitesRequest = new InvitesRequest {
                AccessToken = GlobalSettings.Instance.UserProfile.AccesToken,
                Url         = GlobalSettings.Instance.Endpoints.InviteEndPoints.GetInvitesEndPoint
            };

            InvitesResponse invitesResponse = null;

            try {
                invitesResponse = await _requestProvider.GetAsync <InvitesRequest, InvitesResponse>(invitesRequest);
            }
            catch (ServiceAuthenticationException exc) {
                _identityUtilService.RefreshToken();

                throw exc;
            }
            catch (Exception ex) {
                Crashes.TrackError(ex);
                Debug.WriteLine($"ERROR:{ex.Message}");
            }
            return(invitesResponse);
        }, cancellationToken);
Ejemplo n.º 2
0
        public async Task <IEnumerable <FoundGroupDataItem> > SearchAsync(string value = "", string type = "") =>
        await Task <IEnumerable <FoundGroupDataItem> > .Run(async() => {
            if (!CrossConnectivity.Current.IsConnected)
            {
                throw new InvalidOperationException(AppConsts.ERROR_INTERNET_CONNECTION);
            }

            SearchRequest searchRequest = new SearchRequest {
                Url         = string.Format(GlobalSettings.Instance.Endpoints.SearchEndPoints.SimpleSearchEndPoints, value, type),
                AccessToken = GlobalSettings.Instance.UserProfile.AccesToken
            };

            SearchResponse searchResponse = null;
            IEnumerable <FoundGroupDataItem> foundUserGroups = null;

            try {
                searchResponse = await _requestProvider.GetAsync <SearchRequest, SearchResponse>(searchRequest);

                if (searchResponse != null)
                {
                    foundUserGroups = _foundUserGroupDataItemFactory.BuildFoundGroupDataItems(searchResponse);
                }
            } catch (ServiceAuthenticationException exc) {
                _identityUtilService.RefreshToken();

                throw exc;
            } catch (Exception ex) {
                Crashes.TrackError(ex);

                throw;
            }

            return(foundUserGroups);
        });
Ejemplo n.º 3
0
        public async Task <List <TeamMember> > GetTeamMembersAsync(CancellationToken cancellationToken = default(CancellationToken), bool noRepeatings = false) =>
        await Task.Run(async() => {
            if (!CrossConnectivity.Current.IsConnected)
            {
                throw new InvalidOperationException(AppConsts.ERROR_INTERNET_CONNECTION);
            }

            List <TeamMember> teamMembers = new List <TeamMember>();

            GetTeamMembersRequest getTeamMembersRequest = new GetTeamMembersRequest {
                AccessToken = GlobalSettings.Instance.UserProfile.AccesToken,
                Url         = GlobalSettings.Instance.Endpoints.TeamMemberEndPoints.GetTeamMembersEndPoint
            };

            GetTeamMembersResponse getTeamMembersResponse = null;

            try {
                getTeamMembersResponse = await _requestProvider.GetAsync <GetTeamMembersRequest, GetTeamMembersResponse>(getTeamMembersRequest);

                if (getTeamMembersResponse != null)
                {
                    if (noRepeatings)
                    {
                        teamMembers = getTeamMembersResponse.TeamMembers.GroupBy <TeamMember, long>(teamMember => teamMember.Team.Id).Select <IGrouping <long, TeamMember>, TeamMember>(group => group.First()).ToList();
                    }
                    else
                    {
                        teamMembers = getTeamMembersResponse.TeamMembers.ToList();
                    }
                }
                else
                {
                    throw new InvalidOperationException(CANT_GET_TEAM_MEMBER_BY_MEMBER_ID_ERROR_MESSAGE);
                }
            }
            catch (ServiceAuthenticationException exc) {
                _identityUtilService.RefreshToken();

                throw exc;
            }
            catch (Exception ex) {
                Crashes.TrackError(ex);

                throw;
            }

            return(teamMembers);
        }, cancellationToken);
Ejemplo n.º 4
0
        public async Task <MediaDTO> UploadMediaToTrayAsync(FileDTO file, CancellationTokenSource cancellationTokenSource) =>
        await Task <MediaDTO> .Run(async() => {
            if (!CrossConnectivity.Current.IsConnected)
            {
                throw new InvalidOperationException(AppConsts.ERROR_INTERNET_CONNECTION);
            }

            MediaDTO media = null;

            try {
                UploadMediaRequest uploadMediaRequest = new UploadMediaRequest {
                    AccessToken = GlobalSettings.Instance.UserProfile.AccesToken,
                    Url         = GlobalSettings.Instance.Endpoints.ProfileMediaEndPoints.UploadMedia,
                    Data        = file
                };

                UploadMediaResponse uploadMediaResponse = await _requestProvider.PostAsync <UploadMediaRequest, UploadMediaResponse>(uploadMediaRequest);

                if (uploadMediaResponse != null)
                {
                    media = _mediaFactory.BuildMediaDTO(uploadMediaResponse);
                }
                else
                {
                    throw new InvalidOperationException(CANT_UPLOAD_MEDIA_COMMON_ERROR);
                }
            }
            catch (ServiceAuthenticationException exc) {
                _identityUtilService.RefreshToken();

                throw exc;
            }
            catch (Exception ex) {
                media = null;

                Crashes.TrackError(ex);

                Debug.WriteLine($"ERROR:{ex.Message}");
                throw;
            }

            return(media);
        }, cancellationTokenSource.Token);
Ejemplo n.º 5
0
        public async Task <AddFriendResponse> AddFriendAsync(string friendShortId, CancellationToken cancellationToken) =>
        await Task.Run(async() => {
            if (!CrossConnectivity.Current.IsConnected)
            {
                throw new InvalidOperationException(AppConsts.ERROR_INTERNET_CONNECTION);
            }

            // Get friend profile.
            GetProfileResponse friendProfile = await _profileService.GetProfileByShortIdAsync(friendShortId, cancellationToken);

            if (friendProfile == null)
            {
                throw new Exception("Friend profile not found.");
            }

            AddFriendRequest addFriendRequest = new AddFriendRequest {
                AccessToken = GlobalSettings.Instance.UserProfile.AccesToken,
                Url         = GlobalSettings.Instance.Endpoints.FriendEndPoints.AddFriendRequestEndPoint,
                Data        = new AddFriendDataModel {
                    FriendId    = friendProfile.Id,
                    ProfileId   = GlobalSettings.Instance.UserProfile.Id,
                    ProfileType = GlobalSettings.Instance.UserProfile.ProfileType.ToString()
                }
            };

            AddFriendResponse addFriendResponse = null;

            try {
                addFriendResponse = await _requestProvider.PostAsync <AddFriendRequest, AddFriendResponse>(addFriendRequest);
            }
            catch (ServiceAuthenticationException exc) {
                _identityUtilService.RefreshToken();

                throw exc;
            }
            catch (Exception ex) {
                Crashes.TrackError(ex);

                Debug.WriteLine($"ERROR:{ex.Message}");
                throw new Exception((JsonConvert.DeserializeObject <AddFriendException>(ex.Message)).Empty.FirstOrDefault());
            }
            return(addFriendResponse);
        }, cancellationToken);
Ejemplo n.º 6
0
        public Task <OpponentDTO> CreateOpponentAsync(CreateOpponentDataModel createOpponentDataModel, CancellationTokenSource cancellationTokenSource) =>
        Task <OpponentDTO> .Run(async() => {
            if (!CrossConnectivity.Current.IsConnected)
            {
                throw new InvalidOperationException(AppConsts.ERROR_INTERNET_CONNECTION);
            }

            OpponentDTO createdOpponent = null;

            CreateOpponentRequest createOpponentRequest = new CreateOpponentRequest()
            {
                AccessToken = GlobalSettings.Instance.UserProfile.AccesToken,
                Url         = GlobalSettings.Instance.Endpoints.ScheduleEndpoints.CreateNewOpponent,
                Data        = createOpponentDataModel
            };

            try {
                CreateOpponentResponse createOpponentResponse = await _requestProvider.PostAsync <CreateOpponentRequest, CreateOpponentResponse>(createOpponentRequest);

                if (createOpponentResponse != null)
                {
                    createdOpponent = BuildOpponent(createOpponentResponse);
                }
                else
                {
                    throw new InvalidOperationException(CREATE_OPPONENT_COMMON_ERROR_MESSAGE);
                }
            }
            catch (ServiceAuthenticationException exc) {
                _identityUtilService.RefreshToken();

                throw exc;
            }
            catch (Exception exc) {
                Crashes.TrackError(exc);

                throw;
            }

            return(createdOpponent);
        }, cancellationTokenSource.Token);
Ejemplo n.º 7
0
        public async Task <List <MessageDTO> > GetFriendChatAsync(long friendId, CancellationToken cancellationToken) =>
        await Task.Run(async() => {
            if (!CrossConnectivity.Current.IsConnected)
            {
                throw new InvalidOperationException(AppConsts.ERROR_INTERNET_CONNECTION);
            }

            List <MessageDTO> messages = new List <MessageDTO>();

            GetMessagesRequest getMessagesRequest = new GetMessagesRequest {
                AccessToken = GlobalSettings.Instance.UserProfile.AccesToken,
                Url         = string.Format(GlobalSettings.Instance.Endpoints.ChatEndPoints.GetMessagesEndPoint,
                                            string.Empty,
                                            friendId,
                                            GlobalSettings.Instance.UserProfile.Id,
                                            GlobalSettings.Instance.UserProfile.ProfileType.ToString())
            };

            GetMessagesResponse getAllFriendsResponse = null;

            try {
                getAllFriendsResponse = await _requestProvider.GetAsync <GetMessagesRequest, GetMessagesResponse>(getMessagesRequest);
                if (getAllFriendsResponse != null)
                {
                    messages = getAllFriendsResponse?.Messages.ToList();
                }
            }
            catch (ServiceAuthenticationException exc) {
                _identityUtilService.RefreshToken();

                throw exc;
            }
            catch (Exception ex) {
                Crashes.TrackError(ex);

                throw;
            }
            return(messages);
        }, cancellationToken);
Ejemplo n.º 8
0
        public Task <FamilyDTO> GetFamilyAsync(CancellationTokenSource cancellationTokenSource) =>
        Task <FamilyDTO> .Run(async() => {
            if (!CrossConnectivity.Current.IsConnected)
            {
                throw new InvalidOperationException(AppConsts.ERROR_INTERNET_CONNECTION);
            }

            FamilyDTO familyDTO = null;

            GetFamilyRequest getFamilyRequest = new GetFamilyRequest()
            {
                AccessToken = GlobalSettings.Instance.UserProfile.AccesToken,
                Url         = GlobalSettings.Instance.Endpoints.FamilyEndpoints.GetFamilyEndpoint
            };

            try {
                GetFamilyResponse getFamilyResponse = await _requestProvider.GetAsync <GetFamilyRequest, GetFamilyResponse>(getFamilyRequest);

                if (getFamilyResponse != null)
                {
                    familyDTO = new FamilyDTO()
                    {
                        Id       = getFamilyResponse.Id,
                        Members  = getFamilyResponse.Members,
                        ParentId = getFamilyResponse.ParentId
                    };
                }
            } catch (HttpRequestExceptionEx exc) {
                GetFamilyResponse erroredGetFamilyResponse = JsonConvert.DeserializeObject <GetFamilyResponse>(exc.Message);

                string output = string.Format("{0}",
                                              erroredGetFamilyResponse.Errors?.FirstOrDefault());

                output = (string.IsNullOrWhiteSpace(output) || string.IsNullOrEmpty(output)) ? GET_FAMILY_COMMON_ERROR : output;

                throw new InvalidOperationException(output.Trim());
            } catch (ServiceAuthenticationException exc) {
                _identityUtilService.RefreshToken();

                throw exc;
            } catch (Exception exc) {
                Crashes.TrackError(exc);

                throw exc;
            }

            return(familyDTO);
        });
Ejemplo n.º 9
0
        public async Task <List <SportDTO> > GetSportsAsync(CancellationToken cancellationToken) =>
        await Task.Run(async() => {
            if (!CrossConnectivity.Current.IsConnected)
            {
                throw new InvalidOperationException(AppConsts.ERROR_INTERNET_CONNECTION);
            }

            List <SportDTO> sports = null;

            if (_sportsList != null && _sportsList.Any())
            {
                sports = _sportsList.ToList();
            }
            else
            {
                sports = new List <SportDTO>();

                GetSportsRequest getSportsRequest = new GetSportsRequest {
                    AccessToken = GlobalSettings.Instance.UserProfile.AccesToken,
                    Url         = GlobalSettings.Instance.Endpoints.SportEndPoints.GetSportsEndPoint
                };

                GetSportsResponse getSportsResponse = null;

                try {
                    getSportsResponse = await _requestProvider.GetAsync <GetSportsRequest, GetSportsResponse>(getSportsRequest);
                    cancellationToken.ThrowIfCancellationRequested();

                    if (getSportsResponse != null && getSportsResponse.Sports.Any())
                    {
                        sports      = getSportsResponse.Sports.ToList();
                        _sportsList = getSportsResponse.Sports.ToArray <SportDTO>();
                    }
                }
                catch (ServiceAuthenticationException exc) {
                    _identityUtilService.RefreshToken();

                    throw exc;
                }
                catch (Exception ex) {
                    Crashes.TrackError(ex);
                    Debug.WriteLine($"{ex.Message}");
                }
            }

            return(sports);
        }, cancellationToken);
Ejemplo n.º 10
0
        public Task <bool> UpdateOuterProfileInfoAsync(OuterProfileEditDataModel profileEdit, CancellationTokenSource cancellationTokenSource) =>
        Task <bool> .Run(async() => {
            if (!CrossConnectivity.Current.IsConnected)
            {
                throw new InvalidOperationException(AppConsts.ERROR_INTERNET_CONNECTION);
            }

            UpdateOuterProfileRequest updateOuterProfileRequest = new UpdateOuterProfileRequest {
                Url         = GlobalSettings.Instance.Endpoints.ProfileEndpoints.OuterProfileEditEndPoint,
                AccessToken = GlobalSettings.Instance.UserProfile.AccesToken,
                Data        = profileEdit
            };

            UpdateOuterProfileResponse updateOuterProfileResponse = null;
            bool completion = false;

            try {
                updateOuterProfileResponse =
                    await _requestProvider.PostAsync <UpdateOuterProfileRequest, UpdateOuterProfileResponse>(updateOuterProfileRequest);

                completion = true;
            }
            catch (ServiceAuthenticationException exc) {
                completion = false;
                _identityUtilService.RefreshToken();

                throw exc;
            }
            catch (Exception exc) {
                completion = false;
                Crashes.TrackError(exc);

                throw exc;
            }

            return(completion);
        });
Ejemplo n.º 11
0
        public async Task <List <PostDTO> > GetPostsAsync(string authorshortId = "", string pageId = "", CancellationToken cancellationToken = default(CancellationToken)) =>
        await Task.Run(async() => {
            if (!CrossConnectivity.Current.IsConnected)
            {
                throw new InvalidOperationException(AppConsts.ERROR_INTERNET_CONNECTION);
            }

            List <PostDTO> posts = new List <PostDTO>();

            GetPostsRequest getPostsRequest = new GetPostsRequest {
                Url = string.Format(GlobalSettings.Instance.Endpoints.PostEndpoints.GetPostsPoint,
                                    authorshortId,
                                    pageId,
                                    GlobalSettings.Instance.UserProfile.Id,
                                    GlobalSettings.Instance.UserProfile.ProfileType.ToString()),
                AccessToken = GlobalSettings.Instance.UserProfile.AccesToken
            };

            GetPostsResponse getPostsResponse = null;

            try {
                getPostsResponse =
                    await _requestProvider.GetAsync <GetPostsRequest, GetPostsResponse>(getPostsRequest);

                if (getPostsResponse.Posts != null)
                {
                    posts = getPostsResponse.Posts.Select <PostDTO, PostDTO>(pDTO => {
                        pDTO.PublishTime = pDTO.PublishTime.ToLocalTime();
                        pDTO.Comments.ForEach <CommentDTO>(cDTO => cDTO.CreationTime = cDTO.CreationTime.ToLocalTime());
                        pDTO.Text = NormalizeTextMessage(pDTO.Text);

                        return(pDTO);
                    }).ToList();
                }
            }
            catch (ServiceAuthenticationException exc) {
                _identityUtilService.RefreshToken();

                throw exc;
            }
            catch (Exception ex) {
                Crashes.TrackError(ex);

                Debug.WriteLine($"ERROR:{ex.Message}");
                throw new Exception(ex.Message);
            }

            return(posts);
        }, cancellationToken);
Ejemplo n.º 12
0
        public Task <CreateTeamResponse> CreateTeamAsync(CreateTeamDataModel createTeamDataModel, CancellationToken cancellationToken = default(CancellationToken)) =>
        Task.Run(async() => {
            if (!CrossConnectivity.Current.IsConnected)
            {
                throw new InvalidOperationException(AppConsts.ERROR_INTERNET_CONNECTION);
            }

            CreateTeamRequest createTeamRequest = new CreateTeamRequest {
                AccessToken = GlobalSettings.Instance.UserProfile.AccesToken,
                Url         = GlobalSettings.Instance.Endpoints.TeamEndPoints.CreateTeamEndPoint,
                Data        = createTeamDataModel
            };

            CreateTeamResponse createTeamResponse = null;

            try {
                createTeamResponse = await _requestProvider.PostAsync <CreateTeamRequest, CreateTeamResponse>(createTeamRequest);
            }
            catch (ServiceAuthenticationException exc) {
                _identityUtilService.RefreshToken();

                throw exc;
            }
            catch (HttpRequestExceptionEx exc) {
                CreateTeamBadResponse createTeamBadResponse = JsonConvert.DeserializeObject <CreateTeamBadResponse>(exc.Message);

                string output = string.Format("{0}",
                                              createTeamBadResponse.Name?.FirstOrDefault());

                output = (string.IsNullOrWhiteSpace(output) || string.IsNullOrEmpty(output)) ? TeamService.CREATE_NEW_TEAM_COMMON_ERROR_MESSAGE : output;

                throw new InvalidOperationException(output.Trim());
            }
            catch (Exception ex) {
                Crashes.TrackError(ex);
                throw;
            }

            return(createTeamResponse);
        }, cancellationToken);
Ejemplo n.º 13
0
        public Task <string> LoginAsync(string userName, string password, CancellationToken cancellationToken) =>
        Task.Run(async() => {
            if (!CrossConnectivity.Current.IsConnected)
            {
                throw new InvalidOperationException(AppConsts.ERROR_INTERNET_CONNECTION);
            }

            LoginRequest loginRequest = new LoginRequest {
                Url  = string.Format(GlobalSettings.Instance.Endpoints.AuthenticationEndpoints.LoginEndPoints),
                Data = new LoginRequestDataModel()
                {
                    Password = password,
                    Username = userName
                }
            };

            LoginResponse loginResponse = null;

            try {
                loginResponse = await _requestProvider.PostAsync <LoginRequest, LoginResponse>(loginRequest);
            }
            catch (ServiceAuthenticationException exc) {
                _identityUtilService.RefreshToken();

                throw exc;
            }
            catch (HttpRequestExceptionEx exc) {
                Crashes.TrackError(exc);

                string output = "";

                try {
                    LoginResponse bagLoginResponse = JsonConvert.DeserializeObject <LoginResponse>(exc.Message);

                    output = string.Format("{0} {1}",
                                           bagLoginResponse.Errors?.FirstOrDefault(),
                                           bagLoginResponse.User?.FirstOrDefault().Split('\r').FirstOrDefault());
                }
                catch {
                    Debugger.Break();
                    output = _COMMON_LOGIN_ERROR;
                }

                output = (string.IsNullOrWhiteSpace(output) || string.IsNullOrEmpty(output)) ? _COMMON_LOGIN_ERROR : output;

                throw new InvalidOperationException(output);
            }
            catch (Exception ex) {
                Crashes.TrackError(ex);

                string output = "";

                try {
                    LoginResponse bagLoginResponse = JsonConvert.DeserializeObject <LoginResponse>(ex.Message);

                    output = string.Format("{0} {1}",
                                           bagLoginResponse.Errors?.FirstOrDefault(),
                                           bagLoginResponse.User?.FirstOrDefault().Split('\r').FirstOrDefault());
                }
                catch {
                    Debugger.Break();
                    output = _COMMON_LOGIN_ERROR;
                }

                output = (string.IsNullOrWhiteSpace(output) || string.IsNullOrEmpty(output)) ? _COMMON_LOGIN_ERROR : output;

                throw new InvalidOperationException(output);
            }

            return(loginResponse?.AccessToken);
        }, cancellationToken);