예제 #1
0
        public Task <bool> PublishPostAsync(PublishPostDataModel publishPostDataModel, CancellationTokenSource cancellationTokenSource) =>
        Task.Run(async() => {
            if (!CrossConnectivity.Current.IsConnected)
            {
                throw new InvalidOperationException(AppConsts.ERROR_INTERNET_CONNECTION);
            }

            PublishNewPostRequest publishNewPostRequest = new PublishNewPostRequest()
            {
                Url         = GlobalSettings.Instance.Endpoints.PostEndpoints.PublishNewPostEndPoint,
                AccessToken = GlobalSettings.Instance.UserProfile.AccesToken,
                Data        = publishPostDataModel
            };

            try {
                PublishNewPostResponse publishNewPostResponse = await _requestProvider.PostAsync <PublishNewPostRequest, PublishNewPostResponse>(publishNewPostRequest);

                if (publishNewPostResponse != null)
                {
                    return(true);
                }
            }
            catch (ServiceAuthenticationException exc) {
                _identityUtilService.RefreshToken();

                throw exc;
            }
            catch (HttpRequestExceptionEx exc) {
                string output = "";

                try {
                    PublishNewPostBadResponse publishNewPostBadResponse = JsonConvert.DeserializeObject <PublishNewPostBadResponse>(exc.Message);

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

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

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

                Debugger.Break();
                return(false);
            }

            return(false);
        }, cancellationTokenSource.Token);
예제 #2
0
        public Task <bool> EditPostAsync(long postId, PublishPostDataModel publishPostDataModel, CancellationTokenSource cancellationTokenSource) =>
        Task <PostDTO> .Run(async() => {
            if (!CrossConnectivity.Current.IsConnected)
            {
                throw new InvalidOperationException(AppConsts.ERROR_INTERNET_CONNECTION);
            }

            EditPostRequest editPostRequest = new EditPostRequest()
            {
                Url         = string.Format(GlobalSettings.Instance.Endpoints.PostEndpoints.EditPostEndPoint, postId),
                AccessToken = GlobalSettings.Instance.UserProfile.AccesToken,
                Data        = publishPostDataModel
            };

            try {
                EditPostResponse editPostResponse = await _requestProvider.PostAsync <EditPostRequest, EditPostResponse>(editPostRequest);

                if (editPostResponse != null)
                {
                    return(true);
                }
            }
            catch (ServiceAuthenticationException exc) {
                _identityUtilService.RefreshToken();

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

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

            return(false);
        }, cancellationTokenSource.Token);