예제 #1
0
        public static List <Pagination> Cash(string cashquery, int countofpages)
        {
            if (!Directory.Exists((Path + @"Cash\" + cashquery)))
            {
                Directory.CreateDirectory(Path + @"Cash\" + cashquery);
            }
            List <string> files = Directory.EnumerateFiles(Path + @"Cash\" + cashquery).ToList();

            files.ForEach(file =>
            {
                File.Delete(file);
            });

            AggregatorModel    model    = new AggregatorModel();
            List <GeneralPost> allposts = new List <GeneralPost>();
            SearchResult       result   = new SearchResult();

            result = model.Search(cashquery);
            allposts.AddRange(result.Posts);
            for (int i = 0; i < countofpages - 1; i++)
            {
                result = model.More(cashquery, result.VKPagination, result.InstPagination, result.TwitterPagination);
                if (result.Posts.Count != 0)
                {
                    allposts.AddRange(result.Posts);
                }
                else
                {
                    countofpages = i + 2;
                    break;
                }
            }
            result.Posts = allposts;
            List <Thread> imageThreads = new List <Thread>();

            imageNum = 0;

            foreach (var post in result.Posts)
            {
                Thread imageThread = new Thread(() =>
                {
                    post.Image = DownloadImage(post.Image, cashquery);
                });

                Thread avatarThread = new Thread(() =>
                {
                    post.AuthorAvatar = DownloadImage(post.AuthorAvatar, cashquery);
                });

                imageThreads.Add(avatarThread);
                imageThreads.Add(imageThread);
                avatarThread.Start();
                imageThread.Start();
            }

            foreach (Thread thread in imageThreads)
            {
                thread.Join();
            }

            DBWorker dbworker = new DBWorker();

            dbworker.DeleteAllPostsByHashTag(null);
            dbworker.DeleteAllPostsByHashTag(cashquery);
            dbworker.DeletePagination(cashquery);
            dbworker.AddAllPosts(result.Posts, cashquery);
            dbworker.AddPagination(new Pagination()
            {
                DateOfAdd            = DateTime.Now,
                CountOfPages         = countofpages,
                VKPagination         = result.VKPagination,
                InstagrammPagination = result.InstPagination,
                TwitterPagination    = result.TwitterPagination,
                HashTag = cashquery
            });

            return(dbworker.GetAllPagination());
        }
예제 #2
0
        public string More(string query, string vkPage, string instPage, string twPage)
        {
            AggregatorModel aggregator = new AggregatorModel();

            return(JsonConvert.SerializeObject(aggregator.More(query, vkPage, instPage, twPage)));
        }