/// <summary>
    /// OnAfterSave event.
    /// </summary>
    private void ControlOnAfterSave(object sender, EventArgs eventArgs)
    {
        FacebookPostInfo facebookPost = Control.EditedObject as FacebookPostInfo;

        if (facebookPost == null)
        {
            return;
        }

        if (!facebookPost.FacebookPostPostAfterDocumentPublish)
        {
            try
            {
                FacebookPostInfoProvider.PublishFacebookPost(facebookPost.FacebookPostID);
            }
            catch (Exception ex)
            {
                EventLogProvider.LogWarning("Social marketing - Facebook post", "PUBLISHPOST", ex, SiteContext.CurrentSiteID,
                                            String.Format("An error occurred while publishing the Facebook post with ID {0}.", facebookPost.FacebookPostID));
                Control.ShowError(Control.GetString("sm.facebook.posts.msg.unknownerror"));
            }
        }

        // Invoke event to set the form's state properly
        ControlOnAfterDataLoad(sender, eventArgs);
    }
    /// <summary>
    /// Form OnAfterSave event.
    /// </summary>
    private void Form_OnAfterSave(object sender, EventArgs e)
    {
        if ((PostInfo == null) || !HasUserModifyPermission)
        {
            return;
        }

        if (Document != null)
        {
            if (!PostInfo.FacebookPostDocumentGUID.HasValue)
            {
                PostInfo.FacebookPostDocumentGUID = Document.DocumentGUID;
            }

            if (PostInfo.FacebookPostPostAfterDocumentPublish && !IsUnderWorkflow && !PostInfo.IsPublished)
            {
                // Post will be scheduled on time when document gets published
                PostInfo.FacebookPostScheduledPublishDateTime = Document.DocumentPublishFrom;
            }

            if (PostInfo.HasChanged)
            {
                FacebookPostInfoProvider.SetFacebookPostInfo(PostInfo);
            }
        }

        // Check whether the post should be published or scheduled now (post WON'T be published/scheduled if it should be published with the document which is under workflow)
        if (!PostInfo.IsPublished && !(PostInfo.FacebookPostPostAfterDocumentPublish && IsUnderWorkflow))
        {
            PublishPost(PostInfo.FacebookPostID);
        }
        LoadPostDataIntoControl(PostInfo);
    }
示例#3
0
    /// <summary>
    /// Gets and updates Facebook post. Called when the "Get and update post" button is pressed.
    /// Expects the CreateFacebookPost method to be run first.
    /// </summary>
    private bool GetAndUpdateFacebookPost()
    {
        // Get an page to which the post is tied
        FacebookAccountInfo page = FacebookAccountInfoProvider.GetFacebookAccountInfo("MyNewPage", SiteContext.CurrentSiteID);

        if (page == null)
        {
            throw new Exception("[FacebookApiExamples.GetAndUpdateFacebookPost]: Page 'My new page' wasn't found.");
        }

        // Get the Facebook post from DB
        FacebookPostInfo post = FacebookPostInfoProvider.GetFacebookPostInfosByAccountId(page.FacebookAccountID).FirstOrDefault();

        if (post != null)
        {
            // Update the properties
            post.FacebookPostText = post.FacebookPostText + " Edited.";

            // Save the changes into DB
            FacebookPostInfoProvider.SetFacebookPostInfo(post);

            return(true);
        }

        return(false);
    }
