Extending C# .NET application - build a custom scr

2020-02-26 07:23发布

I need to build a scripting interface for my C# program that does system level testing of embedded firmware.

My application contains libraries to fully interact with the devices. There are separate libraries for initiating actions, getting output and tracking success/failure. My application also has a GUI for managing multiple devices and assigning many scripts to be run.

For the testers (non-programmers, but technical), I need to provide a scripting interface that will allow them to come up with different scenarios for testing and run them. They are just going to call my APIs and then return a result to my program (pass/fail and message).

A very basic example of what I want:

TURN_POWER_ON
TUNE_FREQUENCY frequency
WAIT 5
IF GET_FREQUENCY == frequency
  REPORT_PASS "Successfully tuned to " + frequency
ELSE
  REPORT_FAIL "Failed to tune to " + frequency
ENDIF
TURN_POWER_OFF

Where the reporting, power and frequency functions are provided by my C# libraries.

Will something like IronRuby or IronPython be good for this, or should I just build my own very basic language?

Does the Ruby/Python code get messy when trying to include a bunch of .NET compiled assemblies? I want it to be easy to learn and code for non-programmers and programmers alike.

EDIT:

Thanks for all the great responses. I chose IronPython as the answer since it had the most support, but I'll spend a bit of time with each of IronPython, Boo and IronRuby to see what the testers would prefer to write scripts in.

9条回答
啃猪蹄的小仙女
2楼-- · 2020-02-26 07:49

We are using embedded Iron Python for pricing formula in one of our project. This is how a real sample on how it looks like.

E_DOCUMENT_CHECK = DCPAV * ADS_NUM
E_SPECIFIC_TAX = STV
E_RESOURCE_DEV = RDV
E_LP_ISSUANCE = LPIV
E_ANNUAL_FEES = APFCV * SA * SIDES_NUM
E_SERVICE_FEES= MAX(
MINSFV,
E_DOCUMENT_CHECK+E_SPECIFIC_TAX+E_RESOURCE_DEV+E_LP_ISSUANCE+E_ANNUAL_FEES)
TOTAL= E_DOCUMENT_CHECK+E_SPECIFIC_TAX+E_RESOURCE_DEV+E_LP_ISSUANCE+E_ANNUAL_FEES+E_SERVICE_FEES

It is really straightforward to implement. The Max() function for example is just one of the custom C# method that we import to the IronPython engine and it looks natural to use in a configuration settings.

查看更多
仙女界的扛把子
3楼-- · 2020-02-26 07:54

You could just use C# itself as the scripting language as described here CrowsProgramming - Runtime Scripting in .Net

查看更多
甜甜的少女心
4楼-- · 2020-02-26 07:55

From the DSL you're going for, I'd recommend to use CUCUMBER with IronRuby.

With Cucumber, testers write tests that look something like that:

Scenario: See all vendors
Given I am logged in as a user in the administrator role
And There are 3 vendors
When I go to the manage vendors page
Then I should see the first 3 vendor names

It is very easy to make this language fit your needs. Just google "Cucumber and IronRuby" and you'll find several guides and blog posts to get you started.

查看更多
登录 后发表回答