Beispiel #1
0
        public virtual void Rollback()
        {
            if (this.args.Restore)
            {
                this.step = OperationStep.STARTED;
            }

            if (this.step == OperationStep.NONE || this.step == OperationStep.BACKEDUP)
            {
                Console.WriteLine("No rollback required");
                return;
            }

            if (this.step == OperationStep.STARTED && !this.args.NoStart)
            {
                this.Stop();
                Console.WriteLine(this.args.DeployType + " stop complete...");
            }

            if (this.step == OperationStep.STARTED || this.step == OperationStep.DEPLOYED)
            {
                this.Restore();
                Console.WriteLine(this.args.DeployType + " restore complete...");
            }

            if ((this.step == OperationStep.STARTED || this.step == OperationStep.DEPLOYED || this.step == OperationStep.STOPPED) && !this.args.NoStop)
            {
                this.Start();
                Console.WriteLine(this.args.DeployType + " start complete...");
            }
        }
Beispiel #2
0
        public virtual void Execute()
        {
            this.args.Restore = true;

            if (!this.args.NoBackup)
            {
                this.Backup();
                Console.WriteLine(this.args.DeployType + " backup complete...");
            }
            step = OperationStep.BACKEDUP;

            if (!this.args.NoStop)
            {
                this.Stop();
                Console.WriteLine(this.args.DeployType + " stop complete...");
            }
            step = OperationStep.STOPPED;

            this.Deploy();
            Console.WriteLine(this.args.DeployType + " deploy complete...");
            step = OperationStep.DEPLOYED;

            if (!this.args.NoStart)
            {
                this.Start();
                Console.WriteLine(this.args.DeployType + " start complete...");
            }
            step = OperationStep.STARTED;
        }
Beispiel #3
0
 protected virtual IEnumerable <OperationTransformerBase> ObtainTransformers(OperationStep step, ScaffoldOperationConfiguration configuration)
 {
     if (step.GetScope() == TransformationScope.AfterGlobals)
     {
         return(configuration.GlobalTransformers.Union(step.GetTransformers()));
     }
     return(step.GetTransformers().Union(configuration.GlobalTransformers));
 }
Beispiel #4
0
        public void OperationStep_InitialState_HasExpectedValues()
        {
            var title = "Test Step";
            var step  = new OperationStep(1, title, () => { return(Task.FromResult(true)); });

            step.Should().NotBeNull();
            step.Status.Should().Be(OperationStepStatus.NotStarted);
            step.OnAction.Should().NotBeNull();
            step.DisplayText.Should().Be(title);
            step.ErrorText.Should().BeNullOrWhiteSpace();
        }
Beispiel #5
0
        public void OperationStep_CorrectInitialState()
        {
            var title = "Test Step";
            var step  = new OperationStep(1, title, trueAction);

            step.Should().NotBeNull();
            step.Status.Should().Be(OperationStepStatus.NotStarted);
            step.OnAction.Should().NotBeNull();
            step.DisplayText.Should().Be(title);
            step.ErrorText.Should().BeNullOrWhiteSpace();
        }
Beispiel #6
0
        public void OperationStep_FailsCorrectly()
        {
            var title = "Test Step";
            var step  = new OperationStep(1, title, falseAction);

            step.Should().NotBeNull();
            step.Start();
            Thread.Sleep(500);
            step.Status.Should().Be(OperationStepStatus.InProgress);
            Thread.Sleep(3000);
            step.Status.Should().Be(OperationStepStatus.Failed);
        }
