/// <summary> /// Initializes a new instance of the <see cref="TextScriptPanelViewModel"/> class. /// </summary> /// <param name="panelTitle">The title of the panel associated to this view model.</param> /// <param name="scriptingProxy">A <see cref="IScriptingProxy"/> object to perform the script commands associated to CDP4.</param> /// <param name="openSessions">The list of the open <see cref="ISession"/>.</param> public TextScriptPanelViewModel(string panelTitle, IScriptingProxy scriptingProxy, ReactiveList <ISession> openSessions) : base(panelTitle, scriptingProxy, "*.txt", openSessions, false) { this.IsRunButtonVisible = false; this.IsSelectSessionVisible = false; this.IsClearOutputButtonVisible = false; this.IsStopScriptButtonVisible = false; this.IsScriptVariablesPanelVisible = false; }
/// <summary> /// Initializes a new instance of the <see cref="ScriptingEngineRibbonPageGroupViewModel"/> class /// </summary> public ScriptingEngineRibbonPageGroupViewModel(IPanelNavigationService panelNavigationService, IOpenSaveFileDialogService fileDialogService, IScriptingProxy scriptingProxy) { if (panelNavigationService == null) { throw new ArgumentNullException(nameof(panelNavigationService)); } if (fileDialogService == null) { throw new ArgumentNullException(nameof(fileDialogService)); } if (scriptingProxy == null) { throw new ArgumentNullException(nameof(scriptingProxy)); } this.PanelNavigationService = panelNavigationService; this.fileDialogService = fileDialogService; this.scriptingProxy = scriptingProxy; CDPMessageBus.Current.Listen <NavigationPanelEvent>() .Where(x => x.ViewModel.ToString().Contains("ScriptPanelViewModel") && x.PanelStatus == PanelStatus.Closed) .ObserveOn(RxApp.MainThreadScheduler) .Subscribe(this.HandleClosedPanel); this.OpenSessions = new ReactiveList <ISession>(); this.OpenSessions.ChangeTrackingEnabled = true; this.OpenSessions.CountChanged.Select(x => x != 0).ToProperty(this, x => x.HasSession, out this.hasSession); CDPMessageBus.Current.Listen <SessionEvent>().Subscribe(this.SessionChangeEventHandler); this.initialDialogPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "file.txt"); this.PathScriptingFiles = new Dictionary <string, string>(); this.CollectionScriptPanelViewModels = new ObservableCollection <IScriptPanelViewModel>(); CDPMessageBus.Current.Listen <ScriptPanelEvent>().Subscribe(this.ScriptPanelEventHandler); this.NewPythonScriptCommand = ReactiveCommand.Create(); this.NewPythonScriptCommand.Subscribe(_ => this.ExecuteCreateNewScript("python", ScriptingLaguageKindSupported.Python)); this.NewLuaScriptCommand = ReactiveCommand.Create(); this.NewLuaScriptCommand.Subscribe(_ => this.ExecuteCreateNewScript("lua", ScriptingLaguageKindSupported.Lua)); this.NewTextScriptCommand = ReactiveCommand.Create(); this.NewTextScriptCommand.Subscribe(_ => this.ExecuteCreateNewScript("text", ScriptingLaguageKindSupported.Text)); this.OpenScriptCommand = ReactiveCommand.Create(); this.OpenScriptCommand.Subscribe(_ => this.OpenScriptFile()); this.SaveAllCommand = ReactiveCommand.Create(); this.SaveAllCommand.Subscribe(_ => this.SaveAllScripts()); }
/// <summary> /// The constructor of the <see cref="ScriptPanelViewModel"/> class. /// </summary> /// <param name="panelTitle">The title of the panel associated to this view model.</param> /// <param name="scriptingProxy">A <see cref="IScriptingProxy"/> object to perform the script commands associated to CDP4.</param> /// <param name="fileExtension">The file extension associated to the tab item view-model.</param> /// <param name="openSessions">The list of the open <see cref="ISession"/>.</param> /// <param name="areTerminalsExistByDefault">Indicates whether the input and output terminals exist by default</param> protected ScriptPanelViewModel(string panelTitle, IScriptingProxy scriptingProxy, string fileExtension, ReactiveList <ISession> openSessions, bool areTerminalsExistByDefault) { this.Caption = panelTitle; this.ScriptingProxy = scriptingProxy; this.OpenSessions = openSessions; this.FileExtension = fileExtension; this.InitAvalonEditor(); this.Identifier = Guid.NewGuid(); this.ScriptVariables = new List <KeyValuePair <string, dynamic> >(); this.SaveScriptCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.IsDirty)); this.SaveScriptCommand.Subscribe(_ => this.SaveScript()); this.ExecuteScriptCommand = ReactiveCommand.CreateAsyncTask(this.WhenAnyValue(x => x.CanExecuteScript), _ => this.ExecuteScript(), RxApp.MainThreadScheduler); this.StopScriptCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.IsScriptExecuted)); this.StopScriptCommand.Subscribe(_ => this.StopScript()); this.ClearOutputCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.CanClearOutput)); this.ClearOutputCommand.Subscribe(_ => this.ClearOutput()); this.WhenAnyValue(vm => vm.OpenSessions.Count) .ObserveOn(RxApp.MainThreadScheduler) .Subscribe(_ => this.ReactOnOpenSessionsChange()); this.WhenAnyValue(vm => vm.IsDirty) .ObserveOn(RxApp.MainThreadScheduler) .Subscribe(_ => this.ReactOnIsDirtyChange()); this.WhenAnyValue(vm => vm.IsScriptExecuted) .ObserveOn(RxApp.MainThreadScheduler) .Subscribe(_ => this.ReactOnIsScriptExecutedChange()); this.cancellationTokenSource = new CancellationTokenSource(); this.CancellationToken = cancellationTokenSource.Token; if (areTerminalsExistByDefault) { this.InputTerminal = new InputTerminal(this); this.OutputTerminal = new OutputTerminal(); this.OutputTerminal.TextChanged += (s, e) => this.ReactOnOutputContentChange(); this.AreTerminalsVisible = true; this.ReactOnOutputContentChange(); } }
/// <summary> /// Constructor of the <see cref="PythonScriptPanelViewModel"/> /// </summary> /// <param name="panelTitle">The title of the panel associated to this view model.</param> /// <param name="scriptingProxy">A <see cref="IScriptingProxy"/> object to perform the script commands associated to CDP4.</param> /// <param name="openSessions">The list of the open <see cref="ISession"/>.</param> public PythonScriptPanelViewModel(string panelTitle, IScriptingProxy scriptingProxy, ReactiveList <ISession> openSessions) : base(panelTitle, scriptingProxy, "*.py", openSessions, true) { this.LoadHighlightingSheet(PythonHighlighting); this.Engine = Python.CreateEngine(); this.Engine.Runtime.LoadAssembly(typeof(string).Assembly); this.Engine.Runtime.LoadAssembly(typeof(Uri).Assembly); var searchPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); var paths = this.Engine.GetSearchPaths(); paths.Add(searchPath); this.Engine.SetSearchPaths(paths); this.Scope = this.Engine.CreateScope(); this.Scope.SetVariable(Command, this.ScriptingProxy); }
/// <summary> /// Initializes a new instance of the <see cref="LuaScriptPanelViewModel"/> class. /// </summary> /// <param name="panelTitle">The title of the panel associated to this view model.</param> /// <param name="scriptingProxy">A <see cref="IScriptingProxy"/> object to perform the script commands associated to CDP4.</param> /// <param name="openSessions">The list of the open <see cref="ISession"/>.</param> public LuaScriptPanelViewModel(string panelTitle, IScriptingProxy scriptingProxy, ReactiveList <ISession> openSessions) : base(panelTitle, scriptingProxy, "*.lua", openSessions, true) { this.LoadHighlightingSheet(LuaHighlighting); UserData.RegisterType <IScriptingProxy>(); this.CommandObject = UserData.Create(this.ScriptingProxy); // We create an object to interprete the Lua script and we register IScriptingProxy to use its methods in the script this.Interpreter = new Script(); Interpreter.Globals.Set(Command, this.CommandObject); Interpreter.Options.DebugPrint = s => { Application.Current.Dispatcher.Invoke( DispatcherPriority.Input, new Action(() => this.OutputTerminal.AppendText(string.Format("{0} \n", s)))); }; this.ignoredVariables = Interpreter.Globals.Keys.Select(x => x.ToString()).ToArray(); }
public ScriptingEngineRibbon(IPanelNavigationService panelNavigationService, IOpenSaveFileDialogService fileDialogService, IScriptingProxy scriptingProxy) { this.InitializeComponent(); this.DataContext = new ScriptingEngineRibbonPageGroupViewModel(panelNavigationService, fileDialogService, scriptingProxy); }