Example #1
0
        protected bool getUrlAddresses(string type)
        {
            DAL.enderecosUrlSingleton             enderecos = DAL.enderecosUrlSingleton.Instance;
            DAL.poiDatabase.enderecosURLDataTable rows      = enderecos.getUrlsByType(requestType);
            DAL.siteTypeSingleton siteType = DAL.siteTypeSingleton.Instance;
            int siteTypeId = (int)siteType.getIdByType(type);

            foreach (DAL.poiDatabase.enderecosURLRow row in rows)
            {
                foreach (string link in fetchDataFromWeb(row.url, type))
                {
                    enderecos.storeUrlsArray(link, siteTypeId);
                }
            }

            return(true);
        }
Example #2
0
        //public HtmlParserObject[] getHtmlContent()
        public bool getHtmlContent()
        {
            DAL.enderecosUrlSingleton             enderecos = DAL.enderecosUrlSingleton.Instance;
            DAL.poiDatabase.enderecosURLDataTable rows      = enderecos.getUrlsByType(requestType);
            var tempHtmlData = new List <HtmlPoi>();

            foreach (DAL.poiDatabase.enderecosURLRow row in rows)
            {
                //HttpWebRequest request = (HttpWebRequest)WebRequest.Create(row.url);
                HttpWebRequest  request  = (HttpWebRequest)WebRequest.Create("http://www.imt.pt/workshops_seminarios.php");
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();

                if (response.StatusCode == HttpStatusCode.OK)
                {
                    Stream       receiveStream = response.GetResponseStream();
                    StreamReader readStream    = null;

                    if (response.CharacterSet == null)
                    {
                        readStream = new StreamReader(receiveStream);
                    }
                    else
                    {
                        readStream = new StreamReader(receiveStream, Encoding.GetEncoding(response.CharacterSet));
                    }

                    string data     = readStream.ReadToEnd();
                    var    parser   = new HtmlParser();
                    var    document = parser.Parse(data);

                    string body = ExtractHeaderContentFromHtml(data);

                    //bool result = this.ParseHtmlContents(body);
                    string content = ExtractHtmlContentFromHtml(body);

                    response.Close();
                    readStream.Close();
                }
            }

            // TODO store poi's in database with threads ??
            //Poi.ThreadPoi poi = new Poi.ThreadPoi(tempRssData.ToArray<Feed>());

            return(true);
        }
Example #3
0
        public Feed[] getRssFeeds()
        {
            DAL.poiSingleton pois = DAL.poiSingleton.Instance;

            DAL.enderecosUrlSingleton             enderecos = DAL.enderecosUrlSingleton.Instance;
            DAL.poiDatabase.enderecosURLDataTable rows      = enderecos.getUrlsByType(requestType);

            DAL.categorySingleton categoriesSingleton          = DAL.categorySingleton.Instance;
            DAL.poiDatabase.categoriesDataTable categoriesRows = categoriesSingleton.getCategories();

            string[] categoriesArray = categoriesSingleton.getCategoriesToArray(true);



            var tempRssData = new List <Feed>();

            foreach (DAL.poiDatabase.enderecosURLRow row in rows)
            {
                XmlReader       reader      = XmlReader.Create(row.url);
                SyndicationFeed feedsObject = SyndicationFeed.Load(reader);
                reader.Close();
                Feed feed = new Feed();

                Poi.Poi poi = new Poi.Poi();


                foreach (SyndicationItem item in feedsObject.Items)
                {
                    string title = "";
                    try
                    {
                        title = item.Title.Text;
                    }
                    catch (NullReferenceException ex)
                    {
                        title = "";
                    }
                    if (this.verifyEligibilaty(categoriesArray, title.Trim().ToLower()))
                    {
                        int i = 0;
                        // verificar se o titulo contém alguma key word
                        feed.Title = title;
                        if (item.Links[0].Uri.IsAbsoluteUri)
                        {
                            feed.Link = item.Links[0].Uri.AbsoluteUri;
                        }

                        feed.Content = item.Summary.Text;
                        if (item.Categories.LongCount() > 0)
                        {
                            string[] categories = new string[item.Categories.LongCount()];
                            foreach (SyndicationCategory category in item.Categories)
                            {
                                categories[i] = category.Name;
                                i++;
                            }
                            feed.Category = categories;
                        }
                        else
                        {
                            string[] categories = new string[1];
                            categories[0] = "Generic";
                            feed.Category = categories;
                        }

                        //feed.Date = item.PublishDate.Date;
                        Boolean result = false;
                        if (pois.alreadyExists(title) == false)
                        {
                            result = poi.storePoi(requestType, feed, row.id_enderecosURL);
                        }

                        if (result == true)
                        {
                            tempRssData.Add(feed);
                        }
                    }
                }
            }

            // TODO store poi's in database with threads ??
            //Poi.ThreadPoi poi = new Poi.ThreadPoi(tempRssData.ToArray<Feed>());

            return(tempRssData.ToArray <Feed>());
        }