本文整理汇总了C#中ICommand.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# ICommand.GetType方法的具体用法?C# ICommand.GetType怎么用?C# ICommand.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ICommand
的用法示例。
在下文中一共展示了ICommand.GetType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RouteToHandler
public void RouteToHandler(ICommand command)
{
//optype set in logger context information about the logical operation that the system is executing
//is used to group log messages togheter and to correlate child log to a logical operation.
_logger.SetOpType("command", command.GetType().FullName + " Id:" + command.Id);
_logger.Info("[queue] processing command " + command.ToString());
var commandType = command.GetType();
//get the executor function from the catalog, and then simply execute the command.
var commandinvoker = _commandHandlerCatalog.GetExecutorFor(commandType);
try
{
commandinvoker.Invoke(command);
_logger.Info("[queue] command handled " + command.ToString());
}
catch (System.Exception ex)
{
//TODO log or do something better instead of retrhowing exception
_logger.Error("[queue] Command error " + ex.Message, ex);
throw;
}
finally
{
_logger.RemoveOpType();
}
}
示例2: GetCommandOptions
public IDictionary<OptionAttribute, PropertyInfo> GetCommandOptions(ICommand command)
{
var result = new Dictionary<OptionAttribute, PropertyInfo>();
foreach (PropertyInfo propInfo in command.GetType().GetProperties())
{
if (!command.IncludedInHelp(propInfo.Name))
{
continue;
}
foreach (OptionAttribute attr in propInfo.GetCustomAttributes(typeof(OptionAttribute), inherit: true))
{
if (!propInfo.CanWrite && !TypeHelper.IsMultiValuedProperty(propInfo))
{
// If the property has neither a setter nor is of a type that can be cast to ICollection<> then there's no way to assign
// values to it. In this case throw.
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture,
LocalizedResourceManager.GetString("OptionInvalidWithoutSetter"), command.GetType().FullName + "." + propInfo.Name));
}
result.Add(attr, propInfo);
}
}
return result;
}
示例3: GetCommandTopic
public string GetCommandTopic(ICommand command)
{
if (_commandTopics.ContainsKey(command.GetType()))
return _commandTopics[command.GetType()];
return command.GetType().Namespace;
}
示例4: Execute
public void Execute(ICommand command)
{
var commandQueue = _commandQueueRouter.Route(command);
if (commandQueue == null)
{
throw new Exception("Could not route the command to an appropriate command queue.");
}
var waitHandle = new ManualResetEvent(false);
var commandAsyncResult = new CommandAsyncResult(waitHandle);
_commandAsyncResultManager.Add(command.Id, commandAsyncResult);
commandQueue.Enqueue(command);
waitHandle.WaitOne(command.MillisecondsTimeout);
_commandAsyncResultManager.Remove(command.Id);
if (!commandAsyncResult.IsCompleted)
{
throw new CommandTimeoutException(command.Id, command.GetType());
}
else if (commandAsyncResult.Exception != null)
{
throw new CommandExecuteException(command.Id, command.GetType(), commandAsyncResult.Exception);
}
else if (commandAsyncResult.ErrorMessage != null)
{
throw new CommandExecuteException(command.Id, command.GetType(), commandAsyncResult.ErrorMessage);
}
}
示例5: Excute
/// <summary>
/// Executes the supplied command asynchronously.
/// </summary>
/// <param name="command">The command to execute.</param>
public static void Excute(ICommand command)
{
Task.Factory
.StartNew(() =>
{
Log.Debug(string.Format("Executing '{0}'.", command.GetType()));
command.Execute();
}, TaskCreationOptions.LongRunning)
.ContinueWith(task => Log.Fatal(string.Format("'{0}', failed.", command.GetType()), task.Exception), TaskContinuationOptions.OnlyOnFaulted);
}
示例6: Publish
public virtual void Publish(ICommand command)
{
Logger.Verbose("Authorizing command {0}", command.GetType().Name);
commandAuthorizer.Authorize(command);
Logger.Verbose("Publishing command {0}", command.GetType().Name);
commandRetry.Retry(TryPublish, command);
}
示例7: Dispatch
/// <summary>
/// Dispatch the command
/// </summary>
/// <param name="command">Command to invoke</param>
public void Dispatch(ICommand command)
{
if (command == null) throw new ArgumentNullException("command");
var handlerType = typeof(IHandlerOf<>).MakeGenericType(command.GetType());
var method = handlerType.GetMethod("Invoke", new Type[] { command.GetType() });
var handler = _serviceLocator.Resolve(handlerType);
var decorated = Decorate(command.GetType(), handler);
// workaround so that TargetInvocationException is not thrown.
((dynamic) decorated).Invoke((dynamic)command);
}
示例8: Dispatch
public void Dispatch(ICommand cmd)
{
try
{
this.bus.Dispatch(cmd);
this.Log(cmd.GetType().FullName, this.ToJson(cmd), this.SerializeObject(cmd), true);
}
catch (Exception ex)
{
var str = new string(ex.ToString().Take(499).ToArray());
this.Log(cmd.GetType().FullName, str, this.SerializeObject(cmd), false);
throw;
}
}
示例9: Publish
public void Publish(ICommand command)
{
try
{
Logger.Verbose("Publishing command {0}", command.GetType().Name);
publisher.Publish(command);
Logger.Verbose("Completed publishing command {0}", command.GetType().Name);
}
catch (Exception ex)
{
Logger.Error("Error: {0}", ex.Message);
throw;
}
}
示例10: AuthorizeCommand
private void AuthorizeCommand(ICommand command)
{
var authorizeAttribute = Attribute.GetCustomAttributes(command.GetType())
.FirstOrDefault(x => x is AuthorizeAttribute) as AuthorizeAttribute;
if (authorizeAttribute == null || currentUser.IsInRole(authorizeAttribute.Roles))
{
return;
}
string message = String.Format("User {0} attempted to execute command {1} which requires roles {2}", currentUser, command.GetType().Name, authorizeAttribute);
throw new UnauthorizedAccessException(message);
}
示例11: Process
public void Process(ICommand command)
{
var handlerType = typeof(ICommandHandler<>).MakeGenericType(command.GetType());
dynamic handler = _context.Resolve(handlerType);
handler.Handle((dynamic)command);
}
示例12: GetHandlers
public IEnumerable<ICommandHandler> GetHandlers(ICommand command)
{
if (command == null) throw new ArgumentNullException("command");
var commandType = command.GetType();
var handlerType = typeof (ICommandHandler<>).MakeGenericType(commandType);
return locator.GetAllInstances(handlerType).Cast<ICommandHandler>();
}
示例13: listReadyCommandsWithTypeFilter
public List<ICommand> listReadyCommandsWithTypeFilter(ICommand aktCommandType)
{
if (aktCommandType.GetType() == typeof(comSolveKollision))
{
return listReadyCommands;
}
List<ICommand> listReadyCommandsFilter = new List<ICommand>();
foreach (ICommand aktCom in listReadyCommands)
{
if (aktCom.GetType() == aktCommandType.GetType())
listReadyCommandsFilter.Add(aktCom);
}
return listReadyCommandsFilter;
}
示例14: GetAttribute
//private static void UpdateCheckedState(StopAstConversion stopCode)
//{
// // this does not work.
// foreach (MenuItem item in MainWindow.Instance.GetMainMenuItems())
// {
// if (!(item.Command is StopMenuCommand))
// continue;
// var attr = GetAttribute(item.Command);
// if (attr.StopCode == stopCode)
// {
// item.IsCheckable = true;
// item.IsChecked = true;
// }
// else
// {
// item.IsChecked = false;
// }
// }
//}
private static StopRLMenuCommandAttribute GetAttribute(ICommand command)
{
var attr = command.GetType().GetCustomAttributes(typeof(StopRLMenuCommandAttribute), true)
.Cast<StopRLMenuCommandAttribute>()
.FirstOrDefault();
return attr;
}
示例15: Execute
public void Execute(ICommand command)
{
var commandHandler = _commandHandleProvider.GetInternalCommandHandle(command.GetType());
var commandContext = new CommandContext(_repository);
commandHandler(commandContext, command);
var aggregateRoots = commandContext.AggregateRoots;
if (aggregateRoots.Count > 1)
throw new Exception("one command handler can change just only one aggregateRoot.");
var aggregateRoot = aggregateRoots.First().Value;
var domainEvents = aggregateRoot.GetUnCommitEvents();
var eventStream = BuildEventStream(aggregateRoot, command.CommandId);
_eventStore.AppendAsync(eventStream);
if (aggregateRoot.Version % 3 == 0)
_snapshotStorage.Create(new SnapshotRecord(aggregateRoot.AggregateRootId, aggregateRoot.Version,
_binarySerializer.Serialize(aggregateRoot)));
_eventPublisher.PublishAsync(domainEvents);
aggregateRoot.Clear();
Console.WriteLine(aggregateRoot.ToString());
Console.WriteLine("DomainEvents count is {0}", domainEvents.Count);
}