Esempio n. 1
0
        /// <summary>
        /// Since this application is really just a wrapper around 3 other editors, the scripting service
        /// needs to do some special handling for commonly named variables. </summary>
        /// <param name="container"></param>
        private static void InitializeScriptingVariables(CompositionContainer container)
        {
            try
            {
                ScriptingService scriptingService = container.GetExportedValue <ScriptingService>();
                if (scriptingService != null)
                {
                    scriptingService.RemoveVariable("editor");
                    StatechartEditorSample.Editor stateChartEditor = container.GetExportedValue <StatechartEditorSample.Editor>();
                    if (stateChartEditor != null)
                    {
                        scriptingService.SetVariable("stateChartEditor", stateChartEditor);
                    }
                    CircuitEditorSample.Editor circuitEditor = container.GetExportedValue <CircuitEditorSample.Editor>();
                    if (circuitEditor != null)
                    {
                        scriptingService.SetVariable("circuitEditor", circuitEditor);
                    }
                    FsmEditorSample.Editor fsmEditor = container.GetExportedValue <FsmEditorSample.Editor>();
                    if (fsmEditor != null)
                    {
                        scriptingService.SetVariable("fsmEditor", fsmEditor);
                    }

                    IContextRegistry contextRegistry = container.GetExportedValue <IContextRegistry>();
                    if (contextRegistry != null)
                    {
                        contextRegistry.ActiveContextChanged += delegate
                        {
                            //Note this assumes this is the last ActiveContextChanged listener to be called.
                            //Each of the Circuit/Fsm/StatechartEditors also set these variables
                            //(2 out of 3 will set them to null), so it is important this is the last listener invoked.
                            EditingContext editingContext = contextRegistry.ActiveContext.As <EditingContext>();
                            scriptingService.SetVariable("editingContext", editingContext);
                            IViewingContext viewContext = contextRegistry.GetActiveContext <IViewingContext>();
                            scriptingService.SetVariable("view", viewContext);
                        };
                    }
                }
            }
            catch { }
        }