Ejemplo n.º 1
0
            private static bool SaveRecomment(Blog blog, string imageUrl, string category)
            {
                if (imageUrl == "")
                {
                    return(true);
                }
                string fileName = CrawlerUtility.GetFileContent(imageUrl, Const.CoverFileDirectory, "http://www.ed2kers.com/");

                if (string.IsNullOrEmpty(fileName))
                {
                    fileName = imageUrl;
                }
                string localFilePath = Const.CoverFileDirectory + fileName;

                string yunUrl = "";

                //UploadUtility.UploadLocalFile(localFilePath);
                Info("localFile:{0} upload to yunUrl:{1}", localFilePath, yunUrl);
                var recomment = new Recomment()
                {
                    BlogId    = blog.Id,
                    CoverName = fileName,
                    Title     = blog.Title,
                    TimeStamp = DateTime.Now,
                    Category  = SetCategory(category)
                };

                if (!string.IsNullOrEmpty(yunUrl))
                {
                    recomment.YunUrl      = yunUrl;
                    recomment.ImageStatus = ImageStatus.Yun;
                }
                return(SyncUtility.SyncRecomment(recomment));
            }
Ejemplo n.º 2
0
        private static bool SaveRecomment(Blog blog, string coverImgUrl)
        {
            if (coverImgUrl == "")
            {
                return(true);
            }
            string fileName = CrawlerUtility.GetFileContent(coverImgUrl, Const.CoverFileDirectory, "http://www.zimuzu.tv/");

            if (string.IsNullOrEmpty(fileName))
            {
                return(true);
            }
            string localFilePath = Const.CoverFileDirectory + fileName;
            var    image         = Domain.Helper.ImgHandler.ZoomPicture(Image.FromFile(localFilePath), 200, 110);

            image.Save(localFilePath);
            string yunUrl = UploadUtility.UploadLocalFile(localFilePath);

            Console.WriteLine("localFile:{0} upload to yunUrl:{1}", localFilePath, yunUrl);
            var recomment = new Recomment()
            {
                BlogId    = blog.Id,
                CoverName = fileName,
                Title     = blog.Title,
                TimeStamp = DateTime.Now,
                Category  = SetCategoryByTitle(blog.Title)
            };

            if (!string.IsNullOrEmpty(yunUrl))
            {
                recomment.YunUrl      = yunUrl;
                recomment.ImageStatus = ImageStatus.Yun;
            }
            return(SyncUtility.SyncRecomment(recomment));
        }
Ejemplo n.º 3
0
        private static bool SaveRecomment(Blog blog, string imageUrl, string category)
        {
            if (imageUrl == "")
            {
                return(true);
            }
            string fileName = CrawlerUtility.GetFileContent(imageUrl, Const.CoverFileDirectory, "http://www.mp4ba.com/");

            if (fileName == "")
            {
                return(true);
            }

            var recomment = new Recomment()
            {
                BlogId    = blog.Id,
                Title     = blog.Title,
                CoverName = fileName,
                TimeStamp = DateTime.Now
            };

            if (category.Contains("电影"))
            {
                recomment.Category = RecommentCategory.电影;
            }
            if (category.Contains("电视剧"))
            {
                recomment.Category = RecommentCategory.剧集;
            }
            if (category == "欧美电视剧")
            {
                recomment.Category = RecommentCategory.美剧;
            }
            if (category == "日韩电视剧")
            {
                recomment.Category = RecommentCategory.韩剧;
            }
            if (category == "综艺娱乐")
            {
                recomment.Category = RecommentCategory.综艺;
            }
            string localFilePath = Const.CoverFileDirectory + fileName;
            var    image         = Domain.Helper.ImgHandler.ZoomPicture(Image.FromFile(localFilePath), 200, 110);

            image.Save(localFilePath);
            string yunUrl = UploadUtility.UploadLocalFile(localFilePath);

            Console.WriteLine("localFile:{0} upload to yunUrl:{1}", localFilePath, yunUrl);
            if (!string.IsNullOrEmpty(yunUrl))
            {
                recomment.YunUrl      = yunUrl;
                recomment.ImageStatus = ImageStatus.Yun;
            }
            return(SyncUtility.SyncRecomment(recomment));
        }
Ejemplo n.º 4
0
        private static bool SaveRecomment(Blog blog, string imageUrl, string category)
        {
            if (imageUrl == "http://verycd.gdajie.com/img/default_cover.jpg" || imageUrl == "")
            {
                return(true);
            }
            string fileName = CrawlerUtility.GetFileContent(imageUrl, Const.CoverFileDirectory, "http://www.gdajie.com/");

            if (string.IsNullOrEmpty(fileName))
            {
                return(true);
            }
            string localFilePath = Const.CoverFileDirectory + fileName;

            try
            {
                using (var localImage = Image.FromFile(localFilePath))
                {
                    var image = ImgHandler.ZoomPicture(localImage, 200, 110);
                    image.Save(localFilePath);
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex, "localFilePath:{0}", localFilePath);
                return(true);
            }

            string yunUrl = UploadUtility.UploadLocalFile(localFilePath);

            Info("localFile:{0} upload to yunUrl:{1}", localFilePath, yunUrl);
            var recomment = new Recomment()
            {
                BlogId    = blog.Id,
                CoverName = fileName,
                Title     = blog.Title,
                TimeStamp = DateTime.Now,
                Category  = SetCategory(category)
            };

            if (!string.IsNullOrEmpty(yunUrl))
            {
                recomment.YunUrl      = yunUrl;
                recomment.ImageStatus = ImageStatus.Yun;
            }
            return(SyncUtility.SyncRecomment(recomment));
        }
