コード例 #1
0
        public void ExecuteCommand(ICommandMapping mapping, CommandPayload payload = null)
        {
            bool   hasPayload       = payload != null && payload.HasPayload();
            bool   injectionEnabled = hasPayload && mapping.PayloadInjectionEnabled;
            object command          = null;

            if (injectionEnabled)
            {
                MapPayload(payload);
            }

            if (mapping.Guards.Count == 0 || Guards.Approve(_injector, mapping.Guards))
            {
                Type commandClass = mapping.CommandClass;
                if (mapping.FireOnce && _removeMapping != null)
                {
                    _removeMapping(mapping);
                }
                command = _injector.GetOrCreateNewInstance(commandClass);
                if (mapping.Hooks.Count > 0)
                {
                    _injector.Map(commandClass).ToValue(command);
                    Hooks.Apply(_injector, mapping.Hooks);
                    _injector.Unmap(commandClass);
                }
            }

            if (injectionEnabled)
            {
                UnmapPayload(payload);
            }

            if (command != null && mapping.ExecuteMethod != null)
            {
                if (_onPreprocessCommandExecuting != null)
                {
                    _onPreprocessCommandExecuting.Invoke(command, mapping);
                }

                MethodInfo executeMethod = command.GetType().GetMethod(mapping.ExecuteMethod);
                object     result        = (hasPayload && executeMethod.GetParameters().Length > 0)
                                        ? executeMethod.Invoke(command, payload.Values.ToArray())
                                        : executeMethod.Invoke(command, null);
                if (_handleResult != null)
                {
                    _handleResult.Invoke(result, command, mapping);
                }
            }
        }
コード例 #2
0
        /*============================================================================*/
        /* Private Functions                                                          */
        /*============================================================================*/

        private void RunProcess(object view, Type type, IViewProcessorMapping mapping)
        {
            if (Guards.Approve(_injector, mapping.Guards))
            {
                if (mapping.Processor == null)
                {
                    mapping.Processor = CreateProcessor(mapping.ProcessorClass);
                }
                Hooks.Apply(_injector, mapping.Hooks);

                MethodInfo processMethod = mapping.Processor.GetType().GetMethod(ProcessMethodName);
                if (processMethod != null && processMethod.GetParameters().Length == 3)
                {
                    processMethod.Invoke(mapping.Processor, new object[3] {
                        view, type, _injector
                    });
                }
            }
        }
コード例 #3
0
        /*============================================================================*/
        /* Private Functions                                                          */
        /*============================================================================*/

        private object CreateMediator(object item, IMediatorMapping mapping)
        {
            object mediator = GetMediator(item, mapping);

            if (mediator != null)
            {
                return(mediator);
            }

            if (mapping.Guards.Count == 0 || Guards.Approve(_injector, mapping.Guards))
            {
                mediator = _injector.InstantiateUnmapped(mapping.MediatorType);
                if (mapping.Hooks.Count > 0)
                {
                    _injector.Map(mapping.MediatorType).ToValue(mediator);
                    Hooks.Apply(_injector, mapping.Hooks);
                    _injector.Unmap(mapping.MediatorType);
                }
                AddMediator(mediator, item, mapping);
            }
            return(mediator);
        }