Exemplo n.º 1
0
        public Task SendCommentAsync(CommentBody commentBody, CancellationTokenSource cancellationTokenSource) =>
        Task.Run(async() => {
            try {
                DrivenEvent announceActor = new DrivenEvent()
                {
                    Id        = Guid.NewGuid().ToString(),
                    EventType = DrivenActorEvents.CommentPost,
                    Data      = JsonConvert.SerializeObject(commentBody),
                };

                string url         = BaseSingleton <GlobalSetting> .Instance.RestEndpoints.AnnouncementEndPoints.NewAnnounce;
                string accessToken = BaseSingleton <GlobalSetting> .Instance.UserProfile.AccesToken;

                await _requestProvider.PostAsync <object, DrivenEvent>(url, announceActor, accessToken);
            }
            catch (ServiceAuthenticationException) {
                await _identityService.LogOutAsync();
            }
            catch (Exception exc) {
                Crashes.TrackError(exc);
            }
        }, cancellationTokenSource.Token);
Exemplo n.º 2
0
        public Task NewAnnouncementAsync(AnnounceBodyRequest announceBodyRequest, CancellationTokenSource cancellationTokenSource = default(CancellationTokenSource), string eventId = "") =>
        Task.Run(async() => {
            try {
                DrivenEvent announceActor = new DrivenEvent()
                {
                    Id        = string.IsNullOrEmpty(eventId) ? Guid.NewGuid().ToString() : eventId,
                    Data      = JsonConvert.SerializeObject(announceBodyRequest),
                    EventType = DrivenActorEvents.NewAnnounce,
                    UserNetId = BaseSingleton <GlobalSetting> .Instance.UserProfile.NetId
                };

                string url         = BaseSingleton <GlobalSetting> .Instance.RestEndpoints.AnnouncementEndPoints.NewAnnounce;
                string accessToken = BaseSingleton <GlobalSetting> .Instance.UserProfile.AccesToken;

                await _requestProvider.PostAsync <object, DrivenEvent>(url, announceActor, accessToken);
            }
            catch (ServiceAuthenticationException) {
                await _identityService.LogOutAsync();
            }
            catch (Exception exc) {
                Crashes.TrackError(exc);
            }
        }, cancellationTokenSource.Token);
Exemplo n.º 3
0
        public Task DeleteAnnounceAsync(string id, CancellationTokenSource cancellationTokenSource) =>
        Task.Run(async() => {
            try {
                DrivenEvent announceActor = new DrivenEvent()
                {
                    Id        = Guid.NewGuid().ToString(),
                    Data      = id,
                    EventType = DrivenActorEvents.RemovePost,
                    UserNetId = BaseSingleton <GlobalSetting> .Instance.UserProfile.NetId
                };

                string url         = BaseSingleton <GlobalSetting> .Instance.RestEndpoints.AnnouncementEndPoints.NewAnnounce;
                string accessToken = BaseSingleton <GlobalSetting> .Instance.UserProfile.AccesToken;

                await _requestProvider.PostAsync <object, DrivenEvent>(url, announceActor, accessToken);
            }
            catch (ServiceAuthenticationException) {
                await _identityService.LogOutAsync();
            }
            catch (Exception exc) {
                Crashes.TrackError(exc);
            }
        }, cancellationTokenSource.Token);
