Example #1
0
        public async Task DeployAsync(IDeploymentContext context,
                                      IEnumerable <IDeploymentResource> resources,
                                      CancellationToken cancellationToken)
        {
            //
            // Create a map between resources and activities, so we can easily
            // map dependencies later on
            //
            var order = 0;
            var map   = new Dictionary <IDeploymentResource, IDeploymentActivity>();

            foreach (var resource in resources)
            {
                order++;
                var t        = typeof(IDeploymentResourceProvider <>);
                var x        = t.MakeGenericType(resource.GetType());
                var provider = context.DeploymentServices.GetService(x);
                var adaptor  = new DeploymentResourceProviderAdaptor(provider);
                Expression <Func <Task> > expression = () => adaptor.SetAsync(context, resource, cancellationToken);
                var activity = new DeploymentActivity(resource.Key, expression, order);
                map.Add(resource, activity);
            }

            //
            // Add all the acitivies to the graph
            //
            var activityGraph = new Graph <IDeploymentActivity>();

            foreach (var value in map.Values)
            {
                activityGraph.Add(value);
            }

            //
            // Create dependencies between activities
            //
            foreach (var pair in map)
            {
                var resource = pair.Key;
                var activity = pair.Value;

                foreach (var antecedent in resource.Antecedents)
                {
                    var antecedentActivity = map[antecedent];
                    activityGraph.SetAntecedent(activity, antecedentActivity);
                }
            }

            //
            // Execute the activities
            //
            await activityGraph.Walk(activity => activity.ExecuteAsync(), context.Parallel);
        }
        public async Task Constructor_Should_Wrap_Provider()
        {
            // Act
            var provider         = new StubResourceProvider1();
            var target           = new DeploymentResourceProviderAdaptor(provider);
            var resource         = new MockResource(null);
            var resourceProvider = new MockDeploymentResourceProvider();
            var context          = new MockDeploymentContext(resourceProvider);
            await target.SetAsync(context, resource, CancellationToken.None);

            //Assert
            Assert.IsTrue(provider.BeenCalled);
        }