本文整理汇总了C#中NuGet.OptimizedZipPackage类的典型用法代码示例。如果您正苦于以下问题:C# OptimizedZipPackage类的具体用法?C# OptimizedZipPackage怎么用?C# OptimizedZipPackage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
OptimizedZipPackage类属于NuGet命名空间,在下文中一共展示了OptimizedZipPackage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: push_package
public static void push_package(ChocolateyConfiguration config, string nupkgFilePath)
{
var timeout = TimeSpan.FromSeconds(Math.Abs(config.PushCommand.TimeoutInSeconds));
if (timeout.Seconds <= 0)
{
timeout = TimeSpan.FromMinutes(5); // Default to 5 minutes
}
const bool disableBuffering = false;
var packageServer = new PackageServer(config.Sources, ApplicationParameters.UserAgent);
packageServer.SendingRequest += (sender, e) => { if (config.Verbose) "chocolatey".Log().Info(ChocolateyLoggers.Verbose, "{0} {1}".format_with(e.Request.Method, e.Request.RequestUri)); };
var package = new OptimizedZipPackage(nupkgFilePath);
try
{
packageServer.PushPackage(
config.PushCommand.Key,
package,
new FileInfo(nupkgFilePath).Length,
Convert.ToInt32(timeout.TotalMilliseconds),
disableBuffering);
}
catch (InvalidOperationException ex)
{
var message = ex.Message;
if (!string.IsNullOrWhiteSpace(message) && message.Contains("(500) Internal Server Error"))
{
throw new ApplicationException("There was an internal server error, which might mean the package already exists on a Simple OData Server.", ex);
}
throw;
}
"chocolatey".Log().Info(ChocolateyLoggers.Important, () => "{0} was pushed successfully to {1}".format_with(package.GetFullName(), config.Sources));
}
示例2: PublishPackage
public void PublishPackage(string file, string apiKey)
{
var packageServer = new PackageServer("https://nuget.org/", "ripple");
var package = new OptimizedZipPackage(file);
RippleLog.Info("Publishing " + file + " with " + apiKey);
packageServer.PushPackage(apiKey, package, (int)60.Minutes().TotalMilliseconds);
}
示例3: PublishPackage
public void PublishPackage(string serverUrl, string file, string apiKey)
{
var packageServer = new PackageServer(serverUrl, "ripple");
var package = new OptimizedZipPackage(file);
RippleLog.Info("Publishing " + file + " with " + apiKey);
try
{
packageServer.PushPackage(apiKey, package, (int) 60.Minutes().TotalMilliseconds);
}
catch (InvalidOperationException ex)
{
if (ex.Message.Contains("already exists"))
{
ConsoleWriter.Write(ConsoleColor.Yellow, "File {0} already exists on the server".ToFormat(file));
}
else
{
ConsoleWriter.Write(ConsoleColor.Red, "File {0} failed!");
ConsoleWriter.Write(ConsoleColor.Red, ex.ToString());
}
}
}
示例4: OpenPackage
protected virtual IPackage OpenPackage(string path)
{
if (!FileSystem.FileExists(path))
{
return null;
}
if (Path.GetExtension(path) == Constants.PackageExtension)
{
OptimizedZipPackage package;
try
{
package = new OptimizedZipPackage(FileSystem, path);
}
catch (FileFormatException ex)
{
throw new InvalidDataException(String.Format(CultureInfo.CurrentCulture, NuGetResources.ErrorReadingPackage, path), ex);
}
// Set the last modified date on the package
package.Published = FileSystem.GetLastModified(path);
return package;
}
else if (Path.GetExtension(path) == Constants.ManifestExtension)
{
if (FileSystem.FileExists(path))
{
return new UnzippedPackage(FileSystem, Path.GetFileNameWithoutExtension(path));
}
}
return null;
}
示例5: should_still_have_the_package_installed_with_the_expected_version_of_the_package
public void should_still_have_the_package_installed_with_the_expected_version_of_the_package()
{
var packageFile = Path.Combine(Scenario.get_top_level(), "lib", Configuration.PackageNames, Configuration.PackageNames + Constants.PackageExtension);
var package = new OptimizedZipPackage(packageFile);
package.Version.Version.to_string().ShouldEqual("1.0.0.0");
}
示例6: should_not_touch_the_floating_dependency
public void should_not_touch_the_floating_dependency()
{
var packageFile = Path.Combine(Scenario.get_top_level(), "lib", "isdependency", "isdependency.nupkg");
var package = new OptimizedZipPackage(packageFile);
package.Version.Version.to_string().ShouldEqual("1.0.0.0");
}
示例7: OpenPackage
protected virtual IPackage OpenPackage(string path)
{
if (FileSystem.FileExists(path))
{
OptimizedZipPackage package;
try
{
package = new OptimizedZipPackage(FileSystem, path);
}
catch (FileFormatException ex)
{
throw new InvalidDataException(String.Format(CultureInfo.CurrentCulture, NuGetResources.ErrorReadingPackage, path), ex);
}
// Set the last modified date on the package
package.Published = FileSystem.GetLastModified(path);
return package;
}
else
{
// if the .nupkg file doesn't exist, fall back to searching for the .nuspec file
var nuspecPath = Path.ChangeExtension(path, Constants.ManifestExtension);
if (FileSystem.FileExists(nuspecPath))
{
return new UnzippedPackage(FileSystem, Path.GetFileNameWithoutExtension(nuspecPath));
}
}
return null;
}
示例8: should_upgrade_the_exact_version_dependency
public void should_upgrade_the_exact_version_dependency()
{
var packageFile = Path.Combine(Scenario.get_top_level(), "lib", "isexactversiondependency", "isexactversiondependency.nupkg");
var package = new OptimizedZipPackage(packageFile);
package.Version.Version.to_string().ShouldEqual("1.0.1.0");
}
示例9: should_install_the_expected_version_of_the_package
public void should_install_the_expected_version_of_the_package()
{
var packageFile = Path.Combine(Scenario.get_top_level(), "lib", "installpackage", "installpackage" + Constants.PackageExtension);
var package = new OptimizedZipPackage(packageFile);
package.Version.Version.to_string().ShouldEqual("1.0.0.0");
}
示例10: install_run
public ConcurrentDictionary<string, PackageResult> install_run(ChocolateyConfiguration config, Action<PackageResult> continueAction)
{
_fileSystem.create_directory_if_not_exists(ApplicationParameters.PackagesLocation);
var packageInstalls = new ConcurrentDictionary<string, PackageResult>(StringComparer.InvariantCultureIgnoreCase);
//todo: handle all
SemanticVersion version = config.Version != null ? new SemanticVersion(config.Version) : null;
IList<string> packageNames = config.PackageNames.Split(new[] { ApplicationParameters.PackageNamesSeparator }, StringSplitOptions.RemoveEmptyEntries).or_empty_list_if_null().ToList();
if (packageNames.Count == 1)
{
var packageName = packageNames.DefaultIfEmpty(string.Empty).FirstOrDefault();
if (packageName.EndsWith(Constants.PackageExtension) || packageName.EndsWith(Constants.ManifestExtension))
{
this.Log().Debug("Updating source and package name to handle *.nupkg or *.nuspec file.");
packageNames.Clear();
config.Sources = _fileSystem.get_directory_name(_fileSystem.get_full_path(packageName));
if (packageName.EndsWith(Constants.ManifestExtension))
{
packageNames.Add(_fileSystem.get_file_name_without_extension(packageName));
this.Log().Debug("Building nuspec file prior to install.");
config.Input = packageName;
// build package
pack_run(config);
}
else
{
var packageFile = new OptimizedZipPackage(_fileSystem.get_full_path(packageName));
packageNames.Add(packageFile.Id);
}
}
}
// this is when someone points the source directly at a nupkg
// e.g. -source c:\somelocation\somewhere\packagename.nupkg
if (config.Sources.to_string().EndsWith(Constants.PackageExtension))
{
config.Sources = _fileSystem.get_directory_name(_fileSystem.get_full_path(config.Sources));
}
var packageManager = NugetCommon.GetPackageManager(
config, _nugetLogger,
installSuccessAction: (e) =>
{
var pkg = e.Package;
var packageResult = packageInstalls.GetOrAdd(pkg.Id.to_lower(), new PackageResult(pkg, e.InstallPath));
packageResult.InstallLocation = e.InstallPath;
packageResult.Messages.Add(new ResultMessage(ResultType.Debug, ApplicationParameters.Messages.ContinueChocolateyAction));
if (continueAction != null) continueAction.Invoke(packageResult);
},
uninstallSuccessAction: null,
addUninstallHandler: true);
foreach (string packageName in packageNames.or_empty_list_if_null())
{
//todo: get smarter about realizing multiple versions have been installed before and allowing that
remove_rollback_directory_if_exists(packageName);
IPackage installedPackage = packageManager.LocalRepository.FindPackage(packageName);
if (installedPackage != null && (version == null || version == installedPackage.Version) && !config.Force)
{
string logMessage = "{0} v{1} already installed.{2} Use --force to reinstall, specify a version to install, or try upgrade.".format_with(installedPackage.Id, installedPackage.Version, Environment.NewLine);
var nullResult = packageInstalls.GetOrAdd(packageName, new PackageResult(installedPackage, _fileSystem.combine_paths(ApplicationParameters.PackagesLocation, installedPackage.Id)));
nullResult.Messages.Add(new ResultMessage(ResultType.Warn, logMessage));
nullResult.Messages.Add(new ResultMessage(ResultType.Inconclusive, logMessage));
this.Log().Warn(ChocolateyLoggers.Important, logMessage);
continue;
}
if (installedPackage != null && (version == null || version == installedPackage.Version) && config.Force)
{
this.Log().Debug(() => "{0} v{1} already installed. Forcing reinstall.".format_with(installedPackage.Id, installedPackage.Version));
version = installedPackage.Version;
}
if (installedPackage != null && version != null && version < installedPackage.Version && !config.AllowMultipleVersions && !config.AllowDowngrade)
{
string logMessage = "A newer version of {0} (v{1}) is already installed.{2} Use --allow-downgrade to attempt to install older versions, or use side by side to allow multiple versions.".format_with(installedPackage.Id, installedPackage.Version, Environment.NewLine);
var nullResult = packageInstalls.GetOrAdd(packageName, new PackageResult(installedPackage, _fileSystem.combine_paths(ApplicationParameters.PackagesLocation, installedPackage.Id)));
nullResult.Messages.Add(new ResultMessage(ResultType.Error, logMessage));
this.Log().Error(ChocolateyLoggers.Important, logMessage);
continue;
}
IPackage availablePackage = packageManager.SourceRepository.FindPackage(packageName, version, config.Prerelease, allowUnlisted: false);
if (availablePackage == null)
{
var logMessage = "{0} not installed. The package was not found with the source(s) listed.{1} If you specified a particular version and are receiving this message, it is possible that the package name exists but the version does not.{1} Version: \"{2}\"{1} Source(s): \"{3}\"".format_with(packageName, Environment.NewLine, config.Version, config.Sources);
this.Log().Error(ChocolateyLoggers.Important, logMessage);
var noPkgResult = packageInstalls.GetOrAdd(packageName, new PackageResult(packageName, version.to_string(), null));
noPkgResult.Messages.Add(new ResultMessage(ResultType.Error, logMessage));
continue;
}
//.........这里部分代码省略.........
示例11: Upload
public async Task<IHttpActionResult> Upload()
{
if (!Request.Content.IsMimeMultipartContent())
throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
var provider = new MultipartMemoryStreamProvider();
await Request.Content.ReadAsMultipartAsync(provider);
string output = null;
foreach (var file in provider.Contents)
{
var filename = file.Headers.ContentDisposition.FileName.Trim('\"');
if (!Directory.Exists(_sourcePath))
Directory.CreateDirectory(_sourcePath);
var path = Path.Combine(_sourcePath, filename);
using (var stream = File.Create(path))
{
var s = await file.ReadAsByteArrayAsync();
await stream.WriteAsync(s, 0, s.Length);
}
if (!PackageHelper.IsPackageFile(path))
{
var ex = new Exception("File is not a package!");
Log.Error(ex);
return InternalServerError(ex);
}
var pkg = new OptimizedZipPackage(path);
try
{
await pkg.Uninstall(_sourcePath, _deployOption.InstallPath);
}
catch (InvalidOperationException ex)
{
Log.Error(ex);
if (!ex.Message.StartsWith("Unable to find package"))
throw;
}
catch (TimeoutException ex)
{
Log.Error(ex);
}
catch (Exception ex)
{
Log.Error(ex);
return InternalServerError(ex);
}
string installPath;
try
{
installPath = await pkg.Install(_sourcePath, _deployOption.InstallPath);
}
catch (Exception ex)
{
Log.Error(ex);
return InternalServerError(ex);
}
string deployScript;
if ((deployScript = await pkg.GetDeployScript()) != null)
{
var args = new ListDictionary
{
{"installPath", installPath},
{"toolsPath", Path.Combine(installPath, "tools")},
{"package", pkg},
{"project", null}
};
if (!Script.Execute(deployScript, args, ref output))
{
var ex = new Exception(output);
Log.Error(ex);
return InternalServerError(ex);
}
}
}
Log.InfoFormat("Deploy success: {0}", output);
return Ok(output);
}
示例12: OpenPackage
private OptimizedZipPackage OpenPackage(string path)
{
OptimizedZipPackage zip = null;
if (_fileSystem.FileExists(path))
{
try
{
zip = new OptimizedZipPackage(_fileSystem, path);
}
catch (FileFormatException ex)
{
throw new InvalidDataException(String.Format(CultureInfo.CurrentCulture, NuGetResources.ErrorReadingPackage, path), ex);
}
// Set the last modified date on the package
zip.Published = _fileSystem.GetLastModified(path);
}
return zip;
}
示例13: PublishPackage
public IPublishReportItem PublishPackage(string serverUrl, string file, string apiKey)
{
var packageServer = new PackageServer(serverUrl, "ripple");
var package = new OptimizedZipPackage(file);
RippleLog.Info("Publishing " + file + " with " + apiKey);
try
{
var info = new FileInfo(file);
packageServer.PushPackage(apiKey, package, info.Length, (int)60.Minutes().TotalMilliseconds);
return new PublishSuccessful(package);
}
catch (Exception ex)
{
// TODO -- Hate this
if (ex.Message.Contains("exists"))
{
return new VersionAlreadyExists(package);
}
return new PublishFailure(package, ex);
}
}
示例14: OpenPackage
protected override IPackage OpenPackage(string path)
{
OptimizedZipPackage package;
try
{
package = new OptimizedZipPackage(FileSystem, path);
}
catch (FileFormatException ex)
{
throw new InvalidDataException(String.Format(CultureInfo.CurrentCulture, NuGetResources.ErrorReadingPackage, path), ex);
}
return package;
}
示例15: should_have_the_erroring_upgraded_package_in_the_lib_bad_directory
public void should_have_the_erroring_upgraded_package_in_the_lib_bad_directory()
{
var packageFile = Path.Combine(Scenario.get_top_level(), "lib-bad", Configuration.PackageNames, Configuration.PackageNames + Constants.PackageExtension);
var package = new OptimizedZipPackage(packageFile);
package.Version.Version.to_string().ShouldEqual("2.0.0.0");
}