Esempio n. 1
0
        public SwitchExecutiveControl(
            string editTimeConfiguration,
            string runTimeConfiguration,
            UpdateConfigurationDelegate updateConfigurationDelegate,
            PanelPresentation requestedPresentation)
        {
            InitializeComponent();

            /* used to save/load our view models and models.  for save we serialize
             * and return the string to InstrumentStudio via the UpdateConfiguraitonDelegate.  This
             * class also handles not saving during load.  */
            var saveDelegator = new SaveDelegator(updateConfigurationDelegate);

            /* crete the main view model which creates all the child view models and models.  by
             * doing this creation here we imply that the view is created first. Also we:
             *
             * 1. check the registry to see if SwitchExecutive is installed.
             * 2. create a DriverOperations class that is basically our model and conneciton to the driver.
             * 3. create a status option that is shared to all view models.  this allows any code to report errors. */
            var mainViewModel =
                new SwitchExecutiveControlViewModel(
                    requestedPresentation,
                    NISwitchExecutiveDriverOperations.IsDriverInstalled(),
                    (ISwitchExecutiveDriverOperations) new NISwitchExecutiveDriverOperations(),
                    (ISave)saveDelegator,
                    (IStatus) new Status());

            /* attach the serialize and deserialize commands after.  This allows us to create any objects we need
             * prior to creating the ViewModels ... just for a cleaner construction. */
            saveDelegator.Attach(
                serialize: new Func <string>(() => mainViewModel.Serialize()),
                deserialize: o => mainViewModel.Deserialize(o));


            this.DataContext = mainViewModel;

            // update our state based on the state saved in the .sfp file
            saveDelegator.Deserialize(editTimeConfiguration);
            // restore connections from the saved file
            mainViewModel.ApplyLoadFromFile();
        }
Esempio n. 2
0
 public SaveDelegator(UpdateConfigurationDelegate updateConfigurationDelegate)
 {
     this.updateConfiguration = updateConfigurationDelegate;
 }
 /// <summary>
 /// This method is called by InstrumentStudio when your plugin is placed within a document. It should return the visual (FrameworkElement) that
 /// you want displayed.
 /// </summary>
 /// <param name="editTimeConfiguration">The previously saved edit-time configuration (empty string if this is the first instantiation)</param>
 /// <param name="runTimeConfiguration">The previously saved run-time configuration (empty string if this is the first instantiation)</param>
 /// <param name="updateConfigurationDelegate">Use this delegate whenever you want to notify InstrumentStudio that your plugin's configuration has changed.
 /// Strings that are passed will be persisted with the .sfp. Upon reopening the .sfp, InstrumentStudio will pass these strings as the
 /// "editTimeConfiguration" and "runTimeConfiguration" inputs so that you can restore the state of your UI.</param>
 /// <param name="requestedPresentation">Render your UI accordingly, based on whether your plugin is placed in a small panel (ConfigurationOnly) or
 /// large panel (ConfigurationWithVisualization).</param>
 /// <returns>The IInstrumentStudioPlugin to be hosted.</returns>
 public IPanelPlugin CreatePlugin(string editTimeConfiguration, string runTimeConfiguration, UpdateConfigurationDelegate updateConfigurationDelegate, PanelPresentation requestedPresentation)
 {
     return(new SwitchExecutiveControl(editTimeConfiguration, runTimeConfiguration, updateConfigurationDelegate, requestedPresentation));
 }