コード例 #1
0
ファイル: TweetController.cs プロジェクト: unchase/App
 public TweetController(
     ILogger <DiagnosticsController> logger,
     TweetSettings tweetSettings,
     PushNotificationsManager pushNotificationsManager)
 {
     this.logger                   = logger;
     this.tweetSettings            = tweetSettings;
     this.pushNotificationsManager = pushNotificationsManager;
 }
コード例 #2
0
ファイル: DiagnosticsController.cs プロジェクト: DotNetRu/App
 public DiagnosticsController(
     ILogger <DiagnosticsController> logger,
     RealmSettings realmSettings,
     TweetSettings tweetSettings,
     VkontakteSettings vkontakteSettings,
     PushSettings pushSettings)
 {
     this.logger            = logger;
     this.realmSettings     = realmSettings;
     this.tweetSettings     = tweetSettings;
     this.vkontakteSettings = vkontakteSettings;
     this.pushSettings      = pushSettings;
 }
コード例 #3
0
ファイル: TweetService.cs プロジェクト: unchase/App
        /// <summary>
        /// Returns tweets by SpdDotNet/DotNetRu (if it's retweet then original tweet is returned instead of retweet)
        /// </summary>
        /// <returns>
        /// Returns a list of tweets.
        /// </returns>
        internal static async Task <List <Tweet> > GetAsync(TweetSettings tweetSettings)
        {
            try
            {
                var auth = new ApplicationOnlyAuthorizer
                {
                    CredentialStore =
                        new InMemoryCredentialStore
                    {
                        ConsumerKey =
                            tweetSettings.ConsumerKey,
                        ConsumerSecret =
                            tweetSettings.ConsumerSecret
                    },
                };
                await auth.AuthorizeAsync();

                using var twitterContext = new TwitterContext(auth);
                var spbDotNetTweets =
                    await(from tweet in twitterContext.Status
                          where tweet.Type == StatusType.User && tweet.ScreenName == "spbdotnet" &&
                          tweet.TweetMode == TweetMode.Extended
                          select tweet).ToListAsync();

                var dotnetRuTweets =
                    await(from tweet in twitterContext.Status
                          where tweet.Type == StatusType.User && tweet.ScreenName == "DotNetRu" &&
                          tweet.TweetMode == TweetMode.Extended
                          select tweet).ToListAsync();

                var unitedTweets = spbDotNetTweets.Union(dotnetRuTweets).Where(tweet => !tweet.PossiblySensitive).Select(GetTweet);

                var tweetsWithoutDuplicates = unitedTweets.GroupBy(tw => tw.StatusID).Select(g => g.First());

                var sortedTweets = tweetsWithoutDuplicates.OrderByDescending(x => x.CreatedDate).ToList();

                return(sortedTweets);
            }
            catch (Exception e)
            {
                Logger.LogError(e, "Unhandled error while getting original tweets");
            }

            return(new List <Tweet>());
        }
コード例 #4
0
        /// <summary>
        /// Returns tweets by SpdDotNet/DotNetRu (if it's retweet then original tweet is returned instead of retweet)
        /// </summary>
        /// <returns>
        /// Returns a list of tweets.
        /// </returns>
        internal static async Task <List <ISocialPost> > GetAsync(TweetSettings tweetSettings, List <string> communities)
        {
            try
            {
                var auth = new ApplicationOnlyAuthorizer
                {
                    CredentialStore =
                        new InMemoryCredentialStore
                    {
                        ConsumerKey =
                            tweetSettings.ConsumerKey,
                        ConsumerSecret =
                            tweetSettings.ConsumerSecret
                    },
                };
                await auth.AuthorizeAsync();

                using var twitterContext = new TwitterContext(auth);

                IEnumerable <Status> unitedTweets = new List <Status>();
                foreach (var communityGroup in communities)
                {
                    var communityGroupTweets =
                        await(from tweet in twitterContext.Status
                              where tweet.Type == StatusType.User && tweet.ScreenName == communityGroup &&
                              tweet.TweetMode == TweetMode.Extended
                              select tweet).ToListAsync();

                    unitedTweets = communityGroupTweets.Union(unitedTweets).Where(tweet => !tweet.PossiblySensitive);
                }

                var tweetsWithoutDuplicates = unitedTweets.Select(GetTweet).GroupBy(tw => tw.StatusId).Select(g => g.First());

                var sortedTweets = tweetsWithoutDuplicates.OrderByDescending(x => x.CreatedDate).Cast <ISocialPost>().ToList();

                return(sortedTweets);
            }
            catch (Exception e)
            {
                Logger.LogError(e, "Unhandled error while getting original tweets");
            }

            return(new List <ISocialPost>());
        }