public SizableImages(List<int> counts)
 {
     for (int i = 0; i < counts.Count(); i++)
     {
         tweetsTotalCount = counts.Sum();
         SizableImage simage = new SizableImage();
         simage.id = i;
         simage.size = 1 + (int)(MAX_SIZE * (double)counts[i] / tweetsTotalCount);
         simage.positionX = 0;
         simage.positionY = 0;
         images.Add(simage);
     }
     images.Sort((x, y) => (-x.size).CompareTo(-y.size));
 }
 public void ResetLastAccessed(List<Objects.Option> options, int defaultPollingInterval)
 {
     if (options.Count(x => x.Active) > 0)
     {
         DateTime currentDate = DateTime.Now.ToUniversalTime();
         DateTime defaultLastCheckedDate = currentDate.AddMilliseconds(-defaultPollingInterval);
         foreach (Objects.Option option in options.Where(x => x.Active))
         {
             switch ((TwitterOptionId)option.OptionId)
             {
                 case TwitterOptionId.TweetCount:
                     option.LastAccessed = currentDate.AddMinutes(-option.Numerics[0]);
                     break;
                 default:
                     option.LastAccessed = defaultLastCheckedDate;
                     break;
             }
         }
     }
 }
        public List<Objects.Notification> TestForNotifications(List<Objects.Option> options)
        {
            var notifications = new List<Objects.Notification>(options.Count);
            //return notifications;
            if (options.Count(x => x.Active) > 0)
            {
                using (var ctx = new LinqToTwitter.TwitterContext(auth))
                {

                    try
                    {
                        //Account account = accounts.SingleOrDefault();
                        Account account = ctx.Account.Single(acct => acct.Type == AccountType.VerifyCredentials && acct.SkipStatus == true);
                        //var account = twitterCtx.Account
                        //    .Where(t => t.Type == AccountType.VerifyCredentials)
                        //    .FirstOrDefault(t => t.SkipStatus == true);
                        User user = account.User;
                        Status tweet = user.Status ?? new Status();
                        Console.WriteLine("User (#" + user.Identifier.ID
                                            + "): " + user.Identifier.ScreenName
                                            + "\nTweet: " + tweet.Text
                                            + "\nTweet ID: " + tweet.StatusID + "\n");

                        Console.WriteLine("Account credentials are verified.");
                    }
                    catch (System.Net.WebException wex)
                    {
                        Console.WriteLine("Twitter did not recognize the credentials. Response from Twitter: " + wex.Message);
                    }

                    //var testMessageNotification = new FritzNotifier.Objects.Notification(this.NotificationApplication, this.WebsiteOrProgramAddress, 0, "Test sender" + " sent message " + "message 1", "New message from " + "Test sender", DateTime.Now);
                    //var testSimpleMessage = new FritzNotifier.Objects.Notification(this.NotificationApplication, this.WebsiteOrProgramAddress, 0, "simple notification", null, DateTime.Now);

                    //notifications.Add(testMessageNotification);
                    //notifications.Add(testSimpleMessage);
                    //return notifications;

                    try
                    {
                        DateTime currentDateLocal = DateTime.Now;
                        DateTime currentDate = currentDateLocal.ToUniversalTime();
                        foreach (Objects.Option option in options.Where(x => x.Active))
                        {
                            switch ((TwitterOptionId)option.OptionId)
                            {
                                case TwitterOptionId.TweetCount:
                                    // if enough time has passed since we last accessed this
                                    if ((currentDate - option.LastAccessed).TotalMinutes > option.Numerics[0])
                                    {
                                        int tweetCount =
                                            (from tweet in ctx.Status
                                             where tweet.Type == StatusType.Home &&
                                             tweet.CreatedAt > option.LastAccessed
                                             select tweet).Count();

                                        if (tweetCount > 0)
                                        {
                                            var newTweetCountNotification = new FritzNotifier.Objects.Notification(this.NotificationApplication, this.WebsiteOrProgramAddress, 0, tweetCount.ToString() + " new tweets.", tweetCount.ToString() + " new tweets.", currentDateLocal);
                                            option.LastAccessed = currentDate;
                                            notifications.Add(newTweetCountNotification);
                                        }
                                    }
                                    break;
                                case TwitterOptionId.DirectMessage:
                                    var directMsgs =
                                        (from dm in ctx.DirectMessage
                                         where dm.Type == DirectMessageType.SentTo &&
                                         dm.CreatedAt > option.LastAccessed
                                         select dm).ToList();
                                    foreach (var directMsg in directMsgs)
                                    {
                                        // handle appropriately
                                        var newDirectMessageNotification = new FritzNotifier.Objects.Notification(this.NotificationApplication, this.WebsiteOrProgramAddress, 0, directMsg.Sender.Name + " sent message " + directMsg.Text, "New message from " + directMsg.Sender.Name, currentDateLocal);
                                        notifications.Add(newDirectMessageNotification);
                                        option.LastAccessed = currentDate;
                                    }

                                    break;
                            }
                        }
                    }
                    catch (System.Net.WebException wex)
                    {
                        Console.WriteLine("Twitter did not recognize the credentials. Response from Twitter: " + wex.Message);
                    }
                }
            }

            return notifications;
        }
 public JsonResult Status(string id)
 {
     Authorize();
     string screenName = ViewBag.User;
     IEnumerable<TweetViewModel> friendTweets = new List<TweetViewModel>();
     if (string.IsNullOrEmpty(screenName))
     {
         return Json(friendTweets, JsonRequestBehavior.AllowGet);
     }
     twitterCtx = new TwitterContext(auth);
     friendTweets =
         (from tweet in twitterCtx.Status
          where tweet.Type == StatusType.Show &&
                tweet.ID == id
          select GetTweetViewModel(tweet))
         .ToList();
     if (friendTweets.Count() > 0)
         return Json(friendTweets.ElementAt(0), JsonRequestBehavior.AllowGet);
     else
         return Json(new TweetViewModel { Tweet = "Requested Status Not Found" }, JsonRequestBehavior.AllowGet);
 }
