private void PublishEvent <TArgs>(
            ScreenLifecycleEvent <TArgs> @event,
            TArgs args
            ) where TArgs : ScreenEventArgs
        {
            try {
                _aggregator.Publish(@event, args);
            } catch (Exception ex) {
                if (ex.IsCritical())
                {
                    throw;
                }

                try {
                    _aggregator.Publish(
                        ScreenEvents.LifecycleExceptionOccured,
                        new ScreenEventArgs(_target)
                        );
                } finally {
                    throw new ScreenLifecycleException(
                              ExceptionTexts.LifecycleExceptionOccured,
                              ex
                              );
                }
            }
        }
Example #2
0
        private void DefineTransition <TArgs>(
            LifecycleState from,
            LifecycleState to,
            ScreenLifecycleEvent <TArgs> on,
            Action <EventPublication> action,
            Func <EventPublication, bool> condition = null
            ) where TArgs : ScreenEventArgs
        {
            condition = condition ?? AlwaysTrueCondition;

            Func <EventPublication, bool> c = on != null ?
                                              pub => pub.Event == on && condition(pub) :
                                              condition;

            _sm.DefineTransition(from, to, c, action);
        }
Example #3
0
        public void RegisterHandler <TArgs>(
            ScreenLifecycleEvent <TArgs> @event,
            Action <TArgs> handler,
            ExecutionOrder order = ExecutionOrder.Default
            ) where TArgs : ScreenEventArgs
        {
            IEventSubscription sub;
            bool isInitializeWithoutSubject = typeof(TArgs) == typeof(InitializeEventArgs);
            bool isInitializeWithSubject    = typeof(InitializeEventArgs).IsAssignableFrom(typeof(TArgs));

            if (isInitializeWithoutSubject)
            {
                sub = new InitializeSubscription(
                    @event,
                    order,
                    (Action <InitializeEventArgs>)handler
                    );
            }
            else if (isInitializeWithSubject)
            {
                Type subjectType = typeof(TArgs)
                                   .GetGenericArguments()
                                   .Single();

                Type subscriptionType = typeof(InitializeSubscription <>)
                                        .MakeGenericType(subjectType);

                sub = (IEventSubscription)Activator.CreateInstance(
                    subscriptionType,
                    @event,
                    order,
                    handler
                    );
            }
            else
            {
                sub = new EventSubscription <TArgs>(
                    @event,
                    handler,
                    order
                    );
            }

            _handlers.Add(sub);
        }