Exemplo n.º 1
0
        private async Task ExecuteLoadItemsCommand()
        {
            if (IsBusy)
            {
                return;
            }

            IsBusy = true;

            try
            {
                FeedItems.Clear();

                var items = await _feedRepository.GetAll(StaticData.RssFeed);

                foreach (var item in items)
                {
                    FeedItems.Add(item);
                }
            }
            catch (Exception ex)
            {
                var page   = new ContentPage();
                var result = page.DisplayAlert("Error", "Unable to load podcast feed. " + ex.Message, "OK");

                Insights.Report(ex, new Dictionary <string, string> {
                    { "Error", "Unable to load podcast feed." },
                    { "Message", ex.Message },
                    { "Result", result.ToString() }
                });
            }

            IsBusy = false;
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Execute()
        {
            var feedItems = await _feedRepository.GetAll();

            var sw = new StringWriterWithEncoding(Encoding.UTF8);

            using (var xmlWriter = XmlWriter.Create(sw, new XmlWriterSettings {
                Async = true, Indent = true
            }))
            {
                var writer = new RssFeedWriter(xmlWriter);
                foreach (var feedItem in feedItems)
                {
                    var item = new SyndicationItem
                    {
                        Title       = feedItem.Title,
                        Description = feedItem.Description,
                        Id          = feedItem.Id,
                        Published   = feedItem.CreateDateTime
                    };
                    item.AddContributor(new SyndicationPerson(feedItem.Author, "*****@*****.**"));
                    await writer.Write(item);
                }

                xmlWriter.Flush();
            }

            return(new ObjectResult(sw.ToString()));
        }
Exemplo n.º 3
0
        private async Task ExecuteLoadItemsCommand()
        {
            if (IsBusy)
            {
                return;
            }

            IsBusy    = true;
            IsNotBusy = false;

            try
            {
                FeedItems.Clear();

                var items = await _feedRepository.GetAll(StaticData.RssFeed);

                foreach (var item in items)
                {
                    FeedItems.Add(item);
                }

                LastFeedItem = FeedItems[0];

                PodcastTitle = LastFeedItem.Title;
                PodcastDate  = LastFeedItem.PublishDate;

                if (LastFeedItem.FileImage != null)
                {
                    FileImage = LastFeedItem.FileImage;
                }
                else
                {
                    FileImage = "empty_image.png";
                }
            }
            catch (Exception ex)
            {
                var page   = new ContentPage();
                var result = page.DisplayAlert("Error", "Unable to load podcast feed. " + ex.Message, "OK");

                Insights.Report(ex, new Dictionary <string, string> {
                    { "Error", "Unable to load podcast feed." },
                    { "Message", ex.Message },
                    { "Result", result.ToString() }
                });
            }

            IsBusy    = false;
            IsNotBusy = true;
        }
Exemplo n.º 4
0
        public HttpResponseMessage GetList()
        {
            List <FeedViewModel> items;

            try
            {
                LoggerSource.Instance.GetLogger(typeof(FeedController)).Trace("GetList called");
                items = _repository.GetAll()
                        .Select(item => new FeedViewModel(item, this.PortalSettings.PortalId))
                        .ToList();
                //var jsonSettings = new JsonSerializerSettings()
                //{
                //    ContractResolver = new CamelCasePropertyNamesContractResolver()
                //};
                var ret = JsonConvert.SerializeObject(items, Formatting.Indented);
                return(Request.CreateResponse(HttpStatusCode.OK, ret, "application/json"));
            }
            catch (System.Exception ex)
            {
                //Log to DotNetNuke and reply with Error
                Exceptions.LogException(ex);
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message));
            }
        }
Exemplo n.º 5
0
        //public IEnumerable<View> Get()
        public HttpResponseMessage Get()
        {
            IList <FeedViewModel> items;

            try
            {
                items = _repository.GetAll()
                        .Select(item => new FeedViewModel(item, this.PortalSettings.PortalId))
                        .ToList();

                return(Request.CreateResponse(HttpStatusCode.OK, items, new SyndicationFeedFormatter(), "application/rss+xml"));
            }
            catch (System.Exception ex)
            {
                //Log to DotNetNuke and reply with Error
                Exceptions.LogException(ex);
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message));
            }
        }
Exemplo n.º 6
0
        static async Task Main(string[] args)
        {
            Console.OutputEncoding = System.Text.Encoding.UTF8;
            CommandsParser commandParser = new CommandsParser();
            IFeedService   feedService   = new FeedService();

            _feedRepository = new FeedXmlRepository();
            string[] arrString;
            //_feedRepository.Create(new Feed() { Name = "news", Url = "https://www.liga.net/news/rss.xml" });
            //_feedRepository.Create(new Feed() { Name = "articles", Url = "https://www.liga.net/news/articles/rss.xml" });
            //_feedRepository.Create(new Feed() { Name = "interview", Url = "https://www.liga.net/news/interview/rss.xml" });
            //_feedRepository.Create(new Feed() { Name = "opinion", Url = "https://www.liga.net/opinion/rss.xml" });
            //_feedRepository.Create(new Feed() { Name = "crypto", Url = "https://www.liga.net/fin/crypto/rss.xml" });
            //_feedRepository.Create(new Feed() { Name = "blog", Url = "https://www.liga.net/rss/blog.xml" });
            //_feedRepository.Create(new Feed() { Name = "vlog", Url = "https://www.liga.net/tech/vlog/rss.xml" });

            //_feedRepository.Create(new Feed() { Name = "news2.0", Url = "https://www.liga.net/news/rss.xml" });
            //var result = _feedRepository.GetAll();
            //var res = _feedRepository.GetByName("news2.0");
            //_feedRepository.Delete("news2.0");
            while (true)
            {
                do
                {
                    Console.Write("Enter the command->");
                }while (!commandParser.TryParse(Console.ReadLine(), out arrString));

                try
                {
                    switch (arrString[0].ToLower())
                    {
                    case "add":
                        _feedRepository.Create(new Feed {
                            Name = arrString[1], Url = arrString[2]
                        });
                        Console.WriteLine("Feed added");
                        break;

                    case "remove":
                        _feedRepository.Delete(arrString[1]);
                        Console.WriteLine("Feed removed");
                        break;

                    case "download":
                        var feeds = _feedRepository.GetAll();
                        if (feeds.Count == 0)
                        {
                            Console.WriteLine("XML-file with feeds is empty");
                            continue;
                        }
                        IList <string> names = new List <string>();
                        for (int i = 1; i < arrString.Length; i++)
                        {
                            if (feeds.Where(x => x.Name == arrString[i]).Count() > 0)
                            {
                                names.Add(feeds.Where(x => x.Name == arrString[i]).Select(x => x.Url).FirstOrDefault());
                            }
                        }
                        if (names.Count < 1)
                        {
                            Console.WriteLine("Nothing was found");
                            continue;
                        }

                        await feedService.Run(names.ToArray());

                        break;
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            }
            //var feeds = _feedRepository.GetAll();
            //string[] urls = feeds.Select(f => f.Url).ToArray();


            //await feedService.Run(urls);
        }
Exemplo n.º 7
0
 public async Task <IEnumerable <Feed> > GetFeedsAsync(string userName)
 {
     return((await _feedRepository.GetAll()).Where(feed => feed.UserName == userName));
 }
Exemplo n.º 8
0
 public ApiResponse <List <Feed> > GetAll()
 {
     return(_feedRepository.GetAll());
 }