private void DownloadProfilePicture(TwitterViewModel.StatusResponse status) { var path = WebHelpers.TwitterProfileImagePath; if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } try { var extension = Path.GetExtension(status.User.ProfileImageUrl); var imagePath = Path.Combine(path, status.User.ScreenName + extension); using (var client = new WebClient()) { client.DownloadFile(status.User.ProfileImageUrl, imagePath); } ProfileImagePath = imagePath; } catch (Exception ex) { Log.TraceErr("TweetViewModel: Couldn't download profile picture from {0}. {1}", status.User.ProfileImageUrl, ex.ToString()); } }
internal TweetViewModel(TwitterViewModel.StatusResponse status) { if (status == null) { throw new ArgumentNullException("status"); } Created = DateTime.ParseExact(status.CreatedAt, "ddd MMM dd HH:mm:ss zzz yyyy", CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal);; var elapsed = DateTime.UtcNow - Created; CreatedElapsed = elapsed.TotalMinutes < 60 ? elapsed.Minutes + "m" : (int)Math.Floor(elapsed.TotalHours) + "h"; Name = status.User.Name; ScreenName = status.User.ScreenName; _writableContents = new ObservableCollection <TweetSection>(); Contents = new ReadOnlyObservableCollection <TweetSection>(_writableContents); ParseTweet(status); }
private void ParseTweet(TwitterViewModel.StatusResponse status) { if (status.Entities == null) { _writableContents.Add(new TweetSection(status.FullText, TweetSectionType.Text)); return; } var tweetSections = new List <TweetSection>(); tweetSections.Add(new TweetSection(status.FullText, TweetSectionType.Text)); // Add all the HashTag sections foreach (var hashTag in status.Entities.Hashtags.OrderByDescending(ht => ht.Text.Length)) { UpdateListOfSections(hashTag.Text, TweetSectionType.HashTag, tweetSections); } // Add all the UserMention sections foreach (var userMention in status.Entities.UserMentions.OrderByDescending(um => um.ScreenName.Length)) { UpdateListOfSections(userMention.ScreenName, TweetSectionType.UserMention, tweetSections); } // Unescape strings for (var i = 0; i < tweetSections.Count; i++) { var section = tweetSections[i]; if (section.Type != TweetSectionType.Text) { continue; } tweetSections[i] = new TweetSection(HttpUtility.HtmlDecode(section.Text), TweetSectionType.Text); } _writableContents.AddRange(tweetSections); UpdateReplyingTo(status.ReplyingTo); UpdateFormattedText(); DownloadProfilePicture(status); }