/// <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);
    }
示例#2
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);
    }
示例#3
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>
    /// 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();
            }
        }
    }