コード例 #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
ファイル: CommonCompiler.cs プロジェクト: zlphoenix/roslyn
        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
ファイル: CommonCompiler.cs プロジェクト: zlphoenix/roslyn
 protected virtual void PrintError(DiagnosticInfo diagnostic, TextWriter consoleOutput)
 {
     consoleOutput.WriteLine(diagnostic.ToString(Culture));
 }
コード例 #9
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;
            }
        }
コード例 #10
0
 protected virtual void PrintError(DiagnosticInfo diagnostic, TextWriter consoleOutput)
 {
     consoleOutput.WriteLine(diagnostic.ToString(Culture));
 }
コード例 #11
0
ファイル: CommonCompiler.cs プロジェクト: riversky/roslyn
        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
ファイル: CommonCompiler.cs プロジェクト: riversky/roslyn
        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
ファイル: CommonCompiler.cs プロジェクト: riversky/roslyn
        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
ファイル: CommonCompiler.cs プロジェクト: riversky/roslyn
        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
ファイル: CommonCompiler.cs プロジェクト: elemk0vv/roslyn-1
        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;
        }