本文整理汇总了C#中IPackage.GetStream方法的典型用法代码示例。如果您正苦于以下问题:C# IPackage.GetStream方法的具体用法?C# IPackage.GetStream怎么用?C# IPackage.GetStream使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IPackage
的用法示例。
在下文中一共展示了IPackage.GetStream方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddPackage
public void AddPackage(IPackage package)
{
// if the package is already present in the cache, no need to do anything
if (FindPackage(package.Id, package.Version) != null)
{
return;
}
// create the cache directory if it doesn't exist
var cacheDirectory = new DirectoryInfo(Source);
if (!cacheDirectory.Exists)
{
cacheDirectory.Create();
}
// don't want to blow up user's hard drive with too many packages
ClearCache(cacheDirectory, MaxNumberOfPackages);
// now copy the package to the cache
string filePath = GetPackageFilePath(package.Id, package.Version);
using (Stream stream = package.GetStream(),
fileStream = File.Create(filePath))
{
if (stream != null)
{
stream.CopyTo(fileStream);
}
}
}
示例2: CreatePackage
public Package CreatePackage(IPackage nugetPackage, User currentUser)
{
ValidateNuGetPackage(nugetPackage);
var packageRegistration = CreateOrGetPackageRegistration(currentUser, nugetPackage);
var package = CreatePackageFromNuGetPackage(packageRegistration, nugetPackage);
packageRegistration.Packages.Add(package);
using (var tx = new TransactionScope())
{
using (var stream = nugetPackage.GetStream())
{
UpdateIsLatest(packageRegistration);
packageRegistrationRepo.CommitChanges();
packageFileSvc.SavePackageFile(package, stream);
tx.Complete();
}
}
if (package.Status != PackageStatusType.Approved && package.Status != PackageStatusType.Exempted)
{
NotifyForModeration(package, comments: string.Empty);
}
NotifyIndexingService();
return package;
}
示例3: CopyNupkgToTargetPathAsync
protected async Task CopyNupkgToTargetPathAsync(IPackage package)
{
var targetFile = new FileInfo(GetNupkgPath(package));
if (targetFile.Directory != null && !targetFile.Directory.Exists)
{
targetFile.Directory.Create();
}
else if (targetFile.Exists)
{
targetFile.Delete();
}
var fastZipPackage = package as FastZipPackage;
if (fastZipPackage != null)
{
File.Move(fastZipPackage.GetFileLocation(), targetFile.FullName);
fastZipPackage.FileLocation = targetFile.FullName;
return;
}
using (var sourceStream = package.GetStream())
{
using (var targetStream = targetFile.Open(FileMode.Create, FileAccess.Write))
{
await sourceStream.CopyToAsync(targetStream);
}
}
}
示例4: AddPackage
public override void AddPackage(IPackage package)
{
string fileName = PathResolver.GetPackageFileName(package);
using (Stream stream = package.GetStream())
{
FileSystem.AddFile(fileName, stream);
}
}
示例5: AddPackage
public override void AddPackage(IPackage package)
{
//string fileName = PathResolver.GetPackageFileName(package);
string fileName = PathResolver.GetInstallPath(package) + ".nupkg";
using (Stream stream = package.GetStream())
{
FileSystem.AddFile(fileName, stream);
}
}
示例6: RetrieveTemporaryPackageFile
protected string RetrieveTemporaryPackageFile(IPackage package)
{
var temporaryPath = Path.Combine(Path.GetTempPath(), string.Format("{0} {1}.nupkg", package.Id, package.Version));
using (FileStream stream = new FileStream(temporaryPath, FileMode.OpenOrCreate))
{
package.GetStream().CopyTo(stream);
}
return temporaryPath;
}
示例7: PrepareSamplePackage
public void PrepareSamplePackage()
{
package = LoadSamplePackage("Package", "1.0.0");
using (var stream = package.GetStream())
{
packageSize = stream.Length;
}
server = new PackageServer(ServerUrl + "api/packages", "");
}
示例8: AddPackage
public void AddPackage(IPackage package)
{
_logger.Log(MessageLevel.Info, NuGetResources.MirrorCommandPushingPackage, package.GetFullName(), CommandLineUtility.GetSourceDisplayName(_destination.Source));
_destination.PushPackage(
_apiKey,
package,
package.GetStream().Length,
(int)_timeout.TotalMilliseconds,
disableBuffering: false);
_logger.Log(MessageLevel.Info, NuGetResources.MirrorCommandPackagePushed);
}
示例9: PushPackage
public void PushPackage(IPackage package)
{
var timeout = Convert.ToInt32(TimeSpan.FromMinutes(5).TotalMilliseconds);
#if !DEBUG
using (var stream = package.GetStream())
{
var packageSize = stream.Length;
_ps.PushPackage(ApiKey, package, packageSize, timeout, false);
}
#endif
}
示例10: AddPackage
public override void AddPackage(IPackage package)
{
string fileName = PathResolver.GetPackageFileName(package);
if (FileSystem.FileExists(fileName) && !AllowOverrideExistingPackageOnPush)
{
throw new InvalidOperationException(String.Format(NuGetResources.Error_PackageAlreadyExists, package));
}
using (Stream stream = package.GetStream())
{
FileSystem.AddFile(fileName, stream);
}
}
示例11: Add
public void Add(IPackage package)
{
var packageCache = PackageCacheLocation(package);
_fileSystem.EnsureDirectoryExists(packageCache);
var cachedPackagePath = Path.Combine(packageCache, CachedPackageVersionFilename(package.Id, package.Version.ToString()));
if (CachedVersionExistsAndIsUpToDate(package, cachedPackagePath))
{
return;
}
Logger.InfoFormat("Downloading {0} to {1}.", package.Id, package);
File.WriteAllBytes(cachedPackagePath, package.GetStream().ReadAllBytes());
Logger.InfoFormat("Cached {0} to {1}.", package.Id, package);
}
示例12: CopyNupkgToTargetPathAsync
protected async Task CopyNupkgToTargetPathAsync(IPackage package)
{
var targetFile = new FileInfo(GetNupkgPath(package));
if (targetFile.Directory != null && !targetFile.Directory.Exists)
{
targetFile.Directory.Create();
}
using (var sourceStream = package.GetStream())
{
using (var targetStream = targetFile.Open(FileMode.Create, FileAccess.Write))
{
await sourceStream.CopyToAsync(targetStream);
}
}
}
示例13: CreatePackage
public Package CreatePackage(IPackage nugetPackage, User currentUser)
{
ValidateNuGetPackage(nugetPackage);
var packageRegistration = CreateOrGetPackageRegistration(currentUser, nugetPackage);
var package = CreatePackageFromNuGetPackage(packageRegistration, nugetPackage);
packageRegistration.Packages.Add(package);
using (var tx = new TransactionScope())
using (var stream = nugetPackage.GetStream())
{
packageRegistrationRepo.CommitChanges();
packageFileSvc.SavePackageFile(package, stream);
tx.Complete();
}
return package;
}
示例14: AddPackage
public override void AddPackage(IPackage package)
{
// If we exceed the package count then clear the cache.
var files = GetPackageFiles().ToList();
if (files.Count >= MaxPackages)
{
// It's expensive to hit the file system to get the last accessed date for files
// To reduce this cost from occuring frequently, we'll purge packages in batches allowing for a 20% buffer.
var filesToDelete = files.OrderBy(FileSystem.GetLastAccessed)
.Take(files.Count - (int)(0.8 * MaxPackages))
.ToList();
TryClear(filesToDelete);
}
string path = GetPackageFilePath(package);
using (var stream = package.GetStream())
{
TryAct(() => FileSystem.AddFile(path, stream));
}
}
示例15: InstallPackage
public void InstallPackage(IPackage package)
{
var directoryToExpandTo = Path.Combine(_localRepository.Source, package.Id);
foreach (var file in package.GetContentFiles())
{
string pathWithoutContextPrefix = file.Path.Substring("content/".Length);
var fullPath = Path.Combine(directoryToExpandTo, pathWithoutContextPrefix);
Directory.CreateDirectory(Path.GetDirectoryName(fullPath));
using (Stream writeStream = File.OpenWrite(fullPath),
readStream = file.GetStream())
{
readStream.CopyTo(writeStream);
}
}
var packageFile = Path.Combine(directoryToExpandTo, package.GetFullName() + ".nupkg");
using (Stream readStream = package.GetStream(),
writeStream = File.OpenWrite(packageFile))
{
readStream.CopyTo(writeStream);
}
}