Esempio n. 1
0
        public EventAutomation(IComponentContext context, EventAutomationSettings settings)
        {
            Guard.NotNull(() => context, context);
            Guard.NotNull(() => settings, settings);

            this.scope = context.BeginScope(c => { });
            // TODO: see how to make this generic and not tied to Autofac somehow?
            ((ComponentContext)scope).Scope.ComponentRegistry.AddRegistrationSource(this);

            this.binding = scope.Resolve<IBindingFactory>()
                .CreateBinding<IObservable<IEventPattern<object, EventArgs>>>(scope, settings.Binding);

            this.binding.Refresh();
            this.subscription = this.binding.Instance.Subscribe(OnEvent);

            if (settings.CommandSettings != null)
                command = new Lazy<ICommandAutomation>(() => settings.CommandSettings.CreateAutomation(scope));
        }
        /// <summary>
        /// Simulates runtime behavior.
        /// </summary>
        private static Product InstantiateProduct(IComponentContext context)
        {
            var schema = context.Resolve<IToolkitCatalog>().Toolkits.First().Products.First();

            // User instantiates a product via Solution Builder:
            var product = new Product("MyWebService", typeof(IAmazonWebServices).FullName);
            ComponentMapper.SyncProduct(product, schema);

            var productContext = context.BeginScope(b => b.RegisterInstance(product));
            foreach (var setting in schema.Automations)
            {
                product.AddAutomation(setting.CreateAutomation(productContext));
            }

            return product;
        }