Skip to content
dotnetprofessional edited this page May 20, 2014 · 1 revision

#xpf.Script A scripting engine abstraction that makes interacting with various scripting frameworks such as SQL Server, PowerShell and Razor easier and more consistent using a fluent API. While this component is supported on all C# environments the scripting frameworks are typically platform specific.

API

The xpf.Script library provides a consistent base fluent API for executing scripts. Each script engine implementation, such as SQLServer makes use of the common API and provides extensions for specific features unique to that scripting enngine. As an example the SQLServer implementation adds support for Snapshots and ExecuteReader.

The common features provided by all scripting engines are:

UsingScript:

This method takes the name of an embedded resource file which contains the script to be executed. The script name is matched using EndsWIth rather than the exact name. This allows the names to be kept short. You can supply as much of the fully qualified name as you like, thought its generally useful to only supply enough to provide context. This feature also makes it easy to move scripts around without having to modify the code.

example .UsingScript("Scripts.CreateCustomerRecord.sql")

Resource file processing also supports advanced concepts such as referencing child scripts. This allows for scripts to reuse other scripts by simply referencing their name. The engine supports two formats, both of which perform the same function, so its a matter of preference which is used:

include syntax include Scripts.CreateCustomerRecord.sql

:r syntax :r Scripts.CreateCustomerRecord.sql

UsingCommand

In some scenarios you may only want to execute a small amount of script code. So creating a resource file may be over-kill in these situations. This method allows you to supply any valid script for execution.

example .UsingCommand("SELECT * FROM Customer")

Using Assembly:

By default the scripting engine will look for resources in the assembly that is used to call the library. However, in some cases this may not be the correct assembly. In those cases its necessary to tell the scripting engine which assembly contains the embedded script resources. This is necessary as not all platforms support the ability to scan all loaded assemblies.

###xpf.Script.SQLServer: Beta An implementation of xpf.Script for SQL Server. This allows for advanced scripting support such using embedded resources, batching, in and out parameters, and various conversions.

Clone this wiki locally