Exemplo n.º 1
0
        private bool SendStoryMessage(FB_PostInterface entity, string user_access_token, out string postId, out string error)
        {
            dynamic messagePost = new ExpandoObject();

            error  = string.Empty;
            postId = string.Empty;
            try
            {
                if (String.IsNullOrEmpty(user_access_token))
                {
                    error = "user_access_token required";
                    return(false);
                }

                if (entity.ActionId == null)
                {
                    error = "Action not defined";
                    return(false);
                }

                if (entity.CourseId == null)
                {
                    error = "CourseId required";
                    return(false);
                }

                var objectId = GetCourseFbObjectId((int)entity.CourseId);

                if (objectId < 0)
                {
                    error = "course objectId not found";
                    return(false);
                }

                var action = Utils.ParseEnum <FbEnums.eFbActions>(entity.ActionId.ToString());



                messagePost.lfe_course = objectId;
                messagePost.message    = entity.Message;

                var fb = new FacebookClient(user_access_token);

                var post = fb.Post("me/learnfromexpirence:" + action, messagePost);

                postId = post.id;

                return(true);
            }
            catch (Exception ex)
            {
                error = Utils.FormatError(ex);
                Logger.Error("post app message to FB", entity.PostId, ex, CommonEnums.LoggerObjectTypes.FB);
                return(false);
            }
        }
Exemplo n.º 2
0
        private bool SendPostMessage(FB_PostInterface entity, string user_access_token, out string postId, out string error)
        {
            error  = string.Empty;
            postId = string.Empty;
            try
            {
                dynamic messagePost = new ExpandoObject();

                messagePost.link    = entity.LinkedName;
                messagePost.name    = entity.Title;
                messagePost.message = entity.Message;

                if (!String.IsNullOrEmpty(entity.Caption))
                {
                    messagePost.caption = entity.Caption;
                }
                if (!String.IsNullOrEmpty(entity.Description))
                {
                    messagePost.description = entity.Description;
                }
                if (!string.IsNullOrEmpty(entity.ImageUrl))
                {
                    messagePost.picture = entity.ImageUrl;
                }

                // Logger.Debug("post app message with at::" + FB_APP_ACCESS_TOKEN + ", appPageId::" + FB_APP_PAGE_ID + ", msg::" + JsSerializer.Serialize(messagePost));

                messagePost.@from = new { id = FB_APP_ID, name = FB_APP_FROM_NAME };

                var fb = new FacebookClient(user_access_token);

                var post = fb.Post(entity.FbUid + "/feed", messagePost);

                postId = post.id;

                return(true);
            }
            catch (Exception ex)
            {
                error = Utils.FormatError(ex);
                Logger.Error("post message to FB", entity.PostId, ex, CommonEnums.LoggerObjectTypes.FB);
                return(false);
            }
        }
Exemplo n.º 3
0
        private void UpdateRowStatus(FB_PostInterface post, bool postSaved, string postId, string postError)
        {
            if (postSaved)
            {
                post.FbPostId = postId;
                post.Status   = FbEnums.ePostInterfaceStatus.Posted.ToString();
                post.PostOn   = DateTime.Now;
                post.UpdateOn = DateTime.Now;
            }
            else
            {
                post.Status   = FbEnums.ePostInterfaceStatus.Failed.ToString();
                post.Error    = postError;
                post.UpdateOn = DateTime.Now;
            }

            FacebookPostRepository.UnitOfWork.CommitAndRefreshChanges();

            if (postSaved && post.NotificationId != null)
            {
                UpdateNotificationFbPostState((long)post.NotificationId);
            }
        }