示例#1
0
        public void VerifyCpp2EvaluatorNumerics()
        {
            VariableCollection vc = new VariableCollection();
            bool result           = Cpp2StyleEvaluatorDefinition.EvaluateFromString(_logger, "0x20 == '32'", vc);

            Assert.True(result);
        }
        internal static IReadOnlyList <ICreationPath> ListFromModel(IEngineEnvironmentSettings environmentSettings, IReadOnlyList <ICreationPathModel> modelList, IVariableCollection rootVariableCollection)
        {
            List <ICreationPath> pathList = new List <ICreationPath>();

            if (rootVariableCollection == null)
            {
                rootVariableCollection = new VariableCollection();
            }

            foreach (ICreationPathModel model in modelList)
            {
                // Note: this check is probably superfluous. The Model has evaluation info.
                // OTOH: this is probaby a cleaner way to do it.
                if (string.IsNullOrEmpty(model.Condition) ||
                    Cpp2StyleEvaluatorDefinition.EvaluateFromString(environmentSettings, model.Condition, rootVariableCollection))
                {
                    ICreationPath path = new CreationPath()
                    {
                        Path = model.PathResolved
                    };
                    pathList.Add(path);
                }
            }

            return(pathList);
        }
示例#3
0
        public void VerifyCpp2EvaluatorMath()
        {
            VariableCollection vc = new VariableCollection();
            bool result           = Cpp2StyleEvaluatorDefinition.EvaluateFromString(_logger, "4 + 9 / (2 + 1) == (0x38 >> 2) / (1 << 0x01)", vc);

            Assert.True(result);
        }
示例#4
0
        private static IReadOnlyList <IOperationProvider> SetupCustomOperations(IReadOnlyList <ICustomOperationModel> customModel, IDirectory templateRoot, IVariableCollection variables)
        {
            ITemplateEngineHost       host             = templateRoot.MountPoint.EnvironmentSettings.Host;
            List <IOperationProvider> customOperations = new List <IOperationProvider>();

            foreach (ICustomOperationModel opModelUntyped in customModel)
            {
                CustomOperationModel opModel = opModelUntyped as CustomOperationModel;
                if (opModel == null)
                {
                    host.LogMessage($"Operation type = [{opModelUntyped.Type}] could not be cast as a CustomOperationModel");
                    continue;
                }

                string opType    = opModel.Type;
                string condition = opModel.Condition;

                if (string.IsNullOrEmpty(condition) ||
                    Cpp2StyleEvaluatorDefinition.EvaluateFromString(templateRoot.MountPoint.EnvironmentSettings, condition, variables))
                {
                    IOperationConfig realConfigObject;
                    if (_operationConfigLookup.TryGetValue(opType, out realConfigObject))
                    {
                        customOperations.AddRange(
                            realConfigObject.ConfigureFromJObject(opModel.Configuration, templateRoot));
                    }
                    else
                    {
                        host.LogMessage($"Operation type = [{opType}] from configuration is unknown.");
                    }
                }
            }

            return(customOperations);
        }
        internal static List <IPostAction> ListFromModel(IEngineEnvironmentSettings environmentSettings, IReadOnlyList <IPostActionModel> modelList, IVariableCollection rootVariableCollection)
        {
            List <IPostAction> actionList = new List <IPostAction>();

            if (rootVariableCollection == null)
            {
                rootVariableCollection = new VariableCollection();
            }

            foreach (IPostActionModel model in modelList)
            {
                model.EvaluateCondition(environmentSettings, rootVariableCollection);

                if (!model.ConditionResult)
                {
                    // Condition on the post action is blank, or not true. Don't include this post action.
                    continue;
                }

                string chosenInstruction = string.Empty;

                if (model.ManualInstructionInfo != null)
                {
                    foreach (KeyValuePair <string, string> modelInstruction in model.ManualInstructionInfo)
                    {
                        if (string.IsNullOrEmpty(modelInstruction.Value))
                        {
                            // no condition
                            if (string.IsNullOrEmpty(chosenInstruction))
                            {
                                // No condition, and no instruction previously chosen. Take this one.
                                // We don't want a default instruction to override a conditional one.
                                chosenInstruction = modelInstruction.Key;
                            }
                        }
                        else if (Cpp2StyleEvaluatorDefinition.EvaluateFromString(environmentSettings, modelInstruction.Value, rootVariableCollection))
                        {
                            // condition is not blank and true, take this one. This results in a last-in-wins behaviour for conditions that are true.
                            chosenInstruction = modelInstruction.Key;
                        }
                    }
                }

                IPostAction postAction = new PostAction()
                {
                    Description        = model.Description,
                    ActionId           = model.ActionId,
                    ContinueOnError    = model.ContinueOnError,
                    Args               = model.Args,
                    ManualInstructions = chosenInstruction,
                    ConfigFile         = model.ConfigFile,
                };

                actionList.Add(postAction);
            }

            return(actionList);
        }
