/// <summary> /// Form OnAfterSave event. /// </summary> private void Form_OnAfterSave(object sender, EventArgs e) { if (TweetInfo == null || !HasUserModifyPermission) { return; } if (Document != null) { if (!TweetInfo.TwitterPostDocumentGUID.HasValue) { TweetInfo.TwitterPostDocumentGUID = Document.DocumentGUID; } if (TweetInfo.TwitterPostPostAfterDocumentPublish && !IsUnderWorkflow && !TweetInfo.IsPublished) { // Tweet will be scheduled on time when document gets published TweetInfo.TwitterPostScheduledPublishDateTime = Document.DocumentPublishFrom; } if (TweetInfo.HasChanged) { TwitterPostInfoProvider.SetTwitterPostInfo(TweetInfo); } } // Check whether the tweet should be published or scheduled now (tweet WON'T be published/scheduled if it should be published with the document which is under workflow) if (!TweetInfo.IsPublished && !(TweetInfo.TwitterPostPostAfterDocumentPublish && IsUnderWorkflow)) { PublishPost(TweetInfo.TwitterPostID); } LoadPostDataIntoControl(TweetInfo); }
/// <summary> /// Gets and updates a tweet /// </summary> private bool GetAndUpdateTwitterPost() { // Get the channel the tweet is tied to TwitterAccountInfo channel = TwitterAccountInfoProvider.GetTwitterAccountInfo("MyNewTwitterChannel", SiteContext.CurrentSiteID); if (channel == null) { throw new Exception("[ApiExamples.GetAndUpdateTwitterPost]: Account 'MyNewTwitterChannel' has not been found."); } // Get a post tied to the channel TwitterPostInfo tweet = TwitterPostInfoProvider.GetTwitterPostInfoByAccountId(channel.TwitterAccountID).FirstOrDefault(); if (tweet == null) { throw new Exception("[ApiExamples.GetAndUpdateTwitterPost]: No post has been created via these api-examples. (There is no post tied to 'MyNewTwitterChannel'.)"); } // Update the properties tweet.TwitterPostText = tweet.TwitterPostText + " Edited."; // Save the changes into DB TwitterPostInfoProvider.SetTwitterPostInfo(tweet); return(true); }
/// <summary> /// Creates a new tweet. Requires Create Twitter app and Create Twitter channel to be run first. /// </summary> private bool CreateTwitterPost() { // Get the channel the tweet is tied to TwitterAccountInfo channel = TwitterAccountInfoProvider.GetTwitterAccountInfo("MyNewTwitterChannel", SiteContext.CurrentSiteID); if (channel == null) { throw new Exception("[ApiExamples.CreateTwitterPost]: Account 'MyNewTwitterChannel' has not been found."); } // Create new post object TwitterPostInfo tweet = new TwitterPostInfo(); // Set the roperties tweet.TwitterPostTwitterAccountID = channel.TwitterAccountID; tweet.TwitterPostSiteID = SiteContext.CurrentSiteID; tweet.TwitterPostText = "Sample tweet text."; // Should the tweet be scheduled instead of directly posted? tweet.TwitterPostScheduledPublishDateTime = DateTime.Now + TimeSpan.FromMinutes(5); // Save the tweet into DB TwitterPostInfoProvider.SetTwitterPostInfo(tweet); return(true); }
/// <summary> /// Form OnBeforeDataRetrieval. /// </summary> private void Form_OnBeforeDataRetrieval(object sender, EventArgs eventArgs) { if (!HasUserModifyPermission) { return; } if (chkPostToTwitter.Checked) { if ((TweetInfo == null) || TweetInfo.IsEditable) { // Post does not exist or can be modified TweetInfo = SetControlDataIntoPost(TweetInfo); TwitterPostInfoProvider.SetTwitterPostInfo(TweetInfo); } else if (!FormDataEqualsPostInfo(TweetInfo)) { mPublishedWhileEditing = true; } } else { // Checkbox post to Twitter is not checked if (TweetInfo != null) { if (TweetInfo.IsEditable) { // Existing post has to be deleted TwitterPostInfoProvider.DeleteTwitterPostInfo(TweetInfo); TweetInfo = null; InitializeControls(); } else { mPublishedWhileEditing = true; } } else if (mBackCompatibilityValue.HasValue) { // Form has to be cleaned up from old value mBackCompatibilityValue = null; InitializeControls(); } } }