示例#1
0
        private void RunScript(Stream scriptSource)
        {
            var script = _scriptDeserializer.GetDeserializedScript(scriptSource);

            var scriptContext = new ScriptContext(script);

            foreach (var update in script.Update)
            {
                var updateContext = new UpdateContext(update, scriptContext);

                foreach (var step in update.UpdateStep)
                {
                    var stepContext = new UpdateStepContext(step, updateContext);

                    var preconditions = ResolvePreconditions(stepContext, step, script);
                    var context       = new UpdateStepContextWithPreconditions(stepContext, preconditions);
                    if (!_preconditionService.IsMet(context))
                    {
                        _logger.LogInformation($"{context} precondition resulted in skipping the step");
                        continue;
                    }


                    _updateStepService.Execute(context);
                }
            }
        }
示例#2
0
        public bool IsMet(UpdateStepContextWithPreconditions context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (context.Preconditions == null)
            {
                throw new InvalidOperationException();
            }

            return(context.Preconditions.All(p =>
            {
                var updateStepContextPrecondition = new UpdateStepContextPrecondition(context, p);
                var result = IsMet(updateStepContextPrecondition);
                return result;
            }));
        }
示例#3
0
        public void Execute(UpdateStepContextWithPreconditions context)
        {
            foreach (var updateStepHandler in _updateStepHandlers)
            {
                if (!updateStepHandler.CanHandle(context))
                {
                    continue;
                }

                _logger.LogInformation($"Going to execute {context}");

                updateStepHandler.Execute(context);

                _logger.LogInformation($"{context} was executed");

                if (context.Step.MarkAsExecuted)
                {
                    try
                    {
                        _transactionProvider.BeginTransaction();

                        _updateStepExecutedMarker.MarkAsExecuted(context.AssemblyName, context.UpdateVersion,
                                                                 context.StepNumber);

                        _logger.LogInformation($"{context} was marked as executed");

                        _transactionProvider.CommitTransaction();
                    }
                    catch (Exception ex)
                    {
                        _transactionProvider.RollbackTransaction();

                        throw new InvalidOperationException($"{context} couldn't be marked as executed", ex);
                    }
                }
            }
        }
示例#4
0
 public UpdateStepContextWithPreconditions(UpdateStepContextWithPreconditions context) : base(context)
 {
 }