Esempio n. 1
0
    /// <summary>
    /// Load control .
    /// </summary>
    private void LoadSocialBoxes()
    {
        List <String> cta_boxes   = new List <String>();
        int           total_boxes = Convert.ToInt32(SocialBoxCount);

        if (!String.IsNullOrEmpty(CTAS))
        {
            try{
                cta_boxes = Regex.Split(CTAS, "{}").ToList();
            }
            catch (Exception ex)
            {
                EventLogProvider.LogException("SocialApp control", "LoadSocialBoxes CTA", ex);
            }
        }
        int           social_count = total_boxes - cta_boxes.Count();
        List <String> obj_list     = new List <String>();

        if (!String.IsNullOrEmpty(InstagramUserID))
        {
            try
            {
                InstagramManager imgr    = new InstagramManager(InstagramOAuthConsumerID, InstagramOAuthConsumerSecret, RedirectURL);
                List <String>    instgrm = imgr.GetRandom(Convert.ToInt32(InstagramUserID), total_boxes).ToList();
                obj_list = obj_list.Concat(instgrm).ToList();
            }
            catch (Exception ex)
            {
                EventLogProvider.LogException("SocialApp control", "LoadSocialBoxes Instagram", ex);
            }
        }
        if (!String.IsNullOrEmpty(TwitterUser))
        {
            try
            {
                TwitterManager tm = new TwitterManager(TwitterOAuthConsumerID, TwitterOAuthConsumerSecret, TwitterOAuthAccessToken, TwitterOAuthAccessSecret);

                List <String> tweet = tm.GetRandomTweet(TwitterUser, total_boxes).ToList();
                obj_list = obj_list.Concat(tweet).ToList();
            }
            catch (Exception ex)
            {
                EventLogProvider.LogException("SocialApp control", "LoadSocialBoxes Twitter", ex);
            }
        }
        if (!String.IsNullOrEmpty(FacebookUserID))
        {
            try
            {
                FacebookManager fmgr   = new FacebookManager(FacebookAuthToken, FacebookAppID, FacebookClientSecret, FacebookRedirectURI);
                List <String>   fbpost = fmgr.GetRandomPost(FacebookUserID, total_boxes).ToList();
                obj_list = obj_list.Concat(fbpost).ToList();
            }
            catch (Exception ex)
            {
                EventLogProvider.LogException("SocialApp control", "LoadSocialBoxes Facebook", ex);
            }
        }
        if (!String.IsNullOrEmpty(youtube_api_key))
        {
            try
            {
                YouTubeManager ytmgr   = new YouTubeManager(youtube_api_key);
                List <String>  ytvideo = ytmgr.GetVideosByPlaylistID(youtube_playlist_id, total_boxes).ToList();
                obj_list = obj_list.Concat(ytvideo).ToList();
            }
            catch (Exception ex)
            {
                EventLogProvider.LogException("SocialApp control", "LoadSocialBoxes Youtube", ex);
            }
        }

        //Randomize the list of social items and take the top # of social boxes
        obj_list = obj_list.OrderBy(x => Guid.NewGuid()).Take(social_count).ToList();

        //CTAs are always shown, add on to the end of the main list
        if (!String.IsNullOrEmpty(CTAS))
        {
            OtherManager  cta_build = new OtherManager();
            List <String> ctas      = cta_build.BuildCTAList(cta_boxes).ToList();
            obj_list = obj_list.Concat(ctas).ToList();
        }

        //If the number of boxes are less than the number requested, fill with backup images
        if ((obj_list.Count() < total_boxes) && !String.IsNullOrEmpty(BackupImages))
        {
            try
            {
                int           num_images = total_boxes - obj_list.Count();
                OtherManager  img_build  = new OtherManager();
                List <String> imgs       = img_build.BuildImageList(s_images_list, num_images).ToList();
                obj_list = obj_list.Concat(imgs).ToList();
            }
            catch (Exception ex)
            {
                EventLogProvider.LogException("SocialApp control", "LoadSocialBoxes BackupImages", ex);
            }
        }

        //randomize again
        obj_list = obj_list.OrderBy(x => Guid.NewGuid()).ToList();

        StringBuilder sb = new StringBuilder();

        foreach (String s in obj_list)
        {
            sb.Append(s);
        }
        community_box_list.InnerHtml = sb.ToString();
    }