Example #5
0
        public static List<Tweet> Get(string screenname, ulong maxStatusID)
        {
            int fetchMultiplier = int.Parse(
                !string.IsNullOrEmpty(ConfigurationManager.AppSettings["FetchMultiplier"]) ?
                    ConfigurationManager.AppSettings["FetchMultiplier"] : "10");

            List<string> screenNames = new List<string>();
            screenNames.AddRange(TwitterModel.Instance.GetRelevantScreenNames(screenname));

            List<Tweet> tweets = new List<Tweet>();
            screenNames.ForEach(name =>
            {
                var t = Repository<Tweet>.Instance.Query(name + TwitterModel.TWEETS);
                if (t != null) tweets.AddRange(t);
            });
            if (tweets != null)
                tweets = tweets.OrderByDescending(t => t.Status.CreatedAt).ToList();
            if (tweets == null ||
                tweets.Count() < 5 ||
                !tweets.Select(t => t.Status.CreatedAt).IsWithinAverageRecurrenceInterval(multiplier: fetchMultiplier))
            {

                var lastStatusID = (tweets != null && tweets.Count() > 0) ? ulong.Parse(tweets.First().Status.StatusID) : 0;
                var user = UsersCollection.Single(screenname) ?? UsersCollection.PrimaryUser();
                if (user.CanAuthorize)
                {
                    try
                    {
                        Expression<Func<Status, bool>> where;
                        if (maxStatusID > 0 && lastStatusID > 0)
                            where = (s => s.MaxID == maxStatusID &&
                                s.SinceID == lastStatusID &&
                                s.ScreenName == screenname &&
                                s.IncludeEntities == true &&
                                s.Type == StatusType.User &&
                                s.Count == 50);
                        else if (lastStatusID > 0)
                            where = (s => s.SinceID == lastStatusID &&
                                s.ScreenName == screenname &&
                                s.IncludeEntities == true &&
                                s.Type == StatusType.Home &&
                                s.Count == 200);
                        else
                            where = (s => s.ScreenName == screenname &&
                                s.IncludeEntities == true &&
                                s.Type == StatusType.Home &&
                                s.Count == 200);

                        var statuses = TwitterModel.Instance.GetAuthorizedTwitterContext(user.TwitterScreenName)
                            .Status
                            .Where(where)
                            .ToList();

                        List<Tweet> results;

                        if (statuses != null && statuses.Count > 0)
                            results = statuses.Select(s => new Tweet(s)).ToList();
                        else
                            results = null;

                        return results;
                    }
                    catch { return null; }
                }
            }
            return null;
        }
Example #6
0
        public static void SaveTweets(string filepath, List<Tweet> saveTweets) {

            using (System.IO.FileStream fs = new System.IO.FileStream(filepath, System.IO.FileMode.Create))
            {

                using (System.IO.TextWriter writer = new System.IO.StreamWriter(fs, System.Text.Encoding.UTF8))
                {

                    XmlSerializer xs = new XmlSerializer(typeof(List<Tweet>));
                    xs.Serialize(writer, saveTweets);

                }

            }

            SavedExports.Load();

            SavedExports.Instance.ListOfExports.Add(new SavedExports.GestTweetExport()
            {
                dateOfExport = DateTime.Now,
                DirectoryName = filepath,
                NumOfTweets = saveTweets.Count(),
                typeExport = SavedExports.TypeOfExport.API
            });

            SavedExports.Save();

        }