Beispiel #1
0
        /// <summary>
        /// Get Articles From Feed
        /// </summary>
        /// <param name="feedUrl"></param>
        /// <returns></returns>
        public static async Task <ArticleList> GetArticleListFromFeedAsync(string feedUrl)
        {
            var syncClient = new SyndicationClient();
            var lista      = new ArticleList();

            if (InternetConectivity)
            {
                var feed = await syncClient.RetrieveFeedAsync(new Uri(feedUrl));

                foreach (var art in feed.Items)
                {
                    var content = CreateContent(art.NodeValue);
                    lista.Add(new Article()
                    {
                        Title   = art.Title.Text,
                        Content = content,
                        Summary = CreateSummary(art.Summary, content),
                        ImgUri  = Find1stImageFromHtml(content)
                    });
                }
            }
            else
            {
                throw new Exception(INTERNET_REQUIRED);
            }

            return(lista);
        }
        public static async Task <ArticleList> GetArticleListFromFeedAsync(string feedUrl)
        {
            var syncClient = new SyndicationClient();
            var lista      = new ArticleList();

            var feed = await syncClient.RetrieveFeedAsync(new Uri(feedUrl));

            foreach (var art in feed.Items)
            {
                var content = CreateContent(art.NodeValue);

                {
                    var newArticle = new Article()
                    {
                        Title   = art.Title.Text,
                        Content = content,
                        Summary = CreateSummary(art.Summary, content),
                        ImgUri  = Find1stImageFromHtml(content)
                    };
                    lista.Add(newArticle);
                }
            }

            return(lista);
        }
Beispiel #3
0
        /// <summary>
        /// Get Articles From Feed
        /// </summary>
        /// <param name="feedUrl"></param>
        /// <returns></returns>
        public static async Task<ArticleList> GetArticleListFromFeedAsync(string feedUrl)
        {
            var syncClient = new SyndicationClient();
            var lista = new ArticleList();

            if (InternetConectivity)
            {
                var feed = await syncClient.RetrieveFeedAsync(new Uri(feedUrl));
                foreach (var art in feed.Items)
                {
                    var content = CreateContent(art.NodeValue);
                    lista.Add(new Article()
                                {
                                    Title = art.Title.Text,
                                    Content = content,
                                    Summary = CreateSummary(art.Summary, content),
                                    ImgUri = Find1stImageFromHtml(content)
                                });
                }
            }
            else
            {
                throw new Exception(INTERNET_REQUIRED);
            }

            return lista;
        }
Beispiel #4
0
        public void Add()
        {
            var newEntity = new ArticleEntity()
            {
                Deleted     = false,
                Description = "",
                ArticleNo   = "",
                CategoryId  = -1,
                ArticleId   = -1
            };

            SelectedArticle = newEntity;
            ArticleList.Add(newEntity);
            ArticleList = new List <ArticleEntity>(_articleList);
        }
        public static async Task<ArticleList> GetArticleListFromFeedAsync(string feedUrl)
        {
            var syncClient = new SyndicationClient();
            var lista = new ArticleList();

            var feed = await syncClient.RetrieveFeedAsync(new Uri(feedUrl));
            foreach (var art in feed.Items)
            {
                var content = CreateContent(art.NodeValue);

                {
                    var newArticle = new Article() { Title = art.Title.Text,
                    Content = content,
                    Summary = CreateSummary(art.Summary, content),
                    ImgUri = Find1stImageFromHtml(content) };
                    lista.Add(newArticle);
                }
            }

            return lista;
        }
        public async void GetArticlesInPage(int page)
        {
            if (_isInDesignMode)
            {
                for (int i = 0; i < 15; i++)
                {
                    Article sampleArticle = new Article();
                    sampleArticle.Title      = "Article " + i;
                    sampleArticle.AuthorName = "TrouDuc " + (15 - i);
                    sampleArticle.Content    = "Contenu sample!Contenu sample!Contenu sample!Contenu sample!Contenu sample!Contenu sample!Contenu sample!Contenu sample!";
                    sampleArticle.ID         = i;
                    sampleArticle.PostTime   = DateTime.Now;
                    ArticleList.Add(sampleArticle);
                }
            }

            else
            {
                var articleList = await Resources.APIWebTeam.NewsManagment.GetArticlesListOnPage(page);

                IsLoading = false;
                RaisePropertyChanged("IsLoading");

                if (articleList != null)
                {
                    foreach (Article art in articleList)
                    {
                        ArticleList.Add(art);

                        //Façon de tricher pour avoir une animation plus fluide
                        await Task.Delay(50);

                        RaisePropertyChanged("ArticleList");
                    }
                }
            }

            return;
        }
