protected override void Execute(SpecificationContext ctx) { ProjectConstant theConstant = null; // Perform the main work of the task here. if (ctx.Project.Constants.TryGetConstant(MyName.Value, ref theConstant)) { // Set the constant value. theConstant.Value = MyValue.Value; //Check if Value is empty or null if (string.IsNullOrEmpty(MyValue.Value)) { //Report Value is empty. this.SetState(NodeExecutionState.SuccessfulWithWarnings, "The constant value was successfully cleared."); } else { // Mark the Task as successful. this.SetState(NodeExecutionState.Successful, "The constant value was successfully set."); } //Set node output value MyNodeOutput.Fulfill(string.Format("The constant '{0}' value was successfully set.", MyName.Value)); } else { // Mark the Task as failed and report that we could not find the constant. this.SetState(NodeExecutionState.Failed, string.Format("The constant '{0}' does not exist.", MyName.Value)); // Set node output value MyNodeOutput.Fulfill(string.Format("The constant '{0}' does not exist.", MyName.Value)); } }
private static void ThrowSpecificationErrorWithoutLabel(SpecificationContext context, SpecificationResult result, SetDefinitionTarget?priorTarget, SetDefinitionTarget target) { string targetDescription; Type targetType; string targetName; if (priorTarget == null) { var parameter = context.GetFirstVariable(); targetDescription = $"parameter \"{parameter.Label.Name}\""; targetType = parameter.Type; targetName = parameter.Label.Name; } else if (result.TryGetLabelOf(priorTarget, out var priorLabel)) { targetDescription = $"prior variable \"{priorLabel.Name}\""; targetType = priorTarget.Type; targetName = priorLabel.Name; } else { targetDescription = $"prior variable"; targetType = priorTarget.Type; targetName = "x"; } var typeName = target.Type.Name; var variable = ToInitialLowerCase(typeName); var message = $"The set should be joined to the {targetDescription}."; var recommendation = RecommendationEngine.RecommendJoin( new CodeExpression(target.Type, variable), new CodeExpression(targetType, targetName) ); throw new SpecificationException(recommendation == null ? message : $"{message} Consider \"facts.OfType<{typeName}>({variable} => {recommendation})\"."); }
public static Pipeline CreatePipeline(SpecificationContext context, SpecificationResult result) { SetDefinitionTarget?priorTarget = null; foreach (var target in result.Targets) { if (!result.SetDefinitions.Any(set => IsJoinTargeting(set, target))) { if (result.TryGetLabelOf(target, out var label)) { ThrowSpecificationErrorWithLabel(context, result, priorTarget, target, label); } else { ThrowSpecificationErrorWithoutLabel(context, result, priorTarget, target); } } priorTarget = target; } var pipeline = context.Labels .Aggregate(Pipeline.Empty, (p, label) => p.AddStart(label)); foreach (var setDefinition in result.SetDefinitions) { pipeline = AppendToPipeline(pipeline, context, setDefinition, result); } return(pipeline); }
protected override bool Evaluate(SpecificationContext specificationContext) { // If a number is evenly divisible by 2 with no remainder, then it is even. var isEven = (mValue.Value % 2) == 0; return(isEven); }
public static Specification CreateSpecification(SpecificationContext context, SpecificationResult result) { var pipeline = PipelineGenerator.CreatePipeline(context, result); var projection = CreateProjection(result.SymbolValue); return(new Specification(pipeline, projection)); }
public static List <ControlState> SetControlValueListToSpecification(SpecificationContext iContext, List <ControlState> iControlList) { var errorControlState = new List <ControlState>(); //Bouclage sur les Etats de controles pour Application de la synthèse foreach (var controlStateItem in iControlList.Enum()) { try { var theControl = iContext.Project.Navigation.GetControl(controlStateItem.Name); try { if (controlStateItem.Value != null) { iContext.Project.SetControlBaseFromControlState(theControl, controlStateItem); } } catch { } } catch (Exception ex) { throw new Exception("Le controle nommé '" + controlStateItem.Name + "' n'existe pas. Sa suppression n'est pas gérée", ex); } } //Bouclage de vérification car une règle du configurateur pourrait faire une modification après écriture foreach (var controlStateItem in iControlList.Enum()) { try { var theControl = iContext.Project.Navigation.GetControl(controlStateItem.Name); var controlState = iContext.Project.GetControlStateFormControlBase(theControl); if (controlStateItem.Value != null) { if (controlState.Value != controlStateItem.Value) { errorControlState.Add(controlStateItem); } else if (controlState.Value2 != controlStateItem.Value2) { errorControlState.Add(controlStateItem); } } } catch (Exception ex) { throw new Exception("Le controle nommé '" + controlStateItem.Name + "' n'existe pas. Sa suppression n'est pas gérée", ex); } } return(errorControlState); }
protected override void Execute(SpecificationContext ctx) { // Begin reporting process ctx.Report.BeginProcess(myReportClass.Value, myReportTarget.Value, myReportDescription.Value); ///Write report ///Reporting.ReportingLevel.Minimal sets reporting level. Select from following: ///None ///Minimal ///Normal ///Verbose /// Reporting.ReportEntryType.Information sets reporting entry type. Select one from the following: ///Information ///Warning ///Error ctx.Report.WriteEntry(Reporting.ReportingLevel.Minimal, Reporting.ReportEntryType.Information, myReportClass.Value, myReportTarget.Value, myReportDescription.Value, myReportEntryDetail.Value); ///End reporting process ctx.Report.EndProcess(); }
private static Pipeline AppendToPipeline(Pipeline pipeline, SpecificationContext context, SetDefinition setDefinition, SpecificationResult result) { if (setDefinition is SetDefinitionPredecessorChain predecessorChainSet) { var chain = predecessorChainSet.ToChain(); var targetSetDefinition = chain.TargetSetDefinition; var start = targetSetDefinition.Label; var target = new Label(predecessorChainSet.Role, chain.TargetFactType); var path = new Path(start, target); return(pipeline.AddPath(AddPredecessorSteps(path, chain))); } else if (setDefinition is SetDefinitionJoin joinSet) { var head = joinSet.Head; var tail = joinSet.Tail; var sourceSetDefinition = head.TargetSetDefinition; var source = sourceSetDefinition.Label; var target = joinSet.Label; var path = new Path(source, target); return(pipeline.AddPath(PrependSuccessorSteps(AddPredecessorSteps(path, head), tail))); } else if (setDefinition is SetDefinitionConditional conditionalSet) { var targetSetDefinition = conditionalSet.Source; var start = targetSetDefinition.Label; var childPipeline = CreatePipeline( SpecificationContext.Empty .With(start, SpecificationParser.InstanceOfFact(targetSetDefinition.Type), targetSetDefinition.Type), conditionalSet.Condition.SpecificationResult); var conditional = new Conditional(start, conditionalSet.Condition.Exists, childPipeline); return(pipeline.AddConditional(conditional)); } else { throw new NotImplementedException(); } }
public SpecificationRepo(SpecificationContext context) { _context = context; }
public void Given_a_specification_context() { systemUnderTest = new SpecificationContext(); RecordStep(); }
public string GetEditingSpecificationName(SpecificationContext iContext) { return(Path.GetFileNameWithoutExtension(iContext.SpecificationFilePath)); }
protected override bool Evaluate(SpecificationContext specificationContext) { // Do something here to determine if the condition is met. return(MyProperty.Value); }