Ejemplo n.º 1
0
    public static string GetTwitterFeed()
    {
        ITwitterFeed obTF  = new TwitterFeed();
        string       value = obTF.GetTwitterFeed();

        return(value);
    }
Ejemplo n.º 2
0
        /// <summary>
        /// Loads the twitter feeds.
        /// </summary>
        /// <returns>The twitter feeds.</returns>
        /// <param name="context">Context.</param>
        public static List <TwitterFeed> LoadTwitterFeeds(IfyContext context)
        {
            List <TwitterFeed> result = new List <TwitterFeed>();
            TwitterApplication app    = new TwitterApplication(context.GetConfigValue("Twitter-consumerKey"),
                                                               context.GetConfigValue("Twitter-consumerSecret"),
                                                               context.GetConfigValue("Twitter-token"),
                                                               context.GetConfigValue("Twitter-tokenSecret"));

            EntityList <TwitterNews> twitters = new EntityList <TwitterNews>(context);

            twitters.Load();

            foreach (TwitterNews news in twitters)
            {
                TwitterFeed feed = new TwitterFeed(app, context.BaseUrl);
                feed.Identifier     = news.Identifier;
                feed.Title          = news.Title;
                feed.Tags           = (news.Tags != null ? new List <string>(news.Tags.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)) : null);
                feed.Time           = news.Time;
                feed.Url            = news.Url;
                feed.Author         = news.Author;
                feed.AuthorImageUrl = news.AuthorImage;
                feed.Content        = news.Content;
                result.Add(feed);
            }
            return(result);
        }
 /// <deleteTwitterFeed>
 /// Delete Twitter Feed
 /// </summary>
 /// <param name="twtfeed">Set Values of twitter profile id and user id in a TwitterFeed Class Property and Pass the Object of TwitterFeed Class.(Domein.TwitterFeed)</param>
 /// <returns>Return 1 for success and 0 for failure.(int) </returns>
 public int deleteTwitterFeed(TwitterFeed twtfeed)
 {
     //Creates a database connection and opens up a session
     using (NHibernate.ISession session = SessionFactory.GetNewSession())
     {
         //After Session creation, start Transaction.
         using (NHibernate.ITransaction transaction = session.BeginTransaction())
         {
             try
             {
                 //Proceed action, to delete feeds by profile id and user id.
                 NHibernate.IQuery query = session.CreateQuery("delete from TwitterFeed where ProfileId = :twtuserid and UserId = :userid")
                                           .SetParameter("twtuserid", twtfeed.ProfileId)
                                           .SetParameter("userid", twtfeed.UserId);
                 int isUpdated = query.ExecuteUpdate();
                 transaction.Commit();
                 return(isUpdated);
             }
             catch (Exception ex)
             {
                 Console.WriteLine(ex.StackTrace);
                 return(0);
             }
         } //End Transaction
     }     //End Session
 }
        public void Execute(SCPTuple tuple)
        {
            try
            {
                // TwitterFeed tweet = tuple.GetValue(0) as TwitterFeed;
                TwitterFeed tweet = tuple.GetValue(0) as TwitterFeed;
                if (tweet != null)
                {
                    Context.Logger.Info("SQL AZURE: Id:" + tweet.Id.ToString());
                    Context.Logger.Info("SQL AZURE: Text:" + tweet.Text.ToString());
                    Context.Logger.Info("SQL AZURE: RetweetCount:" + tweet.RetweetCount.ToString());
                    Context.Logger.Info("SQL AZURE: FavoriteCount:" + tweet.FavoriteCount.ToString());
                    Context.Logger.Info("SQL AZURE: Score:" + tweet.Score.ToString());
                    Context.Logger.Info("SQL AZURE: Created Date:" + tweet.Createddate.ToString());
                    Context.Logger.Info("SQL AZURE: DateTime.UtcNow:" + DateTime.UtcNow.ToString());
                }

                List <object> rowValue = new List <object>();
                rowValue.Add(tweet.Id);
                rowValue.Add(tweet.Text);
                rowValue.Add(tweet.RetweetCount);
                rowValue.Add(tweet.FavoriteCount);
                rowValue.Add(tweet.Score);
                rowValue.Add(GetSentimentType(tweet.Text));
                rowValue.Add(tweet.Createddate);
                rowValue.Add(DateTime.UtcNow);
                //Upsert(new List<int> { 1 }, rowValue);
                Insert(rowValue);
            }
            catch (Exception ex)
            {
                Context.Logger.Error("An error occured while executing Tuple Id: {0}. Exception Details:\r\n{1}",
                                     tuple.GetTupleId(), ex.ToString());
            }
        }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            var feed = new TwitterFeed();

            Console.WriteLine("----Twitter feed Simulator-----");
            Console.WriteLine(feed.SimulateFeed());
            Console.WriteLine("----Twitter feed Simulator End-----");
            Console.ReadKey();
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Terradue.OpenSearch.Twitter.TwitterNews"/> class.
 /// </summary>
 /// <param name="context">Context.</param>
 /// <param name="feed">Feed.</param>
 public TwitterNews(IfyContext context, TwitterFeed feed) : base(context)
 {
     this.Identifier  = feed.Identifier;
     this.Title       = feed.Title;
     this.Tags        = (feed.Tags != null ? string.Join(",", feed.Tags) : null);
     this.Time        = feed.Time;
     this.Url         = feed.Url;
     this.Author      = feed.Author;
     this.AuthorImage = feed.AuthorImageUrl;
     this.Content     = feed.Content;
 }
        Tweets getTweets(string name)
        {
            DataCache cache   = new DataCache();
            Tweets    entries = cache.Get(name) as Tweets;

            if (entries == null)
            {
                entries = TwitterFeed.GetTweets(name);
                cache.Add(name, entries);
            }
            return(entries);
        }
        Tweets getTweets(string name)
        {
            DataCache cache = new DataCache();

            Tweets entries = Tweets.FromObject(cache.Get(name));

            if (entries == null)
            {
                entries = TwitterFeed.GetTweets(name);
                cache.Add(name, entries.GetBytes());
            }

            return(entries);
        }
 /// <addTwitterFeed>
 /// Add Twitter Feed
 /// </summary>
 /// <param name="twtfeed">Set Values in a TwitterFeed Class Property and Pass the Object of TwitterFeed Class.(Domein.TwitterFeed)</param>
 public void addTwitterFeed(TwitterFeed twtfeed)
 {
     //Creates a database connection and opens up a session
     using (NHibernate.ISession session = SessionFactory.GetNewSession())
     {
         //After Session creation, start Transaction.
         using (NHibernate.ITransaction transaction = session.BeginTransaction())
         {
             //Proceed action, to save data.
             session.Save(twtfeed);
             transaction.Commit();
         } //End Transaction
     }     //End Session
 }
        public void AuthenticateConsumerWithValidParameter()
        {
            //Arrange
            string apiUrl      = "https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=salesforce;include_rts=1;exclude_replies=0;count=10";
            string tokenType   = "bearer";
            string accessToken = "AAAAAAAAAAAAAAAAAAAAAKfL0gAAAAAA8elyR17B3kTQSeS4yAJK%2FhmA248%3DPXw0uFjXC0DtGTZnFha4aOPTs53PlcrOvgeZ88TTzWca8e44kr";

            //Act
            ITwitterFeed obTwitterFeed   = new TwitterFeed();
            string       twitterFeedjson = obTwitterFeed.GetTwitterFeedJson(apiUrl, tokenType, accessToken);

            //Assert
            // When tokenType is null, the expected output is empty string.
            Assert.IsTrue(twitterFeedjson != string.Empty);
        }
        public void AuthenticateConsumerWithInValidTimelineURL()
        {
            //Arrange
            string apiUrl      = "https://api.twitter.com/1.1/statuses/SomeAPI.json?";
            string tokenType   = "bearer";
            string accessToken = "Some Token";

            //Act
            ITwitterFeed obTwitterFeed   = new TwitterFeed();
            string       twitterFeedjson = obTwitterFeed.GetTwitterFeedJson(apiUrl, tokenType, accessToken);

            //Assert
            // When tokenType is null, the expected output is empty string.
            //Exception is ecxpected
        }
        public void AuthenticateConsumerWithInValidAccessToken()
        {
            //Arrange
            string apiUrl      = "https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=salesforce;include_rts=1;exclude_replies=0;count=10";
            string tokenType   = "bearer";
            string accessToken = "Some Token";

            //Act
            ITwitterFeed obTwitterFeed   = new TwitterFeed();
            string       twitterFeedjson = obTwitterFeed.GetTwitterFeedJson(apiUrl, tokenType, accessToken);

            //Assert
            // When tokenType is null, the expected output is empty string.
            //Exception is ecxpected
        }
        public void GetTwitterFeedJsonNullapiUrl()
        {
            //Arrange
            string apiUrl      = null;
            string tokenType   = "Bearer";
            string accessToken = "Some Token";

            //Act
            ITwitterFeed obTwitterFeed   = new TwitterFeed();
            string       twitterFeedjson = obTwitterFeed.GetTwitterFeedJson(apiUrl, tokenType, accessToken);

            //Assert
            // When Consumer key is null, the expected output is empty string.
            Assert.AreEqual(twitterFeedjson, string.Empty);
        }
        public void GetTwitterFeedJsonNulltokenType()
        {
            //Arrange
            string apiUrl      = "https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=salesforce;include_rts=1;exclude_replies=0;count=10";
            string tokenType   = null;
            string accessToken = "Some Token";

            //Act
            ITwitterFeed obTwitterFeed   = new TwitterFeed();
            string       twitterFeedjson = obTwitterFeed.GetTwitterFeedJson(apiUrl, tokenType, accessToken);

            //Assert
            // When tokenType is null, the expected output is empty string.
            Assert.AreEqual(twitterFeedjson, string.Empty);
        }
        public void Execute(SCPTuple tuple)
        {
            var isTickTuple = tuple.GetSourceStreamId().Equals(Constants.SYSTEM_TICK_STREAM_ID);

            if (isTickTuple)
            {
                // Get top 10 higest forwards + retweets count from last time window of 5 seconds
                Context.Logger.Debug($"Total tweets in window: {tweetCache.Count}");
                var topNTweets = tweetCache.OrderByDescending(o => o.Score).Take(Math.Min(10, tweetCache.Count)).ToList();

                foreach (var tweet in topNTweets)
                {
                    this.context.Emit("TWEETRANK_STREAM", new Values(tweet));
                }


                tweetCache.Clear();
            }
            else
            {
                try
                {
                    TwitterFeed tweet = tuple.GetValue(0) as TwitterFeed;
                    if (!tweetCache.Any(o => o.Id.Equals(tweet.Id)))
                    {
                        tweetCache.Add(tweet);
                    }
                    Context.Logger.Info(tweet.ToString());
                    if (enableAck)
                    {
                        this.context.Ack(tuple);
                        Context.Logger.Info("Total Ack: " + ++totalAck);
                    }
                }
                catch (Exception ex)
                {
                    Context.Logger.Error("An error occured while executing Tuple Id: {0}. Exception Details:\r\n{1}",
                                         tuple.GetTupleId(), ex.ToString());
                    if (enableAck)
                    {
                        this.context.Fail(tuple);
                    }
                }
            }
        }
