void Execute(string userInput) { State = ExecutionState.Running; CommandInvocation _currentInvocation = new CommandInvocation(userInput); if (commands.ContainsKey(_currentInvocation.FingerPrint)) { try { commands[_currentInvocation.FingerPrint].Execute(_currentInvocation, this); } catch (Exception _exc) { MainOutput.Enqueue(_exc.Message.Decorat("language", "english"), OutputLevel.Error); if (!SuppressExceptions) { throw; } } } else { PropertyDecorator <string> _message = new PropertyDecorator <string>( "The command-fingerprint \"{0}\" is undefined in the current context.".LegacyForm(( object )userInput)); _message.Set("language", "english"); SystemOutput.Enqueue( new CommandOutput( OutputLevel.Error, _message, DateTime.Now)); } State = ExecutionState.Idle; }
public async Task <int> RunCommand( CommandInfo commandInfo, List <ArgumentInfo> parameterValues) { parameterValues = parameterValues ?? new List <ArgumentInfo>(); //get values for method invocation object[] mergedParameters = _argumentMerger.Merge(parameterValues); //validate all parameters foreach (dynamic param in mergedParameters) { _modelValidator.ValidateModel(param); } //create instance object instance = _appInstanceCreator.CreateInstance(_type, _constructorParamValues, _dependencyResolver, _modelValidator); CommandInvocation commandInvocation = new CommandInvocation { CommandInfo = commandInfo, ParamsForCommandMethod = mergedParameters, Instance = instance, ArgsFromCli = parameterValues }; object returnedObject = _appSettings.CommandInvoker.Invoke(commandInvocation); //disposing -- switch (instance) { case IDisposable disposable: disposable.Dispose(); break; } //disposing -- //default return code for cases when method is of type void instead of int int returnCode = 0; //wait for method to complete switch (returnedObject) { case Task <int> intPromise: returnCode = await intPromise; break; case Task promise: await promise; break; case int intValue: returnCode = intValue; break; //for void and every other return type, the value is already set to 0 } //return the actual return code return(returnCode); }
private void HandlerOnRunnigCommandRemoved(object sender, CommandInvocation invocation) { if (invocation.CommandName.Equals(Command.Name, StringComparison.Ordinal)) { trace.AppendLine("HandlerOnCommandStopped: OnEntry"); finishedEvent.Set(); trace.AppendLine("HandlerOnCommandStopped: OnExit"); } }
public async Task <Result <int, QueryStatus> > Handle(Command request, CancellationToken cancellationToken) { var invocationEntity = new CommandInvocation() { CommandName = request.CommandName, Time = DateTime.Now, GuildId = request.GuildId, ChannelId = request.ChannelId, UserId = request.UserId }; _context.CommandInvocations.Add(invocationEntity); await _context.SaveChangesAsync(); return(QueryResult <int> .Success(invocationEntity.Id)); }
public async Task <IQueryResult <int> > Handle(Command request, CancellationToken cancellationToken) { var invocationEntity = new CommandInvocation { CommandName = request.CommandName, Time = SystemClock.Instance.InZone(DateTimeZone.Utc).GetCurrentLocalDateTime(), GuildId = request.GuildId, ChannelId = request.ChannelId, UserId = request.UserId }; _context.CommandInvocations.Add(invocationEntity); await _context.SaveChangesAsync(); return(QueryResult <int> .Success(invocationEntity.Id)); }
void emitSyntax(PropertyDecorator <string> input) { try { CommandInvocation _invocation = new CommandInvocation(input.Value); for (int _i = 0; _i < _invocation.Tokens.Count( ); _i++) { CommandToken _currentToken = _invocation.Tokens[_i]; if (_currentToken is Arg) { writeArg(_currentToken); } else if (_currentToken is Word) { _currentToken.ToString( ).ColorWrite(ConsoleColor.Yellow); } if (_i < _invocation.Tokens.Count( ) - 1) { Console.Write(" "); } } if (input.Value.EndsWith(" ")) { " ".ColorWrite(ConsoleColor.Black); } " ".ColorWrite(ConsoleColor.Black, ConsoleColor.Green); } catch (SyntaxErrorException) { input.Value.ColorWrite(ConsoleColor.Red); } catch (Exception) { input.Value.ColorWrite(ConsoleColor.Black, ConsoleColor.Red); } }
private void CommandOnStopped(object sender, CommandInvocation eventArgs) { trace.AppendLine("CommandOnStopped: OnEntry"); finishedEvent.Set(); trace.AppendLine("CommandOnStopped: OnExit"); }
// Token: 0x06001644 RID: 5700 RVA: 0x00053BE8 File Offset: 0x00051DE8 private void ProxyCmdletExecution(CmdletProxyInfo cmdletProxyInfo) { ExAssert.RetailAssert(this.context.ExchangeRunspaceConfig != null, "this.context.ExchangeRunspaceConfig should not be null."); string remoteServerFqdn = cmdletProxyInfo.RemoteServerFqdn; int remoteServerVersion = cmdletProxyInfo.RemoteServerVersion; string friendlyVersionInformation = ProxyHelper.GetFriendlyVersionInformation(remoteServerVersion); CmdletProxyInfo.ChangeCmdletProxyParametersDelegate changeCmdletProxyParameters = cmdletProxyInfo.ChangeCmdletProxyParameters; if (Microsoft.Exchange.Diagnostics.Components.Tasks.ExTraceGlobals.FaultInjectionTracer.IsTraceEnabled(TraceType.FaultInjection)) { Microsoft.Exchange.Diagnostics.Components.Tasks.ExTraceGlobals.FaultInjectionTracer.TraceTest <string>(3720752445U, ref remoteServerFqdn); UserToken userToken = this.context.ExchangeRunspaceConfig.ConfigurationSettings.UserToken; ProxyHelper.FaultInjection_UserSid(ref userToken); Microsoft.Exchange.Diagnostics.Components.Tasks.ExTraceGlobals.FaultInjectionTracer.TraceTest <int>(3452316989U, ref remoteServerVersion); } string text = this.GeneratePswsProxyCmdlet(changeCmdletProxyParameters); ExchangeRunspaceConfigurationSettings.ProxyMethod proxyMethod = this.DetermineProxyMethod(remoteServerVersion); if (this.context.CommandShell != null) { this.context.CommandShell.WriteVerbose(Strings.VerboseCmdletProxiedToAnotherServer(text, remoteServerFqdn, friendlyVersionInformation, proxyMethod.ToString())); } Guid uniqueId = this.context.UniqueId; CmdletLogger.SafeAppendColumn(uniqueId, RpsCmdletMetadata.CmdletProxyRemoteServer, this.proxiedObjectCount.ToString(), remoteServerFqdn); CmdletLogger.SafeAppendColumn(uniqueId, RpsCmdletMetadata.CmdletProxyRemoteServerVersion, this.proxiedObjectCount.ToString(), friendlyVersionInformation.ToString()); CmdletLogger.SafeAppendColumn(uniqueId, RpsCmdletMetadata.CmdletProxyMethod, this.proxiedObjectCount.ToString(), proxyMethod.ToString()); try { IEnumerable <PSObject> enumerable; if (proxyMethod == ExchangeRunspaceConfigurationSettings.ProxyMethod.RPS) { PSCommand command = this.GenerateProxyCmdlet(changeCmdletProxyParameters); Task.TaskWarningLoggingDelegate writeWarning = null; if (this.context.CommandShell != null) { writeWarning = new Task.TaskWarningLoggingDelegate(this.context.CommandShell.WriteWarning); } enumerable = ProxyHelper.RPSProxyExecution(this.context.UniqueId, command, remoteServerFqdn, this.context.ExchangeRunspaceConfig, remoteServerVersion, cmdletProxyInfo.ShouldAsyncProxy, writeWarning); } else { enumerable = CommandInvocation.Invoke(this.context.UniqueId, ProxyHelper.GetPSWSProxySiteUri(remoteServerFqdn), text, CredentialCache.DefaultNetworkCredentials, ProxyHelper.GetPSWSProxyRequestHeaders(this.context.ExchangeRunspaceConfig), this.context.ExchangeRunspaceConfig.TypeTable); } foreach (PSObject psobject in enumerable) { object sendToPipeline = psobject; if (psobject.BaseObject != null && !(psobject.BaseObject is PSCustomObject)) { sendToPipeline = psobject.BaseObject; } else if (this.context.ExchangeRunspaceConfig != null) { if (this.context.ExchangeRunspaceConfig.ConfigurationSettings.ClientApplication != ExchangeRunspaceConfigurationSettings.ExchangeApplication.ECP) { if (this.context.ExchangeRunspaceConfig.ConfigurationSettings.ClientApplication != ExchangeRunspaceConfigurationSettings.ExchangeApplication.OSP) { goto IL_2CB; } } try { Task.TaskVerboseLoggingDelegate writeVerbose = null; if (this.context.CommandShell != null) { writeVerbose = new Task.TaskVerboseLoggingDelegate(this.context.CommandShell.WriteWarning); } sendToPipeline = ProxyHelper.ConvertPSObjectToOriginalType(psobject, remoteServerVersion, writeVerbose); } catch (Exception ex) { CmdletLogger.SafeAppendGenericError(uniqueId, "ConvertPSObjectToOriginalTyp", ex, new Func <Exception, bool>(TaskHelper.IsTaskUnhandledException)); Diagnostics.ReportException(ex, Constants.CoreEventLogger, TaskEventLogConstants.Tuple_UnhandledException, null, null, Microsoft.Exchange.Diagnostics.Components.Configuration.Core.ExTraceGlobals.InstrumentationTracer, "Exception from ProxyHelper.ConvertPSObjectToOriginalType : {0}"); } } IL_2CB: if (this.context.CommandShell != null) { this.context.CommandShell.WriteObject(sendToPipeline); } } } catch (Exception ex2) { CmdletLogger.SafeAppendGenericError(this.context.UniqueId, "ProxyCmdletExecution", ex2, new Func <Exception, bool>(TaskHelper.IsTaskUnhandledException)); if (this.context.CommandShell != null) { this.context.CommandShell.WriteError(new CmdletProxyException(text, remoteServerFqdn, friendlyVersionInformation, proxyMethod.ToString(), ex2.Message), ExchangeErrorCategory.ServerOperation, null); } } }
public object Invoke(CommandInvocation commandInvocation) { _actionBeforeInvocation(commandInvocation); return(_inner.Invoke(commandInvocation)); }
/// <summary> /// Raisese the <see cref="vCommands.CommandHost.CommandInvocation"/> event. /// </summary> /// <param name="e">A <see cref="vCommands.EventArguments.HostCommandInvocationEventArgs"/> that contains event data.</param> internal void OnInvocation(HostCommandInvocationEventArgs e) { CommandInvocation?.Invoke(this, e); }