Example #1
0
        public override AsyncRetValue<Boolean> AsyncStartParse(Action<AsyncRetValue<Boolean>> method)
        {
            var result = new AsyncRetValue<Boolean>();
            result.SetProgressRange(0, 1);

            result.SetWorker(() =>
            {
                try
                {
                    this.Parse(this.GetPage(PageUrl));
                    this.SaveEntries();

                    result.Value = true;
                    result.Description = String.Format("{0}", _entries.Count);
                }
                catch (Exception ex)
                {
                    result.AbortProgress(false, ex.Message);

                    _logger.Error(ex.ToString());
                    _logger.WriteLogs();
                }

                result.Complete();
            }, FileName);

            result.OnComplete(method);
            result.StartWork();

            return result;
        }
        public AsyncRetValue<Boolean> AsyncStartParse(Action method)
        {
            var result = new AsyncRetValue<Boolean>();
            result.SetWorker(() =>
            {
                try
                {
                    var pages = new List<String>();

                    var doc = new HtmlDocument();
                    doc.LoadHtml(this.GetPage(ParseUrl + "1"));

                    var nodes = doc.DocumentNode.SelectNodes("//ul[@class='pagination']//li//a");

                    if (nodes != null)
                    {
                        foreach (var node in nodes)
                            pages.Add(node.InnerText);
                    }

                    int maxPage = 0;

                    if (pages.Count > 3)
                        maxPage = Convert.ToInt32(pages[pages.Count - 3]);

                    if (maxPage != 0)
                    {
                        pages = new List<String>();

                        result.SetProgressRange(0, nodes.Count);

                        for (var i = 0; i < maxPage; i++)
                        {
                            pages.Add(this.GetPage(ParseUrl + i));
                            result.MoveProgress(i);
                        }
                    }

                    pages.ForEach((item) => { this.Parse(item); });
                    this.SaveEntries();

                    result.Value = true;
                    result.Description = String.Format("{0}", _entries.Count);
                }
                catch (Exception ex)
                {
                    result.AbortProgress(false, ex.Message);

                    Logger.Error(ex.ToString());
                    Logger.WriteLogs();
                }

                result.Complete();
            }, "Cooperative");

            result.OnComplete(method);
            result.StartWork();

            return result;
        }
Example #3
0
        public AsyncRetValue<Boolean> AsyncCompile(Action method)
        {
            var result = new AsyncRetValue<Boolean>();
            result.SetProgressRange(0, 1);

            result.SetWorker(() =>
            {
                try
                {
                    var allgameList = this.GetGameEntries(false);
                    _serializer.Save<List<GameEntry>>(allgameList, @"completed\games.json");

                    var salesList = this.GetGameEntries(true);
                    _serializer.Save<List<GameEntry>>(salesList, @"completed\sales.json");

                    result.Value = true;
                    result.Description = String.Format("All: {0} | sales: {1}", allgameList.Count, salesList.Count);
                    result.Complete();
                }
                catch (Exception ex)
                {
                    result.AbortProgress(false, ex.Message);

                    _logger.Error(ex.ToString());
                    _logger.WriteLogs();
                }
            }, "Store compiler");

            result.OnComplete(method);
            result.StartWork();

            return result;
        }
Example #4
0
        public override AsyncRetValue<Boolean> AsyncStartParse(Action<AsyncRetValue<Boolean>> method)
        {
            var result = new AsyncRetValue<Boolean>();

            result.SetWorker(() =>
            {
                try
                {
                    var pages = new List<String>();

                    var tempDocs = new List<String>();

                    var doc = new HtmlDocument();
                    doc.LoadHtml(GetPage(PageUrl + "0"));

                    var nodes = doc.DocumentNode.SelectNodes("//div[@id='dr_totalSize']/select");
                    if (nodes != null)
                    {
                        var elements = nodes.Elements("option").ToList();
                        result.SetProgressRange(0, elements.Count);

                        for(var i = 0; i < elements.Count; i++)
                        {
                            var node = elements[i];
                            tempDocs.Add(PageUrl + node.GetAttributeValue("value", String.Empty));
                            result.MoveProgress(i);
                        }
                    }
                    tempDocs.Distinct().ToList().ForEach((item) => { pages.Add(this.GetPage(item)); });

                    pages.ForEach((item) => { this.Parse(item); });

                    this.SaveEntries();

                    result.Value = true;
                    result.Description = String.Format("{0}", _entries.Count);
                }
                catch (Exception ex)
                {
                    result.AbortProgress(false, ex.Message);

                    _logger.Error(ex.ToString());
                    _logger.WriteLogs();
                }

                result.Complete();
            }, FileName);

            result.OnComplete(method);
            result.StartWork();

            return result;
        }
Example #5
0
        public void TestMethod1()
        {
            //arrange

            //act
            var result = new AsyncRetValue<Boolean>();
            result = target.AsyncParseThis("directcod", PrintResult);

            while (!result.IsComplete())
            {
                //
            }

            //assert
            Assert.IsTrue(result.Value);
        }
        public AsyncRetValue<Boolean> AsyncStartParse(Action method)
        {
            int Count = 2;

            var result = new AsyncRetValue<Boolean>();
            result.SetProgressRange(0, Count);

            result.SetWorker(() =>
            {
                try
                {
                    for (int i = 0; i < Count; i++)
                    {
                        this.Parse(this.GetPage(ParseUrl + i.ToString()));
                        result.MoveProgress(i);
                    }

                    this.SaveEntries();

                    result.Value = true;
                    result.Description = String.Format("count: {0}", _entries.Count);
                }
                catch (Exception ex)
                {
                    result.AbortProgress(false, ex.Message);

                    Logger.Error(ex.ToString());
                    Logger.WriteLogs();
                }

                result.Complete();
            }, "Metacritic");

            result.OnComplete(method);

            result.StartWork();

            return result;
        }
