本文整理汇总了C#中Request.GetOptionValue方法的典型用法代码示例。如果您正苦于以下问题:C# Request.GetOptionValue方法的具体用法?C# Request.GetOptionValue怎么用?C# Request.GetOptionValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Request
的用法示例。
在下文中一共展示了Request.GetOptionValue方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddPackageSource
public void AddPackageSource(string name, string location, bool trusted, Request request)
{
// Nice-to-have put a debug message in that tells what's going on.
request.Debug("Calling '{0}::AddPackageSource' '{1}','{2}','{3}'", PackageProviderName, name, location, trusted);
var pkgSource = packageSources.FirstOrDefault(each => each.name.EqualsIgnoreCase(name));
if (pkgSource != null && !request.GetOptionValue(Constants.Parameters.IsUpdate).IsTrue()) {
// pkgSource already exists.
// this is an error.
request.Error(ErrorCategory.ResourceExists, name, Constants.Messages.PackageSourceExists, name);
return;
}
if (pkgSource != null) {
//update
pkgSource.location = location;
pkgSource.isTrusted = trusted;
} else {
// add new
pkgSource = new PkgSource {
name = name,
location = location,
isTrusted = trusted,
isValidated = true
};
// add to the array.
packageSources = packageSources.ConcatSingleItem(pkgSource).ToArray();
}
request.YieldPackageSource(pkgSource.name, pkgSource.location, pkgSource.isTrusted, true, pkgSource.isValidated);
}
示例2: 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);
}
}
示例3: 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;
}