. NET Script (ii)

Source: Internet
Author: User
Tags define config integer
This version of the script is so big that I want to refer to it as a major version number upgrade. The following is a list of fixes and improvements.

A app.config file is added to replace the option XML elements that are duplicated in the. dnml file, such as: Waitforuseraction, entry methods, scripting languages, and common reference assemblies. I also added the ability to add new languages to the scripting engine, so you can write. NET script files in any language, as long as the ' Codeprovider ' class of the language is defined (described in more detail later). The values defined in the app.config file are the same as machine configuration. That is, or, these basic values can be overridden by values in the Dnml file. The value in the DNML file has the highest priority, and it will be used by the scripting engine. But if your. dnml script file does not have any configuration defined, the values in the app.config file will be used. This allows you to define only the actual code in the. dnml file.

User Preference Configuration segment: A user preference segment is added to the app.config file. This section defines three configurations. Default language, script entry, and wait for user action flags. The default language is used to determine the language of the scripting language when there is no language element defined in the DNML file. A portal is a method that the script engine will invoke when the DNML file does not have an entry defined. The waitforuseraction tag is a Boolean value that determines whether the console window is retained after the script is finished and waits for a CRLF key to be pressed. If this is not defined in the DNML file, the value in the config file will be invoked by the scripting engine. Here is an example of this paragraph.

<userpreferences defaultlanguage= "C #" entrypoint= "Main"
Waitforuseraction= "true"/>
Assembly reference Configuration segment: This segment is used to define the assembly required for script execution. Any assembly defined in the segment is compiled at the time of each script run. Only the assembly name, not the full path name, is required. Here is an example of this paragraph.

<referencedAssemblies>
<assembly path= "System.dll"/>
<assembly path= "System.Messaging.dll"/>
<assembly path= "System.Messaging.dll"/>
<assembly path= "System.Security.dll"/>
</referencedAssemblies>
Language Support configuration section: This section lets you dynamically add a new support language to the scripting engine without having to restart cheap engine code. The property name is the name defined in the DNML file, or the DefaultLanguage attribute in the user preference segment. A property assembly is an assembly full path name and file name that contains the Codeprovder implementation of the language. The property Codeprovidername is the code provider class of the language that contains the namespace of the name. Check out the Latebindcodeprovider () method of class Assemblygenerator to see how I added this functionality to the scripting engine.


<supportedLanguages>

<language name= "JScript"
Assembly= "C:\WINNT\Microsoft.NET\Framework\v1.1.4322\Microsoft.JScript.dll"

Codeprovidername= "Microsoft.JScript.JScriptCodeProvider"/>

<language name= "J #"
Assembly= "C:\winnt\microsoft.net\framework\v1.1.4322\vjsharpcodeprovider.dll"

Codeprovidername= "Microsoft.VJSharp.VJSharpCodeProvider"/>

</supportedLanguages>

Update 2/18/04: Version 1.0.2.0
I patched Charlie pointed out of the mentioned DotNetScriptEngine.exe registration. dnml file name extension associated with an error.

An optional entrypoint attribute has also been added for the DNML file format. This allows the user to specify an assembly entry instead of just the "Main" method. If the property entrypoint is populated with a method name, the method becomes the entry point. Otherwise, "Main" becomes the default assembly entry point.

Element language can be defined in the following three ways.

<language name= "C #"/> Main () would be the
Entry to the Assembly
<language name= "C #" EntryPoint ""/> Main () would
Being the entry method to the Assembly
<language name= "C #" entrypoint "Stuff"/> Stuff ()
Would be the entry method to the Assembly
I also added an optional <waitForUserAction> element to the. DNML XML format. This is a new feature that allows you to keep the console window after the script has finished executing. Element waitforuseraction is optional. If it is not included in the. dnml file, the window will remain (open). The property value can be ' true ' or ' false '. If true, the window is preserved. If False, the console window closes immediately after the script has finished executing. This allows you to link several script files to a batch file.

Possible ways to use this element.
--nothing--Console window'll remain open after script has run
<waitforuseraction value= "true"/> Console window would
Remain open after script has run
<waitforuseraction value= "True"/> Console window would
Remain open after script has run
<waitforuseraction value= "TRUE"/> Console window would
Remain open after script has run
<waitforuseraction value= "false"/> Console window would
Close after script has run
<waitforuseraction value= "False"/> Console window would
Close after script has run
<waitforuseraction value= "FALSE"/> Console window would
Close after script has run
Finally, I added the. NET script back to the calling process, cmd or batch file, a value function that can be empty or an integer. There are now two ways to define the return value of a script entry method. You can define it as null, or you can define it as an integer value. If you use a null value, the script will not return anything. If you use an integer value, the script engine returns an integer value to the process that called it.

Examples of two different script entry methods:

The script engine is called.
public static void Main ()
{
.. do stuff
Return
}
The script engine would return a 5 when this script is called.
public static int Main ()
{
.. do stuff
return 5;
}
The script engine is called.
Public Shared Sub Main ()
' ... do stuff
Return
End Sub

The script engine would return a 5 when this script is called.
Public Shared Function Main () as Integer
' ... do stuff
Return 5
End Function



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.