示例#4
0
    /// <summary>
    /// Creates Facebook post. Called when the "Create post" button is pressed.
    /// </summary>
    private bool CreateFacebookPost()
    {
        // Get an page to which the post is tied
        FacebookAccountInfo page = FacebookAccountInfoProvider.GetFacebookAccountInfo("MyNewPage", SiteContext.CurrentSiteID);

        if (page == null)
        {
            throw new Exception("[FacebookApiExamples.CreateFacebookPost]: Page 'My new page' wasn't found.");
        }

        // Create new Facebook post object
        FacebookPostInfo post = new FacebookPostInfo();

        // Set the properties
        post.FacebookPostFacebookAccountID = page.FacebookAccountID;
        post.FacebookPostSiteID            = SiteContext.CurrentSiteID;
        post.FacebookPostText = "Sample post text.";

        // Should the post be scheduled instead of directly posted?
        post.FacebookPostScheduledPublishDateTime = DateTime.Now + TimeSpan.FromMinutes(5);

        // Is the post tied to a document?
        post.FacebookPostDocumentGUID = null;

        // Save the Facebook post into DB
        FacebookPostInfoProvider.SetFacebookPostInfo(post);

        return(true);
    }
 /// <summary>
 /// Publishes Facebook post with given identifier.
 /// </summary>
 /// <param name="postId">Facebook post identifier.</param>
 private void PublishPost(int postId)
 {
     try
     {
         FacebookPostInfoProvider.TryCancelScheduledPublishFacebookPost(postId);
         FacebookPostInfoProvider.PublishFacebookPost(postId);
     }
     catch (Exception ex)
     {
         EventLogProvider.LogWarning("Social marketing - Facebook post", "PUBLISHPOST", ex, SiteContext.CurrentSiteID,
                                     String.Format("An error occurred while publishing the Facebook post with ID {0}.", postId));
     }
 }
    /// <summary>
    /// Gets a link control that opens post details dialog when clicked. Post's content is used as link text.
    /// </summary>
    /// <param name="postId">Facebook post identifier.</param>
    private object GetFacebookPostDetailLink(int postId)
    {
        FacebookPostInfo post = FacebookPostInfoProvider.GetFacebookPostInfo(postId);

        if (LicenseKeyInfoProvider.IsFeatureAvailable(FeatureEnum.SocialMarketingInsights))
        {
            string dialogUrl = String.Format(mFacebookPostDetailsUrlFormat, post.FacebookPostID);
            return(String.Format("<a href=\"{0}\" onclick=\"modalDialog('{0}', 'PostDetails', 480, 570); return false;\" title=\"{1}\">{2}</a>",
                                 dialogUrl,
                                 ResHelper.GetString("sm.facebook.posts.detail.tooltip"),
                                 HTMLHelper.HTMLEncode(TextHelper.LimitLength(post.FacebookPostText, 80))
                                 ));
        }
        return(HTMLHelper.HTMLEncode(TextHelper.LimitLength(post.FacebookPostText, 80)));
    }
    /// <summary>
    /// Gets localized message describing post state.
    /// </summary>
    /// <param name="postId">Post id.</param>
    private object GetPostState(int postId)
    {
        switch (Control.ObjectType)
        {
        // Facebook post
        case FacebookPostInfo.OBJECT_TYPE:
            FacebookPostInfo facebookPost = FacebookPostInfoProvider.GetFacebookPostInfo(postId);
            return(FacebookPostInfoProvider.GetPostPublishStateMessage(facebookPost, MembershipContext.AuthenticatedUser, SiteContext.CurrentSite, true));

        // Twitter post
        case TwitterPostInfo.OBJECT_TYPE:
            TwitterPostInfo twitterPost = TwitterPostInfoProvider.GetTwitterPostInfo(postId);
            return(TwitterPostInfoProvider.GetPostPublishStateMessage(twitterPost, MembershipContext.AuthenticatedUser, SiteContext.CurrentSite, true));
        }

        return(String.Empty);
    }
 /// <summary>
 /// OnAction for Facebook post object type.
 /// </summary>
 private void OnAction_Facebook(string actionName, object actionArgument)
 {
     switch (actionName)
     {
     case "delete":
         try
         {
             FacebookPostInfoProvider.DeleteFacebookPostInfo(ValidationHelper.GetInteger(actionArgument, 0));
         }
         catch (Exception ex)
         {
             EventLogProvider.LogWarning("Social marketing - Facebook post", "DELETEPOST", ex, SiteContext.CurrentSiteID, "Facebook post could not be deleted.");
             Control.ShowError(Control.GetString("sm.facebook.posts.msg.deleteerror"));
         }
         break;
     }
 }
    /// <summary>
    /// Form OnBeforeDataRetrieval.
    /// </summary>
    private void Form_OnBeforeDataRetrieval(object sender, EventArgs eventArgs)
    {
        if (!HasUserModifyPermission)
        {
            return;
        }

        if (chkPostToFacebook.Checked)
        {
            if ((PostInfo == null) || PostInfo.IsEditable)
            {
                // Post does not exist or can be modified
                PostInfo = SetControlDataIntoPost(PostInfo);
                FacebookPostInfoProvider.SetFacebookPostInfo(PostInfo);
            }
            else if (!FormDataEqualsPostInfo(PostInfo))
            {
                mPublishedWhileEditing = true;
            }
        }
        else
        {
            // Checkbox post to Facebook is not checked
            if (PostInfo != null)
            {
                if (PostInfo.IsEditable)
                {
                    // Existing post has to be deleted
                    FacebookPostInfoProvider.DeleteFacebookPostInfo(PostInfo);
                    PostInfo = null;
                    InitializeControls();
                }
                else
                {
                    mPublishedWhileEditing = true;
                }
            }
            else if (mBackCompatibilityValue.HasValue)
            {
                // Form has to be cleaned up from old value
                mBackCompatibilityValue = null;
                InitializeControls();
            }
        }
    }
    /// <summary>
    /// OnAfterDataLoad event
    /// </summary>
    private void ControlOnAfterDataLoad(object sender, EventArgs eventArgs)
    {
        FacebookPostInfo facebookPost = Control.EditedObject as FacebookPostInfo;

        if ((facebookPost != null) && (facebookPost.FacebookPostID > 0))
        {
            string message = FacebookPostInfoProvider.GetPostPublishStateMessage(facebookPost, MembershipContext.AuthenticatedUser, SiteContext.CurrentSite);
            if (facebookPost.IsFaulty)
            {
                Control.ShowError(message);
            }
            else
            {
                Control.ShowInformation(message);
            }

            // Disable control if post has already been published or is faulty
            Control.Enabled = !(facebookPost.IsPublished || facebookPost.IsFaulty);
        }
    }
    /// <summary>
    /// OnBeforeSave event.
    /// </summary>
    private void Control_OnBeforeSave(object sender, EventArgs eventArgs)
    {
        FacebookPostInfo facebookPost = Control.EditedObject as FacebookPostInfo;

        if (facebookPost == null)
        {
            return;
        }

        if (facebookPost.FacebookPostID <= 0)
        {
            // The post is being created, not edited
            return;
        }

        if (!FacebookPostInfoProvider.TryCancelScheduledPublishFacebookPost(facebookPost))
        {
            // The post has been published during user edit. Prevent the changes to take effect
            CancelPendingSave(Control.GetString("sm.facebook.posts.msg.editforbidden"));
        }
    }
