Esempio n. 1
0
        protected override AbstractSource DoCreateNewSource(string name, string url, List <MetaDataObject> templateAndValues)
        {
            string value;
            int    tmp;

            MetaDataObject source = MetaDataObject.FindIn(templateAndValues, SmackProvider.META_SOURCE);

            value = source.GetValueAsString();

            if (String.IsNullOrEmpty(value))
            {
                throw new Exception("No source selected");
            }

            AbstractSource s = new SmackSource(value);

            MetaDataObject pages = MetaDataObject.FindIn(templateAndValues, SmackProvider.META_PAGES);

            value = pages.GetValueAsString();

            if (String.IsNullOrEmpty(value))
            {
                tmp = DefaultPages;
            }
            else
            {
                int.TryParse(value, out tmp);
            }

            pages.SetValue(tmp);

            s.SetMetaData(templateAndValues);

            return(s);
        }
Esempio n. 2
0
        private List <AbstractItem> GetNewItems(SmackSource source)
        {
            string BaseUrl;
            string Selector;

            if (source.Source == SourceNames.ChinaSmack.ToString())
            {
                BaseUrl  = ChinaBase;
                Selector = ChinaSelect;
            }
            else if (source.Source == SourceNames.JapanCrush.ToString())
            {
                BaseUrl  = JapanBase;
                Selector = JapanSelect;
            }
            else
            {
                throw new Exception(source + "not accepted");
            }

            List <AbstractItem> items = new List <AbstractItem>();

            WebClient wc = new WebClient();

            int max = Convert.ToInt32(source.Pages);

            for (int p = 1; p <= max; p++)
            {
                string url = BaseUrl + p;
                string page;

                page = wc.DownloadString(url);

                HtmlDocument doc = new HtmlDocument();
                doc.LoadHtml(page);

                var itemNodes = doc.DocumentNode.SelectNodes(Selector);

                foreach (var a in itemNodes)
                {
                    try
                    {
                        string name = WebUtility.HtmlDecode(a.InnerText);
                        string link = a.Attributes["href"].Value;

                        var post = new Post(source, name, link);
                        items.Add(post);
                    }
                    catch (Exception e)
                    {
                    }
                }
            }

            return(items);
        }
Esempio n. 3
0
        internal static SmackSource CreateFrom(AbstractSource source)
        {
            if (source is SmackSource)
            {
                return((SmackSource)source);
            }

            SmackSource js = new SmackSource(source.SourceName);

            js.SetMetaData(source.GetMetaData());
            js.SetID(source.ID.Value);

            return(js);
        }
Esempio n. 4
0
        protected override List <AbstractItem> GetNewItems(AbstractSource source)
        {
            SmackSource js = SmackSource.CreateFrom(source);

            return(GetNewItems(js));
        }
Esempio n. 5
0
 public override AbstractSource CastSource(GenericSource src)
 {
     return(SmackSource.CreateFrom(src));
 }