public FilePackageJsonSource(string fullPathToFile) {
            if (File.Exists(fullPathToFile)) {
                int retryInterval = 500;
                int attempts = 5;

                // populate _source with retries for recoverable errors.
                while (--attempts >= 0) {
                    try {
                        using (var fin = new FileStream(fullPathToFile, FileMode.Open, FileAccess.Read, FileShare.Read))
                        using (var reader = new StreamReader(fin)) {
                            _source = new ReaderPackageJsonSource(reader);
                            break;
                        }
                    } catch (PackageJsonException pje) {
                        WrapExceptionAndRethrow(fullPathToFile, pje);
                    } catch (IOException) {
                        if (attempts <= 0) { throw; }
                    } catch (UnauthorizedAccessException) {
                        if (attempts <= 0) { throw; }
                    }

                    Thread.Sleep(retryInterval);
                    retryInterval *= 2; // exponential backoff
                }
            }
        }
Exemplo n.º 2
0
        public FilePackageJsonSource(string fullPathToFile)
        {
            if (File.Exists(fullPathToFile))
            {
                int retryInterval = 500;
                int attempts      = 5;

                // populate _source with retries for recoverable errors.
                while (--attempts >= 0)
                {
                    try {
                        using (var fin = new FileStream(fullPathToFile, FileMode.Open, FileAccess.Read, FileShare.Read))
                            using (var reader = new StreamReader(fin)) {
                                _source = new ReaderPackageJsonSource(reader);
                                break;
                            }
                    } catch (PackageJsonException pje) {
                        WrapExceptionAndRethrow(fullPathToFile, pje);
                    } catch (IOException) {
                        if (attempts <= 0)
                        {
                            throw;
                        }
                    } catch (UnauthorizedAccessException) {
                        if (attempts <= 0)
                        {
                            throw;
                        }
                    }

                    Thread.Sleep(retryInterval);
                    retryInterval *= 2; // exponential backoff
                }
            }
        }