示例#12
0
    /// <summary>
    /// Deletes Facebook post. Called when the "Delete post" button is pressed.
    /// Expects the CreateFacebookPost method to be run first.
    /// </summary>
    private bool DeleteFacebookPosts()
    {
        // Get an page to which the post is tied
        FacebookAccountInfo page = FacebookAccountInfoProvider.GetFacebookAccountInfo("MyNewPage", SiteContext.CurrentSiteID);

        if (page == null)
        {
            throw new Exception("[FacebookApiExamples.DeleteFacebookPosts]: Page 'My new page' wasn't found.");
        }

        // Get the Facebook post from DB
        ObjectQuery <FacebookPostInfo> post = FacebookPostInfoProvider.GetFacebookPostInfosByAccountId(page.FacebookAccountID);

        // Delete the Facebook post from CMS and from Facebook
        foreach (FacebookPostInfo deletePost in post)
        {
            FacebookPostInfoProvider.DeleteFacebookPostInfo(deletePost);
        }

        return(post.Count != 0);
    }
    /// <summary>
    /// Shows given Facebook post's publish state.
    /// </summary>
    /// <param name="post">Facebook post.</param>
    private void ShowPostPublishState(FacebookPostInfo post)
    {
        string message = FacebookPostInfoProvider.GetPostPublishStateMessage(post, MembershipContext.AuthenticatedUser, CurrentSite);

        if (String.IsNullOrEmpty(message))
        {
            return;
        }

        if (post.IsFaulty)
        {
            ShowPostStateError(message);
            ShowError(String.Format("<strong>{0}</strong>: {1}", GetString("sm.facebook.autopost"), message));
        }
        else if (post.IsPublished)
        {
            ShowPostStateSuccess(message);
        }
        else
        {
            ShowPostStateInformation(message, MessageTypeEnum.Information);
        }
    }