Example #7
0
        public AsyncRetValue<Boolean> AsyncParseThis(String parserName, Action<AsyncRetValue<Boolean>> method)
        {
            var result = new AsyncRetValue<Boolean>();
            result.SetProgressRange(0, 1);

            var store = _stores.SingleOrDefault(o => o.FileName == parserName);

            if (store != null)
            {
                var retValue = new AsyncRetValue<Boolean>();
                result = store.AsyncStartParse(method);
            }
            else
            {
                result.Value = false;
                result.Description = String.Format("{0} не найден", parserName);
                result.OnComplete(method);
                result.Complete();
            }

            return result;
        }
Example #8
0
        public virtual AsyncRetValue<Boolean> AsyncStartParse(Action<AsyncRetValue<Boolean>> method)
        {
            var result = new AsyncRetValue<Boolean>();
            result.SetProgressRange(0, PageCount);

            result.SetWorker(() =>
            {
                var _pages = new List<String>();
                try
                {
                    for (int i = 0; i < PageCount; i++)
                    {
                        _pages.Add(GetPage(PageUrl + (i + 1).ToString()));
                        result.MoveProgress(i);
                    }

                    _pages.ForEach((page) => { this.Parse(page); });
                    this.SaveEntries();

                    result.Value = true;
                    result.Description = String.Format("{0}", _entries.Count);
                }
                catch (Exception ex)
                {
                    result.AbortProgress(false, ex.Message);

                    _logger.Error(ex.ToString());
                    _logger.WriteLogs();
                }

                result.Complete();
            }, FileName);

            result.OnComplete(method);
            result.StartWork();

            return result;
        }
Example #9
0
        public AsyncRetValue<Boolean> AsyncStartParse(Action method)
        {
            var result = new AsyncRetValue<Boolean>();
            result.SetProgressRange(0, 1);
            result.SetWorker(() =>
            {
                try
                {
                    if (this.GrabTimeLine())
                    {
                        this.SaveEntries();
                        result.Value = true;
                        result.Description = "Count: " + _entries.Count.ToString();
                    }
                    else
                    {
                        result.Value = false;
                        result.Description = "method |GrabTimeLine| return false";
                    }

                }
                catch (Exception ex)
                {
                    result.AbortProgress(false, ex.Message);

                    Logger.Error(ex.ToString());
                    Logger.WriteLogs();
                }

                result.Complete();
            }, "Twitter");

            result.OnComplete(method);
            result.StartWork();

            return result;
        }
Example #10
0
 public void PrintResult(AsyncRetValue<Boolean> result)
 {
     Debug.WriteLine("{0}|{1}", result.Value, result.Description);
     count++;
 }
Example #11
0
        public override AsyncRetValue<Boolean> AsyncStartParse(Action<AsyncRetValue<Boolean>> method)
        {
            var result = new AsyncRetValue<Boolean>();

            result.SetWorker(() =>
            {
                try
                {
                    var _pages = new List<String>();

                    var categoryUrls = new List<String>();
                    categoryUrls.Add(@"http://store.steampowered.com/search/?sort_by=&sort_order=ASC&category1=998&page=");
                    categoryUrls.Add(@"http://store.steampowered.com/search/?sort_by=&sort_order=ASC&category1=997&page=");
                    categoryUrls.Add(@"http://store.steampowered.com/search/?sort_by=&sort_order=ASC&category1=996&page=");
                    categoryUrls.Add(@"http://store.steampowered.com/search/?sort_by=&sort_order=ASC&category1=21&page=");

                    categoryUrls.ForEach((url) =>
                    {
                        var tempString = this.GetPage(url + "1");

                        var doc = new HtmlDocument();
                        doc.LoadHtml(tempString);

                        var list = doc.DocumentNode
                                      .SelectSingleNode("//div[@class='search_pagination_right']")
                                      .Elements("a")
                                      .ToList();

                        var Count = Convert.ToInt32(list[list.Count - 2].InnerText);

                        result.SetProgressRange(0, Count);

                        for (int i = 0; i < Count; i++)
                        {
                            var page = this.GetPage(url + (i + 1).ToString());
                            _pages.Add(page);
                            result.MoveProgress(i);
                        }
                    });

                    _pages.ForEach((item) => { this.Parse(item); });
                    this.SaveEntries();

                    result.Value = true;
                    result.Description = String.Format("{0}", _entries.Count);
                }
                catch (Exception ex)
                {
                    result.AbortProgress(false, ex.Message);

                    _logger.Error(ex.ToString());
                    _logger.WriteLogs();
                }

                result.Complete();
            }, FileName);

            result.OnComplete(method);
            result.StartWork();

            return result;
        }
Example #12
0
        public List<AsyncRetValue<Boolean>> AsyncStartParse(Action<AsyncRetValue<Boolean>> method)
        {
            var result = new List<AsyncRetValue<Boolean>>();

            _stores.ForEach((store) =>
            {
                var retValue = new AsyncRetValue<Boolean>();

                retValue = store.AsyncStartParse(method);
                result.Add(retValue);
            });

            return result;
        }