Beispiel #7
0
        void DoNavigated()
        {
            try
            {
                switch (CurrentNavigation)
                {
                case Navigation.Logout:
                    IsLoggedIn = false;
                    OnNavigatedTo(CurrentNavigation);
                    Info("Logout: DONE");
                    NavigateTo(Navigation.None);
                    break;

                case Navigation.LoginCheck:
                    OnNavigatedTo(CurrentNavigation);
                    if (this.Author.Load())
                    {
                        Info("Was already logged in.");
                        CurrentNavigation = Navigation.Login;
                        DoNavigated();
                    }
                    else
                    {
                        NavigateTo(Navigation.Login);
                    }
                    break;

                case Navigation.Login:
                    OnNavigatedTo(CurrentNavigation);
                    string ErrorElementId = GetElementId("LogonError");

                    if (!string.IsNullOrWhiteSpace(ErrorElementId))
                    {
                        IsLoggedIn = false;
                        NavigateTo(Navigation.None);
                        HtmlElement ErrorElement = this.Document.GetElementById(ErrorElementId);
                        Error("Login: FAILED" + Environment.NewLine + ErrorElement.InnerText);
                    }
                    else
                    {
                        if (this.Author.Load())
                        {
                            IsLoggedIn = true;
                            Info("Login: DONE");
                            NavigateTo(Navigation.ArticleList);
                        }
                        else
                        {
                            IsLoggedIn = false;
                            Error("Can not extract Author Id");
                        }
                    }
                    break;

                case Navigation.ArticleList:

                    Info("Article List: Reading");
                    int ArticleCount = 0;

                    string      prefixForArticles = GetElementId("_MC_AR_ctl");
                    HtmlElement link = this.Document.GetElementById(prefixForArticles + ArticleCount.ToString("00") + "_CAR_Title");

                    if (link == null)
                    {
                        ArticleCount = 1;     // Try to start from 1
                        link         = this.Document.GetElementById(prefixForArticles + ArticleCount.ToString("00") + "_CAR_Title");
                    }

                    while (link != null)
                    {
                        string articleName      = link.InnerText;
                        string linkToTheArticle = link.GetAttribute("href");
                        string articleID        = Regex.Match(linkToTheArticle, "/([0-9]{1,12})/").Groups[1].Value;

                        ArticleList.Add(new ArticleInfo(articleID, articleName));

                        ArticleCount++;
                        link = this.Document.GetElementById(prefixForArticles + ArticleCount.ToString("00") + "_CAR_Title");
                    }

                    Info("Article List: DONE");
                    OnNavigatedTo(CurrentNavigation);
                    NavigateTo(Navigation.None);
                    break;


                case Navigation.Article:

                    OnNavigatedTo(CurrentNavigation);

                    Info(string.Format("Downloading Article: {0}", CurrentArticleInfo.Name));

                    string HtmlText = string.Empty;
                    string FileName;
                    string FilePath;
                    string Folder;

                    if (this.Document.GetElementById("ArticleContent") != null)
                    {
                        string src;
                        Uri    uri;

                        // images
                        string[] images = new string[this.Document.Images.Count];
                        for (int i = 0; i < images.Length; i++)
                        {
                            images[i] = this.Document.Images[i].GetAttribute("src");
                        }

                        Folder = Path.Combine(ArticleFolder, CurrentArticleInfo.Id);
                        Directory.CreateDirectory(Folder);

                        using (WebClient webClient = new WebClient())
                        {
                            webClient.Proxy = null;                                     // To prevent it from trying to determine proxy settings of IE
                            for (int i = 0; i < images.Length; i++)
                            {
                                src      = images[i];
                                uri      = new Uri(src);
                                FileName = Path.GetFileName(uri.LocalPath);

                                FilePath = Path.Combine(ArticleFolder, CurrentArticleInfo.Id, FileName);

                                webClient.DownloadFile(src, FilePath);
                                images[i] = CurrentArticleInfo.Id + "/" + FileName;     // To make src attribute relative
                            }
                        }

                        for (int i = 0; i < images.Length; i++)                         // Change src attributes
                        {
                            this.Document.Images[i].SetAttribute("src", images[i]);
                        }

                        // content
                        HtmlText = this.Document.GetElementById("ArticleContent").InnerHtml;
                    }

                    // save article to disk
                    FileName = CurrentArticleInfo.Name;
                    FileName = FileName.Replace('[', '_');
                    FileName = FileName.Replace(']', '_');
                    FileName = FileName.Replace(':', '_');

                    FilePath = Path.Combine(ArticleFolder, FileName);

                    FilePath = string.IsNullOrWhiteSpace(Path.GetExtension(FilePath)) ? FilePath + ".cpa" : Path.ChangeExtension(FilePath, ".cpa");
                    File.WriteAllText(FilePath, HtmlText, Encoding.UTF8);

                    Info(string.Format("Downloading Article: {0}. DONE", CurrentArticleInfo.Name));
                    NavigateTo(Navigation.None);

                    Action <ArticleInfo> Downloaded = OnArticleDownloaded;
                    OnArticleDownloaded = null;

                    Downloaded?.Invoke(CurrentArticleInfo);

                    break;
                }
            }
            catch (Exception ex)
            {
                OnArticleDownloaded = null;
                Error(ex.Message);
            }
        }
Beispiel #8
0
 public void AddArticle(Article article)
 {
     ArticleList.Add(article);
 }