Exemplo n.º 4
0
        protected override void OnStartListeningToHub()
        {
            _hubConnection.On <object>(UPDATE_POST_LIKES_COUNT, async(args) => {
                try {
                    DrivenEventResponse drivenEventResponse = ParseResponseData <DrivenEventResponse>(args);

                    if (drivenEventResponse.StatusCode == HttpStatusCode.OK)
                    {
                        DrivenEvent drivenEvent = ParseResponseData <DrivenEvent>(drivenEventResponse.Data);

                        PostLikedBody postLikedBody = ParseResponseData <PostLikedBody>(drivenEvent.Data);
                        Device.BeginInvokeOnMainThread(() => PostLikesCountReceived(this, postLikedBody));
                    }
                    else if (drivenEventResponse.StatusCode == HttpStatusCode.Unauthorized)
                    {
                        await DependencyLocator.Resolve <IIdentityService>().LogOutAsync();
                    }
                }
                catch (Exception ex) {
                    Debugger.Break();
                    Crashes.TrackError(ex);
                }
            });

            _hubConnection.On <object>(REMOVE_POST, async(args) => {
                try {
                    DrivenEventResponse drivenEventResponse = ParseResponseData <DrivenEventResponse>(args);

                    if (drivenEventResponse.StatusCode == HttpStatusCode.OK)
                    {
                        DrivenEvent drivenEvent = ParseResponseData <DrivenEvent>(drivenEventResponse.Data);

                        string postId = ParseResponseData <string>(drivenEvent.Data);
                        Device.BeginInvokeOnMainThread(() => DeletedPostReceived(this, postId));
                    }
                    else if (drivenEventResponse.StatusCode == HttpStatusCode.Unauthorized)
                    {
                        await DependencyLocator.Resolve <IIdentityService>().LogOutAsync();
                    }
                }
                catch (Exception ex) {
                    Debugger.Break();
                    Crashes.TrackError(ex);
                }
            });

            _hubConnection.On <object>(NEW_POST_COMMENT, async(args) => {
                try {
                    DrivenEventResponse drivenEventResponse = ParseResponseData <DrivenEventResponse>(args);

                    if (drivenEventResponse.StatusCode == HttpStatusCode.OK)
                    {
                        DrivenEvent drivenEvent = ParseResponseData <DrivenEvent>(drivenEventResponse.Data);

                        Comment comment = ParseResponseData <Comment>(drivenEvent.Data);
                        Device.BeginInvokeOnMainThread(() => NewPostCommentReceived(this, comment));
                    }
                    else if (drivenEventResponse.StatusCode == HttpStatusCode.Unauthorized)
                    {
                        await DependencyLocator.Resolve <IIdentityService>().LogOutAsync();
                    }
                }
                catch (Exception ex) {
                    Debugger.Break();
                    Crashes.TrackError(ex);
                }
            });

            _hubConnection.On <object>(UPDATE_POST_COMMENTS_C0UNT, async(args) => {
                try {
                    DrivenEventResponse drivenEventResponse = ParseResponseData <DrivenEventResponse>(args);

                    if (drivenEventResponse.StatusCode == HttpStatusCode.OK)
                    {
                        DrivenEvent drivenEvent = ParseResponseData <DrivenEvent>(drivenEventResponse.Data);

                        CommentCountBody commentCountBody = ParseResponseData <CommentCountBody>(drivenEvent.Data);
                        Device.BeginInvokeOnMainThread(() => PostCommentsCountReceived(this, commentCountBody));
                    }
                    else if (drivenEventResponse.StatusCode == HttpStatusCode.Unauthorized)
                    {
                        await DependencyLocator.Resolve <IIdentityService>().LogOutAsync();
                    }
                }
                catch (Exception ex) {
                    Debugger.Break();
                    Crashes.TrackError(ex);
                }
            });

            _hubConnection.On <object>(NEW_ANNOUNCE, async(args) => {
                try {
                    Console.WriteLine("===> AnnouncementHubService.NewPostHubEndpoint <===");
                    DrivenEventResponse drivenEventResponse = ParseResponseData <DrivenEventResponse>(args);

                    if (drivenEventResponse.StatusCode == HttpStatusCode.OK)
                    {
                        DrivenEvent drivenEvent = ParseResponseData <DrivenEvent>(drivenEventResponse.Data);

                        Announce announce = ParseResponseData <Announce>(drivenEvent.Data);
                        if (announce != null && announce.AnnounceBody != null && announce.ImageUrl != null)
                        {
                            Device.BeginInvokeOnMainThread(() => NewAnnounceReceived(this, announce));
                        }
                        else
                        {
                            announce = new Announce();
                            AnnounceBody announceBody = ParseResponseData <AnnounceBody>(drivenEvent.Data);
                            announce.AnnounceBody     = announceBody;
                            Device.BeginInvokeOnMainThread(() => NewAnnounceReceived(this, announce));
                        }
                    }
                    else if (drivenEventResponse.StatusCode == HttpStatusCode.Unauthorized)
                    {
                        await DependencyLocator.Resolve <IIdentityService>().LogOutAsync();
                    }
                }
                catch (Exception exc) {
                    Debugger.Break();
                    Crashes.TrackError(exc);
                }
            });
        }