Esempio n. 1
0
        private ScenarioModel CreateScenarioWithMethods(
            [NotNull] ScenarioModel baseScenario,
            [NotNull, ItemNotNull] IEnumerable <MethodActionModel> methods,
            [NotNull] ModelContainer container)
        {
            const string uniqueIdDef = "UniqueId";

            var precedingActionTypes = new[]
            {
                typeof(BarrierActionModel),
                typeof(RebootActionModel)
            };

            var newScenario = (ScenarioModel)baseScenario.Clone();

            newScenario.Id      = container.NextId();
            newScenario.Name    = Api.GetAssemblyAndMethod(methods.First().Method.Expr).Field1.Name;
            newScenario.Actions = new List <BaseActionModel>();

            var originalActions = baseScenario.Actions;

            foreach (var method in methods)
            {
                var index = originalActions.FindIndex(m => m == method);
                var i     = index;
                while (--i >= 0 && precedingActionTypes.Contains(originalActions[i].GetType()))
                {
                }

                while (++i < index)
                {
                    newScenario.Actions.Add(originalActions[i]);
                }

                newScenario.Actions.Add(method);

                if (index < originalActions.Count - 2 &&
                    originalActions[index + 1].GetType() == typeof(WaitForRebootActionModel))
                {
                    newScenario.Actions.Add(originalActions[index + 1]);
                }
            }

            UpdateScenarioDefinitionModel(newScenario, uniqueIdDef, Guid.NewGuid().ToString());
            newScenario.Init(container);
            UpdateReference(newScenario);

            container.Add(newScenario);

            return(newScenario);
        }