Ejemplo n.º 16
0
        public static void SendTwitterRSSFeeds(string[] symbols, List <string> positions, Delivery delivery, List <string> beeters)
        {
            TwitterFeed.Init(AccessToken, UserAccessSecret, ConsumerKey, ConsumerSecret);
            StringBuilder sb   = new StringBuilder();
            string        html = GetResourceFromPath(TwitterRSSHtmlPath);
            var           twitterRSSReportData = TwitterFeed.GetTweets(symbols, positions, beeters);
            string        tableFormat          = @"<tr><td>{0}</td><td>{1}</td><td>{2}</td></tr>";

            foreach (var t in twitterRSSReportData.Where(t => t.Tweet != null))
            {
                sb.Append(string.Format(tableFormat, t.HasPosition, t.Symbol, t.Tweet));
            }
            html = html.Replace("<!--data-->", sb.ToString());
            html = html.Replace("<!--css-->", GetResourceFromPath(CSSStylePath).Replace("text-align:center;", "text-align:left;"));
            html = html.Replace("<!--js-->", GetResourceFromPath(TableSortJS));
            html = html.Replace("<!--rundate-->", DateTime.Now.ToString());

            Send(html, delivery, @"C:\temp\twitterss.html", "FIRPy 2.0 Twitter RSS");
        }
        public ActionResult Index(string name)
        {
            Stopwatch timer = new Stopwatch();

            timer.Start();

            DataCache cache   = new DataCache();
            Tweets    entries = cache.Get(name) as Tweets;

            if (entries == null)
            {
                entries = TwitterFeed.GetTweets(name);
                cache.Add(name, entries);
                mClient.Send(new BrokeredMessage(name));
            }

            timer.Stop();
            ViewBag.LoadTime = timer.Elapsed.TotalMilliseconds;

            return(View(entries));
        }
