File tree Expand file tree Collapse file tree 1 file changed +21
-3
lines changed Expand file tree Collapse file tree 1 file changed +21
-3
lines changed Original file line number Diff line number Diff line change 22using System . IO ;
33using CnBlogPublishTool . Util ;
44using MetaWeblogClient ;
5+ using Polly ;
56
67namespace CnBlogPublishTool
78{
@@ -16,9 +17,26 @@ public static void Init(BlogConnectionInfo info)
1617
1718 public static string Upload ( string filePath )
1819 {
19- FileInfo fileinfo = new FileInfo ( filePath ) ;
20- var mediaObjectInfo = BlogClient . NewMediaObject ( fileinfo . Name , MimeMapping . GetMimeMapping ( filePath ) , File . ReadAllBytes ( filePath ) ) ;
21- return mediaObjectInfo . URL ;
20+ var policy = Policy . Handle < Exception > ( ) . Retry ( 3 , ( exception , retryCount ) =>
21+ {
22+ Console . WriteLine ( "上传失败,正在重试 {0},异常:{1}" , retryCount , exception . Message ) ;
23+ } ) ;
24+ try
25+ {
26+ var url = policy . Execute < string > ( ( ) =>
27+ {
28+ FileInfo fileinfo = new FileInfo ( filePath ) ;
29+ var mediaObjectInfo = BlogClient . NewMediaObject ( fileinfo . Name , MimeMapping . GetMimeMapping ( filePath ) , File . ReadAllBytes ( filePath ) ) ;
30+ return mediaObjectInfo . URL ;
31+ } ) ;
32+
33+ return url ;
34+ }
35+ catch ( Exception e )
36+ {
37+ Console . WriteLine ( "上传失败,异常:{0}" , e . Message ) ;
38+ throw ;
39+ }
2240 }
2341 }
2442}
You can’t perform that action at this time.
0 commit comments