Ejemplo n.º 1
0
        static async Task RunAsync()
        {
            var _context = new DepVDContextDataContext();

            using (var client = new HttpClient())
            {
                List <string> lstToday = new List <string>();
                // TODO - Send HTTP requests
                // New code:
                client.BaseAddress = new Uri("http://open-api.depvd.com");
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                // New code:
                try
                {
                    HttpResponseMessage response = await client.GetAsync("VerifyKey?key=I264N-Z3EG4-6YOBG-FQV8S-EXUR7");

                    if (response.IsSuccessStatusCode)
                    {
                        VerifyKey key = await response.Content.ReadAsAsync <VerifyKey>();

                        //Console.WriteLine("{0}\t{1}\t{2}", key.code, key.content, key.message);
                        if (key.code.Equals("200"))
                        {
                            #region GetVnTopics
                            //TODO: 3 GetVnTopics
                            for (int j = 1; j <= 20; j++) // should 50 ^_^.
                            {
                                HttpResponseMessage response3 = await client.GetAsync("Topic/GetVnTopics?page=" + j);

                                if (response3.IsSuccessStatusCode)
                                {
                                    Product result = await response3.Content.ReadAsAsync <Product>();

                                    if (result.content.topics.Count > 0)
                                    {
                                        foreach (topic t in result.content.topics)
                                        {
                                            if (t.Photos.Count > 0)
                                            {
                                                foreach (Photo p in t.Photos)
                                                {
                                                    if (!_context.ImgLinks.Any(o => o.linkimg == p.absNormal))
                                                    {
                                                        var obj = new ImgLink()
                                                        {
                                                            linkimg    = p.absNormal,
                                                            CreateDate = DateTime.UtcNow,
                                                            Domain     = "depvd.com",
                                                            Category   = "Viet-Nam-sexy-girl",
                                                            Counter    = BuildCounter(t.absViewUrl),
                                                            GroupName  = t.title
                                                        };
                                                        _context.ImgLinks.InsertOnSubmit(obj);
                                                        _context.SubmitChanges();
                                                        Console.WriteLine("GetVnTopics " + p.absNormal);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    else
                                    {
                                        Console.WriteLine("GetVnTopics End: " + j);
                                        break;
                                    }
                                }
                                else
                                {
                                    Console.WriteLine("GetVnTopics Response content: " + response3.Content);
                                }
                            }
                            #endregion

                            #region GetAsiaTopics
                            //TODO: 4 GetAsiaTopics
                            for (int j = 1; j <= 20; j++) // should 50 ^_^.
                            {
                                HttpResponseMessage response4 = await client.GetAsync("Topic/GetAsiaTopics?page=" + j);

                                if (response4.IsSuccessStatusCode)
                                {
                                    Product result = await response4.Content.ReadAsAsync <Product>();

                                    if (result.content.topics.Count > 0)
                                    {
                                        foreach (topic t in result.content.topics)
                                        {
                                            if (t.Photos.Count > 0)
                                            {
                                                foreach (Photo p in t.Photos)
                                                {
                                                    if (!_context.ImgLinks.Any(o => o.linkimg == p.absNormal))
                                                    {
                                                        var obj = new ImgLink()
                                                        {
                                                            linkimg    = p.absNormal,
                                                            CreateDate = DateTime.UtcNow,
                                                            Domain     = "depvd.com",
                                                            Category   = "asia-sexy-girl",
                                                            Counter    = BuildCounter(t.absViewUrl),
                                                            GroupName  = t.title
                                                        };
                                                        _context.ImgLinks.InsertOnSubmit(obj);
                                                        _context.SubmitChanges();
                                                        Console.WriteLine("GetAsiaTopics " + p.absNormal);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    else
                                    {
                                        Console.WriteLine("GetAsiaTopics End: " + j);
                                        break;
                                    }
                                }
                                else
                                {
                                    Console.WriteLine("GetAsiaTopics Response content: " + response4.Content);
                                }
                            }
                            #endregion

                            #region GetUsUkTopics
                            //TODO: 5 GetUsUkTopics
                            for (int j = 1; j <= 20; j++) // should 50 ^_^.
                            {
                                HttpResponseMessage response5 = await client.GetAsync("Topic/GetUsUkTopics?page=" + j);

                                if (response5.IsSuccessStatusCode)
                                {
                                    Product result = await response5.Content.ReadAsAsync <Product>();

                                    if (result.content.topics.Count > 0)
                                    {
                                        foreach (topic t in result.content.topics)
                                        {
                                            if (t.Photos.Count > 0)
                                            {
                                                foreach (Photo p in t.Photos)
                                                {
                                                    if (!_context.ImgLinks.Any(o => o.linkimg == p.absNormal))
                                                    {
                                                        var obj = new ImgLink()
                                                        {
                                                            linkimg    = p.absNormal,
                                                            CreateDate = DateTime.UtcNow,
                                                            Domain     = "depvd.com",
                                                            Category   = "US-UK-sexy-girl",
                                                            Counter    = BuildCounter(t.absViewUrl),
                                                            GroupName  = t.title
                                                        };
                                                        _context.ImgLinks.InsertOnSubmit(obj);
                                                        _context.SubmitChanges();
                                                        Console.WriteLine("GetUsUkTopics " + p.absNormal);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    else
                                    {
                                        Console.WriteLine("GetUsUkTopics End: " + j);
                                        break;
                                    }
                                }
                                else
                                {
                                    Console.WriteLine("GetUsUkTopics Response content: " + response5.Content);
                                }
                            }
                            #endregion

                            #region GetNewTopics
                            //TODO: 1 GetNewTopics
                            for (int j = 1; j <= 20; j++) // should 50 ^_^.
                            {
                                HttpResponseMessage response1 = await client.GetAsync("Topic/GetNewTopics?page=" + j);

                                if (response1.IsSuccessStatusCode)
                                {
                                    Product result = await response1.Content.ReadAsAsync <Product>();

                                    if (result.content.topics.Count > 0)
                                    {
                                        foreach (topic t in result.content.topics)
                                        {
                                            if (t.Photos.Count > 0)
                                            {
                                                foreach (Photo p in t.Photos)
                                                {
                                                    if (!_context.ImgLinks.Any(o => o.linkimg == p.absNormal))
                                                    {
                                                        var obj = new ImgLink()
                                                        {
                                                            linkimg    = p.absNormal,
                                                            CreateDate = DateTime.UtcNow,
                                                            Domain     = "depvd.com",
                                                            Category   = "sexy-girl",
                                                            Counter    = BuildCounter(t.absViewUrl),
                                                            GroupName  = t.title
                                                        };
                                                        _context.ImgLinks.InsertOnSubmit(obj);
                                                        _context.SubmitChanges();
                                                        Console.WriteLine("GetNewTopics :" + p.absNormal);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    else
                                    {
                                        Console.WriteLine("GetNewTopics End: " + j);
                                        break;
                                    }
                                }
                                else
                                {
                                    Console.WriteLine("GetNewTopics Response content: " + response1.Content);
                                }
                            }
                            #endregion

                            #region GetHomeTopics
                            //TODO: 2 GetNewTopics
                            for (int j = 1; j <= 20; j++) // should 50 ^_^.
                            {
                                HttpResponseMessage response2 = await client.GetAsync("Topic/GetHomeTopics?page=" + j);

                                if (response2.IsSuccessStatusCode)
                                {
                                    Product result = await response2.Content.ReadAsAsync <Product>();

                                    if (result.content.topics.Count > 0)
                                    {
                                        foreach (topic t in result.content.topics)
                                        {
                                            if (t.Photos.Count > 0)
                                            {
                                                foreach (Photo p in t.Photos)
                                                {
                                                    if (!_context.ImgLinks.Any(o => o.linkimg == p.absNormal))
                                                    {
                                                        var obj = new ImgLink()
                                                        {
                                                            linkimg    = p.absNormal,
                                                            CreateDate = DateTime.UtcNow,
                                                            Domain     = "depvd.com",
                                                            Category   = "sexy-girl",
                                                            Counter    = BuildCounter(t.absViewUrl),
                                                            GroupName  = t.title
                                                        };
                                                        _context.ImgLinks.InsertOnSubmit(obj);
                                                        _context.SubmitChanges();
                                                        Console.WriteLine("GetHomeTopics " + p.absNormal);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    else
                                    {
                                        Console.WriteLine("GetHomeTopics End: " + j);
                                        break;
                                    }
                                }
                                else
                                {
                                    Console.WriteLine("GetHomeTopics Response content: " + response2.Content);
                                }
                            }
                            #endregion

                            #region GetTopWeekTopics
                            ////TODO: 1 GetNewTopics
                            //for (int j = 1; j <= 1; j++) // should 50 ^_^.
                            //{
                            //    HttpResponseMessage response6 = await client.GetAsync("Topic/GetTopWeekTopics");
                            //    if (response6.IsSuccessStatusCode)
                            //    {
                            //        Product result = await response6.Content.ReadAsAsync<Product>();
                            //        if (result.content.topics.Count > 0)
                            //        {
                            //            foreach (topic t in result.content.topics)
                            //            {
                            //                if (t.Photos.Count > 0)
                            //                {
                            //                    foreach (Photo p in t.Photos)
                            //                    {
                            //                        if (!_context.ImgLinks.Any(o => o.linkimg == p.absNormal))
                            //                        {
                            //                            var obj = new ImgLink()
                            //                            {
                            //                                linkimg = p.absNormal,
                            //                                CreateDate = DateTime.UtcNow,
                            //                                Domain = "depvd.com",
                            //                                Category = "sexy-girl",
                            //                                Counter = BuildCounter(t.absViewUrl),
                            //                                GroupName = t.title
                            //                            };
                            //                            _context.ImgLinks.InsertOnSubmit(obj);
                            //                            _context.SubmitChanges();
                            //                            Console.WriteLine("GetTopWeekTopics " + p.absNormal);
                            //                        }
                            //                    }
                            //                }
                            //            }
                            //        }
                            //        else
                            //        {
                            //            Console.WriteLine("GetTopWeekTopics End: " + j);
                            //            break;
                            //        }
                            //    }
                            //    else
                            //    {
                            //        Console.WriteLine("GetTopWeekTopics Response content: " + response6.Content);
                            //    }
                            //}
                            #endregion
                        }
                    }
                    else
                    {
                        Console.WriteLine(response.Content);
                    }
                }
                catch (Exception exception)
                {
                    Console.WriteLine(exception.ToString());
                    throw exception;
                }
            }
        }
Ejemplo n.º 2
0
 partial void UpdateImgLink(ImgLink instance);
Ejemplo n.º 3
0
 partial void DeleteImgLink(ImgLink instance);
Ejemplo n.º 4
0
 partial void InsertImgLink(ImgLink instance);