Пример #1
0
 /// <summary>
 /// Tags a nes item as read whenever the user clicks on the notificatin popup
 /// </summary>
 /// <param name="item">The news item that was displayed in the popup</param>
 private void NotificationPopupClicked(NewsItem item)
 {
     tlpNewsItems.Controls.Cast<NewsItemControl>().Where(c => c.NewsItem == item).First().TagAsRead();
     _newsService.NotifyNewsItemRead(item);
     item.IsNew = false;
     int nbNews = tlpNewsItems.Controls.Cast<NewsItemControl>().Where(c => c.NewsItem.IsNew).Count();
     UpdateTabText(nbNews > 0);
 }
Пример #2
0
 /// <summary>
 /// Initialises a new instance of the class
 /// </summary>
 /// <param name="newsItem"></param>
 public NewsItemControl(NewsItem newsItem)
 {
     InitializeComponent();
     lblTitle.Text = newsItem.Title;
     NewsItem = newsItem;
     lblFrom.Text = FormatTime(newsItem) + " - " + newsItem.SourceName;
     if (newsItem.IsNew)
     {
         lblFrom.Text += " - NEW";
         lblFrom.ForeColor = Color.Red;
     }
     lblFrom.Click += lblTitle_Click;
     //lblSummary.Text = newsItem.Summary;
 }
Пример #3
0
 /// <summary>
 /// Formats the display of the time the news was published
 /// </summary>
 /// <param name="newsItem">the news item</param>
 /// <returns>A string like xx minutes/hours/days ago</returns>
 private static string FormatTime(NewsItem newsItem)
 {
     var diff = DateTime.Now - newsItem.DateTime;
     if (diff.TotalDays > 1)
     {
         return string.Format("{0} day(s) ago", (int)diff.TotalDays);
     }
     else if (diff.TotalHours > 1)
     {
         return string.Format("{0} hours(s) ago", (int)diff.TotalHours);
     }
     else
     {
         return string.Format("{0} minutes(s) ago", (int)diff.TotalMinutes);
     }
 }
Пример #4
0
 /// <summary>
 /// Returns a string
 /// </summary>
 /// <param name="item"></param>
 /// <returns></returns>
 private string GetSavedFormat(NewsItem item)
 {
     return item.DateTime.ToString(CultureInfo.InvariantCulture) + System.Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(item.Title));
 }
Пример #5
0
 public void NotifyNewsItemRead(NewsItem item)
 {
     string[] lines = new string[0];
     if (File.Exists(GetStoreFile()))
     {
         lines = File.ReadAllLines(GetStoreFile());
     }
     File.WriteAllLines(GetStoreFile(), new string[] { item.Tag });
     File.AppendAllLines(GetStoreFile(), lines);
 }
Пример #6
0
        public bool CheckNewsItemHasBeenRead(NewsItem item)
        {
            if (!File.Exists(GetStoreFile()))
            {
                return false;
            }

            var lines = File.ReadAllLines(GetStoreFile());
            return lines.Any(l => l == item.Tag);
        }