Exemplo n.º 1
0
        public IActivator Subscribe(ActivatorCallback callback)
        {
            var config = new SubscriptionConfiguration()
            {
                OnActivate = callback,
            };

            return(this.Subscribe(config));
        }
Exemplo n.º 2
0
        public IActivator Subscribe(SubscriptionConfiguration config)
        {
            var priority = config.Priority;

            switch (config.PreferredPriority)
            {
            case SubscriptionConfigurationPriority.Highest:
                priority = this.GetHighestPriorityActivator() + 1;
                break;

            case SubscriptionConfigurationPriority.Lowest:
                priority = this.GetLowestPriorityActivator() - 1;
                break;

            case SubscriptionConfigurationPriority.Midrange:
                priority = this.GetHighestPriorityActivator() / 2;
                break;
            }
            var activator = new Activator(this)
            {
                Name          = config.Name,
                Namespace     = this.Namespace,
                Version       = config.Version,
                Priority      = priority,
                SelfActivate  = config.SelfActivate,
                OnActivate    = config.OnActivate,
                OnUnsubscribe = config.OnUnsubscribe,
            };

            this.Activators.Add(activator);
            this.Activators.Sort((x, y) => - 1 * x.Priority.CompareTo(y.Priority));

            // TODO: log subscription

            return(activator);
        }