/// <summary> /// OnAfterSave event. /// </summary> private void ControlOnAfterSave(object sender, EventArgs eventArgs) { TwitterPostInfo twitterPost = Control.EditedObject as TwitterPostInfo; if (twitterPost == null) { return; } if (!twitterPost.TwitterPostPostAfterDocumentPublish) { try { TwitterPostInfoProvider.PublishTwitterPost(twitterPost.TwitterPostID); } catch (Exception ex) { EventLogProvider.LogWarning("Social marketing - Twitter post", "PUBLISHPOST", ex, SiteContext.CurrentSiteID, String.Format("An error occurred while publishing the Twitter post with ID {0}.", twitterPost.TwitterPostID)); Control.ShowError(Control.GetString("sm.twitter.posts.msg.unknownerror")); } } // Invoke event to set the form's state properly ControlOnAfterDataLoad(sender, eventArgs); }
/// <summary> /// Publishes Twitter post with given identifier. /// </summary> /// <param name="postId">Twitter post identifier.</param> private void PublishPost(int postId) { try { TwitterPostInfoProvider.TryCancelScheduledPublishTwitterPost(postId); TwitterPostInfoProvider.PublishTwitterPost(postId); } catch (Exception ex) { EventLogProvider.LogWarning("Social marketing - Twitter post", "PUBLISHPOST", ex, SiteContext.CurrentSiteID, String.Format("An error occurred while publishing the Twitter post with ID {0}.", postId)); } }
/// <summary> /// Publishes a tweet. /// </summary> private bool PublishTweetToTwitter() { // Get the channel the tweet is tied to TwitterAccountInfo channel = TwitterAccountInfoProvider.GetTwitterAccountInfo("MyNewTwitterChannel", SiteContext.CurrentSiteID); if (channel == null) { throw new Exception("[ApiExamples.PublishTweetToTwitter]: 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.PublishTweetToTwitter]: No post has been created via these api-examples. (There is no post tied to 'MyNewTwitterChannel'.)"); } // Publish the post. The Tweet is scheduled for publishing if its FacebookPostScheduledPublishDateTime is set in the future. TwitterPostInfoProvider.PublishTwitterPost(tweet.TwitterPostID); return(true); }