当前位置: 首页>>代码示例>>C#>>正文


C# ICommand.GetType方法代码示例

本文整理汇总了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();
            }
            
        }
开发者ID:AGiorgetti,项目名称:Prxm.Cqrs,代码行数:29,代码来源:DefaultCommandRouter.cs

示例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;
        }
开发者ID:sistoimenov,项目名称:NuGet2,代码行数:26,代码来源:CommandManager.cs

示例3: GetCommandTopic

        public string GetCommandTopic(ICommand command)
        {
            if (_commandTopics.ContainsKey(command.GetType()))
                return _commandTopics[command.GetType()];

            return command.GetType().Namespace;
        }
开发者ID:liuxiqin,项目名称:Sevens,代码行数:7,代码来源:CommandTopicProvider.cs

示例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);
            }
        }
开发者ID:hjlfmy,项目名称:enode,代码行数:29,代码来源:DefaultCommandService.cs

示例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);
 }
开发者ID:dwick,项目名称:UCTemplate,代码行数:14,代码来源:CommandExecutor.cs

示例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);
        }
开发者ID:AdrianFreemantle,项目名称:clientele-training,代码行数:10,代码来源:CommandPublisher.cs

示例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);
        }
开发者ID:adam555,项目名称:Griffin.Container,代码行数:17,代码来源:ContainerDispatcher.cs

示例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;
     }
 }
开发者ID:jaceenet,项目名称:TastyDomainDriven,代码行数:14,代码来源:SqlLoggedBus.cs

示例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;
     }
 }
开发者ID:AdrianFreemantle,项目名称:clientele-training,代码行数:14,代码来源:CommandLogger.cs

示例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);
        }
开发者ID:juanlurie,项目名称:clientele-training,代码行数:14,代码来源:CommandPublisherProxy.cs

示例11: Process

        public void Process(ICommand command)
        {
            var handlerType = typeof(ICommandHandler<>).MakeGenericType(command.GetType());
            dynamic handler = _context.Resolve(handlerType);

            handler.Handle((dynamic)command);
        }
开发者ID:Zargess,项目名称:VHKPlayer,代码行数:7,代码来源:CommandProcessor.cs

示例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>();
 }
开发者ID:DerAlbertCom,项目名称:ApereaFramework,代码行数:7,代码来源:CommandDispatcher.cs

示例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;
        }
开发者ID:ViGor-Thinktank,项目名称:GCML,代码行数:16,代码来源:clsCommandCollection.cs

示例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;
        }
开发者ID:jakesays,项目名称:dot42,代码行数:28,代码来源:MenuRLLanguage.cs

示例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);
        }
开发者ID:liuxiqin,项目名称:Sevens,代码行数:33,代码来源:DefaultCommandProssor.cs


注:本文中的ICommand.GetType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。