Free cookie consent management tool by TermsFeed Policy Generator

Opened 9 years ago

Closed 9 years ago

#2136 closed feature request (done)

Create a scripting environment

Reported by: jkarder Owned by: abeham
Priority: high Milestone: HeuristicLab 3.3.10
Component: Scripting Version: 3.3.9
Keywords: Cc:

Description

A scripting environment should be created to provide rapid prototyping features.

Change History (40)

comment:1 Changed 9 years ago by jkarder

  • Status changed from new to accepted

comment:2 Changed 9 years ago by jkarder

r10331: created branch

comment:3 Changed 9 years ago by jkarder

r10332: added prototype of a scripting environment

comment:4 Changed 9 years ago by jkarder

r10358:

  • refactored HLScriptGeneration to separate outputs from different running HL scripts.
  • added persistence support for HLScripts and fixed cloning
  • added code completion for all types in the currently loaded assemblies
  • merged trunk changes

comment:5 Changed 9 years ago by jkarder

r10359: merged HLScript branch back to trunk

comment:6 Changed 9 years ago by jkarder

  • Owner changed from jkarder to abeham
  • Status changed from accepted to reviewing

comment:7 Changed 9 years ago by mkommend

Some issues which I found during testing:

  • Build configurations, especially paths, are not set correctly
  • Consider renaming the projects / classes (e.g., HeuristicLab.Scripting, HeuristicLabScript)
  • IMHO the complete source code should always be visible, instead of hiding some parts.
  • I would prefer to have a real C# script with a static void main entry point, which could also be executed in other development environments. Another benefit would be that the error line numbers would automatically match the displayed line numbers.
  • Exceptions should additionally be shown in an error dialog. If one does not view the log, the person has no clue that an exception was thrown.

comment:8 Changed 9 years ago by abeham

  • Owner changed from abeham to architects
  • Status changed from reviewing to assigned

comment:9 Changed 9 years ago by abeham

r10391: fixed build configuration, output path and added ignore properties

comment:10 Changed 9 years ago by jkarder

r10401:

  • renamed some HLScript files
  • fixed a bug where variables could be renamed while a script was running
  • the complete source code is now always visible
  • removed "show generated code" feature

comment:11 Changed 9 years ago by abeham

  • Owner changed from architects to jkarder
  • Version changed from branch to 3.3.9

Results of yesterday's meeting:

  • Change plugin to HeuristicLab.Scripting and HeuristicLab.Scripting.Views and adapt the objects (also rename the trac component)
  • Put an extra Compile Button and register F6 as a shortcut
  • Put the output window first and error list second
  • Automatically change tabs: when compiling -> errors, when running -> output
  • When an exception is thrown it should be viewed using the PluginInfrastructure
  • Remove the namespace declaration in the script
  • Names in the VariableStore have to conform to C# property names
  • Contains(string) method to check if a variable is present in the VariableStore
  • Split the start page vertically and group samples and scripts on the right hand side
  • After implementing the changes mkommend will do the code review

comment:12 Changed 9 years ago by abeham

swagner suggested to add the ability to split the script into multiple scripts. Instead of having a Code property that returns only a single string, it should be able to store a collection. The view could be enhanced to include a DockPanel and open each code in a separate docking windows inside that panel as well as to include buttons to add or remove new windows.

comment:13 Changed 9 years ago by jkarder

r10506: applied some of the changes suggested in comment:11:ticket:2136

  • change namespaces to HeuristicLab.Scripting.*
  • added extra compile button and registered F6 as a shortcut
  • changed the order of the output window and the error list
  • tabs (output window and error list) are selected automatically
  • thrown exceptions are shown using the PluginInfrastructure
  • removed namespace declaration in the script
  • names in the VariableStore are now conform to C# property names

comment:14 Changed 9 years ago by jkarder

  • Status changed from assigned to accepted

comment:15 Changed 9 years ago by jkarder

r10474: using RandomEnumerable.SampleProportional in BiasedMultiVRPOperators.

It is listed in this ticket as svn:ignore properties were added to the scripting folders with this changeset.

Last edited 9 years ago by mkommend (previous) (diff)

comment:16 Changed 9 years ago by jkarder

r10510: renamed folders of HeuristicLab.Scripting and HeuristicLab.HLScript.Views

comment:17 Changed 9 years ago by jkarder

r10511: added Contains(string) method to check if a variable is present in the VariableStore

comment:18 Changed 9 years ago by jkarder

r10512:

  • the Variables class now implements IEnumerable<T>
  • added Keys and Values properties to the Variables class

comment:19 Changed 9 years ago by abeham

r10566:

  • Made Variables class public (could be used in other scripts as well)
  • Renamed ItemName to "C# Script"

