public sealed override Task SetVariableAsync(RuntimeVariableName name, string value) { if (this.disposed) { throw new ObjectDisposedException(nameof(GitRaftRepositoryBase)); } if (name == null) { throw new ArgumentNullException(nameof(name)); } if (this.ReadOnly) { throw new NotSupportedException(); } var vars = this.lazyVariables.Value; if (vars.TryGetValue(name, out var currentValue) && currentValue == value) { return(InedoLib.NullTask); } vars[name] = value; this.variablesDirty = true; return(InedoLib.NullTask); }
public override RuntimeValue Evaluate(IOtterContext context) #endif { if (string.IsNullOrEmpty(this.VariableName)) { return(false); } RuntimeValueType[] types; if (string.Equals(this.VariableType, "scalar", StringComparison.OrdinalIgnoreCase)) { types = new[] { RuntimeValueType.Scalar } } ; else if (string.Equals(this.VariableType, "vector", StringComparison.OrdinalIgnoreCase)) { types = new[] { RuntimeValueType.Vector } } ; else if (string.Equals(this.VariableType, "map", StringComparison.OrdinalIgnoreCase)) { types = new[] { RuntimeValueType.Map } } ; else { types = new[] { RuntimeValueType.Scalar, RuntimeValueType.Vector, RuntimeValueType.Map } }; var execContext = context as IOperationExecutionContext; if (execContext == null) { return(null); } foreach (var type in types) { var variableName = new RuntimeVariableName(this.VariableName, type); var value = execContext.TryGetVariableValue(variableName); if (value != null) { return(value.Value); } var functionValue = execContext.TryGetFunctionValue(variableName.ToString()); if (functionValue != null) { return(functionValue.Value); } } return(null); } }
private static RuntimeValue?TryGetFunctionValue(RuntimeVariableName functionName, IOperationExecutionContext context) { try { return(context.TryGetFunctionValue(functionName.ToString())); } catch { return(null); } }
public RompSessionVariable(RuntimeVariableName name, RuntimeValue value) { if (name == null) { throw new ArgumentNullException(nameof(name)); } if (name.Type != value.ValueType) { throw new ArgumentException("Invalid variable value type."); } this.Name = name; this.value = value; }
private ExtensionComponent GetFunction(RuntimeVariableName functionName) { if (functionName == null) { throw new ArgumentNullException(nameof(functionName)); } var functionType = (from c in ExtensionsManager.GetComponentsByBaseClass <VariableFunction>() let aliases = from a in c.ComponentType.GetCustomAttributes <ScriptAliasAttribute>() select a.Alias where aliases.Contains(functionName.Name, StringComparer.OrdinalIgnoreCase) select c).FirstOrDefault(); return(functionType); }
public RuntimeValue?TryGetVariableValue(RuntimeVariableName variableName) { if (variableName == null) { throw new ArgumentNullException(nameof(variableName)); } var maybeValue = this.executerContext?.GetVariableValue(variableName); if (maybeValue != null) { return(maybeValue); } return(RompSessionVariable.GetSessionVariable(variableName)?.GetValue()); }
protected override object EvaluateScalar(object context) { if (string.IsNullOrEmpty(this.VariableName)) { return(false); } RuntimeValueType[] types; if (string.Equals(this.VariableType, "scalar", StringComparison.OrdinalIgnoreCase)) { types = new[] { RuntimeValueType.Scalar } } ; else if (string.Equals(this.VariableType, "vector", StringComparison.OrdinalIgnoreCase)) { types = new[] { RuntimeValueType.Vector } } ; else if (string.Equals(this.VariableType, "map", StringComparison.OrdinalIgnoreCase)) { types = new[] { RuntimeValueType.Map } } ; else { types = new[] { RuntimeValueType.Scalar, RuntimeValueType.Vector, RuntimeValueType.Map } }; var execContext = context as IOperationExecutionContext; foreach (var type in types) { var variableName = new RuntimeVariableName(this.VariableName, type); if (execContext.TryGetVariableValue(variableName) != null) { return(true); } if (execContext.TryGetFunctionValue(variableName.ToString()) != null) { return(true); } } return(false); } }
#pragma warning disable CS0672 // Member overrides obsolete member public override ActionStatement CreateActionStatement( QualifiedName actionName, object _model) #pragma warning restore CS0672 // Member overrides obsolete member { var model = (PSCallOperationModel)_model; return(new ActionStatement("PSCall", model.Arguments .Where(a => !string.IsNullOrEmpty(a.Value) && !a.IsOutput) .ToDictionary(a => a.Name, a => a.Value), new[] { model.ScriptName }, model.Arguments .Where(a => !string.IsNullOrEmpty(a.Value) && RuntimeVariableName.TryParse(a.Value) != null && a.IsOutput) .ToDictionary(a => a.Name, a => RuntimeVariableName.Parse(a.Value)) )); }
public async Task <RuntimeValue?> TryEvaluateFunctionAsync(RuntimeVariableName functionName, IList <RuntimeValue> arguments) { var function = this.GetVariableFunctionInternal(functionName, arguments); if (function == null) { return(null); } if (function is IAsyncVariableFunction asyncFunc) { return(await asyncFunc.EvaluateAsync(this.VariableFunctionContext).ConfigureAwait(false)); } else { return(function.Evaluate(this.VariableFunctionContext)); } }
public static Dictionary <string, RuntimeValue> ExtractVariables(string script, IOperationExecutionContext context) { var vars = ExtractVariablesInternal(script); var results = new Dictionary <string, RuntimeValue>(StringComparer.OrdinalIgnoreCase); foreach (var var in vars) { if (RuntimeVariableName.IsLegalVariableName(var)) { var varName = new RuntimeVariableName(var, RuntimeValueType.Scalar); var varValue = context.TryGetVariableValue(varName) ?? TryGetFunctionValue(varName, context); if (varValue.HasValue) { results[var] = varValue.Value; } } } return(results); }
public sealed override Task <bool> DeleteVariableAsync(RuntimeVariableName name) { if (this.disposed) { throw new ObjectDisposedException(nameof(GitRaftRepositoryBase)); } if (name == null) { throw new ArgumentNullException(nameof(name)); } if (this.ReadOnly) { throw new NotSupportedException(); } bool deleted = this.lazyVariables.Value.Remove(name); this.variablesDirty = deleted; return(Task.FromResult(deleted)); }
public override Task <bool> DeleteVariableAsync(RuntimeVariableName name) { throw new NotImplementedException(); }
public override Task SetVariableAsync(RuntimeVariableName name, string value) { throw new NotImplementedException(); }
public RuntimeValue?TryEvaluateFunction(RuntimeVariableName functionName, IList <RuntimeValue> arguments) { var function = this.GetVariableFunctionInternal(functionName, arguments); return(function?.Evaluate(this.VariableFunctionContext)); }
public RuntimeValue?TryGetVariableValue(RuntimeVariableName variableName) { throw new NotImplementedException(); }
public void SetVariableValue(RuntimeVariableName variableName, RuntimeValue variableValue) { throw new NotImplementedException(); }
public static RompSessionVariable GetSessionVariable(RuntimeVariableName name) => variables.GetValueOrDefault(name.Name);
public Task <IRuntimeVariable> TryGetGlobalVariableAsync(RuntimeVariableName variableName, IExecuterContext context) => Task.FromResult <IRuntimeVariable>(RompSessionVariable.GetSessionVariable(variableName));
private VariableFunction GetVariableFunctionInternal(RuntimeVariableName functionName, IList <RuntimeValue> arguments) { if (functionName == null) { throw new ArgumentNullException(nameof(functionName)); } if (arguments == null) { throw new ArgumentNullException(nameof(arguments)); } var functionType = this.GetFunction(functionName); if (functionType == null) { return(null); } var function = (VariableFunction)Activator.CreateInstance(functionType.ComponentType); var functionParams = (from p in functionType.ComponentType.GetProperties() let a = p.GetCustomAttribute <VariableFunctionParameterAttribute>() where a != null let n = p.GetCustomAttribute <DisplayNameAttribute>() orderby a.Index select new { Property = p, a.Optional, n?.DisplayName }).ToList(); int maxParams = Math.Min(functionParams.Count, arguments.Count); for (int i = 0; i < maxParams; i++) { var argValue = arguments[i]; var param = functionParams[i]; var coercedValue = ScriptPropertyMapper.CoerceValue(argValue, param.Property); param.Property.SetValue(function, coercedValue); } if (maxParams < functionParams.Count) { var missing = functionParams .Skip(maxParams) .FirstOrDefault(p => !p.Optional); if (missing != null) { throw new VariableFunctionArgumentMissingException(missing.DisplayName ?? missing.Property.Name); } } var variadicAttr = functionType.ComponentType.GetCustomAttribute <VariadicVariableFunctionAttribute>(); if (variadicAttr != null) { var variadicProperty = functionType.ComponentType.GetProperty(variadicAttr.VariadicPropertyName); if (variadicProperty != null) { var enumerableType = ScriptPropertyMapper.GetEnumerableType(variadicProperty.PropertyType); if (enumerableType != null) { var list = (IList)Activator.CreateInstance(typeof(List <>).MakeGenericType(enumerableType)); foreach (var arg in arguments.Skip(maxParams)) { list.Add(ScriptPropertyMapper.CoerceValue(arg, variadicProperty, enumerableType)); } variadicProperty.SetValue(function, list); } } } return(function); }