Exemplo n.º 1
0
        public void SavePostMessage(PostMessageDTO postToken, out string error, long?notificationId = null)
        {
            error = string.Empty;

            try
            {
                var entity = postToken.Dto2FbPostInterfaceEntity(notificationId);

                FacebookPostRepository.Add(entity);

                FacebookPostRepository.UnitOfWork.CommitAndRefreshChanges();
            }
            catch (Exception ex)
            {
                error = Utils.FormatError(ex);
                Logger.Error("save  FB message", postToken.MessageId ?? -1, ex, CommonEnums.LoggerObjectTypes.FB);
            }
        }
Exemplo n.º 2
0
        public void SendWaitingPosts()
        {
            try
            {
                var waiting = FbEnums.ePostInterfaceStatus.Waiting.ToString();

                //get all waiting posts
                var posts = FacebookPostRepository.GetMany(x => x.Status == waiting && x.FbPostId == null).ToList();

                if (posts.Count.Equals(0))
                {
                    return;
                }

                Logger.Debug("FB posts found " + posts.Count + " on " + DateTime.Now);

                string postId;
                string postError;

                foreach (var post in posts.Where(post => !post.IsAppPagePost && post.UserId != null && (post.FbUid != null || !String.IsNullOrEmpty(post.FbUserName))))
                {
                    try
                    {
                        // ReSharper disable once PossibleInvalidOperationException => filtered in LINQ
                        var userEntity = UserRepository.GetById((int)post.UserId);

                        if (userEntity == null)
                        {
                            UpdateRowStatus(post, false, null, "user entity not found");
                            continue;
                        }

                        var user_access_token = GetUserAccessToken(userEntity, out postError);


                        if (String.IsNullOrEmpty(user_access_token))
                        {
                            UpdateRowStatus(post, false, null, postError ?? "user_access_token not found");
                            continue;
                        }

                        var postSaved = post.ActionId == null?SendPostMessage(post, user_access_token, out postId, out postError) : SendStoryMessage(post, user_access_token, out postId, out postError);

                        UpdateRowStatus(post, postSaved, postId, postError);
                    }
                    catch (Exception ex)
                    {
                        Logger.Error("send user fb post or story", post.PostId, ex, CommonEnums.LoggerObjectTypes.FB);
                    }
                }

                #region post app messages
                foreach (var post in posts.Where(post => post.IsAppPagePost))
                {
                    var postSaved = SendAppPostMessage(post, out postId, out postError);

                    UpdateRowStatus(post, postSaved, postId, postError);
                }
                #endregion
                //posts stories
            }
            catch (Exception ex)
            {
                Logger.Error("post FB messages service", ex, CommonEnums.LoggerObjectTypes.FB);
            }
        }