Ejemplo n.º 18
0
        protected void btnGetTwitterFeed_OnClick(object sender, EventArgs e)
        {
            try
            {
                lTwitterFeeds = new List <TwitterFeed>();
                using (MyRestService service = new MyRestService())
                {
                    string json = service.GetNews24Feed();
                    JavaScriptSerializer serializer = new JavaScriptSerializer();
                    dynamic items = serializer.Deserialize <object>(json);

                    foreach (var item in items)
                    {
                        TwitterFeed tw = new TwitterFeed();
                        foreach (KeyValuePair <string, object> kvp in item)
                        {
                            switch (kvp.Key)
                            {
                            case "text":
                                tw.Text = Linkify(kvp.Value.ToString());
                                break;

                            case "retweet_count":
                                tw.RetweetCount = Convert.ToInt32(kvp.Value.ToString());
                                break;

                            case "favorite_count":
                                tw.FavouriteCount = Convert.ToInt32(kvp.Value.ToString());
                                break;
                            }
                        }
                        lTwitterFeeds.Add(tw);
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Ejemplo n.º 19
0
 public int updateTwitterFeed(TwitterFeed twtfeed)
 {
     throw new NotImplementedException();
 }
 Tweets getTweets(string name)
 {
     return(TwitterFeed.GetTweets(name));
 }
Ejemplo n.º 21
0
        public void CanSimulateFeed()
        {
            var feed = new TwitterFeed();

            Assert.AreNotEqual(feed.SimulateFeed(), string.Empty);
        }
Ejemplo n.º 22
0
        public void Initialize(Rendering rendering)
        {
            //Get current item
            var dataSource = rendering.DataSource;

            if (dataSource.IsNullOrEmpty())
            {
                dataSource = Sitecore.Configuration.Settings.GetSetting("FeedsDataSource", "{AF7BCA0A-4C7F-4ACA-9956-E4801143775A}");
            }

            CurrentItem = Sitecore.Context.Database.GetItem(dataSource);

            if (CurrentItem != null)
            {
                // Get all social feeds items
                var socialFeeds = CurrentItem.InnerItem.GetChildren().ToList();
                FacebookApi  = new FacebookApi();
                TwitterApi   = new TwitterApi();
                InstagramApi = new InstagramApi();
                YouTubeApi   = new YouTubeApi();
                PinterestApi = new PinterestApi();
                FlickrApi    = new FlickrApi();

                if (socialFeeds.Any())
                {
                    // Get facebook feed item and bind facebook api class properties
                    var facebookFeedItem = socialFeeds.FirstOrDefault(i => i.IsOfType(FacebookFeed.TemplateId));
                    if (facebookFeedItem != null)
                    {
                        var facebookFeed = new FacebookFeed(facebookFeedItem);
                        if (facebookFeed != null)
                        {
                            if (facebookFeed.FacebookAccount.TargetItem != null)
                            {
                                var facebookAccount = new FacebookAccount(facebookFeed.FacebookAccount.TargetItem);

                                if (facebookAccount.SocialLink != null)
                                {
                                    if (!ShowSocialFeed)
                                    {
                                        ShowSocialFeed = true;
                                    }
                                    FacebookApi.ApiId = string.Join("|",
                                                                    new string[]
                                    {
                                        facebookAccount.ApiId.Value, facebookAccount.ApiKey.Value
                                    });
                                    FacebookApi.Icon = facebookAccount.SocialLink != null
                                        ? MediaManager.GetMediaUrl(
                                        new SocialMedia(facebookAccount.SocialLink.TargetItem).SocialIcon.MediaItem)
                                        : "";

                                    // new BaseFeed()

                                    FacebookApi.Priority = GetPriority(facebookFeed.BaseFeed);
                                }
                            }
                        }
                    }

                    // Get twitter feed item and bind twitter api class properties
                    var twitterFeedItem = socialFeeds.FirstOrDefault(i => i.IsOfType(TwitterFeed.TemplateId));
                    if (twitterFeedItem != null)
                    {
                        var twitterFeed = new TwitterFeed(twitterFeedItem);
                        if (twitterFeed != null)
                        {
                            if (twitterFeed.TwitterAccount.TargetItem != null)
                            {
                                var twitterAccount = new TwitterAccount(twitterFeed.TwitterAccount.TargetItem);

                                if (!ShowSocialFeed)
                                {
                                    ShowSocialFeed = true;
                                }
                                TwitterApi.HashTagsWithTokens = string.Join("|", new string[]
                                {
                                    string.Join(",",
                                                twitterFeed.Hashtags.GetItems().Select(i => new Hashtag(i).Value.Value)),
                                    twitterAccount.TwitterToken.Value,
                                    twitterAccount.TwitterTokenSecret.Value,
                                    twitterAccount.TwitterConsumerKey.Value,
                                    twitterAccount.TwitterConsumerSecret.Value
                                });

                                TwitterApi.Icon = twitterAccount.SocialLink != null
                                    ? MediaManager.GetMediaUrl(
                                    new SocialMedia(twitterAccount.SocialLink.TargetItem).SocialIcon.MediaItem)
                                    : "";

                                TwitterApi.Priority = GetPriority(twitterFeed.BaseFeed);
                            }
                        }
                    }

                    // Get instagram feed item and bind instagram api class properties
                    var instagramFeedItem = socialFeeds.FirstOrDefault(i => i.IsOfType(InstagramFeed.TemplateId));

                    if (instagramFeedItem != null)
                    {
                        var instagramFeed = new InstagramFeed(instagramFeedItem);
                        if (instagramFeed != null)
                        {
                            if (instagramFeed.InstagramAccount.TargetItem != null)
                            {
                                var instagramAccount = new InstagramAccount(instagramFeed.InstagramAccount.TargetItem);

                                if (!ShowSocialFeed)
                                {
                                    ShowSocialFeed = true;
                                }
                                InstagramApi.HashTags = string.Join(",",
                                                                    instagramFeed.Hashtags.GetItems().Select(i => new Hashtag(i).Value.Value));
                                InstagramApi.AccessToken = instagramAccount.AccessToken.Value;
                                InstagramApi.ClientId    = instagramAccount.InstagramClientId.Value;
                                InstagramApi.Icon        = instagramAccount.SocialLink != null
                                    ? MediaManager.GetMediaUrl(
                                    new SocialMedia(instagramAccount.SocialLink.TargetItem).SocialIcon.MediaItem)
                                    : "";


                                InstagramApi.Priority = GetPriority(instagramFeed.BaseFeed);
                            }
                        }
                    }


                    // Get youtube feed item and bind youtube api class properties
                    var youTubeFeedItem = socialFeeds.FirstOrDefault(i => i.IsOfType(YoutubeFeed.TemplateId));
                    if (youTubeFeedItem != null)
                    {
                        var youTubeFeed = new YoutubeFeed(youTubeFeedItem);
                        if (youTubeFeed.YouTubeAccount.TargetItem != null)
                        {
                            var youtubeAccount = new YoutubeAccount(youTubeFeed.YouTubeAccount.TargetItem);

                            if (!ShowSocialFeed)
                            {
                                ShowSocialFeed = true;
                            }
                            YouTubeApi.AccountId     = youtubeAccount.AccountId.Value;
                            YouTubeApi.AccountApiKey = youtubeAccount.AccountApiKey.Value;

                            YouTubeApi.Icon = youtubeAccount.SocialLink != null
                                ? MediaManager.GetMediaUrl(
                                new SocialMedia(youtubeAccount.SocialLink.TargetItem).SocialIcon.MediaItem)
                                : "";

                            YouTubeApi.Priority = GetPriority(youTubeFeed.BaseFeed);
                        }
                    }

                    // Get pinterest feed item and bind pinterest api class properties
                    var pinterestFeedItem = socialFeeds.FirstOrDefault(i => i.IsOfType(PinterestFeed.TemplateId));
                    if (pinterestFeedItem != null)
                    {
                        var pinterestFeed = new PinterestFeed(pinterestFeedItem);
                        if (pinterestFeed != null && pinterestFeed.PinterestAccount.TargetItem != null)
                        {
                            var pinterestAccount = new PinterestAccount(pinterestFeed.PinterestAccount.TargetItem);


                            if (!ShowSocialFeed)
                            {
                                ShowSocialFeed = true;
                            }
                            PinterestApi.AccountId = pinterestAccount.AccountId.Value;

                            PinterestApi.Icon = pinterestAccount.SocialLink != null
                                ? MediaManager.GetMediaUrl(
                                new SocialMedia(pinterestAccount.SocialLink.TargetItem).SocialIcon.MediaItem)
                                : "";

                            PinterestApi.Priority = GetPriority(pinterestFeed.BaseFeed);
                        }
                    }

                    // Get flickr feed item and bind flickr api class properties
                    var flickrFeedItem = socialFeeds.FirstOrDefault(i => i.IsOfType(FlickrFeed.TemplateId));
                    if (flickrFeedItem != null)
                    {
                        var flickrFeed = new FlickrFeed(flickrFeedItem);
                        if (flickrFeed != null)
                        {
                            if (flickrFeed.FlickrAccount.TargetItem != null)
                            {
                                var flickrAccount = new FlickrAccount(flickrFeed.FlickrAccount.TargetItem);

                                if (!ShowSocialFeed)
                                {
                                    ShowSocialFeed = true;
                                }
                                FlickrApi.AccountId = flickrAccount.AccountId.Value;
                                FlickrApi.Icon      = flickrAccount.SocialLink != null
                                    ? MediaManager.GetMediaUrl(
                                    new SocialMedia(flickrAccount.SocialLink.TargetItem).SocialIcon.MediaItem)
                                    : "";

                                FlickrApi.Priority = GetPriority(flickrFeed.BaseFeed);
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 23
0
        private void btnStart_Click(object sender, EventArgs e)
        {
            try
            {
                //========================================================================
                // Let's start this puppy up. Do the wait cursor thing, let users know
                // we're doing and loading important stuff.
                //
                // Load all the emojis into an ImageList for the ListView. This takes more
                // time than I'd like so it's definitely something I'd rework if I had
                // more time to optimize things.
                //========================================================================
                if (Regex.IsMatch(txtMaxTweets.Text, @"^\d+$") == false)
                {
                    txtMaxTweets.Text = "1000";
                }

                Cursor.Current      = Cursors.WaitCursor;
                btnStart.Enabled    = false;
                lblElapsedTime.Text = "Loading Emojis...";
                Application.DoEvents();

                string emojiDir  = string.Format("{0}Resources\\emojis", Path.GetFullPath(Path.Combine(Application.StartupPath, @"..\..\")));
                var    imageList = new ImageList();

                try
                {
                    foreach (var item in Directory.GetFiles(emojiDir))
                    {
                        FileInfo fi = new FileInfo(item);
                        imageList.Images.Add(fi.Name, System.Drawing.Image.FromFile(item));
                    }
                }
                catch (Exception eImages)
                {
                    MessageBox.Show("Emoji Images Error. Exception: " + eImages.Message);
                    return;
                }

                //========================================================================
                // Let's hide the wait cursor now and start connecting as it should only
                // take a second or two.
                //========================================================================
                lvEmojis.SmallImageList = imageList;
                Cursor.Current          = Cursors.Default;
                lblElapsedTime.Text     = "Connecting...";
                Application.DoEvents();

                try
                {
                    //========================================================================
                    // Setup the stream object, events and start the start datetime clock.
                    //========================================================================
                    TwitterFeed ssc = new TwitterFeed();
                    ssc.StreamDataReceivedEvent += Ssc_StreamDataReceivedEvent;

                    dtStart = DateTime.Now;
                    ssc.StartStream(Convert.ToInt32(txtMaxTweets.Text), 1);
                }
                catch (Exception eStream)
                {
                    MessageBox.Show("Twitter Stream Connection Error. Exception: " + eStream.Message);
                }
            }
            catch (Exception eStart)
            {
                MessageBox.Show("Start Exception: " + eStart.Message);
            }
        }
Ejemplo n.º 24
0
        public void getUserFeed(oAuthTwitter OAuth, string TwitterScreenName, string TwitterUserId, Guid userId)
        {
            try
            {
                //User user = (User)Session["LoggedUser"];
                TwitterUser twtuser = new TwitterUser();
                JArray      data    = twtuser.GetStatuses_Home_Timeline(OAuth);

                TwitterFeedRepository twtmsgrepo = new TwitterFeedRepository();
                TwitterFeed           twtmsg     = new TwitterFeed();
                foreach (var item in data)
                {
                    twtmsg.UserId = userId;
                    twtmsg.Type   = "twt_feeds";
                    try
                    {
                        twtmsg.Feed = item["text"].ToString().TrimStart('"').TrimEnd('"');
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.StackTrace);
                    }
                    try
                    {
                        twtmsg.SourceUrl = item["source"].ToString().TrimStart('"').TrimEnd('"');
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.StackTrace);
                    }
                    try
                    {
                        twtmsg.ScreenName = TwitterScreenName;
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.StackTrace);
                    }
                    try
                    {
                        twtmsg.ProfileId = TwitterUserId;
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.StackTrace);
                    }
                    try
                    {
                        twtmsg.MessageId = item["id_str"].ToString().TrimStart('"').TrimEnd('"');
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.StackTrace);
                    }
                    try
                    {
                        twtmsg.FeedDate = SocioBoard.Helper.Extensions.ParseTwitterTime(item["created_at"].ToString().TrimStart('"').TrimEnd('"'));
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.StackTrace);
                    }
                    try
                    {
                        twtmsg.InReplyToStatusUserId = item["in_reply_to_status_id_str"].ToString().TrimStart('"').TrimEnd('"');
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.StackTrace);
                    }
                    try
                    {
                        twtmsg.Id = Guid.NewGuid();
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.StackTrace);
                    }
                    try
                    {
                        twtmsg.FromProfileUrl = item["user"]["profile_image_url"].ToString().TrimStart('"').TrimEnd('"');
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.StackTrace);
                    }
                    try
                    {
                        twtmsg.FromName = item["user"]["name"].ToString().TrimStart('"').TrimEnd('"');
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.StackTrace);
                    }
                    try
                    {
                        twtmsg.FromId = item["user"]["id_str"].ToString().TrimStart('"').TrimEnd('"');
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.StackTrace);
                    }
                    twtmsg.EntryDate = DateTime.Now;
                    try
                    {
                        twtmsg.FromScreenName = item["user"]["screen_name"].ToString().TrimStart('"').TrimEnd('"');
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.StackTrace);
                    }
                    if (!twtmsgrepo.checkTwitterFeedExists(twtmsg.ProfileId, twtmsg.UserId, twtmsg.MessageId))
                    {
                        twtmsgrepo.addTwitterFeed(twtmsg);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
            }
        }
Ejemplo n.º 25
0
        public string GetTeamMembeDetailsForGroupReport(string TeamId, string userid, string days)
        {
            string FacebookprofileId = string.Empty;
            string TwitterprofileId = string.Empty;
            string FacebookFanPageId = string.Empty;
            string profid = string.Empty;
            string FacebookInboxMessagecount = string.Empty;
            string TwitterInboxMessagecount = string.Empty;
            Domain.Socioboard.Domain.GroupStatDetails _GroupStatDetails = new Domain.Socioboard.Domain.GroupStatDetails();

            Guid UserId = Guid.Parse(userid);
            try
            {
                List<FacebookAccount> _facebookAccount = new List<FacebookAccount>();
                List<Domain.Socioboard.Domain.TeamMemberProfile> lstTeamMember = teammemberrepo.getAllTeamMemberProfilesOfTeam(Guid.Parse(TeamId));


                foreach (Domain.Socioboard.Domain.TeamMemberProfile TeamMemberProfile in lstTeamMember)
                {

                    #region MyRegion
                    try
                    {
                        if (TeamMemberProfile.ProfileType == "facebook" || TeamMemberProfile.ProfileType == "twitter")
                        {
                            profid += TeamMemberProfile.ProfileId + ',';
                        }

                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.StackTrace);
                    }
                    try
                    {
                        if (TeamMemberProfile.ProfileType == "facebook")
                        {
                            FacebookprofileId += TeamMemberProfile.ProfileId + ',';
                        }

                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.StackTrace);
                    }
                    try
                    {
                        if (TeamMemberProfile.ProfileType == "twitter")
                        {
                            TwitterprofileId += TeamMemberProfile.ProfileId + ',';
                        }

                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.StackTrace);
                    }
                    try
                    {
                        if (TeamMemberProfile.ProfileType == "facebook_page")
                        {
                            FacebookFanPageId += TeamMemberProfile.ProfileId + ',';
                        }

                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.StackTrace);
                    }
                    #endregion

                }

                #region MyRegion
                try
                {
                    profid = profid.Substring(0, profid.Length - 1);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.StackTrace);
                }
                try
                {
                    FacebookFanPageId = FacebookFanPageId.Substring(0, FacebookFanPageId.Length - 1);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.StackTrace);
                }
                try
                {
                    TwitterprofileId = TwitterprofileId.Substring(0, TwitterprofileId.Length - 1);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.StackTrace);
                }
                try
                {
                    FacebookprofileId = FacebookprofileId.Substring(0, FacebookprofileId.Length - 1);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.StackTrace);
                }
                #endregion

                #region Inboxmessagecount
                if (!string.IsNullOrEmpty(FacebookprofileId))
                {
                    try
                    {
                        FacebookMessage _FacebookMessage = new FacebookMessage();
                        FacebookInboxMessagecount = _FacebookMessage.GetAllInboxMessage(userid, FacebookprofileId, days);
                    }
                    catch (Exception ex)
                    {
                        FacebookInboxMessagecount = (0).ToString();
                        Console.WriteLine(ex.StackTrace);
                    }
                }
               
                if (!string.IsNullOrEmpty(TwitterprofileId))
                {
                    try
                    {
                        TwitterFeed _TwitterFeed = new TwitterFeed();
                        TwitterInboxMessagecount = _TwitterFeed.TwitterInboxMessagecount(userid, TwitterprofileId, days);
                    }
                    catch (Exception ex)
                    {
                        TwitterInboxMessagecount = (0).ToString();
                        Console.WriteLine(ex.StackTrace);
                    }
                }
               
                   
               
                _GroupStatDetails.IncommingMessage = (Convert.ToInt32(FacebookInboxMessagecount) + Convert.ToInt32(TwitterInboxMessagecount));
                #endregion

                #region sentmessage
                if (!string.IsNullOrEmpty(profid))
                {
                    try
                    {
                        ScheduledMessage _ScheduledMessage = new ScheduledMessage();
                        _GroupStatDetails.SentMessage = _ScheduledMessage.GetAllScheduledMessage(userid, profid, days);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.StackTrace);
                        _GroupStatDetails.SentMessage = 0;
                    }
                }
                #endregion

                #region twitterfolllower
                try
                {
                    TwitterAccountFollowers _TwitterAccountFollowers = new TwitterAccountFollowers();
                    _GroupStatDetails.TwitterFollower = _TwitterAccountFollowers.FollowerCount(userid, TwitterprofileId, days);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.StackTrace);
                    _GroupStatDetails.TwitterFollower = 0;
                }

                #endregion

                #region fancount
                try
                {
                    FacebookFanPage _FacebookFanPage = new FacebookFanPage();
                    _GroupStatDetails.FacebookFan = _FacebookFanPage.FacebookFans(userid, FacebookFanPageId, days);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.StackTrace);
                    _GroupStatDetails.FacebookFan = 0;
                }

                #endregion


                #region MentionRetweetDetails
                try
                {

                    TwitterMessage _TwitterMessage = new TwitterMessage();
                    _GroupStatDetails.MentionGraph = string.Empty;
                    string graphdetails = _TwitterMessage.GetAllRetweetMentionBydays(userid, TwitterprofileId, days);

                    string[] data = graphdetails.Split('@');
                    foreach (var item in data)
                    {
                        if (item.Contains("usrtwet^"))
                        {
                            _GroupStatDetails.UserTweetGraph = item.Replace("usrtwet^", "");
                        }
                        else if (item.Contains("mention^"))
                        {
                            _GroupStatDetails.MentionGraph = item.Replace("mention^", "");
                        }
                        else if (item.Contains("retwet^"))
                        {
                            _GroupStatDetails.RetweetGraph = item.Replace("retwet^", "");
                        }
                        else if (item.Contains("metion"))
                        {
                            _GroupStatDetails.Mention = Convert.ToInt32(item.Replace("metion", ""));
                        }
                        else if (item.Contains("retwet"))
                        {
                            _GroupStatDetails.Retweet = Convert.ToInt32(item.Replace("retwet", ""));
                        }


                    }


                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.StackTrace);
                } 
                #endregion

                try
                {
                    ScheduledMessage _ScheduledMessage = new ScheduledMessage();

                    string details = _ScheduledMessage.GetAllScheduleMsgDetailsForReport(userid, TwitterprofileId, days);
                    string[] data = details.Split('@');
                    foreach (var item in data)
                    {
                        if (item.Contains("plaintext_"))
                        { 
                        _GroupStatDetails.PlainText = Convert.ToInt32(item.Replace("plaintext_",""));
                        
                        }

                        else
                        {
                          _GroupStatDetails.PhotoLink = Convert.ToInt32(item);
                        }
                    }

                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.StackTrace);
                }

            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
                return "Something Went Wrong";
            }

            return new JavaScriptSerializer().Serialize(_GroupStatDetails);

           
        }