本文整理汇总了C#中CommandOrigin类的典型用法代码示例。如果您正苦于以下问题:C# CommandOrigin类的具体用法?C# CommandOrigin怎么用?C# CommandOrigin使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CommandOrigin类属于命名空间,在下文中一共展示了CommandOrigin类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExecCommandThatDependsOnSelectedNodes
/// <summary>
/// Executes a command that can only be executed once the whole selection is known.
/// </summary>
/// <param name="cmdGroup">Unique identifier of the command group</param>
/// <param name="cmdId">The command to be executed.</param>
/// <param name="cmdExecOpt">Values describe how the object should execute the command.</param>
/// <param name="vaIn">Pointer to a VARIANTARG structure containing input arguments. Can be NULL</param>
/// <param name="vaOut">VARIANTARG structure to receive command output. Can be NULL.</param>
/// <param name="commandOrigin">The origin of the command. From IOleCommandTarget or hierarchy.</param>
/// <param name="selectedNodes">The list of the selected nodes.</param>
/// <param name="handled">An out parameter specifying that the command was handled.</param>
/// <returns>If the method succeeds, it returns S_OK. If it fails, it returns an error code.</returns>
protected virtual int ExecCommandThatDependsOnSelectedNodes(Guid cmdGroup, uint cmdId, uint cmdExecOpt, IntPtr vaIn, IntPtr vaOut, CommandOrigin commandOrigin, IList<HierarchyNode> selectedNodes, out bool handled) {
handled = false;
if (cmdGroup == VsMenus.guidVsUIHierarchyWindowCmds) {
switch (cmdId) {
case (uint)VSConstants.VsUIHierarchyWindowCmdIds.UIHWCMDID_RightClick:
// The UIHWCMDID_RightClick is what tells an IVsUIHierarchy in a UIHierarchyWindow
// to put up the context menu. Since the mouse may have moved between the
// mouse down and the mouse up, GetCursorPos won't tell you the right place
// to put the context menu (especially if it came through the keyboard).
// So we pack the proper menu position into pvaIn by
// memcpy'ing a POINTS struct into the VT_UI4 part of the pvaIn variant. The
// code to unpack it looks like this:
// ULONG ulPts = V_UI4(pvaIn);
// POINTS pts;
// memcpy((void*)&pts, &ulPts, sizeof(POINTS));
// You then pass that POINTS into DisplayContextMenu.
handled = true;
return this.DisplayContextMenu(selectedNodes, vaIn);
default:
break;
}
} else if (cmdGroup == VsMenus.guidStandardCommandSet2K) {
switch ((VsCommands2K)cmdId) {
case VsCommands2K.ViewInClassDiagram:
handled = true;
return this.ShowInDesigner(selectedNodes);
}
}
return (int)OleConstants.OLECMDERR_E_NOTSUPPORTED;
}
示例2: CmdletProviderContext
internal CmdletProviderContext(CmdletProviderContext contextToCopyFrom)
{
this.credentials = PSCredential.Empty;
this._origin = CommandOrigin.Internal;
this.accumulatedObjects = new Collection<PSObject>();
this.accumulatedErrorObjects = new Collection<ErrorRecord>();
this.stopReferrals = new Collection<CmdletProviderContext>();
if (contextToCopyFrom == null)
{
throw PSTraceSource.NewArgumentNullException("contextToCopyFrom");
}
this.executionContext = contextToCopyFrom.ExecutionContext;
this.command = contextToCopyFrom.command;
if (contextToCopyFrom.Credential != null)
{
this.credentials = contextToCopyFrom.Credential;
}
this.drive = contextToCopyFrom.Drive;
this.force = (bool) contextToCopyFrom.Force;
this.CopyFilters(contextToCopyFrom);
this.suppressWildcardExpansion = contextToCopyFrom.SuppressWildcardExpansion;
this.dynamicParameters = contextToCopyFrom.DynamicParameters;
this._origin = contextToCopyFrom._origin;
this.stopping = contextToCopyFrom.Stopping;
contextToCopyFrom.StopReferrals.Add(this);
this.copiedContext = contextToCopyFrom;
}
示例3: ScriptCommandProcessorBase
protected ScriptCommandProcessorBase(ScriptBlock scriptBlock, ExecutionContext context, bool useLocalScope, CommandOrigin origin, SessionStateInternal sessionState)
{
this._dontUseScopeCommandOrigin = false;
base.CommandInfo = new ScriptInfo(string.Empty, scriptBlock, context);
base._fromScriptFile = false;
this.CommonInitialization(scriptBlock, context, useLocalScope, sessionState);
base.Command.CommandOriginInternal = origin;
}
示例4: IsVisible
public static bool IsVisible(CommandOrigin origin, object valueToCheck)
{
if (origin != CommandOrigin.Internal)
{
IHasSessionStateEntryVisibility visibility = valueToCheck as IHasSessionStateEntryVisibility;
if (visibility != null)
{
return (visibility.Visibility == SessionStateEntryVisibility.Public);
}
}
return true;
}
示例5: HierarchyCommandContext
// --------------------------------------------------------------------------------------------
/// <summary>
/// Initializes a new instance of the <see cref="HierarchyCommandContext"/> class.
/// </summary>
/// <param name="package">The package owning this context.</param>
/// <param name="selection">The list of selected nodes belonging to this context.</param>
/// <param name="origin">The command origin.</param>
// --------------------------------------------------------------------------------------------
public HierarchyCommandContext(PackageBase package, IList<HierarchyNode> selection,
CommandOrigin origin)
: base(package)
{
_Nodes = new ReadOnlyCollection<HierarchyNode>(selection);
_Origin = origin;
Handled = true;
_ExplicitStatusSet = false;
_Supported = false;
_Disabled = false;
_Invisible = false;
}
示例6: _CreateCommand
private CommandProcessorBase _CreateCommand(string commandName, CommandOrigin commandOrigin, bool? useLocalScope)
{
if (this.context == null)
{
throw PSTraceSource.NewInvalidOperationException("DiscoveryExceptions", "ExecutionContextNotSet", new object[0]);
}
CommandDiscovery commandDiscovery = this.context.CommandDiscovery;
if (commandDiscovery == null)
{
throw PSTraceSource.NewInvalidOperationException("DiscoveryExceptions", "CommandDiscoveryMissing", new object[0]);
}
return commandDiscovery.LookupCommandProcessor(commandName, commandOrigin, useLocalScope);
}
示例7: GetVariable
/// <summary>
/// Get a variable out of session state. This interface supports
/// the scope specifiers like "global:foobar"
/// </summary>
///
/// <param name="name">
/// name of variable to look up
/// </param>
///
/// <param name="origin">
/// Origin of the command making this request.
/// </param>
///
/// <returns>
/// The specified variable.
/// </returns>
///
/// <exception cref="ArgumentNullException">
/// If <paramref name="name"/> is null.
/// </exception>
///
internal PSVariable GetVariable(string name, CommandOrigin origin)
{
if (name == null)
{
throw PSTraceSource.NewArgumentNullException("name");
}
VariablePath variablePath = new VariablePath(name, VariablePathFlags.Variable | VariablePathFlags.Unqualified);
SessionStateScope scope = null;
PSVariable resultItem = GetVariableItem(variablePath, out scope, origin);
return resultItem;
} // GetVariable
示例8: GetCmdlet
/// <summary>
/// Gets the value of the specified cmdlet from the cmdlet table.
/// </summary>
///
/// <param name="cmdletName">
/// The name of the cmdlet value to retrieve.
/// </param>
///
/// <param name="origin">
/// The origin of hte command trying to retrieve this cmdlet.
/// </param>
///
/// <returns>
/// The CmdletInfo representing the cmdlet.
/// </returns>
///
internal CmdletInfo GetCmdlet(string cmdletName, CommandOrigin origin)
{
CmdletInfo result = null;
if (String.IsNullOrEmpty(cmdletName))
{
return null;
}
// Use the scope enumerator to find the alias using the
// appropriate scoping rules
SessionStateScopeEnumerator scopeEnumerator =
new SessionStateScopeEnumerator(_currentScope);
foreach (SessionStateScope scope in scopeEnumerator)
{
result = scope.GetCmdlet(cmdletName);
if (result != null)
{
// Now check the visibility of the cmdlet...
SessionState.ThrowIfNotVisible(origin, result);
// Make sure the cmdlet isn't private or if it is that the current
// scope is the same scope the cmdlet was retrieved from.
if ((result.Options & ScopedItemOptions.Private) != 0 &&
scope != _currentScope)
{
result = null;
}
else
{
break;
}
}
}
return result;
} // GetCmdlet
示例9: ShouldRunInternal
internal void ShouldRunInternal(CommandInfo commandInfo, CommandOrigin origin, PSHost host)
{
bool flag = false;
bool flag2 = false;
Exception reason = null;
try
{
lock (this.policyCheckLock)
{
flag = this.ShouldRun(commandInfo, origin, host, out reason);
}
}
catch (Exception exception2)
{
CommandProcessorBase.CheckForSevereException(exception2);
reason = exception2;
flag2 = true;
flag = false;
}
if (!flag)
{
if (reason == null)
{
throw new PSSecurityException(AuthorizationManagerBase.AuthorizationManagerDefaultFailureReason);
}
if (reason is PSSecurityException)
{
throw reason;
}
string message = reason.Message;
if (flag2)
{
message = AuthorizationManagerBase.AuthorizationManagerDefaultFailureReason;
}
PSSecurityException exception3 = new PSSecurityException(message, reason);
throw exception3;
}
}
示例10: SetAliasValue
internal AliasInfo SetAliasValue(string name, string value, ScopedItemOptions options, System.Management.Automation.ExecutionContext context, bool force, CommandOrigin origin)
{
if (!this.GetAliases().ContainsKey(name))
{
if (this.GetAliases().Count > (this.AliasCapacity.FastValue - 1))
{
SessionStateOverflowException exception = new SessionStateOverflowException(name, SessionStateCategory.Alias, "AliasOverflow", SessionStateStrings.AliasOverflow, new object[] { this.AliasCapacity.FastValue });
throw exception;
}
AliasInfo info = new AliasInfo(name, value, context, options);
this.GetAliases()[name] = info;
}
else
{
AliasInfo valueToCheck = this.GetAliases()[name];
if (((valueToCheck.Options & ScopedItemOptions.Constant) != ScopedItemOptions.None) || (!force && ((valueToCheck.Options & ScopedItemOptions.ReadOnly) != ScopedItemOptions.None)))
{
SessionStateUnauthorizedAccessException exception2 = new SessionStateUnauthorizedAccessException(name, SessionStateCategory.Alias, "AliasNotWritable", SessionStateStrings.AliasNotWritable);
throw exception2;
}
if ((options & ScopedItemOptions.Constant) != ScopedItemOptions.None)
{
SessionStateUnauthorizedAccessException exception3 = new SessionStateUnauthorizedAccessException(name, SessionStateCategory.Alias, "AliasCannotBeMadeConstant", SessionStateStrings.AliasCannotBeMadeConstant);
throw exception3;
}
if (((options & ScopedItemOptions.AllScope) == ScopedItemOptions.None) && ((valueToCheck.Options & ScopedItemOptions.AllScope) != ScopedItemOptions.None))
{
SessionStateUnauthorizedAccessException exception4 = new SessionStateUnauthorizedAccessException(name, SessionStateCategory.Alias, "AliasAllScopeOptionCannotBeRemoved", SessionStateStrings.AliasAllScopeOptionCannotBeRemoved);
throw exception4;
}
SessionState.ThrowIfNotVisible(origin, valueToCheck);
this.RemoveAliasFromCache(valueToCheck.Name, valueToCheck.Definition);
if (force)
{
this.GetAliases().Remove(name);
valueToCheck = new AliasInfo(name, value, context, options);
this.GetAliases()[name] = valueToCheck;
}
else
{
valueToCheck.Options = options;
valueToCheck.SetDefinition(value, false);
}
}
this.AddAliasToCache(name, value);
return this.GetAliases()[name];
}
示例11: AddCmdletToCache
internal CmdletInfo AddCmdletToCache(string name, CmdletInfo cmdlet, CommandOrigin origin, System.Management.Automation.ExecutionContext context)
{
bool flag = false;
try
{
List<CmdletInfo> list;
if (!this.GetCmdlets().TryGetValue(name, out list))
{
list = new List<CmdletInfo> {
cmdlet
};
this.GetCmdlets().Add(name, list);
if ((cmdlet.Options & ScopedItemOptions.AllScope) != ScopedItemOptions.None)
{
this.GetAllScopeCmdlets()[name].Insert(0, cmdlet);
}
}
else
{
if (!string.IsNullOrEmpty(cmdlet.ModuleName))
{
foreach (CmdletInfo info in list)
{
if (string.Equals(cmdlet.FullName, info.FullName, StringComparison.OrdinalIgnoreCase))
{
if (cmdlet.ImplementingType == info.ImplementingType)
{
return null;
}
flag = true;
break;
}
}
}
else
{
foreach (CmdletInfo info2 in list)
{
if (cmdlet.ImplementingType == info2.ImplementingType)
{
return null;
}
flag = true;
break;
}
}
if (!flag)
{
list.Insert(0, cmdlet);
}
}
}
catch (ArgumentException)
{
flag = true;
}
if (flag)
{
throw PSTraceSource.NewNotSupportedException("DiscoveryExceptions", "DuplicateCmdletName", new object[] { cmdlet.Name });
}
return this.GetCmdlets()[name][0];
}
示例12: SetAliasItem
internal AliasInfo SetAliasItem(AliasInfo aliasToSet, bool force, CommandOrigin origin = CommandOrigin.Internal)
{
if (!this.GetAliases().ContainsKey(aliasToSet.Name))
{
if (this.GetAliases().Count > (this.AliasCapacity.FastValue - 1))
{
SessionStateOverflowException exception = new SessionStateOverflowException(aliasToSet.Name, SessionStateCategory.Alias, "AliasOverflow", SessionStateStrings.AliasOverflow, new object[] { this.AliasCapacity.FastValue });
throw exception;
}
this.GetAliases()[aliasToSet.Name] = aliasToSet;
}
else
{
AliasInfo valueToCheck = this.GetAliases()[aliasToSet.Name];
SessionState.ThrowIfNotVisible(origin, valueToCheck);
if (((valueToCheck.Options & ScopedItemOptions.Constant) != ScopedItemOptions.None) || (((valueToCheck.Options & ScopedItemOptions.ReadOnly) != ScopedItemOptions.None) && !force))
{
SessionStateUnauthorizedAccessException exception2 = new SessionStateUnauthorizedAccessException(aliasToSet.Name, SessionStateCategory.Alias, "AliasNotWritable", SessionStateStrings.AliasNotWritable);
throw exception2;
}
if (((aliasToSet.Options & ScopedItemOptions.AllScope) == ScopedItemOptions.None) && ((valueToCheck.Options & ScopedItemOptions.AllScope) != ScopedItemOptions.None))
{
SessionStateUnauthorizedAccessException exception3 = new SessionStateUnauthorizedAccessException(aliasToSet.Name, SessionStateCategory.Alias, "AliasAllScopeOptionCannotBeRemoved", SessionStateStrings.AliasAllScopeOptionCannotBeRemoved);
throw exception3;
}
this.RemoveAliasFromCache(valueToCheck.Name, valueToCheck.Definition);
this.GetAliases()[aliasToSet.Name] = aliasToSet;
}
this.AddAliasToCache(aliasToSet.Name, aliasToSet.Definition);
return this.GetAliases()[aliasToSet.Name];
}
示例13: GetVariable
internal PSVariable GetVariable(string name, CommandOrigin origin)
{
PSVariable variable;
this.TryGetVariable(name, origin, false, out variable);
return variable;
}
示例14: TryNormalSearch
private static CommandInfo TryNormalSearch(string commandName, ExecutionContext context, CommandOrigin commandOrigin, SearchResolutionOptions searchResolutionOptions, CommandTypes commandTypes, ref Exception lastError)
{
CommandInfo current = null;
CommandSearcher searcher = new CommandSearcher(commandName, searchResolutionOptions, commandTypes, context) {
CommandOrigin = commandOrigin
};
try
{
if (!searcher.MoveNext())
{
if (!commandName.Contains("-") && !commandName.Contains(@"\"))
{
discoveryTracer.WriteLine("The command [{0}] was not found, trying again with get- prepended", new object[] { commandName });
commandName = "get" + '-' + commandName;
try
{
current = LookupCommandInfo(commandName, commandTypes, searchResolutionOptions, commandOrigin, context);
}
catch (CommandNotFoundException)
{
}
}
return current;
}
current = searcher.Current;
}
catch (ArgumentException exception)
{
lastError = exception;
}
catch (PathTooLongException exception2)
{
lastError = exception2;
}
catch (FileLoadException exception3)
{
lastError = exception3;
}
catch (FormatException exception4)
{
lastError = exception4;
}
catch (MetadataException exception5)
{
lastError = exception5;
}
return current;
}
示例15: TryModuleAutoLoading
private static CommandInfo TryModuleAutoLoading(string commandName, ExecutionContext context, string originalCommandName, CommandOrigin commandOrigin, CommandInfo result, ref Exception lastError)
{
int length = commandName.IndexOfAny(new char[] { ':', '\\' });
if ((length == -1) || (commandName[length] == ':'))
{
return null;
}
string str = commandName.Substring(0, length);
string str2 = commandName.Substring(length + 1, (commandName.Length - length) - 1);
if ((string.IsNullOrEmpty(str) || string.IsNullOrEmpty(str2)) || str.EndsWith(".", StringComparison.Ordinal))
{
return null;
}
try
{
discoveryTracer.WriteLine("Executing module-qualified search: {0}", new object[] { commandName });
context.CommandDiscovery.RegisterLookupCommandInfoAction("ActiveModuleSearch", commandName);
CmdletInfo cmdlet = context.SessionState.InvokeCommand.GetCmdlet(@"Microsoft.PowerShell.Core\Import-Module");
if ((commandOrigin == CommandOrigin.Internal) || ((cmdlet != null) && (cmdlet.Visibility == SessionStateEntryVisibility.Public)))
{
List<PSModuleInfo> modules = context.Modules.GetModules(new string[] { str }, false);
PSModuleInfo info2 = null;
if ((modules == null) || (modules.Count == 0))
{
CommandInfo commandInfo = new CmdletInfo("Import-Module", typeof(ImportModuleCommand), null, null, context) {
Visibility = cmdlet.Visibility
};
Command command = new Command(commandInfo);
Collection<PSModuleInfo> collection = null;
discoveryTracer.WriteLine("Attempting to load module: {0}", new object[] { str });
try
{
collection = PowerShell.Create(RunspaceMode.CurrentRunspace).AddCommand(command).AddParameter("Name", str).AddParameter("Scope", "GLOBAL").AddParameter("ErrorAction", ActionPreference.Ignore).AddParameter("PassThru").AddParameter("WarningAction", ActionPreference.Ignore).AddParameter("Verbose", false).AddParameter("Debug", false).Invoke<PSModuleInfo>();
}
catch (Exception exception)
{
discoveryTracer.WriteLine("Encountered error importing module: {0}", new object[] { exception.Message });
lastError = exception;
CommandProcessorBase.CheckForSevereException(exception);
}
if ((collection == null) || (collection.Count == 0))
{
string resourceStr = StringUtil.Format(DiscoveryExceptions.CouldNotAutoImportModule, str);
CommandNotFoundException exception2 = new CommandNotFoundException(originalCommandName, lastError, "CouldNotAutoLoadModule", resourceStr, new object[0]);
throw exception2;
}
info2 = collection[0];
}
else
{
info2 = modules[0];
}
if (info2.ExportedCommands.ContainsKey(str2))
{
result = info2.ExportedCommands[str2];
}
}
return result;
}
catch (CommandNotFoundException)
{
throw;
}
catch (Exception exception3)
{
CommandProcessorBase.CheckForSevereException(exception3);
}
finally
{
context.CommandDiscovery.UnregisterLookupCommandInfoAction("ActiveModuleSearch", commandName);
}
return result;
}