示例#1
0
        /// <summary>
        /// Execute
        /// </summary>
        public override void Execute()
        {
            using (new PerformanceMonitor())
            {
                var profiles = userCore.PublicProfilesFull(Application.Default);
                foreach (var profile in profiles)
                {
                    var social = new CodeStormSocial()
                    {
                        AbcHandle     = profile.Handle,
                        TwitterHandle = profile.TwitterHandle,
                        GitHubHandle  = profile.GitHubHandle,
                    };

                    try
                    {
                        if (!string.IsNullOrWhiteSpace(social.TwitterHandle))
                        {
                            var tweets   = twitter.ByUser(social.TwitterHandle, 5);
                            var links    = new List <string>();
                            var mentions = new List <string>();
                            foreach (var tweet in tweets)
                            {
                                links.AddRange(tweet.ParseLinks());
                                mentions.AddRange(tweet.ParseMentions().Distinct());
                            }

                            var twitterMentions = new List <Mention>();
                            foreach (var mention in mentions.Distinct())
                            {
                                var userMention = new Mention()
                                {
                                    TwitterHandle = mention,
                                };

                                userMention.AbcHandle = (from data in profiles
                                                         where data.TwitterHandle == mention
                                                         select data.Handle).FirstOrDefault();

                                twitterMentions.Add(userMention);
                            }

                            social.TwitterLinks = links;

                            social.TwitterMentions = twitterMentions;
                        }
                        else
                        {
                            log.Log("Twitter Handle is empty.");
                        }
                    }
                    catch (Exception ex)
                    {
                        base.log.Log(ex, EventTypes.Error, (int)ServiceFault.Unknown);
                    }

                    container.Save(social.AbcHandle, social);
                }
            }
        }