public GitVersionCalculateTool(ILog log, INextVersionCalculator nextVersionCalculator, IVariableProvider variableProvider, IGitPreparer gitPreparer, IGitVersionCache gitVersionCache, IGitVersionCacheKeyFactory cacheKeyFactory, IOptions <GitVersionOptions> options, Lazy <GitVersionContext> versionContext) { this.log = log ?? throw new ArgumentNullException(nameof(log)); this.nextVersionCalculator = nextVersionCalculator ?? throw new ArgumentNullException(nameof(nextVersionCalculator)); this.variableProvider = variableProvider ?? throw new ArgumentNullException(nameof(variableProvider)); this.gitPreparer = gitPreparer ?? throw new ArgumentNullException(nameof(gitPreparer)); this.cacheKeyFactory = cacheKeyFactory ?? throw new ArgumentNullException(nameof(cacheKeyFactory)); this.gitVersionCache = gitVersionCache ?? throw new ArgumentNullException(nameof(gitVersionCache)); this.options = options ?? throw new ArgumentNullException(nameof(options)); this.versionContext = versionContext ?? throw new ArgumentNullException(nameof(versionContext)); }
public ManagedWrapperProjectsPluginGenerator( IConsoleWriter consoleWriter, IFileGenerator fileGenerator, IFileManipulator fileManipulator, IUserInputProvider userInputProvider, IVariableProvider variableProvider, IPathProvider pathProvider, ITools tools) { _consoleWriter = consoleWriter; _fileGenerator = fileGenerator; _fileManipulator = fileManipulator; _userInputProvider = userInputProvider; _variableProvider = variableProvider; _pathProvider = pathProvider; _tools = tools; }
public GitVersionCalculateTool(ILog log, INextVersionCalculator nextVersionCalculator, IVariableProvider variableProvider, IGitPreparer gitPreparer, IGitVersionCache gitVersionCache, IGitVersionCacheKeyFactory cacheKeyFactory, IOptions <GitVersionOptions> options, Lazy <GitVersionContext> versionContext) { this.log = log.NotNull(); this.nextVersionCalculator = nextVersionCalculator.NotNull(); this.variableProvider = variableProvider.NotNull(); this.gitPreparer = gitPreparer.NotNull(); this.cacheKeyFactory = cacheKeyFactory.NotNull(); this.gitVersionCache = gitVersionCache.NotNull(); this.options = options.NotNull(); this.versionContext = versionContext.NotNull(); }
/// <inheritdoc /> public object Execute(IVariableProvider variables) { if (variables == null) { throw new InvalidOperationException("Javascript execution needs global variables"); } Engine engine = new Engine { ClrTypeConverter = new JavascriptTypeConverter() }; WorkableLogger logger = variables.GetProvider("log").GetVariable("log") as WorkableLogger; engine.SetValue("load", importservice.Clone(logger)); engine.SetValue("await", (Func <Task, object>)Helpers.Tasks.AwaitTask); foreach (string name in variables.Variables) { object hostobject = variables[name]; if (hostobject == null) { // v8 doesn't like null host objects continue; } engine.SetValue(name, hostobject); } switch (language) { case ScriptLanguage.JavaScript: script ??= new JavaScriptParser(code).ParseScript(); return(engine.Execute(script).GetCompletionValue().ToObject()); case ScriptLanguage.TypeScript: string transpiled = ReactEnvironment.Current.Babel.Transform($"function main():any{{{code}}}\nvar _result=main();", "unknown.ts"); script ??= new JavaScriptParser(transpiled).ParseScript(); engine.Execute(script); return(engine.GetValue("_result").ToObject()); default: throw new ArgumentException($"Unsupported language '{language}' as JavaScript"); } }
public NativeProjectsPluginGenerator( IConsoleWriter consoleWriter, IFileGenerator fileGenerator, IFileManipulator fileManipulator, IUserInputProvider userInputProvider, IVariableProvider variableProvider, IProjectInformation projectInformation, ITfsPaths tfsPaths, ITools tools) { _consoleWriter = consoleWriter; _fileGenerator = fileGenerator; _fileManipulator = fileManipulator; _userInputProvider = userInputProvider; _variableProvider = variableProvider; _projectInformation = projectInformation; _tfsPaths = tfsPaths; _tools = tools; }
/// <summary> /// When this method is called, the input file will be moved to the destination file provided /// in the constructor for this instance. /// When the next processor is called, it will be called with the location of the destination file, /// not the inputFile to this method. /// </summary> /// <param name="inputFile">The input file to process</param> /// <param name="variables">The variable provider</param> /// <param name="nextCaller">The next processor to call</param> public void Process(string inputFile, IVariableProvider variables, Action <string> nextCaller) { FileInfo inputFileInfo = new FileInfo(inputFile); string newFileName = Guid.NewGuid() + Path.GetExtension(inputFile); FileInfo destinationFileInfo = new FileInfo(Path.Combine(destinationDirectoryInfo.FullName, newFileName)); if (!destinationDirectoryInfo.Exists) { destinationDirectoryInfo.Create(); } Logger.InfoFormat("Moving input file '{0}", inputFile); inputFileInfo.MoveTo(destinationFileInfo.FullName); // pass the new file name to the next caller nextCaller(destinationFileInfo.FullName); }
/// <summary> /// Evaluates the expression using the supplied <paramref name="variableProvider"/> and returns the result. /// </summary> /// <exception cref="ArgumentNullException">Thrown when <paramref name="variableProvider"/> is null.</exception> /// <exception cref="Exceptions.ExpressiveException">Thrown when there is a break in the evaluation process, check the InnerException for further information.</exception> /// <param name="variableProvider">The <see cref="IVariableProvider"/> implementation to provide variable values during evaluation.</param> /// <returns>The result of the evaluation.</returns> public T Evaluate <T>(IVariableProvider variableProvider) { if (variableProvider is null) { throw new ArgumentNullException(nameof(variableProvider)); } try { return((T)this.Evaluate(variableProvider)); } catch (ExpressiveException) { throw; } catch (Exception ex) { throw new ExpressiveException(ex); } }
public void BindComponent(object sender, PDFDataBindEventArgs args) { if (null == this.ItemValueProvider) { this.ItemValueProvider = args.Context.Items.ValueProvider( args.Context.CurrentIndex, args.Context.DataStack.HasData ? args.Context.DataStack.Current : null); } object value; if (this.TryEvaluate(this.ItemValueProvider, sender, args.Context, out value)) { this.SetPropertyValue(sender, value, Expression.ToString(), BoundTo, args.Context); } else { args.Context.TraceLog.Add(TraceLevel.Warning, "Expression Binding", "The expression '" + this.OriginalExpression + "' for '" + sender.ToString() + "' on property '" + this.BoundTo.Name + "' could not be evaluated "); } }
/// <inheritdoc /> protected override object AssignToken(IScriptToken token, ScriptContext context) { IVariableProvider provider = context.Variables.GetProvider(Name); if (provider == null) { // auto declare variable in current scope if variable is not found provider = context.Variables; } if (!(provider is IVariableContext variablecontext)) { throw new ScriptRuntimeException($"Variable {Name} not writable", this); } object value = token.Execute(context); variablecontext.SetVariable(Name, value); return(value); }
/// <summary> /// Creates and initializes a new processor based on the supplied configuration /// </summary> /// <param name="provider">The variable provider, used for specializing /// any variables found within the initialization parameters</param> /// <param name="element">The processor element to use</param> /// <returns>The created processor</returns> private IDocumentProcessor LoadProcessorFromConfig(IVariableProvider provider, XElement element) { const StringComparison Comp = StringComparison.InvariantCultureIgnoreCase; XAttribute nameAttribute = element.Attribute("name"); if (nameAttribute == null) { return(null); } // determine the name of the processor to map to string processorName = nameAttribute.Value; // locate the factory by its name var factory = processors.FirstOrDefault(p => string.Compare(p.ProcessorName, processorName, Comp) == 0); // load and specialize any initialisation parameters for this factory IDictionary <string, string> parameters = LoadParameters(provider, element); return(factory != null?factory.Create(parameters) : null); }
public GitVersionTool(ILog log, INextVersionCalculator nextVersionCalculator, IVariableProvider variableProvider, IGitPreparer gitPreparer, IGitVersionCache gitVersionCache, IGitVersionCacheKeyFactory cacheKeyFactory, IOutputGenerator outputGenerator, IWixVersionFileUpdater wixVersionFileUpdater, IGitVersionInfoGenerator gitVersionInfoGenerator, IAssemblyInfoFileUpdater assemblyInfoFileUpdater, IOptions <GitVersionOptions> options, Lazy <GitVersionContext> versionContext) { this.log = log ?? throw new ArgumentNullException(nameof(log)); this.nextVersionCalculator = nextVersionCalculator ?? throw new ArgumentNullException(nameof(nextVersionCalculator)); this.variableProvider = variableProvider ?? throw new ArgumentNullException(nameof(variableProvider)); this.gitPreparer = gitPreparer ?? throw new ArgumentNullException(nameof(gitPreparer)); this.cacheKeyFactory = cacheKeyFactory ?? throw new ArgumentNullException(nameof(cacheKeyFactory)); this.gitVersionCache = gitVersionCache ?? throw new ArgumentNullException(nameof(gitVersionCache)); this.outputGenerator = outputGenerator ?? throw new ArgumentNullException(nameof(outputGenerator)); this.wixVersionFileUpdater = wixVersionFileUpdater ?? throw new ArgumentNullException(nameof(wixVersionFileUpdater)); this.gitVersionInfoGenerator = gitVersionInfoGenerator ?? throw new ArgumentNullException(nameof(gitVersionInfoGenerator)); this.assemblyInfoFileUpdater = assemblyInfoFileUpdater ?? throw new ArgumentNullException(nameof(gitVersionInfoGenerator)); this.options = options ?? throw new ArgumentNullException(nameof(options)); this.versionContext = versionContext ?? throw new ArgumentNullException(nameof(versionContext)); }
protected bool TryEvaluate(IVariableProvider provider, object owner, PDFDataContext context, out object value) { value = null; bool result; try { value = this.Expression.Evaluate(provider); result = true; } catch (Exception ex) { string id; if (owner is IPDFComponent component) { id = component.ID; } else { id = ""; } string message = "Cannot bind the values for '" + owner.ToString() + "' with id " + id; result = false; if (context.Conformance == ParserConformanceMode.Lax) { context.TraceLog.Add(TraceLevel.Error, "Data Binding", message, ex); } else { throw new Scryber.PDFBindException(message, ex); } } return(result); }
public GitVersionTool(ILog log, INextVersionCalculator nextVersionCalculator, IVariableProvider variableProvider, IConsole console, IGitVersionCache gitVersionCache, IGitVersionCacheKeyFactory cacheKeyFactory, IBuildServerResolver buildServerResolver, IWixVersionFileUpdater wixVersionFileUpdater, IGitVersionInformationGenerator gitVersionInformationGenerator, IAssemblyInfoFileUpdater assemblyInfoFileUpdater, IOptions <Arguments> options, Lazy <GitVersionContext> versionContext) { this.log = log ?? throw new ArgumentNullException(nameof(log)); this.console = console ?? throw new ArgumentNullException(nameof(console)); this.nextVersionCalculator = nextVersionCalculator ?? throw new ArgumentNullException(nameof(nextVersionCalculator)); this.variableProvider = variableProvider ?? throw new ArgumentNullException(nameof(variableProvider)); this.cacheKeyFactory = cacheKeyFactory ?? throw new ArgumentNullException(nameof(cacheKeyFactory)); this.gitVersionCache = gitVersionCache ?? throw new ArgumentNullException(nameof(gitVersionCache)); this.wixVersionFileUpdater = wixVersionFileUpdater ?? throw new ArgumentNullException(nameof(wixVersionFileUpdater)); this.gitVersionInformationGenerator = gitVersionInformationGenerator ?? throw new ArgumentNullException(nameof(gitVersionInformationGenerator)); this.assemblyInfoFileUpdater = assemblyInfoFileUpdater ?? throw new ArgumentNullException(nameof(gitVersionInformationGenerator)); this.options = options ?? throw new ArgumentNullException(nameof(options)); this.versionContext = versionContext ?? throw new ArgumentNullException(nameof(versionContext)); buildServer = buildServerResolver.Resolve(); }
/// <summary> /// Called to execute a command line process to perform a document conversion. /// </summary> /// <param name="inputFile">The input file to process</param> /// <param name="variables">The variable provider</param> /// <param name="next">The next processor to call</param> public void Process(string inputFile, IVariableProvider variables, Action <string> next) { string outputFile = GenerateOutputFileName(outputDirectoryInfo, outputFileExtension); string fullCommandLine = string.Format(commandLineTemplate, inputFile, outputFile); Logger.InfoFormat("Process called with input file of '{0}'", inputFile); Logger.InfoFormat("Output file is '{0}'", outputFile); Logger.InfoFormat("Full command line: '{0}'", fullCommandLine); var proc = new Process { StartInfo = { FileName = this.executablePath, RedirectStandardOutput = true, UseShellExecute = false, CreateNoWindow = true, Arguments = fullCommandLine } }; proc.Start(); // To avoid deadlocks, always read the output stream first and then wait. // Reference: https://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo.redirectstandardoutput(v=vs.110).aspx string output = proc.StandardOutput.ReadToEnd(); proc.WaitForExit(); if (File.Exists(inputFile)) { File.Delete(inputFile); } next(outputFile); }
public static IExpressionTreeNode <T> BuildTree <T>(IEnumerable <IToken> tokenizedExpression, IVariableProvider <T> variableProvider) { var operationsStack = new Stack <IOperationToken>(); var resultStack = new Stack <IExpressionTreeNode <T> >(); foreach (var token in tokenizedExpression) { switch (token) { case LiteralToken <T> literalToken: resultStack.Push(literalToken.GetExpressionTreeNode()); break; case VariableToken variableToken: resultStack.Push(variableToken.GetExpressionTreeNode(variableProvider)); break; case OpeningParenthesisToken openingParenthesisToken: operationsStack.Push(openingParenthesisToken); break; case ClosingParenthesisToken _: HandleClosingParenthesisToken(operationsStack, resultStack); break; case IOperationToken operationToken: HandleOperationToken(operationsStack, operationToken, resultStack); break; } } AppendRemainingOperationsToResult(operationsStack, resultStack); return(resultStack.Pop()); }
public Layout <T> InflateChild <T>(XmlLayoutElement parent, string layoutXml, IVariableProvider provider = null) where T : Component { var element = InflateChild(parent, layoutXml, provider); return(new Layout <T>(element, element.GetComponent <T>())); }
public GitVersionCalculator(ILog log, IConfigProvider configProvider, IGitVersionCache gitVersionCache, INextVersionCalculator nextVersionCalculator, IVariableProvider variableProvider, IOptions <Arguments> options, IGitVersionCacheKeyFactory cacheKeyFactory) { this.log = log ?? throw new ArgumentNullException(nameof(log)); this.configProvider = configProvider ?? throw new ArgumentNullException(nameof(configProvider)); this.gitVersionCache = gitVersionCache ?? throw new ArgumentNullException(nameof(gitVersionCache)); this.nextVersionCalculator = nextVersionCalculator ?? throw new ArgumentNullException(nameof(nextVersionCalculator)); this.variableProvider = variableProvider ?? throw new ArgumentNullException(nameof(variableProvider)); this.options = options ?? throw new ArgumentNullException(nameof(options)); this.cacheKeyFactory = cacheKeyFactory ?? throw new ArgumentNullException(nameof(cacheKeyFactory)); }
public static NodeEvaluationResult CreateVariable(IVariableProvider variable) { int id = variable.Id; IDebuggerManager debugger = variable.Debugger; NodeStackFrame stackFrame = variable.StackFrame; NodeEvaluationResult parent = variable.Parent; string name = variable.Name; string fullName = GetFullName(parent, variable.Name, ref name); string stringValue; string typeName = variable.TypeName; NodeExpressionType type = 0; if (variable.Attributes.HasFlag(PropertyAttribute.ReadOnly)) { type |= NodeExpressionType.ReadOnly; } if (variable.Attributes.HasFlag(PropertyAttribute.DontEnum)) { type |= NodeExpressionType.Private; } switch (typeName) { case "undefined": stringValue = "undefined"; typeName = "Undefined"; break; case "null": stringValue = "null"; typeName = "Null"; break; case "number": stringValue = variable.Value; typeName = "Number"; break; case "boolean": stringValue = variable.Value.ToLowerInvariant(); typeName = "Boolean"; type |= NodeExpressionType.Boolean; break; case "regexp": stringValue = variable.Value; typeName = "Regular Expression"; type |= NodeExpressionType.Expandable; break; case "function": stringValue = string.IsNullOrEmpty(variable.Text) ? "{Function}" : variable.Text; typeName = "Function"; type |= NodeExpressionType.Function | NodeExpressionType.Expandable; break; case "string": stringValue = variable.Value; typeName = "String"; type |= NodeExpressionType.String; break; case "object": stringValue = variable.Class == "Object" ? "{...}" : string.Format("{{{0}}}", variable.Class); typeName = "Object"; type |= NodeExpressionType.Expandable; break; case "error": stringValue = variable.Value; if (!string.IsNullOrEmpty(stringValue) && stringValue.StartsWith("Error: ")) { stringValue = variable.Value.Substring(7); } typeName = "Error"; type |= NodeExpressionType.Expandable; break; default: stringValue = variable.Value; break; } return new NodeEvaluationResult(debugger, stringValue, null, typeName, name, fullName, type, stackFrame, id); }
/// <inheritdoc /> public async Task <T> ExecuteAsync <T>(IVariableProvider variables = null, CancellationToken cancellationtoken = new CancellationToken()) { return(Converter.Convert <T>(await ExecuteAsync(variables, cancellationtoken))); }
public IBoundVariable Bind(XmlLayoutElement element, T instance, IVariableProvider provider) { var value = provider.GetValue <P>(VariableName); return(new BoundVariable(element, instance, value, Setter)); }
public void SetUp() { environment = new TestEnvironment(); log = new NullLog(); variableProvider = new VariableProvider(log); }
public GitVersionCalculator(IFileSystem fileSystem, ILog log, IConfigFileLocator configFileLocator, IConfigProvider configProvider, IBuildServerResolver buildServerResolver, IGitVersionCache gitVersionCache, IGitVersionFinder gitVersionFinder, IGitPreparer gitPreparer, IVariableProvider variableProvider, IOptions <Arguments> options) { this.fileSystem = fileSystem ?? throw new ArgumentNullException(nameof(fileSystem)); this.log = log ?? throw new ArgumentNullException(nameof(log)); this.configFileLocator = configFileLocator ?? throw new ArgumentNullException(nameof(configFileLocator)); this.configProvider = configProvider ?? throw new ArgumentNullException(nameof(configProvider)); this.buildServerResolver = buildServerResolver ?? throw new ArgumentNullException(nameof(buildServerResolver)); this.gitVersionCache = gitVersionCache ?? throw new ArgumentNullException(nameof(gitVersionCache)); this.gitVersionFinder = gitVersionFinder ?? throw new ArgumentNullException(nameof(gitVersionFinder)); this.gitPreparer = gitPreparer ?? throw new ArgumentNullException(nameof(gitPreparer)); this.variableProvider = variableProvider ?? throw new ArgumentNullException(nameof(variableProvider)); this.arguments = options.Value; }
public VariableProviderDictionary(IVariableProvider variableProvider) { this.variableProvider = variableProvider; }
/// <summary> /// creates a new <see cref="ScriptContext"/> /// </summary> /// <param name="variables">global script variables</param> /// <param name="arguments">arguments provided at runtime</param> public ScriptContext(IVariableContext variables, IVariableProvider arguments) { Variables = variables; Arguments = arguments; }
/// <summary> /// Creates a new Chained variable provider /// </summary> /// <param name="vars"></param> /// <param name="next"></param> public StyleChainedVariableProvider(StyleVariableSet vars, IVariableProvider next) { this._variables = vars ?? throw new ArgumentNullException(nameof(vars)); this._next = next; }
/// <summary> /// creates a new <see cref="ScriptContext"/> /// </summary> /// <param name="variables">global script variables</param> /// <param name="arguments">arguments provided at runtime</param> /// <param name="cancellationToken">cancellation token used to abort script execution (optional)</param> public ScriptContext(IVariableContext variables, IVariableProvider arguments, CancellationToken cancellationToken) : this(variables, arguments) { CancellationToken = cancellationToken; }
public static NodeEvaluationResult CreateVariable(IVariableProvider variable) { int id = variable.Id; IDebuggerManager debugger = variable.Debugger; NodeStackFrame stackFrame = variable.StackFrame; NodeEvaluationResult parent = variable.Parent; string name = variable.Name; string fullName = GetFullName(parent, variable.Name, ref name); string stringValue; string typeName = variable.TypeName; NodeExpressionType type = 0; if (variable.Attributes.HasFlag(PropertyAttribute.ReadOnly)) { type |= NodeExpressionType.ReadOnly; } if (variable.Attributes.HasFlag(PropertyAttribute.DontEnum)) { type |= NodeExpressionType.Private; } switch (typeName) { case "undefined": stringValue = "undefined"; typeName = "Undefined"; break; case "null": stringValue = "null"; typeName = "Null"; break; case "number": stringValue = variable.Value; typeName = "Number"; break; case "boolean": stringValue = variable.Value.ToLowerInvariant(); typeName = "Boolean"; type |= NodeExpressionType.Boolean; break; case "regexp": stringValue = variable.Value; typeName = "Regular Expression"; type |= NodeExpressionType.Expandable; break; case "function": stringValue = string.IsNullOrEmpty(variable.Text) ? "{Function}" : variable.Text; typeName = "Function"; type |= NodeExpressionType.Function | NodeExpressionType.Expandable; break; case "string": stringValue = variable.Value; typeName = "String"; type |= NodeExpressionType.String; break; case "object": stringValue = variable.Class == "Object" ? "{...}" : string.Format("{{{0}}}", variable.Class); typeName = "Object"; type |= NodeExpressionType.Expandable; break; case "error": stringValue = variable.Value; if (!string.IsNullOrEmpty(stringValue) && stringValue.StartsWith("Error: ")) { stringValue = variable.Value.Substring(7); } typeName = "Error"; type |= NodeExpressionType.Expandable; break; default: stringValue = variable.Value; break; } return(new NodeEvaluationResult(debugger, stringValue, null, typeName, name, fullName, type, stackFrame, id)); }
/// <summary> /// Processes the input file. This instance does nothing of use other than ensuring /// a non null instance can be supplied as the next argument to the final processor /// in a processor chain. /// </summary> /// <param name="inputFile">The input file to process</param> /// <param name="variables">The variable provider</param> /// <param name="next">The next processor to call</param> public void Process(string inputFile, IVariableProvider variables, Action <string> next) { }
/// <inheritdoc /> public T Execute <T>(IVariableProvider variables = null) { return(Converter.Convert <T>(Execute(variables))); }
/// <summary> /// /// </summary> /// <param name="variableProvider"></param> public VariableController(IVariableProvider variableProvider) { _variableProvider = variableProvider; }
/// <summary> /// creates a new <see cref="Script"/> /// </summary> /// <param name="script">root token of script to be executed</param> /// <param name="scriptvariables">access to script variables</param> internal Script(IScriptToken script, IVariableProvider scriptvariables) { this.script = script; this.scriptvariables = scriptvariables; }