private bool TryDeleteFile(string filePath, TextWriter consoleOutput) { try { if (File.Exists(filePath)) { FileDelete(filePath); } return(true); } catch (Exception e) { // Treat all possible exceptions uniformly, so we report // "Could not write to output file"/"can't open '***' for writing" // for all as in the native CS/VB compiler. if (consoleOutput != null) { DiagnosticInfo diagnosticInfo = new DiagnosticInfo(MessageProvider, (int)MessageProvider.ERR_OutputWriteFailed, filePath, e.Message); consoleOutput.WriteLine(diagnosticInfo.ToString(Culture)); } return(false); } }
private bool TryMoveFile(string sourcePath, string destinationPath, TextWriter consoleOutput) { try { FileMove(sourcePath, destinationPath); return(true); } catch (Exception e) { // There can be various exceptions caught here including: // - DirectoryNotFoundException when a given path is not found // - IOException when a device like a:\ is not ready // - UnauthorizedAccessException when a given path is not accessible // - NotSupportedException when a given path is in an invalid format // // Treat them uniformly, so we report "Cannot open 'filename' for writing" for all as in the native VB compiler. if (consoleOutput != null) { DiagnosticInfo diagnosticInfo = new DiagnosticInfo(MessageProvider, (int)MessageProvider.ERR_CantOpenFileWrite, destinationPath, e.Message); consoleOutput.WriteLine(diagnosticInfo.ToString(Culture)); } return(false); } }
private FileStream CreateTempFile(TextWriter consoleOutput, out string fileName) { // now catching in response to watson bucket 148019219 try { fileName = GetTempFileName(); var result = FileOpen(fileName, FileMode.CreateNew, FileAccess.ReadWrite, FileShare.None); if (OnCreateTempFile != null) { OnCreateTempFile(fileName, result); } return(result); } catch (IOException ex) { if (consoleOutput != null) { DiagnosticInfo diagnosticInfo = new DiagnosticInfo(MessageProvider, (int)MessageProvider.ERR_FailedToCreateTempFile, ex.Message); consoleOutput.WriteLine(diagnosticInfo.ToString(Culture)); } } fileName = null; return(null); }
/// <summary> /// Takes an exception produced while writing to a file stream and produces a diagnostic. /// </summary> public void ReportStreamWriteException(Exception e, string filePath, TextWriter consoleOutput) { if (consoleOutput != null) { var diagnostic = new DiagnosticInfo(this, ERR_OutputWriteFailed, filePath, e.Message); consoleOutput.WriteLine(diagnostic.ToString(consoleOutput.FormatProvider)); } }
private FileStream OpenFile(string filePath, TextWriter consoleOutput, FileMode mode = FileMode.Open, FileAccess access = FileAccess.ReadWrite, FileShare share = FileShare.None) { try { return(FileOpen(filePath, mode, access, share)); } catch (Exception e) { if (consoleOutput != null) { // TODO: distinct error message? DiagnosticInfo diagnosticInfo = new DiagnosticInfo(MessageProvider, (int)MessageProvider.ERR_OutputWriteFailed, filePath, e.Message); consoleOutput.WriteLine(diagnosticInfo.ToString(Culture)); } return(null); } }
private string CreateTempFile(TextWriter consoleOutput) { string result = null; // now catching in response to watson bucket 148019219 try { result = PathGetTempFileName(); } catch (IOException ex) { if (consoleOutput != null) { DiagnosticInfo diagnosticInfo = new DiagnosticInfo(MessageProvider, (int)MessageProvider.ERR_FailedToCreateTempFile, ex.Message); consoleOutput.WriteLine(diagnosticInfo.ToString(Culture)); } } return(result); }
private Stream OpenFile(string filePath, TextWriter consoleOutput, object mode = null, object access = null, object share = null) { mode = mode ?? PortableShim.FileMode.Open; access = access ?? PortableShim.FileAccess.ReadWrite; share = share ?? PortableShim.FileShare.None; try { return(FileOpen(filePath, mode, access, share)); } catch (Exception e) { if (consoleOutput != null) { // TODO: distinct error message? DiagnosticInfo diagnosticInfo = new DiagnosticInfo(MessageProvider, (int)MessageProvider.ERR_OutputWriteFailed, filePath, e.Message); consoleOutput.WriteLine(diagnosticInfo.ToString(Culture)); } return(null); } }
protected virtual void PrintError(DiagnosticInfo diagnostic, TextWriter consoleOutput) { consoleOutput.WriteLine(diagnostic.ToString(Culture)); }
private Stream OpenFile(string filePath, TextWriter consoleOutput, object mode = null, object access = null, object share = null) { mode = mode ?? PortableShim.FileMode.Open; access = access ?? PortableShim.FileAccess.ReadWrite; share = share ?? PortableShim.FileShare.None; try { return FileOpen(filePath, mode, access, share); } catch (Exception e) { if (consoleOutput != null) { // TODO: distinct error message? DiagnosticInfo diagnosticInfo = new DiagnosticInfo(MessageProvider, (int)MessageProvider.ERR_OutputWriteFailed, filePath, e.Message); consoleOutput.WriteLine(diagnosticInfo.ToString(Culture)); } return null; } }
protected virtual void PrintError(DiagnosticInfo diagnostic, TextWriter consoleOutput) { consoleOutput.WriteLine(diagnostic.ToString(Culture)); }
private bool TryMoveFile(string sourcePath, string destinationPath, TextWriter consoleOutput) { try { FileMove(sourcePath, destinationPath); return true; } catch (Exception e) { // There can be various exceptions caught here including: // - DirectoryNotFoundException when a given path is not found // - IOException when a device like a:\ is not ready // - UnauthorizedAccessException when a given path is not accessible // - NotSupportedException when a given path is in an invalid format // // Treat them uniformly, so we report "Cannot open 'filename' for writing" for all as in the native VB compiler. if (consoleOutput != null) { DiagnosticInfo diagnosticInfo = new DiagnosticInfo(MessageProvider, (int)MessageProvider.ERR_CantOpenFileWrite, destinationPath, e.Message); consoleOutput.WriteLine(diagnosticInfo.ToString(Culture)); } return false; } }
private bool TryDeleteFile(string filePath, TextWriter consoleOutput) { try { if (File.Exists(filePath)) { FileDelete(filePath); } return true; } catch (Exception e) { // Treat all possible exceptions uniformly, so we report // "Could not write to output file"/"can't open '***' for writing" // for all as in the native CS/VB compiler. if (consoleOutput != null) { DiagnosticInfo diagnosticInfo = new DiagnosticInfo(MessageProvider, (int)MessageProvider.ERR_OutputWriteFailed, filePath, e.Message); consoleOutput.WriteLine(diagnosticInfo.ToString(Culture)); } return false; } }
private FileStream OpenFile(string filePath, TextWriter consoleOutput, FileMode mode = FileMode.Open, FileAccess access = FileAccess.ReadWrite, FileShare share = FileShare.None) { try { return FileOpen(filePath, mode, access, share); } catch (Exception e) { if (consoleOutput != null) { // TODO: distinct error message? DiagnosticInfo diagnosticInfo = new DiagnosticInfo(MessageProvider, (int)MessageProvider.ERR_OutputWriteFailed, filePath, e.Message); consoleOutput.WriteLine(diagnosticInfo.ToString(Culture)); } return null; } }
private string CreateTempFile(TextWriter consoleOutput) { string result = null; // now catching in response to watson bucket 148019219 try { result = PathGetTempFileName(); } catch (IOException ex) { if (consoleOutput != null) { DiagnosticInfo diagnosticInfo = new DiagnosticInfo(MessageProvider, (int)MessageProvider.ERR_FailedToCreateTempFile, ex.Message); consoleOutput.WriteLine(diagnosticInfo.ToString(Culture)); } } return result; }
private FileStream CreateTempFile(TextWriter consoleOutput, out string fileName) { // now catching in response to watson bucket 148019219 try { fileName = GetTempFileName(); var result = FileOpen(fileName, FileMode.CreateNew, FileAccess.ReadWrite, FileShare.None); if (OnCreateTempFile != null) { OnCreateTempFile(fileName, result); } return result; } catch (IOException ex) { if (consoleOutput != null) { DiagnosticInfo diagnosticInfo = new DiagnosticInfo(MessageProvider, (int)MessageProvider.ERR_FailedToCreateTempFile, ex.Message); consoleOutput.WriteLine(diagnosticInfo.ToString(Culture)); } } fileName = null; return null; }