comment:20 Changed 9 years ago by abeham

r10577:

  • Fixed drag-drop behavior in VariableStoreView
  • Added additional information to Script and changed setting name and description

I noticed that if multiple items are to be dragged they're combined into a List<object> and should of course be expanded again. This does not work currently.

comment:21 Changed 9 years ago by jkarder

r10642: fixed automatic selection of tabs (output window and error list)

comment:22 Changed 9 years ago by abeham

The tool tip for the run/stop button needs to reflect the state of the button.

comment:23 Changed 9 years ago by abeham

I would propose to change the type of compiledScript to dynamic. It would allow to compile anything into the running environment, not just scripts. I've attached a patch for this change.

Edit: The patch has become obsolete with the separation of Script and CSharpScript

Last edited 9 years ago by abeham (previous) (diff)

comment:24 Changed 9 years ago by jkarder

r10727:

  • fixed tool tips
  • added Clear() method to remove all variables present in the VariableStore
  • the script cannot be compiled and started with the shortcuts anymore if it is already running

comment:25 Changed 9 years ago by jkarder

  • Owner changed from jkarder to mkommend
  • Status changed from accepted to reviewing

comment:26 Changed 9 years ago by abeham

  • Owner changed from mkommend to abeham
  • Status changed from reviewing to assigned

comment:27 Changed 9 years ago by abeham

  • Status changed from assigned to accepted

comment:28 Changed 9 years ago by abeham

I wanted to change a couple of things to make it easier to embed scripting in other parts of HeuristicLab.

r10731:

  • Split Script into Script and CSharpScript
  • Split ScriptView into ScriptView and CSharpScriptView

comment:29 Changed 9 years ago by abeham

r10747: fixed anchor in ScriptView

comment:30 Changed 9 years ago by abeham

r10761: fixed a bug when switching views

comment:31 Changed 9 years ago by abeham

  • Owner changed from abeham to mkommend
  • Priority changed from medium to high
  • Status changed from accepted to reviewing

I would ask you to do a review of this feature so that we can release this.

comment:32 follow-up: Changed 9 years ago by mkommend

  • Owner changed from mkommend to abeham
  • Status changed from reviewing to assigned

Review comments

Script.cs

  • Remove virtual modifier from the properties that are not overriden
  • CompilationUnitCode is never used (except cloning)
  • Default ctor should not call virtual properties and misses its base ctor call

CSharpScript

  • Make CompiledScript and ScriptThread property private.
  • DeregisterScriptEvents should be called before the CompiledScript is set to null, because otherwise it has no effect (line 111).
  • Check in the compile method if multiple classes derived from CSharpScriptBase are defined, because this would lead to an undefined behavior. You could use Single instead of First for example.
  • Why is reflection used to call the execute method of CSharpScriptBase in CSharpScript.Execute? Wouldn't it be easier to call CompiledScript.Execute(VariableStore); (line 127) and get rid of the reflection code.

CSharpScriptBase

  • Choose a more appropriate name for the usb variable (e.g., script, scriptBase,...).
  • Is it necessary that vars is of type dynamic? Couldn't I type vars statically to Variables?

ScriptView

  • Comment in line 151 is wrong. According to MSDN is resizes the column to the header width.

CSharpScriptView

  • OnContentChanged duplicates code from its base class.
  • The same holds for SetEnabledStateOfControls.

comment:33 Changed 9 years ago by abeham

  • Owner changed from abeham to jkarder

please implement the review comments

comment:34 Changed 9 years ago by jkarder

  • Status changed from assigned to accepted

comment:35 Changed 9 years ago by jkarder

r10857: implemented review comments from mkommend in comment:32:ticket:2136

Last edited 9 years ago by jkarder (previous) (diff)

comment:36 in reply to: ↑ 32 Changed 9 years ago by jkarder

Replying to mkommend:

  • Is it necessary that vars is of type dynamic? Couldn't I type vars statically to Variables?

Yes, vars has to be of type dynamic because otherwise its dynamic runtime behavior (invocation of DynamicObject.TryGetMember() etc.) would not work.

Last edited 9 years ago by jkarder (previous) (diff)

comment:37 Changed 9 years ago by jkarder

  • Owner changed from jkarder to mkommend
  • Status changed from accepted to reviewing

comment:38 Changed 9 years ago by jkarder

r10865: fixed compilation error output in console

comment:39 Changed 9 years ago by mkommend

  • Owner changed from mkommend to abeham
  • Status changed from reviewing to readytorelease

Reviewed r10857 & r10865.

Last edited 9 years ago by mkommend (previous) (diff)

comment:40 Changed 9 years ago by abeham

  • Resolution set to done
  • Status changed from readytorelease to closed
Note: See TracTickets for help on using tickets.