示例#6
0
        public void VerifyCpp2EvaluatorStringEquals()
        {
            VariableCollection vc = new VariableCollection
            {
                ["FIRST_IF"] = "1.2.3"
            };
            bool result = Cpp2StyleEvaluatorDefinition.EvaluateFromString(_logger, "FIRST_IF == '1.2.3'", vc);

            Assert.True(result);
        }
示例#7
0
        public void VerifyCpp2EvaluatorFalse()
        {
            VariableCollection vc = new VariableCollection
            {
                ["FIRST_IF"] = false
            };
            bool result = Cpp2StyleEvaluatorDefinition.EvaluateFromString(_logger, "FIRST_IF", vc);

            Assert.False(result);
        }
示例#8
0
        public void VerifyCpp2EvaluatorTrue()
        {
            VariableCollection vc = new VariableCollection
            {
                ["FIRST_IF"] = true
            };
            bool result = Cpp2StyleEvaluatorDefinition.EvaluateFromString(EnvironmentSettings, "FIRST_IF", vc);

            Assert.True(result);
        }
示例#9
0
        public void VerifyCpp2EvaluatorMultipleNotEqualsAnd()
        {
            VariableCollection vc = new VariableCollection
            {
                ["FIRST_IF"]  = false,
                ["SECOND_IF"] = false
            };
            bool result = Cpp2StyleEvaluatorDefinition.EvaluateFromString(_logger, "!!!FIRST_IF && !SECOND_IF == !FIRST_IF", vc);

            Assert.True(result);
        }
示例#10
0
        public void VerifyCpp2EvaluatorBitShiftAddEquals()
        {
            VariableCollection vc = new VariableCollection
            {
                ["FIRST"]  = 8,
                ["SECOND"] = 5
            };
            bool result = Cpp2StyleEvaluatorDefinition.EvaluateFromString(_logger, "FIRST >> 1 + 2 == 1 + SECOND", vc);

            Assert.True(result);
        }
示例#11
0
        public void VerifyCpp2EvaluatorShifts()
        {
            VariableCollection vc = new VariableCollection
            {
                ["FIRST"]  = "4",
                ["SECOND"] = "64"
            };
            bool result = Cpp2StyleEvaluatorDefinition.EvaluateFromString(_logger, "FIRST << 2 == SECOND >> 2", vc);

            Assert.True(result);
        }
示例#12
0
        public void VerifyCpp2EvaluatorAndEqualsNot()
        {
            VariableCollection vc = new VariableCollection
            {
                ["FIRST_IF"]  = false,
                ["SECOND_IF"] = false
            };
            bool result = Cpp2StyleEvaluatorDefinition.EvaluateFromString(EnvironmentSettings, "FIRST_IF == SECOND_IF && !FIRST_IF", vc);

            Assert.True(result);
        }
 public void EvaluateCondition(IEngineEnvironmentSettings environmentSettings, IVariableCollection variables)
 {
     if (string.IsNullOrEmpty(Condition) ||
         Cpp2StyleEvaluatorDefinition.EvaluateFromString(environmentSettings, Condition, variables))
     {
         ConditionResult = true;
     }
     else
     {
         ConditionResult = false;
     }
 }
 public bool EvaluateCondition(ILogger logger, IVariableCollection variables)
 {
     return(ConditionResult = string.IsNullOrEmpty(Condition) ||
                              Cpp2StyleEvaluatorDefinition.EvaluateFromString(logger, Condition, variables));
 }