示例#14
0
    /// <summary>
    /// Shows given Facebook post's publish state.
    /// </summary>
    /// <param name="post">Facebook post.</param>
    private void ShowPostPublishState(FacebookPostInfo post)
    {
        string message = FacebookPostInfoProvider.GetPostPublishStateMessage(post, MembershipContext.AuthenticatedUser, CurrentSite);

        if (String.IsNullOrEmpty(message))
        {
            return;
        }

        if (post.IsFaulty)
        {
            var errorMessage = FormatErrorMessage(message);
            ShowError(errorMessage);
        }
        else if (post.IsPublished)
        {
            ShowConfirmation(message, true);
        }
        else
        {
            ShowInformation(message);
        }
    }
示例#15
0
    /// <summary>
    /// Publishes a facebook post.
    /// </summary>
    private bool PublishPostToFacebook()
    {
        // Get an page to which the post is tied
        FacebookAccountInfo page = FacebookAccountInfoProvider.GetFacebookAccountInfo("MyNewPage", SiteContext.CurrentSiteID);

        if (page == null)
        {
            throw new Exception("[FacebookApiExamples.PublishPostToFacebook]: Page 'My new page' wasn't found.");
        }

        // Get the Facebook post from DB
        FacebookPostInfo post = FacebookPostInfoProvider.GetFacebookPostInfosByAccountId(page.FacebookAccountID).FirstOrDefault();

        if (post == null)
        {
            throw new Exception("[FacebookApiExamples.PublishPostToFacebook]: No post has been created via these api Examples, or they have been deleted.");
        }

        // Publish the post. The post is scheduled to be published if its FacebookPostScheduledPublishDateTime is set in the future.
        FacebookPostInfoProvider.PublishFacebookPost(post.FacebookPostID);

        return(true);
    }
示例#16
0
    /// <summary>
    /// Loads data from post info object into the dialog.
    /// </summary>
    /// <param name="post">Facebook post info object.</param>
    private void LoadPostIntoDialog(FacebookPostInfo post)
    {
        if ((post == null) || (post.FacebookPostSiteID != SiteContext.CurrentSiteID))
        {
            pnlPostDetail.Visible = false;
            ShowError(GetString("sm.facebook.posts.msg.postnotexist"));
            return;
        }

        lblPostStatus.Text         = FacebookPostInfoProvider.GetPostPublishStateMessage(post, MembershipContext.AuthenticatedUser, SiteContext.CurrentSite, true);
        lblPeopleReachedValue.Text = ValidationHelper.GetString(post.FacebookPostInsightPeopleReached, String.Empty);
        if (post.FacebookPostCampaignID.HasValue)
        {
            CampaignInfo campaign = CampaignInfo.Provider.Get(post.FacebookPostCampaignID.Value);
            if (campaign != null)
            {
                lblCampaign.Text = HTMLHelper.HTMLEncode(campaign.CampaignDisplayName);
            }
        }
        else
        {
            pnlCampaign.Visible = false;
        }

        lblPostText.Text          = GetPostTextHTML(post.FacebookPostText);
        lblPostLikesValue.Text    = ValidationHelper.GetString(post.FacebookPostInsightLikesFromPage, String.Empty);
        lblPostCommentsValue.Text = ValidationHelper.GetString(post.FacebookPostInsightCommentsFromPage, String.Empty);
        lblPostSharesValue.Text   = ValidationHelper.GetString(post.FacebookPostInsightSharesFromPage, String.Empty);

        lblTotalLikesValue.Text    = ValidationHelper.GetString(post.FacebookPostInsightLikesTotal, String.Empty);
        lblTotalCommentsValue.Text = ValidationHelper.GetString(post.FacebookPostInsightCommentsTotal, String.Empty);

        lblHidePostValue.Text     = ValidationHelper.GetString(post.FacebookPostInsightNegativeHidePost, String.Empty);
        lblHideAllPostsValue.Text = ValidationHelper.GetString(post.FacebookPostInsightNegativeHideAllPosts, String.Empty);
        lblReportSpamValue.Text   = ValidationHelper.GetString(post.FacebookPostInsightNegativeReportSpam, String.Empty);
        lblUnlikePageValue.Text   = ValidationHelper.GetString(post.FacebookPostInsightNegativeUnlikePage, String.Empty);
    }