예제 #1
0
        private string GetFileContents(IFileSystem fileSystem, AssetFile asset)
        {
            Stopwatch stopwatch = Stopwatch.StartNew();
            Stream    stream    = null;

            do
            {
                try
                {
                    stream = fileSystem.OpenFile(asset.AbsolutePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);

                    StreamReader reader = asset.Encoding != null ? new StreamReader(stream, asset.Encoding) : new StreamReader(stream);

                    return(reader.ReadToEnd());
                }
                catch (FileNotFoundException)
                {
                    Thread.Sleep(_fileReadRetryDelay);
                }
                catch (IOException)
                {
                    Thread.Sleep(_fileReadRetryDelay);
                }
                catch (UnauthorizedAccessException)
                {
                    Thread.Sleep(_fileReadRetryDelay);
                }
                finally
                {
                    if (stream != null)
                    {
                        stream.Close();
                        stream = null;
                    }
                }
            } while (stopwatch.Elapsed < _fileReadTimeout);

            throw new ApplicationException(String.Format("The timeout of {0} was reached trying to read bundle file '{1}'.", _fileReadTimeout, asset.AbsolutePath));
        }
예제 #2
0
        private string GetFileContents(IFileSystem fileSystem, AssetFile asset)
        {
            Stopwatch stopwatch = Stopwatch.StartNew();
            Stream stream = null;

            do
            {
                try
                {
                    stream = fileSystem.OpenFile(asset.AbsolutePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);

                    StreamReader reader = asset.Encoding != null ? new StreamReader(stream, asset.Encoding) : new StreamReader(stream);

                    return reader.ReadToEnd();
                }
                catch (FileNotFoundException)
                {
                    Thread.Sleep(_fileReadRetryDelay);
                }
                catch (IOException)
                {
                    Thread.Sleep(_fileReadRetryDelay);
                }
                catch (UnauthorizedAccessException)
                {
                    Thread.Sleep(_fileReadRetryDelay);
                }
                finally
                {
                    if (stream != null)
                    {
                        stream.Close();
                        stream = null;
                    }
                }
            } while (stopwatch.Elapsed < _fileReadTimeout);

            throw new ApplicationException(String.Format("The timeout of {0} was reached trying to read bundle file '{1}'.", _fileReadTimeout, asset.AbsolutePath));
        }