예제 #1
0
        /// <inheritdoc />
        public override void ReceiveMessage(object sender, IMessage message)
        {
            //var viewModel = string.IsNullOrEmpty(message.Goal) ? this : ViewModel.FirstOrDefault(temp => temp.Key == message.Goal)?.ViewModel;
            ViewModelBase viewModel = this;

            if (!message.Predicate(new ViewModelPage(this)))
            {
                viewModel = ViewModel.FirstOrDefault(temp => message.Predicate(temp))?.ViewModel;
            }
            if (viewModel == null)
            {
                return;
            }
            IComposite composite = message as ICombinationComposite;

            if (composite != null)
            {
                composite.Run(viewModel, message);
            }
            else
            {
                composite = Composite.FirstOrDefault(temp => temp.Message == message.GetType());
                if (composite != null)
                {
                    composite.Run(viewModel, message);
                }
                else
                {
                    if (viewModel == this)
                    {
                        return;
                    }
                    if (viewModel is IReceiveMessage)
                    {
                        ((IReceiveMessage)viewModel).ReceiveMessage(sender, message);
                    }
                }
            }
        }