Exemple #1
0
        /// <summary>
        /// Funkcja zapisująca wybraną wiadomość do bazy danych
        /// </summary>
        /// <param name="archiveListCategories">Lista kategorii dostępnych w bazie danych</param>
        /// <param name="news">Wiadomość do zapisania</param>
        public void AddSelectedArticle(ObservableCollection<Category> archiveListCategories, News news)
        {
            bool newsExist = _rssContext.News.Any(n => n.Id == news.Id);
            if (!newsExist)
            {
                _rssContext.News.Add(new News
                   {
                       Category = news.Category,
                       Date = news.Date,
                       Description = news.Description,
                       Photo = news.Photo,
                       Title = news.Title,
                       UrlNews = news.UrlNews,
                       UrlImage = news.UrlImage,
                       Id = news.Id
                   });

                _rssContext.SaveChanges();

                if (!archiveListCategories.Any(n => n.Name == news.Category))
                    UpdateArchiveCategory(archiveListCategories, news.Category, true);
            }
        }
Exemple #2
0
        /// <summary>
        /// Dekoduje z opisu ze znacznikami HTML do normalnego opisu 
        /// </summary>
        /// <param name="news">Wiadomość do dekodowania</param>
        private void ParseDescription(News news)
        {
            StringWriter myWriter = new StringWriter();
            string description = string.Empty;
            string start = string.Empty;
            string end = ResourceRss.EndDescription;
            int index = 0;
            HttpUtility.HtmlDecode(news.Description, myWriter);
            string decode = myWriter.ToString();

            if (decode[0] == Convert.ToChar(ResourceRss.OneSymbol) && decode[1] == Convert.ToChar(ResourceRss.TwoSymbol))
            {
                start = ResourceRss.StartDescription;
                if (news.UrlImage == null && decode.Contains(ResourceRss.CheckedTwice) == false)
                    start = ResourceRss.StartDescriptionWithoutImage;
                index = decode.IndexOf(start);
            }

            if (!decode.Contains(end))
                end = ResourceRss.EndDescriptionBr;

            if (index > -1)
            {
                for (int i = index + start.Length; i < decode.Length; i++)
                {
                    if (i + end.Length < decode.Length)
                    {
                        string tmp = decode.Substring(i, end.Length);
                        if (tmp != end)
                            description += decode[i];
                        else
                        {
                            if (description != string.Empty)
                                news.Description = description[0] == '-' ? description.Substring(1) : description;
                            return;
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Wywołuje funkcje do zapisywania wiadomości do bazy danych
        /// </summary>
        /// <param name="obj"></param>
        private void Save(object obj)
        {
            News newsSave = new News();
            int index = SelectedIndexListBoxNews;
            if (obj is Int32)
                index = (int)obj;
            newsSave.Title = LineNews[index].Title;
            newsSave.Description = LineNews[index].Description;
            newsSave.Id = LineNews[index].Id;
            newsSave.UrlImage = LineNews[index].UrlImage;
            newsSave.Category = LineNews[index].Category;
            newsSave.UrlNews = LineNews[index].UrlNews;
            newsSave.Date = LineNews[index].Date;
            newsSave.Photo = GetImageAsByte(newsSave.UrlImage);

            RSSrepo rssRepo = new RSSrepo();
            rssRepo.AddSelectedArticle(ArchiveListCategories, newsSave);
        }
Exemple #4
0
 /// <summary>
 /// Dekoduje z id ze znacznikami HTML do normalnego id 
 /// </summary>
 /// <param name="news">Wiadomość do dekodowania</param>
 public void ParseId(News news)
 {
     string ipLong = news.Id;
     int index = ipLong.IndexOf(ResourceRss.SearchId);
     news.Id = ipLong.Substring(index + ResourceRss.SearchId.Length, Convert.ToInt32(ResourceRss.LengthId));
 }
        /// <summary>
        /// Wyświetla informacje wiadomości na zakładce nowe, lub wczytuje wiadomości z bazy na zakładce archiwalne
        /// </summary>
        private void ReadNews()
        {
            LineNews = new ObservableCollection<News>();
            News = new News();
            SelectedIndexListBoxNews = 0;
            if (SelectedIndexTab == 0)
                Reader.ParseXml(LineNews, ListCategories[SelectedIndexCategories]);
            else if (ArchiveListCategories.Any())
            {
                if (SelectedIndexCategories < 0)
                    Reader.ReadBase(LineNews, ArchiveListCategories, ArchiveListCategories[0]);
                else
                    Reader.ReadBase(LineNews, ArchiveListCategories, ArchiveListCategories[SelectedIndexCategories]);
            }

            ShowDescription();
        }