本文整理汇总了C#中Request.YieldSoftwareIdentity方法的典型用法代码示例。如果您正苦于以下问题:C# Request.YieldSoftwareIdentity方法的具体用法?C# Request.YieldSoftwareIdentity怎么用?C# Request.YieldSoftwareIdentity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Request
的用法示例。
在下文中一共展示了Request.YieldSoftwareIdentity方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FindPackageByFile
/// <summary>
/// Finds packages given a locally-accessible filename
/// Package information must be returned using <c>request.YieldPackage(...)</c> function.
/// </summary>
/// <param name="file">the full path to the file to determine if it is a package</param>
/// <param name="id">
/// if this is greater than zero (and the number should have been generated using <c>StartFind(...)</c>,
/// the core is calling this multiple times to do a batch search request. The operation can be delayed until
/// <c>CompleteFind(...)</c> is called
/// </param>
/// <param name="request">
/// An object passed in from the CORE that contains functions that can be used to interact with
/// the CORE and HOST
/// </param>
public void FindPackageByFile(string file, int id, Request request)
{
if( request == null ) {
throw new ArgumentNullException("request");
}
if( string.IsNullOrWhiteSpace(file) ) {
throw new ArgumentNullException("file");
}
// Nice-to-have put a debug message in that tells what's going on.
request.Debug("Calling '{0}::FindPackageByFile' '{1}','{2}'", ProviderName, file, id);
if (file.FileExists())
{
var info = new CabInfo(file);
request.YieldSoftwareIdentity(file, info.Name, null, null, null, null, null, file, info.Name);
var files = info.GetFiles();
foreach (var i in files) {
// read the properties file
if (i.FullNameExtension == ".txt")
{
request.Debug("Reading properties file {0}", i.FullName);
using (var reader = i.OpenText())
{
var contents = reader.ReadToEnd();
Dictionary<string, string> keyValuePairs = contents.Split('\n').Select(line => line.Split('=')).Where(v => v.Count() == 2).ToDictionary(pair => pair[0], pair => pair[1]);
foreach (var pair in keyValuePairs)
{
request.AddMetadata(pair.Key.Replace(' ', '_'), pair.Value.Replace("\"", "").Replace("\r", ""));
}
}
}
}
}
}
示例2: UninstallPackage
/// <summary>
/// Uninstalls a package
/// </summary>
/// <param name="fastPackageReference"></param>
/// <param name="request">An object passed in from the CORE that contains functions that can be used to interact with the CORE and HOST</param>
public void UninstallPackage(string fastPackageReference, Request request)
{
// TODO: improve this debug message that tells us what's going on (what about the dynamic parameters)
var parts = fastPackageReference.Split(RequestHelper.NullChar);
request.Debug("Entering '{0}::UninstallPackage' '{1}'", PackageProviderName, [email protected]("' '"));
// TODO: add dynamic parameters for AllVersions and ForceDependencies
foreach (var package in _chocolatey.Set(conf =>
{
conf.CommandName = "Uninstall";
//conf.Sources = parts[0];
conf.PackageNames = parts[1];
conf.Version = parts[2];
}).List<PackageResult>())
{
request.YieldSoftwareIdentity(package);
}
}
示例3: FindPackageByFile
/*
/// <summary>
/// Finds packages given a locally-accessible filename
///
/// Package information must be returned using <c>request.YieldPackage(...)</c> function.
/// </summary>
/// <param name="file">the full path to the file to determine if it is a package</param>
/// <param name="id">if this is greater than zero (and the number should have been generated using <c>StartFind(...)</c>, the core is calling this multiple times to do a batch search request. The operation can be delayed until <c>CompleteFind(...)</c> is called</param>
/// <param name="request">An object passed in from the CORE that contains functions that can be used to interact with the CORE and HOST</param>
public void FindPackageByFile(string file, int id, Request request)
{
// TODO: improve this debug message that tells us what's going on.
request.Debug("Entering '{0}::FindPackageByFile' '{1}','{2}'", PackageProviderName, file, id);
// TODO: implement searching for a package by analyzing the package file, or remove this method
}
/// <summary>
/// Finds packages given a URI.
///
/// The function is responsible for downloading any content required to make this work
///
/// Package information must be returned using <c>request.YieldPackage(...)</c> function.
/// </summary>
/// <param name="uri">the URI the client requesting a package for.</param>
/// <param name="id">if this is greater than zero (and the number should have been generated using <c>StartFind(...)</c>, the core is calling this multiple times to do a batch search request. The operation can be delayed until <c>CompleteFind(...)</c> is called</param>
/// <param name="request">An object passed in from the CORE that contains functions that can be used to interact with the CORE and HOST</param>
public void FindPackageByUri(Uri uri, int id, Request request)
{
// TODO: improve this debug message that tells us what's going on.
request.Debug("Entering '{0}::FindPackageByUri' '{1}','{2}'", PackageProviderName, uri, id);
// TODO: implement searching for a package by it's unique uri (or remove this method)
}
/// <summary>
/// Downloads a remote package file to a local location.
/// </summary>
/// <param name="fastPackageReference"></param>
/// <param name="location"></param>
/// <param name="request">An object passed in from the CORE that contains functions that can be used to interact with the CORE and HOST</param>
public void DownloadPackage(string fastPackageReference, string location, Request request)
{
// TODO: improve this debug message that tells us what's going on.
request.Debug("Entering '{0}::DownloadPackage' '{1}','{2}'", PackageProviderName, fastPackageReference, location);
// TODO: actually download the package ...
}
/// <summary>
/// Returns package references for all the dependent packages
/// </summary>
/// <param name="fastPackageReference"></param>
/// <param name="request">An object passed in from the CORE that contains functions that can be used to interact with the CORE and HOST</param>
public void GetPackageDependencies(string fastPackageReference, Request request)
{
// TODO: improve this debug message that tells us what's going on.
request.Debug("Entering '{0}::GetPackageDependencies' '{1}'", PackageProviderName, fastPackageReference);
// TODO: check dependencies
}
*/
/// <summary>
/// Installs a given package.
/// </summary>
/// <param name="fastPackageReference">A provider supplied identifier that specifies an exact package</param>
/// <param name="request">An object passed in from the CORE that contains functions that can be used to interact with the CORE and HOST</param>
public void InstallPackage(string fastPackageReference, Request request)
{
request.Debug("Entering '{0}::InstallPackage' '{1}'", PackageProviderName, fastPackageReference);
var parts = fastPackageReference.Split(RequestHelper.NullChar);
var force = false;
var forceStr = request.GetOptionValue("Force");
if (!string.IsNullOrEmpty(forceStr))
{
bool.TryParse(forceStr, out force);
}
foreach (var package in _chocolatey.Set(conf =>
{
conf.CommandName = "Install";
conf.Sources = GetSource(parts[0]).Select(cs => cs.Value)[email protected](";");
conf.PackageNames = parts[1];
conf.Version = parts[2];
conf.AllowUnofficialBuild = true;
conf.Force = force;
}).List<PackageResult>())
{
request.YieldSoftwareIdentity(package);
}
}
示例4: GetInstalledPackages
/// <summary>
/// Returns the packages that are installed
/// </summary>
/// <param name="name">the package name to match. Empty or null means match everything</param>
/// <param name="requiredVersion">the specific version asked for. If this parameter is specified (ie, not null or empty string) then the minimum and maximum values are ignored</param>
/// <param name="minimumVersion">the minimum version of packages to return . If the <code>requiredVersion</code> parameter is specified (ie, not null or empty string) this should be ignored</param>
/// <param name="maximumVersion">the maximum version of packages to return . If the <code>requiredVersion</code> parameter is specified (ie, not null or empty string) this should be ignored</param>
/// <param name="request">
/// An object passed in from the CORE that contains functions that can be used to interact with
/// the CORE and HOST
/// </param>
public void GetInstalledPackages(string name, string requiredVersion, string minimumVersion, string maximumVersion, Request request)
{
// TODO: improve this debug message that tells us what's going on.
request.Debug("Entering '{0}::GetInstalledPackages' '{1}' '{2}' '{3}' '{4}'", PackageProviderName, name, requiredVersion, minimumVersion, maximumVersion);
var versions = ParseVersion(requiredVersion, minimumVersion, maximumVersion);
foreach (var package in _chocolatey.Set(conf =>
{
conf.CommandName = "List";
conf.Input = name;
conf.ListCommand.LocalOnly = true;
conf.AllowUnofficialBuild = true;
}).List<PackageResult>())
{
SemanticVersion actual;
if (SemanticVersion.TryParse(package.Version, out actual) && (actual < versions.Item1 || actual > versions.Item2))
{
continue;
}
request.YieldSoftwareIdentity(package);
}
}
示例5: FindPackage
/// <summary>
/// Searches package sources given name and version information
///
/// Package information must be returned using <c>request.YieldPackage(...)</c> function.
/// </summary>
/// <param name="name">a name or partial name of the package(s) requested</param>
/// <param name="requiredVersion">A specific version of the package. Null or empty if the user did not specify</param>
/// <param name="minimumVersion">A minimum version of the package. Null or empty if the user did not specify</param>
/// <param name="maximumVersion">A maximum version of the package. Null or empty if the user did not specify</param>
/// <param name="id">if this is greater than zero (and the number should have been generated using <c>StartFind(...)</c>, the core is calling this multiple times to do a batch search request. The operation can be delayed until <c>CompleteFind(...)</c> is called</param>
/// <param name="request">An object passed in from the CORE that contains functions that can be used to interact with the CORE and HOST</param>
public void FindPackage(string name, string requiredVersion, string minimumVersion, string maximumVersion, int id, Request request)
{
request.Debug("Entering '{0}::FindPackage' '{1}','{2}','{3}','{4}', '{5}'", PackageProviderName, name, requiredVersion, minimumVersion, maximumVersion, id);
request.Debug("FindPackage:: " + [email protected]("|"));
var versions = ParseVersion(requiredVersion, minimumVersion, maximumVersion);
var sources = GetSource(request.PackageSources.ToArray());
// TODO: need to support URLs for sources ...
foreach(var package in _chocolatey.Set(conf =>
{
conf.CommandName = "List";
conf.Input = name;
conf.Sources = sources.Select(cs => cs.Value)[email protected](";");
conf.Version = requiredVersion;
conf.AllowUnofficialBuild = true;
}).List<PackageResult>())
{
SemanticVersion actual;
if (SemanticVersion.TryParse(package.Version, out actual) && (actual < versions.Item1 || actual > versions.Item2))
{
continue;
}
request.YieldSoftwareIdentity(package);
}
}
示例6: Yield
internal void Yield(Request request, string searchKey)
{
request.YieldSoftwareIdentity(fastPath, name, version, versionScheme, summary, source, searchKey, fullPath, packageFileName);
}
示例7: YieldPackage
private bool YieldPackage(ProductInstallation package, string searchKey, Request request) {
if (request.YieldSoftwareIdentity(package.ProductCode, package.ProductName, package.ProductVersion.ToString(), "multipartnumeric", package["Summary"], package.InstallSource, searchKey, package.InstallLocation, "?") != null) {
if (request.AddMetadata(package.ProductCode, "ProductCode", package.ProductCode) == null) {
return false;
}
if (request.AddMetadata(package.ProductCode, "UpgradeCode", package["UpgradeCode"]) == null) {
return false;
}
return true;
}
return false;
}
示例8: UninstallPackage
/// <summary>
/// Uninstalls a package
/// </summary>
/// <param name="fastPackageReference"></param>
/// <param name="request">
/// An object passed in from the CORE that contains functions that can be used to interact with
/// the CORE and HOST
/// </param>
public void UninstallPackage(string fastPackageReference, Request request) {
if( request == null ) {
throw new ArgumentNullException("request");
}
if( string.IsNullOrWhiteSpace(fastPackageReference) ) {
throw new ArgumentNullException("fastPackageReference");
}
// Nice-to-have put a debug message in that tells what's going on.
request.Debug("Calling '{0}::UninstallPackage' '{1}'", ProviderName, fastPackageReference);
try {
Guid guid;
if (!Guid.TryParse(fastPackageReference, out guid)) {
request.Error(ErrorCategory.InvalidArgument, fastPackageReference, Constants.Messages.UnableToResolvePackage, fastPackageReference);
return;
}
var product = ProductInstallation.GetProducts(fastPackageReference, null, UserContexts.All).FirstOrDefault();
if (product == null) {
request.Error(ErrorCategory.InvalidArgument, fastPackageReference, Constants.Messages.UnableToResolvePackage, fastPackageReference);
return;
}
var productVersion = product.ProductVersion.ToString();
var productName = product.ProductName;
var summary = product["Summary"];
Installer.SetInternalUI(InstallUIOptions.UacOnly | InstallUIOptions.Silent);
_progressId = request.StartProgress(0, "Uninstalling MSI '{0}'", productName);
var handler = CreateProgressHandler(request);
Installer.SetExternalUI(handler, InstallLogModes.Progress | InstallLogModes.Info);
Installer.InstallProduct(product.LocalPackage, "REMOVE=ALL REBOOT=REALLYSUPPRESS");
Installer.SetInternalUI(InstallUIOptions.Default);
Installer.SetExternalUI(handler, InstallLogModes.None);
// YieldPackage(product,fastPackageReference, request);
if (request.YieldSoftwareIdentity(fastPackageReference, productName, productVersion, "multipartnumeric", summary, "", fastPackageReference, "", "") != null) {
request.AddMetadata(fastPackageReference, "ProductCode", fastPackageReference);
}
request.Warning("Reboot is required to complete uninstallation.");
} catch (Exception e) {
e.Dump();
}
request.CompleteProgress(_progressId, true);
_progressId = 0;
}
示例9: YieldPackage
/// <summary>
/// Yields package information to OneGet Core
/// </summary>
/// <param name="searchKey"></param>
/// <param name="request"></param>
/// <param name="title"></param>
/// <param name="supportUrl"></param>
/// <param name="date"></param>
/// <param name="resultCode"></param>
/// <param name="description"></param>
/// <returns>Whether operation succeeded or was interrupted</returns>
private bool YieldPackage(string searchKey, Request request, string title, string supportUrl, DateTime? date, int? resultCode, string description)
{
if (request.YieldSoftwareIdentity(title, title, null, null, description, null, searchKey, "?", "?") != null)
{
if (request.AddMetadata("SupportUrl", supportUrl) == null)
{
return false;
}
if (date != null && request.AddMetadata("Date", ((DateTime)date).ToString(CultureInfo.CurrentCulture)) == null)
{
return false;
}
if (resultCode != null && request.AddMetadata("ResultCode", resultCode.ToString()) == null)
{
return false;
}
return true;
}
return false;
}
示例10: YieldPackage
private bool YieldPackage(string path, string searchKey, Dictionary<string, string> properties, Request request) {
var productName = properties.Get("DisplayName") ?? "";
var productVersion = properties.Get("DisplayVersion") ?? "";
var publisher = properties.Get("Publisher") ?? "";
var uninstallString = properties.Get("QuietUninstallString") ?? properties.Get("UninstallString") ?? "";
var comments = properties.Get("Comments") ?? "";
if (request.YieldSoftwareIdentity(path, productName, productVersion, "unknown", comments, "", searchKey, "", "") != null) {
if (properties.Keys.Where(each => !string.IsNullOrWhiteSpace(each)).Any(k => request.AddMetadata(path, k.MakeSafeFileName(), properties[k]) == null)) {
return false;
}
}
return true;
}
示例11: YieldPackages
private bool YieldPackages(string hive, RegistryKey regkey, string name,string requiredVersion, string minimumVersion, string maximumVersion, Request request) {
if (regkey != null) {
var includeWindowsInstaller = request.GetOptionValue("IncludeWindowsInstaller").IsTrue();
var includeSystemComponent = request.GetOptionValue("IncludeSystemComponent").IsTrue();
foreach (var key in regkey.GetSubKeyNames()) {
var subkey = regkey.OpenSubKey(key);
if (subkey != null) {
var properties = subkey.GetValueNames().ToDictionaryNicely(each => each.ToString(), each => (subkey.GetValue(each) ?? string.Empty).ToString(), StringComparer.OrdinalIgnoreCase);
if (!includeWindowsInstaller && properties.ContainsKey("WindowsInstaller") && properties["WindowsInstaller"] == "1") {
continue;
}
if (!includeSystemComponent && properties.ContainsKey("SystemComponent") && properties["SystemComponent"] == "1") {
continue;
}
var productName = "";
if (!properties.TryGetValue("DisplayName", out productName)) {
// no product name?
continue;
}
if (string.IsNullOrWhiteSpace(name) || productName.IndexOf(name, StringComparison.OrdinalIgnoreCase) > -1) {
var productVersion = properties.Get("DisplayVersion") ?? "";
var publisher = properties.Get("Publisher") ?? "";
var uninstallString = properties.Get("QuietUninstallString") ?? properties.Get("UninstallString") ?? "";
var comments = properties.Get("Comments") ?? "";
var fp = hive + @"\" + subkey;
if (!string.IsNullOrEmpty(requiredVersion)) {
if (SoftwareIdentityVersionComparer.CompareVersions("unknown", requiredVersion, productVersion) != 0) {
continue;
}
} else {
if (!string.IsNullOrEmpty(minimumVersion) && SoftwareIdentityVersionComparer.CompareVersions("unknown", productVersion, minimumVersion) < 0) {
continue;
}
if (!string.IsNullOrEmpty(maximumVersion) && SoftwareIdentityVersionComparer.CompareVersions("unknown", productVersion, maximumVersion) > 0) {
continue;
}
}
if (request.YieldSoftwareIdentity(fp, productName, productVersion, "unknown", comments, "", name, "", "") != null) {
if (properties.Keys.Where(each => !string.IsNullOrWhiteSpace(each)).Any(k => request.AddMetadata(fp, k.MakeSafeFileName(), properties[k]) == null)) {
return false;
}
}
}
}
}
}
return true;
}
示例12: FindPackage
public void FindPackage(string name, string requiredVersion, string minimumVersion, string maximumVersion, int id, Request request)
{
// Nice-to-have put a debug message in that tells what's going on.
request.Debug("Calling '{0}::FindPackage' '{1}','{2}','{3}','{4}','{5}'", PackageProviderName, name, requiredVersion, minimumVersion, maximumVersion, id);
var supplySourceToChainedProvider = new object[] {
new {
GetSources = new Func<IEnumerable<string>>(() => new string[] {"http://nuget.org/api/v2"})
}
, request
};
if (string.IsNullOrEmpty(name) || name == "zlib") {
var pkgs = request.ProviderServices.FindPackageByCanonicalId("nuget:zlib/1.2.8.7", supplySourceToChainedProvider).ToArray();
if (pkgs.Length > 0) {
var p = pkgs[0];
request.YieldSoftwareIdentity("zlib", p.Name, p.Version, p.VersionScheme, p.Summary, "built-in", "zlib", "", "");
foreach (var d in p.Dependencies) {
request.AddDependency(PackageProviderName, request.ProviderServices.ParsePackageName(d), request.ProviderServices.ParsePackageVersion(d), "built-in", null);
}
}
}
if (!string.IsNullOrEmpty(name) && name == "zlib.redist" && requiredVersion == "1.2.8.7") {
var pkgs = request.ProviderServices.FindPackageByCanonicalId("nuget:zlib.redist/1.2.8.7", supplySourceToChainedProvider).ToArray();
if (pkgs.Length > 0) {
var p = pkgs[0];
request.YieldSoftwareIdentity("zlib.redist", p.Name, p.Version, p.VersionScheme, p.Summary, "built-in", "zlib", "", "");
foreach (var d in p.Dependencies) {
request.AddDependency(PackageProviderName, request.ProviderServices.ParsePackageName(d), request.ProviderServices.ParsePackageVersion(d), "built-in", null);
}
}
}
}
示例13: FindPackage
public void FindPackage(string name, string requiredVersion, string minimumVersion, string maximumVersion, int id, Request request)
{
// Nice-to-have put a debug message in that tells what's going on.
request.Debug("Calling '{0}::FindPackage' '{1}','{2}','{3}','{4}'", PackageProviderName, requiredVersion, minimumVersion, maximumVersion, id);
if (name == "test") {
// this just returns packages so we can test the calls for creating software identity objects back in the core.
var pkg = request.YieldSoftwareIdentity("firstpackage", "first", "1.0", "multipartnumeric", "first package", "built-in", "test", "", "");
if (pkg != null) {
if (request.IsCanceled) {
return;
} // check early, check often.
// add a dependency to another package.
var link = request.AddDependency(PackageProviderName, "second", "1.1", null, null);
if (request.IsCanceled) {
return;
} // check early, check often.
var entity = request.AddEntity("garrett", "http://fearthecowboy.com", Iso19770_2.Role.Publisher, null);
if (request.IsCanceled) {
return;
} // check early, check often.
var icon = request.AddLink(new Uri("http://contoso.com/icon.png"), "icon", "image/icon", null, null, null, null);
if (request.IsCanceled) {
return;
} // check early, check often.
request.AddMetadata("Something", "Shiny");
request.AddMetadata(pkg, "SomeKey", "SomeValue");
request.AddMetadata(pkg, new Uri("http://oneget.org/oneget"), "testkey", "testvalue");
if (request.IsCanceled) {
return;
} // check early, check often.
// some expected payload data
var payload = request.AddPayload();
request.Debug("Payload:{0}", payload);
if (request.IsCanceled) {
return;
} // check early, check often.
var dir = request.AddDirectory(payload, "installDir", "", "PROGRAMFILES", false);
request.Debug("Directory:{0}", dir);
if (request.IsCanceled) {
return;
} // check early, check often.
var file = request.AddFile(dir, "foo.txt", null, null, true, 10240, "1.0");
request.Debug("File:{0}", file);
if (request.IsCanceled) {
return;
} // check early, check often.
var regkey = request.AddResource(payload, "regkey");
request.AddMetadata(regkey, "key", "hklm/software/testing/foo");
request.AddMetadata(regkey, "value", "hklm/software/testing/foo");
if (request.IsCanceled) {
return;
} // check early, check often.
}
pkg = request.YieldSoftwareIdentity("secondpackage", "second", "1.1", "multipartnumeric", "second package", "built-in", "test", "", "");
if (pkg != null) {
if (request.IsCanceled) {
return;
} // check early, check often.
var entity = request.AddEntity("garrett", "http://fearthecowboy.com", Iso19770_2.Role.Publisher, null);
if (request.IsCanceled) {
return;
} // check early, check often.
// show some evidence (yeah, this should have been in the getinstalledpackages but ... lazy.)
var evidence = request.AddEvidence(DateTime.Now, "thispc");
request.AddProcess(evidence, "foo.exe", 100);
var meta = request.AddMeta(pkg);
request.AddMetadata(meta, "sample", "value");
request.AddMetadata(meta, new Uri("http://oneget.org/oneget"), "testkey", "testvalue");
var link = request.AddDependency(PackageProviderName, "third", "[1.0]", null, null);
}
}
}