Пример #1
0
        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);
            }
        }
Пример #2
0
        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);
            }
        }
Пример #3
0
        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);
        }
Пример #4
0
 /// <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));
     }
 }
Пример #5
0
        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);
            }
        }
Пример #6
0
        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);
        }
Пример #7
0
        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);
            }
        }
Пример #8
0
 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;
            }
        }
Пример #10
0
 protected virtual void PrintError(DiagnosticInfo diagnostic, TextWriter consoleOutput)
 {
     consoleOutput.WriteLine(diagnostic.ToString(Culture));
 }
Пример #11
0
        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;
            }
        }
Пример #12
0
        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;
            }
        }
Пример #13
0
        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;
            }
        }
Пример #14
0
        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;
        }
Пример #15
0
        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;
        }