Exemplo n.º 1
0
        private void doWork()
        {
            while (true)
            {
                try
                {
                    string url = "";
                    lock (_in_queue)
                    {
                        while (_in_queue.Count == 0 && !doExit)
                        {
                            Monitor.Wait(_in_queue);
                        }
                        if (doExit)
                        {
                            break;
                        }
                        url = _in_queue.Dequeue();
                    }

                    List <Channel> res = RssFetcher.getFeedFromURL(url);
                    lock (_out_queue)
                    {
                        _out_queue.Enqueue(res);
                        Monitor.Pulse(_out_queue);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
Exemplo n.º 2
0
        private void doWork()
        {
            while (true)
            {
                try
                {
                    string url = "";
                    lock (_in_queue)
                    {
                        while (_in_queue.Count == 0 && !doExit)
                        {
                            Monitor.Wait(_in_queue);
                        }
                        if (doExit)
                        {
                            break;
                        }
                        url = _in_queue.Dequeue();
                    }

                    List <Channel> res = RssFetcher.getFeedFromURL(url);

                    var          ser = new System.Runtime.Serialization.Json.DataContractJsonSerializer(typeof(List <Channel>));
                    MemoryStream ms  = new MemoryStream();
                    ser.WriteObject(ms, res);
                    string res_str = Encoding.UTF8.GetString(ms.ToArray());
                    ms.Close();

                    HttpWebRequest request = WebRequest.Create("http://localhost:49714/WebService.svc/enqueue_filter") as HttpWebRequest;
                    request.Method        = "POST";
                    request.ContentType   = "application/json";
                    request.ContentLength = Encoding.UTF8.GetByteCount(res_str);

                    StreamWriter sw = new StreamWriter(request.GetRequestStream());
                    sw.Write(res_str);
                    sw.Close();
                    request.GetResponse();
                }
                catch (Exception ex)
                {
                    Console.Error.WriteLine(ex.Message);
                }
            }
        }
Exemplo n.º 3
0
        public void LoadNews(ObservableCollection <NewsViewModel> newsList)
        {
            newsList.Clear();
            _userThreadPool.ClearQueue();

            foreach (FeedModel feed in FeedsList)
            {
                feed.Status = FeedStatus.Ready;

                if (!feed.IsShown)
                {
                    continue;
                }

                feed.Status = FeedStatus.Waiting;

                _userThreadPool.EnqueueTask(() =>
                {
                    feed.Status = FeedStatus.Loading;
                    IList <NewsModel> result = RssFetcher.FetchNews(feed.Link);

                    if (result == null)
                    {
                        feed.Status = FeedStatus.Error;
                    }
                    else
                    {
                        // to add items in observable-collection's dispatcher thread
                        _context.Send((x) =>
                        {
                            foreach (var news in result)
                            {
                                var res = new NewsViewModel(news);
                                newsList.Add(res);
                            }
                            feed.Status = FeedStatus.Ready;
                        }, null);
                    }
                });
            }
        }
Exemplo n.º 4
0
 public RssController(Helper helper, ILogger <RssController> logger, RssFetcher fetcher)
 {
     this.helper  = helper;
     this.logger  = logger;
     this.fetcher = fetcher;
 }