Example #1
0
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         _recommentService.Dispose();
     }
     base.Dispose(disposing);
 }
Example #2
0
 private void UpdateServiceProcess()
 {
     while (true)
     {
         try
         {
             ImageUrlService imageService   = new ImageUrlService();
             var             blogImageList  = imageService.GetLocalList();
             int             blogImageCount = blogImageList.Count;
             MessageLog("updating blogImageCount:" + blogImageCount);
             int successCount = 0;
             foreach (ImageUrl image in blogImageList)
             {
                 string localPath = BlogFileDirectory + image.Url;
                 string yunUrl    = UploadUtility.UploadLocalFile(localPath);
                 if (yunUrl == "")
                 {
                     Thread.Sleep(5 * 60 * 1000);
                     continue;
                 }
                 image.YunUrl      = yunUrl;
                 image.ImageStatus = ImageStatus.Yun;
                 if (imageService.Update(image))
                 {
                     MessageLog("update success,localPath:{0} uploaded yunUrl:{1}", localPath, yunUrl);
                     successCount++;
                 }
                 else
                 {
                     MessageLog("update fail,localPath:{0} uploaded yunUrl:{1}", localPath, yunUrl);
                 }
                 Thread.Sleep(15 * 1000);
             }
             MessageLog("updated blogImageCount:" + successCount);
             imageService.Dispose();
             RecommentService recommentService = new RecommentService();
             var coverImageList  = recommentService.GetLocalList();
             int coverImageCount = coverImageList.Count;
             MessageLog("updating coverImageCount:" + coverImageCount);
             successCount = 0;
             foreach (Recomment image in coverImageList)
             {
                 string localPath = CoverFileDirectory + image.CoverName;
                 string yunUrl    = UploadUtility.UploadLocalFile(localPath);
                 if (yunUrl == "")
                 {
                     Thread.Sleep(5 * 60 * 1000);
                     continue;
                 }
                 image.YunUrl      = yunUrl;
                 image.ImageStatus = ImageStatus.Yun;
                 if (recommentService.Update(image))
                 {
                     MessageLog("update success,localPath:{0} uploaded yunUrl:{1}", localPath, yunUrl);
                     successCount++;
                 }
                 else
                 {
                     MessageLog("update fail,localPath:{0} uploaded yunUrl:{1}", localPath, yunUrl);
                 }
                 Thread.Sleep(15 * 1000);
             }
             MessageLog("updated blogImageCount:" + successCount);
             recommentService.Dispose();
             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);
         }
     }
 }