@@ -1446,70 +1446,80 @@ public void Open(string encoding)
14461446
14471447 public void OpenWriteWithRetry ( string encoding )
14481448 {
1449- int attempts = 0 ;
1450- bool opened = false ;
1451- while ( ! opened && attempts < 3 )
1449+ _lastError = 0 ;
1450+ _lastErrorDescription = "" ;
1451+ if ( validSource ( ) )
14521452 {
1453- try
1453+ int attempts = 0 ;
1454+ bool opened = false ;
1455+ while ( ! opened && attempts < 3 )
14541456 {
14551457#pragma warning disable SCS0018 // Path traversal: injection possible in {1} argument passed to '{0}'
1456- _fileStreamWriter = new FileStream ( _file . FullName ,
1457- FileMode . Append | FileMode . OpenOrCreate ,
1458- FileAccess . Write ,
1459- FileShare . Read ) ;
1460- #pragma warning restore SCS0018 // Path traversal: injection possible in {1} argument passed to '{0}'
1461- _fileWriter = new StreamWriter ( _fileStreamWriter , GXUtil . GxIanaToNetEncoding ( encoding , false ) ) ;
1462- opened = true ;
1463- }
1464- catch ( IOException ex )
1465- {
1466- attempts ++ ;
1467- if ( attempts >= 3 )
1458+ try
1459+ {
1460+ _fileStreamWriter = new FileStream ( _file . FullName ,
1461+ FileMode . Append | FileMode . OpenOrCreate ,
1462+ FileAccess . Write ,
1463+ FileShare . Read ) ;
1464+ _fileWriter = new StreamWriter ( _fileStreamWriter , GXUtil . GxIanaToNetEncoding ( encoding , false ) ) ;
1465+ opened = true ;
1466+ }
1467+ catch ( IOException ex )
1468+ {
1469+ attempts ++ ;
1470+ if ( attempts >= 3 )
1471+ {
1472+ setError ( ex ) ;
1473+ break ;
1474+ }
1475+ System . Threading . Thread . Sleep ( 2000 ) ;
1476+ }
1477+ catch ( Exception e )
14681478 {
1469- setError ( ex ) ;
1479+ setError ( e ) ;
14701480 break ;
14711481 }
1472- System . Threading . Thread . Sleep ( 2000 ) ;
1473- }
1474- catch ( Exception e )
1475- {
1476- setError ( e ) ;
1477- break ;
1482+ #pragma warning restore SCS0018 // Path traversal: injection possible in {1} argument passed to '{0}'
14781483 }
14791484 }
14801485 }
14811486
14821487 public void OpenReadWithRetry ( string encoding )
14831488 {
1484- int attempts = 0 ;
1485- bool opened = false ;
1486- while ( ! opened && attempts < 3 )
1489+ _lastError = 0 ;
1490+ _lastErrorDescription = "" ;
1491+ if ( validSource ( ) )
14871492 {
1488- try
1493+ int attempts = 0 ;
1494+ bool opened = false ;
1495+ while ( ! opened && attempts < 3 )
14891496 {
14901497#pragma warning disable SCS0018 // Path traversal: injection possible in {1} argument passed to '{0}'
1491- _fileStreamReader = new FileStream ( _file . FullName ,
1492- FileMode . Open ,
1493- FileAccess . Read ,
1494- FileShare . ReadWrite ) ;
1495- #pragma warning restore SCS0018 // Path traversal: injection possible in {1} argument passed to '{0}'
1496- _fileReader = new StreamReader ( _fileStreamReader , GXUtil . GxIanaToNetEncoding ( encoding , false ) ) ;
1497- opened = true ;
1498- }
1499- catch ( IOException ex )
1500- {
1501- attempts ++ ;
1502- if ( attempts >= 3 )
1498+ try
1499+ {
1500+ _fileStreamReader = new FileStream ( _file . FullName ,
1501+ FileMode . Open ,
1502+ FileAccess . Read ,
1503+ FileShare . ReadWrite ) ;
1504+ _fileReader = new StreamReader ( _fileStreamReader , GXUtil . GxIanaToNetEncoding ( encoding , false ) ) ;
1505+ opened = true ;
1506+ }
1507+ catch ( IOException ex )
1508+ {
1509+ attempts ++ ;
1510+ if ( attempts >= 3 )
1511+ {
1512+ setError ( ex ) ;
1513+ break ;
1514+ }
1515+ System . Threading . Thread . Sleep ( 2000 ) ;
1516+ }
1517+ catch ( Exception e )
15031518 {
1504- setError ( ex ) ;
1519+ setError ( e ) ;
15051520 break ;
15061521 }
1507- System . Threading . Thread . Sleep ( 2000 ) ;
1508- }
1509- catch ( Exception e )
1510- {
1511- setError ( e ) ;
1512- break ;
1522+ #pragma warning restore SCS0018 // Path traversal: injection possible in {1} argument passed to '{0}'
15131523 }
15141524 }
15151525 }
0 commit comments