/// <summary> /// Called when the creation of a new script is required. /// </summary> /// <param name="scriptHost">The object handles the script running.</param> /// <param name="selectScriptLanguage">The function that provides the selected script language.</param> /// <param name="storeScriptInformation">The function that stores the information about the new script.</param> /// <param name="timer">The function that creates and stores timing intervals.</param> private static void OnCreateNewScript( IHostScripts scriptHost, Func <Tuple <bool, ScriptDescriptionModel> > selectScriptLanguage, Action <ScriptDescriptionModel, ISyntaxVerifier> storeScriptInformation, Func <string, IDisposable> timer) { // If there is no project facade, then we're in // designer mode, or something else silly. if (scriptHost == null) { throw new CreationOfNewScriptCanceledException(); } using (timer("Creating new script")) { var tuple = selectScriptLanguage(); if (!tuple.Item1) { // The user didn't select anything so just bail. throw new CreationOfNewScriptCanceledException(); } var verifier = scriptHost.VerifySyntax(tuple.Item2.Language); storeScriptInformation(tuple.Item2, verifier); } }
public NewScriptCommand( IHostScripts scriptHost, Func <Tuple <bool, ScriptDescriptionModel> > selectScriptLanguage, Action <ScriptDescriptionModel, ISyntaxVerifier> storeScriptInformation, Func <string, IDisposable> timer) : base( obj => OnCreateNewScript(scriptHost, selectScriptLanguage, storeScriptInformation, timer), obj => CanCreateNewScript(scriptHost)) { }
public OpenScriptCommand( IHostScripts scriptHost, Func <Tuple <FileInfo, ScriptDescriptionModel> > selectScriptLanguage, Action <ScriptDescriptionModel, FileInfo, ISyntaxVerifier> storeScriptInformation, Func <string, IDisposable> timer) : base( obj => OnLoadScript(scriptHost, selectScriptLanguage, storeScriptInformation, timer), obj => CanLoadScript(scriptHost)) { }
private static bool CanCreateNewScript(IHostScripts scriptHost) { // If there is no project facade, then we're in // designer mode, or something else silly. if (scriptHost == null) { return(false); } return(!scriptHost.IsExecutingScript); }
/// <summary> /// Runs a given script. /// </summary> /// <param name="scriptHost">The object that controls the script system.</param> /// <param name="info">The information describing the running script.</param> private static void OnRunScript(IHostScripts scriptHost, ScriptRunInformation info) { // If there is no facade then we're in design mode or something // else weird. if ((scriptHost == null) || (info == null)) { return; } var result = scriptHost.Execute(info.Language, info.Script, info.ScriptOutput as TextWriter); info.ScriptRunningTask = result.Item1; info.CancellationToken = result.Item2; }
/// <summary> /// Cancels the running of the script. /// </summary> /// <param name="scriptHost">The object that controls the script system.</param> /// <param name="info">The information describing the running script.</param> /// <param name="timer">The function that creates and stores timing intervals.</param> private static void OnCancelScriptRun(IHostScripts scriptHost, ScriptRunInformation info, Func <string, IDisposable> timer) { // If there is no facade then we're in design mode or something // else weird. if (scriptHost == null) { return; } if (info != null) { using (timer("Cancelling script run")) { // Note that the cancellation may take some time ...? info.CancellationToken.Cancel(); info.ScriptRunningTask.Wait(); } } }
/// <summary> /// Loads the kernel. /// </summary> private static void LoadKernel() { // At a later stage we need to clean this up. // there are two constants and a DI reference. var bootstrapper = new KernelBootstrapper( s_ShutdownEvent, container => { s_UiContainer = container; s_ScriptHost = s_UiContainer.Resolve <IHostScripts>(); s_Diagnostics = s_UiContainer.Resolve <SystemDiagnostics>(); s_ApplicationFacade = s_UiContainer.Resolve <IAbstractApplications>(); }); // Load the core system. This will automatically // run the UI bootstrapper which will then // load up the UI and display it. bootstrapper.Load(); }
/// <summary> /// Closes the script host. /// </summary> /// <param name="scriptHost">The object that controls the script system.</param> /// <param name="info">The information describing the running script.</param> /// <param name="timer">The function that creates and stores timing intervals.</param> private static void OnCloseScript(IHostScripts scriptHost, ScriptRunInformation info, Func <string, IDisposable> timer) { // If there is no facade then we're in design mode or something // else weird. if (scriptHost == null) { return; } // All we do in here is to stop the script if it is running. There is nothing else to do if (info != null) { using (timer("Closing script")) { if ((info.CancellationToken != null) && (info.ScriptRunningTask != null)) { info.CancellationToken.Cancel(); info.ScriptRunningTask.Wait(); } } } }
/// <summary> /// Loads the kernel. /// </summary> private static void LoadKernel() { // At a later stage we need to clean this up. // there are two constants and a DI reference. var bootstrapper = new KernelBootstrapper( s_ShutdownEvent, container => { s_UiContainer = container; s_ScriptHost = s_UiContainer.Resolve<IHostScripts>(); s_Diagnostics = s_UiContainer.Resolve<SystemDiagnostics>(); s_ApplicationFacade = s_UiContainer.Resolve<IAbstractApplications>(); }); // Load the core system. This will automatically // run the UI bootstrapper which will then // load up the UI and display it. bootstrapper.Load(); }
/// <summary> /// Initializes a new instance of the <see cref="CancelScriptRunCommand"/> class. /// </summary> /// <param name="scriptHost">The object that controls the script system.</param> /// <param name="timer">The function that creates and stores timing intervals.</param> public CancelScriptRunCommand(IHostScripts scriptHost, Func <string, IDisposable> timer) : base(obj => OnCancelScriptRun(scriptHost, obj as ScriptRunInformation, timer), obj => CanCancelScriptRun(scriptHost)) { }
private static bool CanCancelScriptRun(IHostScripts scriptHost) { return((scriptHost != null) && scriptHost.IsExecutingScript); }
/// <summary> /// Initializes a new instance of the <see cref="RunScriptCommand"/> class. /// </summary> /// <param name="scriptHost">The object that controls the script system.</param> public RunScriptCommand(IHostScripts scriptHost) : base(obj => OnRunScript(scriptHost, obj as ScriptRunInformation), obj => CanRunScript(scriptHost)) { }
private static bool CanRunScript(IHostScripts scriptHost) { return((scriptHost != null) && !scriptHost.IsExecutingScript); }