/// <summary> /// Returns a stream backed by the specified package if it exists; otherwise returns null. /// </summary> /// <param name="packageId">The ID of the package.</param> /// <param name="packageVersion">The version of the package.</param> /// <returns>Stream backed by the specified package if it exists; otherwise null.</returns> /// <exception cref="ArgumentNullException"><paramref name="packageId"/> is null or contains only whitespace or <paramref name="packageVersion"/> is null.</exception> public override Stream OpenPackage(string packageId, SemanticVersion packageVersion) { if (string.IsNullOrWhiteSpace(packageId)) { throw new ArgumentNullException("packageId"); } if (packageVersion == null) { throw new ArgumentNullException("packageVersion"); } InitPackageStore(); _logger.Debug("OpenPackage('" + packageId + "', '" + packageVersion + "') called"); var packagePath = Path.Combine(RootPath, packageId); if (!_fileSystemOperations.DirectoryExists(packagePath)) { _logger.Warn("Attempted to open package '" + packageId + "', version '" + packageVersion + "', in folder '" + packagePath + "' but the folder didn't exist"); return(null); } var versionPath = Path.Combine(packagePath, packageId + "." + packageVersion + ".nupkg"); if (!_fileSystemOperations.FileExists(versionPath)) { _logger.Warn("Attempted to open package '" + packageId + "', version '" + packageVersion + "', at path '" + versionPath + "' but it didn't exist"); return(null); } try { return(_fileSystemOperations.GetFileStream(versionPath, FileMode.Open, FileAccess.Read, FileShare.Read | FileShare.Delete)); } catch (FileNotFoundException ex) { _logger.Error("File not found error looking for package '" + packageId + "', version '" + packageVersion + "'.", ex); return(null); } catch (DirectoryNotFoundException ex) { _logger.Error("Directory not found error looking for package '" + packageId + "', version '" + packageVersion + "'.", ex); return(null); } }