Example #1
0
    /// <summary>
    /// Creates a Twitter App based on the credentials provided in text boxes.
    /// </summary>
    private bool CreateTwitterApp()
    {
        // Verify that app's credentials have been set
        if (string.IsNullOrEmpty(txtConsumerKey.Text) || string.IsNullOrEmpty(txtConsumerSecret.Text))
        {
            throw new Exception("[ApiExamples.CreateTwitterApp]: Empty values for 'Twitter consumer key' and 'Twitter consumer secret' are not allowed. Please provide your app's credentials.");
        }

        // Create new Twitter app object
        TwitterApplicationInfo app = new TwitterApplicationInfo();

        // Set the roperties
        app.TwitterApplicationDisplayName = "My new Twitter app";
        app.TwitterApplicationName        = "MyNewTwitterApp";

        app.TwitterApplicationConsumerKey    = txtConsumerKey.Text;
        app.TwitterApplicationConsumerSecret = txtConsumerSecret.Text;

        app.TwitterApplicationSiteID = SiteContext.CurrentSiteID;

        // Save the Twitter app into DB
        TwitterApplicationInfoProvider.SetTwitterApplicationInfo(app);

        return(true);
    }
Example #2
0
    /// <summary>
    /// Gets a Twitter app from the database and modifies it.
    /// </summary>
    private bool GetAndUpdateTwitterApp()
    {
        // Get the app from DB
        TwitterApplicationInfo app = TwitterApplicationInfoProvider.GetTwitterApplicationInfo("MyNewTwitterApp", SiteContext.CurrentSiteName);

        if (app != null)
        {
            // Update the app
            app.TwitterApplicationDisplayName = app.TwitterApplicationDisplayName.ToLowerCSafe();

            //Save the changes into DB
            TwitterApplicationInfoProvider.SetTwitterApplicationInfo(app);

            return(true);
        }

        return(false);
    }
Example #3
0
    /// <summary>
    /// Attempts to upgrade settings from the old way to he new-one.
    /// </summary>
    /// <param name="site">site we are importing for</param>
    /// <returns>true on success, false on failure</returns>
    private static void ImportTwitterSettings(SiteInfo site)
    {
        TwitterApplicationInfo twittAppInfo = new TwitterApplicationInfo()
        {
            TwitterApplicationDisplayName    = site.DisplayName + "Twitter App",
            TwitterApplicationName           = site.SiteName + "TwitterApp",
            TwitterApplicationConsumerKey    = SettingsKeyInfoProvider.GetStringValue(site.SiteName + ".CMSTwitterConsumerKey"),
            TwitterApplicationConsumerSecret = SettingsKeyInfoProvider.GetStringValue(site.SiteName + ".CMSTwitterConsumerSecret"),
            TwitterApplicationSiteID         = site.SiteID
        };

        if (String.IsNullOrWhiteSpace(twittAppInfo.TwitterApplicationConsumerKey) || String.IsNullOrWhiteSpace(twittAppInfo.TwitterApplicationConsumerSecret))
        {
            return;
        }

        try
        {
            TwitterApplicationInfoProvider.SetTwitterApplicationInfo(twittAppInfo);
            twittAppInfo = TwitterApplicationInfoProvider.GetTwitterApplicationInfo(site.SiteName + "TwitterApp", site.SiteName);
        }
        catch (Exception ex)
        {
            EventLogProvider.LogException("Upgrade to 8.0", "Upgrade of SocialMarketing", ex, additionalMessage: "Error during Twitter application storage to DB for site " + site.SiteName, siteId: site.SiteID);

            return;
        }

        TwitterAccountInfo twittAccountInfo = new TwitterAccountInfo()
        {
            TwitterAccountName                 = site.SiteName + "TwitterChannel",
            TwitterAccountDisplayName          = site.DisplayName + " Twitter Channel",
            TwitterAccountTwitterApplicationID = twittAppInfo.TwitterApplicationID,
            TwitterAccountSiteID               = site.SiteID,
            TwitterAccountAccessToken          = SettingsKeyInfoProvider.GetStringValue(site.SiteName + ".CMSTwitterAccessToken"),
            TwitterAccountAccessTokenSecret    = SettingsKeyInfoProvider.GetStringValue(site.SiteName + ".CMSTwitterAccessTokenSecret"),
            TwitterAccountIsDefault            = true,
        };

        twittAccountInfo.TwitterAccountUserID = GetTwitterUserId(twittAppInfo, twittAccountInfo);

        if (String.IsNullOrWhiteSpace(twittAccountInfo.TwitterAccountAccessToken) || String.IsNullOrWhiteSpace(twittAccountInfo.TwitterAccountAccessTokenSecret))
        {
            return;
        }

        try
        {
            TwitterAccountInfoProvider.SetTwitterAccountInfo(twittAccountInfo);
        }
        catch (Exception ex)
        {
            EventLogProvider.LogException("Upgrade to 8.0", "Upgrade of SocialMarketing", ex, additionalMessage: "Error during Twitter channel storage to DB for site " + site.SiteName, siteId: site.SiteID);

            return;
        }

        // URL shortener
        if (!SettingsKeyInfoProvider.IsValueInherited(site.SiteName + ".CMSTwitterURLShortenerType"))
        {
            string shortener = SettingsKeyInfoProvider.GetStringValue(site.SiteName + ".CMSTwitterURLShortenerType");
            SettingsKeyInfoProvider.SetValue(site.SiteName + ".CMSSocialMarketingURLShorteningTwitter", shortener);
        }

        return;
    }