Ejemplo n.º 5
0
        private static bool SaveRecomment(Blog blog, string imageUrl, string category)
        {
            if (imageUrl == "http://verycd.gdajie.com/img/default_cover.jpg" || imageUrl == "")
            {
                return(true);
            }
            string fileName = CrawlerUtility.GetFileContent(imageUrl, Const.CoverFileDirectory, "http://www.gdajie.com/");

            if (string.IsNullOrEmpty(fileName))
            {
                return(true);
            }
            string localFilePath = Const.CoverFileDirectory + fileName;
            var    image         = Domain.Helper.ImgHandler.ZoomPicture(Image.FromFile(localFilePath), 200, 110);

            image.Save(localFilePath);
            string yunUrl = UploadUtility.UploadLocalFile(localFilePath);

            Console.WriteLine("localFile:{0} upload to yunUrl:{1}", localFilePath, yunUrl);
            var recomment = new Recomment()
            {
                BlogId    = blog.Id,
                CoverName = fileName,
                Title     = blog.Title,
                TimeStamp = DateTime.Now,
                Category  = SetCategory(category)
            };

            if (!string.IsNullOrEmpty(yunUrl))
            {
                recomment.YunUrl      = yunUrl;
                recomment.ImageStatus = ImageStatus.Yun;
            }
            return(SyncUtility.SyncRecomment(recomment));
            //Context.Set<Recomment>().Add(recomment);
            //Context.SaveChanges();
        }
Ejemplo n.º 6
0
        private void UpdateServiceProcess()
        {
            while (true)
            {
                try
                {
                    var blogImageList  = ImageUrlDao.GetToUploadList();
                    int blogImageCount = blogImageList.Count;
                    MessageLog("updating blogImageCount:" + blogImageCount);
                    int successCount = 0;
                    foreach (ImageUrl image in blogImageList)
                    {
                        string localPath = Const.BlogFileDirectory + image.Url;
                        string yunUrl    = UploadUtility.UploadLocalFile(localPath);
                        if (yunUrl == "")
                        {
                            Thread.Sleep(5 * 60 * 1000);
                            continue;
                        }
                        image.YunUrl      = yunUrl;
                        image.ImageStatus = ImageStatus.Yun;
                        if (SyncUtility.SyncImageUrl(image))
                        {
                            MessageLog("sync success,localPath:{0} uploaded yunUrl:{1}", localPath, yunUrl);
                            ImageUrlDao.DeleteRecord(image.Id);
                            successCount++;
                        }
                        else
                        {
                            MessageLog("sync fail,localPath:{0} uploaded yunUrl:{1}", localPath, yunUrl);
                        }
                        Thread.Sleep(15 * 1000);
                    }
                    MessageLog("updated blogImageCount:" + successCount);

                    var coverImageList  = RecommentDao.GetToUploadList();
                    int coverImageCount = coverImageList.Count;
                    MessageLog("updating coverImageCount:" + coverImageCount);
                    successCount = 0;
                    foreach (Recomment image in coverImageList)
                    {
                        if (image.CoverName.Trim().StartsWith("http"))
                        {
                            image.CoverName = CrawlerUtility.GetFileContent(image.CoverName.Trim(),
                                                                            Const.CoverFileDirectory, "");
                            if (string.IsNullOrEmpty(image.CoverName))
                            {
                                continue;
                            }
                        }
                        string localPath = Const.CoverFileDirectory + image.CoverName;
                        string yunUrl    = UploadUtility.UploadLocalFile(localPath);
                        if (yunUrl == "")
                        {
                            //Thread.Sleep(5 * 60 * 1000);
                            continue;
                        }
                        image.YunUrl      = yunUrl;
                        image.ImageStatus = ImageStatus.Yun;
                        if (SyncUtility.SyncRecomment(image))
                        {
                            MessageLog("sync success,localPath:{0} uploaded yunUrl:{1}", localPath, yunUrl);
                            RecommentDao.DeleteRecord(image.Id);
                            successCount++;
                        }
                        else
                        {
                            MessageLog("sync fail,localPath:{0} uploaded yunUrl:{1}", localPath, yunUrl);
                        }
                        Thread.Sleep(15 * 1000);
                    }
                    MessageLog("updated blogImageCount:" + successCount);
                    if (blogImageCount == 0 && coverImageCount == 0)
                    {
                        MessageLog("record empty,sleeping 10 minutes");
                        Thread.Sleep(10 * 60 * 1000);
                    }
                }
                catch (ThreadAbortException threadAbortException)
                {
                    Logger.Error(threadAbortException);
                    break;
                }
                catch (Exception ex)
                {
                    Logger.Error(ex);
                    Thread.Sleep(10 * 60 * 1000);
                }
            }
        }