Beispiel #7
0
        public void OperationStep_FullLifecycle_RaisesExpectedEvents()
        {
            var canComplete = false;
            var hasStarted  = false;

            var title = "Test Step";
            var step  = new OperationStep(1, title, () => { hasStarted = true; SpinWait.SpinUntil(() => { return(canComplete); }, 10000); return(Task.FromResult(true)); });

            using var monitor = step.Monitor();

            // check initial state
            step.Should().NotBeNull();
            step.Status.Should().Be(OperationStepStatus.NotStarted);
            step.OnAction.Should().NotBeNull();
            step.DisplayText.Should().Be(title);
            step.ErrorText.Should().BeNullOrWhiteSpace();

            // fire off the operation step on another thread so that we can watch its status here
            Task.Run(() =>
            {
                step.Start();
            }).ConfigureAwait(false);
            SpinWait.SpinUntil(() => { return(hasStarted); }, 10000);

            // check for in-progress state
            step.Status.Should().Be(OperationStepStatus.InProgress);
            step.ErrorText.Should().BeNullOrWhiteSpace();

            monitor.Should().RaisePropertyChangeFor(c => c.Status);
            monitor.Should().RaisePropertyChangeFor(c => c.Label);
            monitor.Clear();

            // allow the step to complete
            canComplete = true;

            // ensure that the step reaches the final state without an error
            var hasCompleted = SpinWait.SpinUntil(() => { return(step.Status == OperationStepStatus.Succeeded); }, 10000);

            hasCompleted.Should().BeTrue();
            step.ErrorText.Should().BeNullOrWhiteSpace();

            monitor.Should().RaisePropertyChangeFor(c => c.Status);
            monitor.Should().RaisePropertyChangeFor(c => c.Label);
        }
Beispiel #8
0
        public void OperationStep_OnReset_HasExpectedValues()
        {
            var canComplete = false;
            var hasStarted  = false;

            var title = "Test Step";
            var step  = new OperationStep(1, title, () => { hasStarted = true; SpinWait.SpinUntil(() => { return(canComplete); }, 10000); return(Task.FromResult(false)); });

            // check initial state
            step.Should().NotBeNull();
            step.Status.Should().Be(OperationStepStatus.NotStarted);
            step.OnAction.Should().NotBeNull();
            step.DisplayText.Should().Be(title);
            step.ErrorText.Should().BeNullOrWhiteSpace();

            // fire off the operation step on another thread so that we can watch its status here
            Task.Run(() =>
            {
                step.Start();
            }).ConfigureAwait(false);
            SpinWait.SpinUntil(() => { return(hasStarted); }, 10000);

            // check for in-progress state
            step.Status.Should().Be(OperationStepStatus.InProgress);
            step.ErrorText.Should().BeNullOrWhiteSpace();

            // allow the step to complete
            canComplete = true;

            // ensure that the step reaches the final state without an error
            var hasCompleted = SpinWait.SpinUntil(() => { return(step.Status > OperationStepStatus.InProgress); }, 10000);

            hasCompleted.Should().BeTrue();

            step.Status.Should().Be(OperationStepStatus.Failed);
            step.ErrorText.Should().BeNullOrWhiteSpace();

            // reset the step and check its state again
            step.ErrorText = "reset should clear this text!";
            step.Reset();
            step.Status.Should().Be(OperationStepStatus.NotStarted);
            step.ErrorText.Should().BeNullOrWhiteSpace();
        }
Beispiel #9
0
        protected virtual IEnumerable <Operation> BuildOperations(OperationStep step, ScaffoldOperationConfiguration configuration, SourcingContext context)
        {
            var source          = step.GetSource(configuration);
            var sourcingResults = source.Generate(context);

            foreach (var result in sourcingResults)
            {
                var destinationFilename = result.FileName;
                var destinationFilepath = result.FilePath;
                var streamTransformers  = new List <IStreamTransformer>();

                foreach (var transformer in configuration.GlobalTransformers.Union(step.GetTransformers()))
                {
                    destinationFilepath = transformer.TransformFilename(destinationFilepath);
                    destinationFilename = transformer.TransformFilename(destinationFilename);
                    streamTransformers.Add(transformer.CreateStreamTransformer());
                }

                var actualTransformer = new CompoundStreamTransformer(streamTransformers);

                var persistenceContext = new PersistenceContext()
                {
                    FilePath        = destinationFilepath,
                    Filename        = destinationFilename,
                    TargetDirectory = context.TargetRoot
                };

                foreach (var emitter in step.GetEmitters())
                {
                    foreach (var actualEmitter in  emitter.CreatePersisters(persistenceContext))
                    {
                        yield return(new Operation(result.Provider, actualTransformer, actualEmitter));
                    }
                }
            }
        }