Example #1
0
        internal static async Task ExecuteScript(string scriptCode, bool forceExecution)
        {
            var sceneModel = ViewModelLocator.Scene;

            try
            {
                var references = new Assembly[]
                {
                    // [RS] To use SharpGL types.
                    typeof(SceneElement).Assembly,
                    // [RS] To use types from the UI, e.g. the view models.
                    typeof(SceneModel).Assembly
                };

                var imports = new string[]
                {
                    "SharpGL.SceneGraph.Core",
                    "SharpGL.SceneGraph.Quadrics",
                    "SharpGL.SceneGraph.Primitives",
                    "SharpGL.SceneGraph.Transformations",
                    "WaveDev.ModelR.ViewModels"
                };

                var scriptOptions = ScriptOptions.Default
                                    .WithReferences(references)
                                    .WithImports(imports);

                var context = new ScriptingContext(sceneModel.UserModels, sceneModel.SceneObjectModels);
                var globals = new ScriptingGlobals(context);

                var script = CSharpScript.Create(scriptCode, scriptOptions, typeof(ScriptingGlobals));

                var diagnostics = script.Compile();

                if (!forceExecution && diagnostics.Count() > 0)
                {
                    return;
                }

                var state = await script.RunAsync(globals);

                await ProcessScriptResult(sceneModel, state);
            }
            catch (Exception exception)
            {
                var message = new MessageViewModel(exception.Message);

                sceneModel.Errors.Add(message);
            }
        }
Example #2
0
 public ScriptingGlobals(ScriptingContext adapter)
 {
     ModelR = adapter;
 }