internal FSMComponent(Dictionary <string, State> states, IVariableCollection variables, string startState) { this.variables = variables; this.startState = startState; this.states = states; this.states.Values.ForEach(x => x.FSM = this); }
private static void ValidateParent(IVariableCollection variables, ISequenceFlowContainer parent) { foreach (IVariable variable in variables) { variable.Parent = parent; } }
private static ArgumentValue CreateArgumentValue( InputField argument, IDictionary <string, IValueNode> argumentValues, IVariableCollection variables, Func <string, IError> createError) { object argumentValue; try { argumentValue = CoerceArgumentValue( argument, variables, argumentValues); } catch (ScalarSerializationException ex) { throw new QueryException(createError(ex.Message)); } if (argument.Type is NonNullType && argumentValue == null) { throw new QueryException(createError(string.Format( CultureInfo.InvariantCulture, TypeResources.ArgumentValueBuilder_NonNull, argument.Name, TypeVisualizer.Visualize(argument.Type)))); } InputTypeNonNullCheck.CheckForNullValueViolation( argument.Type, argumentValue, createError); return(new ArgumentValue(argument.Type, argumentValue)); }
private static IVariableCollection SetupVariables(IEngineEnvironmentSettings environmentSettings, IParameterSet parameters, IVariableConfig variableConfig) { IVariableCollection variables = VariableCollection.SetupVariables(environmentSettings, parameters, variableConfig); foreach (Parameter param in parameters.ParameterDefinitions.OfType <Parameter>()) { // Add choice values to variables - to allow them to be recognizable unquoted if (param.EnableQuotelessLiterals && param.IsChoice()) { foreach (string choiceKey in param.Choices.Keys) { if ( variables.TryGetValue(choiceKey, out object existingValueObj) && existingValueObj is string existingValue && !string.Equals(choiceKey, existingValue, StringComparison.CurrentCulture) ) { throw new InvalidOperationException(string.Format(LocalizableStrings.RunnableProjectGenerator_CannotAddImplicitChoice, choiceKey, existingValue)); } variables[choiceKey] = choiceKey; } } } return(variables); }
public static void Populate(IVariableCollection variables) { variables.Add(new DIRECTORY_SEPARATOR()); variables.Add(new @true()); variables.Add(new @false()); variables.Add(new @null()); }
private static bool TryGetMultiplierFromObject( FieldNode field, IVariableCollection variables, string multiplierPath, out int value) { var path = new Queue <string>(multiplierPath.Split('.')); string name = path.Dequeue(); ArgumentNode argument = field.Arguments .FirstOrDefault(t => t.Name.Value == name); if (argument == null) { value = default; return(false); } IValueNode current = argument.Value; while (current is ObjectValueNode) { if (current is ObjectValueNode obj) { current = ResolveObjectField(obj, path); } } return(TryParseValue(current, variables, out value)); }
private static ArgumentValue CreateArgumentValue( FieldSelection fieldSelection, InputField argument, Dictionary <string, IValueNode> argumentValues, IVariableCollection variables, Path path) { object argumentValue = null; try { argumentValue = CoerceArgumentValue( argument, variables, argumentValues); } catch (ScalarSerializationException ex) { throw new QueryException(QueryError.CreateArgumentError( ex.Message, path, fieldSelection.Nodes.First(), argument.Name)); } if (argument.Type is NonNullType && argumentValue == null) { throw new QueryException(QueryError.CreateArgumentError( $"The argument type of '{argument.Name}' is a " + "non-null type.", path, fieldSelection.Nodes.First(), argument.Name)); } return(new ArgumentValue(argument.Type, argumentValue)); }
public void EvaluateConfig(IEngineEnvironmentSettings environmentSettings, IVariableCollection vars, IMacroConfig rawConfig, IParameterSet parameters, ParameterSetter setter) { ConstantMacroConfig config = rawConfig as ConstantMacroConfig; if (config == null) { throw new InvalidCastException("Couldn't cast the rawConfig as ConstantMacroConfig"); } Parameter p; if (parameters.TryGetParameterDefinition(config.VariableName, out ITemplateParameter existingParam)) { // If there is an existing parameter with this name, it must be reused so it can be referenced by name // for other processing, for example: if the parameter had value forms defined for creating variants. // When the param already exists, use its definition, but set IsVariable = true for consistency. p = (Parameter)existingParam; p.IsVariable = true; } else { p = new Parameter { IsVariable = true, Name = config.VariableName }; } vars[config.VariableName] = config.Value; setter(p, config.Value); }
public void EvaluateConfig(IEngineEnvironmentSettings environmentSettings, IVariableCollection vars, IMacroConfig rawConfig, IParameterSet parameters, ParameterSetter setter) { EvaluateMacroConfig config = rawConfig as EvaluateMacroConfig; if (config == null) { throw new InvalidCastException("Couldn't cast the rawConfig as EvaluateMacroConfig"); } ConditionEvaluator evaluator = EvaluatorSelector.Select(config.Evaluator); byte[] data = Encoding.UTF8.GetBytes(config.Value); int len = data.Length; int pos = 0; IProcessorState state = new GlobalRunSpec.ProcessorState(environmentSettings, vars, data, Encoding.UTF8); bool result = evaluator(state, ref len, ref pos, out bool faulted); Parameter p = new Parameter { IsVariable = true, Name = config.VariableName }; setter(p, result.ToString()); }
public static Dictionary <string, ArgumentValue> CoerceArgumentValues( this FieldSelection fieldSelection, IVariableCollection variables, Path path) { Dictionary <string, ArgumentValue> coercedArgumentValues = new Dictionary <string, ArgumentValue>(); Dictionary <string, IValueNode> argumentValues = fieldSelection.Selection.Arguments .Where(t => t.Value != null) .ToDictionary(t => t.Name.Value, t => t.Value); foreach (InputField argument in fieldSelection.Field.Arguments) { coercedArgumentValues[argument.Name] = CreateArgumentValue( argument, argumentValues, variables, message => QueryError.CreateArgumentError( message, path, fieldSelection.Nodes.First(), argument.Name)); } return(coercedArgumentValues); }
private static ArgumentValue CreateArgumentValue( InputField argument, IDictionary <string, IValueNode> argumentValues, IVariableCollection variables, Func <string, IError> createError) { object argumentValue = null; try { argumentValue = CoerceArgumentValue( argument, variables, argumentValues); } catch (ScalarSerializationException ex) { throw new QueryException(createError(ex.Message)); } if (argument.Type is NonNullType && argumentValue == null) { throw new QueryException(createError( $"The argument type of '{argument.Name}' " + "is a non-null type.")); } return(new ArgumentValue(argument.Type, argumentValue)); }
public void EvaluateConfig(IEngineEnvironmentSettings environmentSettings, IVariableCollection vars, IMacroConfig rawConfig, IParameterSet parameters, ParameterSetter setter) { JoinMacroConfig config = rawConfig as JoinMacroConfig; if (config == null) { throw new InvalidCastException("Couldn't cast the rawConfig as ConcatenationMacroConfig"); } List <string> values = new List <string>(); foreach (KeyValuePair <string, string> symbol in config.Symbols) { switch (symbol.Key) { case "ref": string value; if (!vars.TryGetValue(symbol.Value, out object working)) { if (parameters.TryGetRuntimeValue(environmentSettings, symbol.Value, out object resolvedValue, true)) { value = resolvedValue.ToString(); } else { value = string.Empty; } }
private static bool?EvaluateDirective( this DirectiveNode directive, IVariableCollection variables) { if (directive == null) { return(null); } ArgumentNode argumentNode = directive.Arguments.SingleOrDefault(); if (argumentNode == null) { throw new QueryException(new QueryError( $"The {directive.Name.Value} attribute is not valid.")); } if (argumentNode.Value is BooleanValueNode b) { return(b.Value); } if (argumentNode.Value is VariableNode v) { return(variables.GetVariable <bool>(v.Name.Value)); } throw new QueryException(new QueryError( $"The {directive.Name.Value} if-argument value has to be a 'Boolean'.")); }
public void EvaluateDeferredConfig(IVariableCollection vars, IMacroConfig rawConfig, IParameterSet parameters, ParameterSetter setter) { GeneratedSymbolDeferredMacroConfig deferredConfig = rawConfig as GeneratedSymbolDeferredMacroConfig; if (deferredConfig == null) { throw new InvalidCastException("Couldn't cast the rawConfig as a GeneratedSymbolDeferredMacroConfig"); } JToken formatToken; if (!deferredConfig.Parameters.TryGetValue("format", out formatToken)) { throw new ArgumentNullException("format"); } string format = formatToken.ToString(); bool utc; JToken utcToken; if (deferredConfig.Parameters.TryGetValue("utc", out utcToken)) { utc = utcToken.ToBool(); } else { utc = false; } IMacroConfig realConfig = new NowMacroConfig(deferredConfig.VariableName, format, utc); EvaluateConfig(vars, realConfig, parameters, setter); }
public FieldHelper( FieldCollector fieldCollector, DirectiveLookup directives, IVariableCollection variables, ICollection <IError> errors) { if (directives == null) { throw new ArgumentNullException(nameof(directives)); } if (variables == null) { throw new ArgumentNullException(nameof(variables)); } if (errors == null) { throw new ArgumentNullException(nameof(errors)); } _fieldCollector = fieldCollector;; _errors = errors; _directives = directives; }
public static Dictionary <string, ArgumentValue> CoerceArgumentValues( this FieldSelection fieldSelection, IVariableCollection variables) { Dictionary <string, ArgumentValue> coercedArgumentValues = new Dictionary <string, ArgumentValue>(); Dictionary <string, IValueNode> argumentValues = fieldSelection.Selection.Arguments .Where(t => t.Value != null) .ToDictionary(t => t.Name.Value, t => t.Value); foreach (InputField argument in fieldSelection.Field.Arguments) { string argumentName = argument.Name; IInputType argumentType = argument.Type; IValueNode defaultValue = argument.DefaultValue; object argumentValue = CoerceArgumentValue( argumentName, argumentType, defaultValue, variables, argumentValues); if (argumentType is NonNullType && argumentValue == null) { throw new QueryException(new QueryError( $"The argument type of '{argumentName}' is a " + "non-null type.")); } coercedArgumentValues[argumentName] = new ArgumentValue( argumentType, argumentValue); } return(coercedArgumentValues); }
public static bool TryGetMultiplierValue( FieldNode field, IVariableCollection variables, string multiplier, out int value) { if (field == null) { throw new ArgumentNullException(nameof(field)); } if (variables == null) { throw new ArgumentNullException(nameof(variables)); } if (multiplier == null) { throw new ArgumentNullException(nameof(multiplier)); } return(multiplier.IndexOf('.') == -1 ? TryGetMultiplierFromArgument( field, variables, multiplier, out value) : TryGetMultiplierFromObject( field, variables, multiplier, out value)); }
public void EvaluateConfig(IEngineEnvironmentSettings environmentSettings, IVariableCollection vars, IMacroConfig config, IParameterSet parameters, ParameterSetter setter) { CoalesceMacroConfig realConfig = config as CoalesceMacroConfig; if (realConfig == null) { throw new InvalidCastException("Unable to cast config as a CoalesceMacroConfig"); } object targetValue = null; if (vars.TryGetValue(realConfig.SourceVariableName, out object currentSourceValue) && !Equals(currentSourceValue ?? string.Empty, realConfig.DefaultValue ?? string.Empty)) { targetValue = currentSourceValue; } else { if (!vars.TryGetValue(realConfig.FallbackVariableName, out targetValue)) { environmentSettings.Host.LogDiagnosticMessage("Unable to find a variable to fall back to called " + realConfig.FallbackVariableName, "Authoring", realConfig.SourceVariableName, realConfig.DefaultValue); targetValue = realConfig.DefaultValue; } } Parameter pd = new Parameter { IsVariable = true, Name = config.VariableName }; vars[config.VariableName] = targetValue?.ToString(); setter(pd, targetValue?.ToString()); }
private void AddVariableTypeDatas(HashSet <ITypeData> typeDatas, IVariableCollection variables) { foreach (IVariable variable in variables.Where(variable => null != variable.Type)) { typeDatas.Add(variable.Type); } }
public static IVariable GetVariable(ISequence sequence, string runtimeVariable) { string[] variableElement = runtimeVariable.Split(VarNameDelim.ToCharArray()); IVariableCollection varCollection = sequence.Variables; return(varCollection.FirstOrDefault(item => item.Name.Equals(variableElement[variableElement.Length - 1]))); }
public Task <ICreationResult> CreateAsync(IEngineEnvironmentSettings environmentSettings, ITemplate templateData, IParameterSet parameters, IComponentManager componentManager, string targetDirectory) { RunnableProjectTemplate template = (RunnableProjectTemplate)templateData; ProcessMacros(environmentSettings, componentManager, template.Config.OperationConfig, parameters); IVariableCollection variables = VariableCollection.SetupVariables(environmentSettings, parameters, template.Config.OperationConfig.VariableSetup); template.Config.Evaluate(parameters, variables, template.ConfigFile); IOrchestrator basicOrchestrator = new Core.Util.Orchestrator(); RunnableProjectOrchestrator orchestrator = new RunnableProjectOrchestrator(basicOrchestrator); GlobalRunSpec runSpec = new GlobalRunSpec(template.TemplateSourceRoot, componentManager, parameters, variables, template.Config.OperationConfig, template.Config.SpecialOperationConfig, template.Config.LocalizationOperations, template.Config.PlaceholderFilename); foreach (FileSource source in template.Config.Sources) { runSpec.SetupFileSource(source); string target = Path.Combine(targetDirectory, source.Target); orchestrator.Run(runSpec, template.TemplateSourceRoot.DirectoryInfo(source.Source), target); } // todo: add anything else we'd want to report to the broker return(Task.FromResult <ICreationResult>(new CreationResult() { PostActions = PostAction.ListFromModel(environmentSettings, template.Config.PostActionModel, variables), PrimaryOutputs = CreationPath.ListFromModel(environmentSettings, template.Config.PrimaryOutputs, variables) })); }
public static IVariable GetVariable(ISequenceGroup sequenceGroup, string runtimeVariable) { string[] variableElement = runtimeVariable.Split(VarNameDelim.ToCharArray()); IVariableCollection varCollection = null; if (2 == variableElement.Length) { varCollection = sequenceGroup.Variables; } else if (3 == variableElement.Length) { int sequenceIndex = int.Parse(variableElement[1]); if (sequenceIndex == CommonConst.SetupIndex) { varCollection = sequenceGroup.SetUp.Variables; } else if (sequenceIndex == CommonConst.TeardownIndex) { varCollection = sequenceGroup.TearDown.Variables; } else { varCollection = sequenceGroup.Sequences[sequenceIndex].Variables; } } return(varCollection.FirstOrDefault(item => item.Name.Equals(variableElement[variableElement.Length - 1]))); }
public Task <ICreationResult> CreateAsync( IEngineEnvironmentSettings environmentSettings, IRunnableProjectConfig runnableProjectConfig, IDirectory templateSourceRoot, IParameterSet parameters, string targetDirectory, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); ProcessMacros(environmentSettings, runnableProjectConfig.OperationConfig, parameters); IVariableCollection variables = SetupVariables(environmentSettings, parameters, runnableProjectConfig.OperationConfig.VariableSetup); runnableProjectConfig.Evaluate(parameters, variables); IOrchestrator basicOrchestrator = new Core.Util.Orchestrator(environmentSettings.Host.Logger, environmentSettings.Host.FileSystem); RunnableProjectOrchestrator orchestrator = new RunnableProjectOrchestrator(basicOrchestrator); GlobalRunSpec runSpec = new GlobalRunSpec(templateSourceRoot, environmentSettings.Components, parameters, variables, runnableProjectConfig.OperationConfig, runnableProjectConfig.SpecialOperationConfig, runnableProjectConfig.IgnoreFileNames); foreach (FileSourceMatchInfo source in runnableProjectConfig.Sources) { runSpec.SetupFileSource(source); string target = Path.Combine(targetDirectory, source.Target); orchestrator.Run(runSpec, templateSourceRoot.DirectoryInfo(source.Source), target); } return(Task.FromResult(GetCreationResult(environmentSettings.Host.Logger, runnableProjectConfig, variables))); }
public IReadOnlyList <IFileChange> GetFileChanges(IEngineEnvironmentSettings environmentSettings, ITemplate templateData, IParameterSet parameters, IComponentManager componentManager, string targetDirectory) { RunnableProjectTemplate template = (RunnableProjectTemplate)templateData; ProcessMacros(environmentSettings, componentManager, template.Config.OperationConfig, parameters); IVariableCollection variables = VariableCollection.SetupVariables(environmentSettings, parameters, template.Config.OperationConfig.VariableSetup); template.Config.Evaluate(parameters, variables, template.ConfigFile); IOrchestrator basicOrchestrator = new Core.Util.Orchestrator(); RunnableProjectOrchestrator orchestrator = new RunnableProjectOrchestrator(basicOrchestrator); GlobalRunSpec runSpec = new GlobalRunSpec(template.TemplateSourceRoot, componentManager, parameters, variables, template.Config.OperationConfig, template.Config.SpecialOperationConfig, template.Config.LocalizationOperations, template.Config.PlaceholderFilename); List <IFileChange> changes = new List <IFileChange>(); foreach (FileSource source in template.Config.Sources) { runSpec.SetupFileSource(source); string target = Path.Combine(targetDirectory, source.Target); changes.AddRange(orchestrator.GetFileChanges(runSpec, template.TemplateSourceRoot.DirectoryInfo(source.Source), target)); } return(changes); }
public ICreationEffects GetCreationEffects(IEngineEnvironmentSettings environmentSettings, ITemplate templateData, IParameterSet parameters, IComponentManager componentManager, string targetDirectory) { RunnableProjectTemplate template = (RunnableProjectTemplate)templateData; ProcessMacros(environmentSettings, componentManager, template.Config.OperationConfig, parameters); IVariableCollection variables = VariableCollection.SetupVariables(environmentSettings, parameters, template.Config.OperationConfig.VariableSetup); template.Config.Evaluate(parameters, variables, template.ConfigFile); IOrchestrator basicOrchestrator = new Core.Util.Orchestrator(); RunnableProjectOrchestrator orchestrator = new RunnableProjectOrchestrator(basicOrchestrator); GlobalRunSpec runSpec = new GlobalRunSpec(template.TemplateSourceRoot, componentManager, parameters, variables, template.Config.OperationConfig, template.Config.SpecialOperationConfig, template.Config.LocalizationOperations, template.Config.IgnoreFileNames); List <IFileChange2> changes = new List <IFileChange2>(); foreach (FileSourceMatchInfo source in template.Config.Sources) { runSpec.SetupFileSource(source); changes.AddRange(orchestrator.GetFileChanges(runSpec, template.TemplateSourceRoot.DirectoryInfo(source.Source), targetDirectory, source.Target)); } return(new CreationEffects2 { FileChanges = changes, CreationResult = GetCreationResult(environmentSettings, template, variables) }); }
public static bool Include( this IEnumerable <DirectiveNode> directives, IVariableCollection variables) { return(directives.GetIncludeDirective() .EvaluateDirective(variables) ?? true); }
public IValueNode RewriteValue( IValueNode value, IType type, IVariableCollection variables, ITypeConversion typeConversion) { if (value is null) { throw new ArgumentNullException(nameof(value)); } if (type is null) { throw new ArgumentNullException(nameof(type)); } if (variables is null) { throw new ArgumentNullException(nameof(variables)); } if (typeConversion is null) { throw new ArgumentNullException(nameof(typeConversion)); } _variables = variables; _typeConversion = typeConversion; _type.Clear(); _type.Push(type); return(RewriteValue(value, null)); }
public static bool Skip( this IEnumerable <DirectiveNode> directives, IVariableCollection variables) { return(directives.GetSkipDirective() .EvaluateDirective(variables) ?? false); }
public void EvaluateConfig(IEngineEnvironmentSettings environmentSettings, IVariableCollection vars, IMacroConfig rawConfig, IParameterSet parameters, ParameterSetter setter) { GuidMacroConfig config = rawConfig as GuidMacroConfig; if (config == null) { throw new InvalidCastException("Couldn't cast the rawConfig as GuidMacroConfig"); } string guidFormats; if (!string.IsNullOrEmpty(config.Format)) { guidFormats = config.Format; } else { guidFormats = GuidMacroConfig.DefaultFormats; } Guid g = Guid.NewGuid(); for (int i = 0; i < guidFormats.Length; ++i) { string value = char.IsUpper(guidFormats[i]) ? g.ToString(guidFormats[i].ToString()).ToUpperInvariant() : g.ToString(guidFormats[i].ToString()).ToLowerInvariant(); Parameter p = new Parameter { IsVariable = true, Name = config.VariableName + "-" + guidFormats[i], DataType = config.DataType }; vars[p.Name] = value; setter(p, value); } Parameter pd; if (parameters.TryGetParameterDefinition(config.VariableName, out ITemplateParameter existingParam)) { // If there is an existing parameter with this name, it must be reused so it can be referenced by name // for other processing, for example: if the parameter had value forms defined for creating variants. // When the param already exists, use its definition, but set IsVariable = true for consistency. pd = (Parameter)existingParam; pd.IsVariable = true; } else { pd = new Parameter { IsVariable = true, Name = config.VariableName }; } string value = char.IsUpper(config.DefaultFormat) ? g.ToString(config.DefaultFormat.ToString()).ToUpperInvariant() : g.ToString(config.DefaultFormat.ToString()).ToLowerInvariant(); vars[config.VariableName] = value; setter(pd, value); }
public InterpretedClass(ClassDeclarationExpression expression, Scope scope) { _rootscope = scope.Root; _name = expression.Name; _parents = expression.Parents; _interfaces = expression.Interfaces; _methods = new MethodCollection(); _fields = new FieldCollection(); _classes = new ClassCollection(); _static_variables = new VariableCollection(); ScriptScope script_scope = null; scope.FindNearestScope <ScriptScope> (ss => script_scope = ss); foreach (ClassMethodDeclarationExpression m in expression.Methods) { _methods.Add(new InterpretedMethod(m, script_scope)); } foreach (ClassFieldDeclarationExpression f in expression.Fields) { IVariable var = _static_variables.EnsureExists(f.Name); if (f.Initializer is Expression initializer_expr) { var.Value = Interpreters.Execute(initializer_expr, script_scope).ResultValue; } } }