示例#1
0
        private static PersistedLabState CreatePersistentObject(LabStateManager runningState)
        {
            PersistedLabState persistedState = new PersistedLabState();

            // Persist layer
            foreach (IConfigurationLayer l in runningState.Engine.Configuration.Layers)
            {
                PersistedConfigurationLayer persistedLayer = new PersistedConfigurationLayer();
                persistedState.ConfigurationLayers.Add(persistedLayer);

                persistedLayer.LayerName = l.LayerName;
                foreach (IConfigurationItem i in l.Items)
                {
                    PersistedConfigurationItem persistedItem = new PersistedConfigurationItem();
                    persistedItem.ServiceOrPluginId = i.ServiceOrPluginFullName;
                    persistedItem.Status            = i.Status;
                    persistedItem.StatusReason      = i.StatusReason;

                    persistedLayer.Items.Add(persistedItem);
                }
            }

            // Persist service and plugins -- We already have the mocks, so we can use them.
            foreach (ServiceInfo s in runningState.ServiceInfos)
            {
                persistedState.Services.Add(s);
            }
            foreach (PluginInfo p in runningState.PluginInfos)
            {
                persistedState.Plugins.Add(p);
            }

            return(persistedState);
        }
示例#2
0
        public static void SerializeToXml(LabStateManager state, XmlWriter w)
        {
            PersistedLabState stateToSerialize = CreatePersistentObject(state);

            w.WriteStartElement("Yodii.Lab");

            w.WriteStartElement("Services");
            foreach (ServiceInfo si in state.ServiceInfos)
            {
                w.WriteStartElement("Service");
                SerializeServiceInfoToXmlWriter(si, w);
                w.WriteEndElement();
            }
            w.WriteEndElement();

            w.WriteStartElement("Plugins");
            foreach (PluginInfo pi in state.PluginInfos)
            {
                w.WriteStartElement("Plugin");
                SerializePluginInfoToXmlWriter(pi, w);
                w.WriteEndElement();
            }
            w.WriteEndElement();

            w.WriteStartElement("Configuration");
            SerializeConfigurationManager(stateToSerialize, w);
            w.WriteEndElement();

            w.WriteEndElement();
        }
        /// <summary>
        /// Creates a new instance of this ViewModel.
        /// </summary>
        /// <param name="loadDefaultState">True if the default XML state should be loaded, false to start on an empty state.</param>
        public MainWindowViewModel( bool loadDefaultState = false )
        {
            _recentFiles = new CKObservableSortedArrayList<RecentFile>( ( a, b ) => DateTime.Compare( b.AccessTime, a.AccessTime ) );

            // Lab objects, live objects and static infos are managed in the LabStateManager.
            _labStateManager = new LabStateManager();
            _engine = _labStateManager.Engine;

            _labStateManager.Engine.PropertyChanged += Engine_PropertyChanged;
            _labStateManager.ServiceInfos.CollectionChanged += ServiceInfos_CollectionChanged;
            _labStateManager.PluginInfos.CollectionChanged += PluginInfos_CollectionChanged;
            _labStateManager.RunningPlugins.CollectionChanged += RunningPlugins_CollectionChanged;

            _engine.Configuration.Layers.CollectionChanged += Layers_CollectionChanged;

            _activityMonitor = new ActivityMonitor();

            _activityMonitor.OpenTrace().Send( "Hello world" );

            _graph = new YodiiGraph( _engine.Configuration, _labStateManager );

            _removeSelectedVertexCommand = new RelayCommand( RemoveSelectedVertexExecute, CanEditSelectedVertex );
            _toggleEngineCommand = new RelayCommand( ToggleEngineExecute );
            _openFileCommand = new RelayCommand( OpenFileExecute );
            _saveAsFileCommand = new RelayCommand( SaveAsFileExecute );
            _saveCommand = new RelayCommand( SaveExecute ); // Save is always available.e
            _reorderGraphLayoutCommand = new RelayCommand( ReorderGraphLayoutExecute );
            _createPluginCommand = new RelayCommand( CreatePluginExecute, CanEditItems );
            _createServiceCommand = new RelayCommand( CreateServiceExecute, CanEditItems );
            _openConfigurationEditorCommand = new RelayCommand( OpenConfigurationEditorExecute );
            _newFileCommand = new RelayCommand( NewFileExecute );
            _revokeAllCommandsCommand = new RelayCommand( RevokeAllCommandsExecute, CanRevokeAllCommands );
            _autoPositionCommand = new RelayCommand( AutoPositionExecute );

            LoadRecentFiles();

            // Appication is only available on WPF context.
            if( Application.Current != null )
            {
                _autosaveTimer = new DispatcherTimer( DispatcherPriority.Background, Application.Current.Dispatcher );
            }
            else
            {
                _autosaveTimer = new DispatcherTimer( DispatcherPriority.Background, Dispatcher.CurrentDispatcher );
            }

            _autosaveTimer.Interval = new TimeSpan( 0, 0, 5 );
            _autosaveTimer.Tick += AutosaveTick;

            // Autosave timer is started from outside, using StartAutosaveTimer().

            if( loadDefaultState ) LoadDefaultState();
        }
        internal LabXmlDeserializer( LabStateManager state, XmlReader r )
        {
            this.state = state;
            this.r = r;
            deserializedState = new PersistedLabState();
            // Used to index reference links between plugins and services.
            pendingGeneralizations = new List<PendingGeneralization>();
            pendingPluginServices = new List<PendingPluginService>();
            pendingServiceReferences = new List<PendingServiceReference>();

            loadedServices = new CKSortedArrayKeyList<ServiceInfo, string>( s => s.ServiceFullName, false );
            loadedPlugins = new CKSortedArrayKeyList<PluginInfo, string>( p => p.PluginFullName, false );
        }
示例#5
0
        internal LabXmlDeserializer(LabStateManager state, XmlReader r)
        {
            this.state        = state;
            this.r            = r;
            deserializedState = new PersistedLabState();
            // Used to index reference links between plugins and services.
            pendingGeneralizations   = new List <PendingGeneralization>();
            pendingPluginServices    = new List <PendingPluginService>();
            pendingServiceReferences = new List <PendingServiceReference>();

            loadedServices = new CKSortedArrayKeyList <ServiceInfo, string>(s => s.ServiceFullName, false);
            loadedPlugins  = new CKSortedArrayKeyList <PluginInfo, string>(p => p.PluginFullName, false);
        }
示例#6
0
        internal YodiiGraph(IConfigurationManager configManager, LabStateManager serviceManager)
            : base()
        {
            Debug.Assert(serviceManager != null);
            Debug.Assert(configManager != null);

            _serviceInfos         = serviceManager.LabServiceInfos;
            _pluginInfos          = serviceManager.LabPluginInfos;
            _configurationManager = configManager;
            _serviceManager       = serviceManager;

            _serviceInfos.CollectionChanged            += _serviceInfos_CollectionChanged;
            _pluginInfos.CollectionChanged             += _pluginInfos_CollectionChanged;
            _configurationManager.ConfigurationChanged += _configurationManager_ConfigurationChanged;

            UpdateVerticesWithConfiguration(_configurationManager.FinalConfiguration);
        }
        private static PersistedLabState CreatePersistentObject( LabStateManager runningState )
        {
            PersistedLabState persistedState = new PersistedLabState();

            // Persist layer
            foreach( IConfigurationLayer l in runningState.Engine.Configuration.Layers )
            {
                PersistedConfigurationLayer persistedLayer = new PersistedConfigurationLayer();
                persistedState.ConfigurationLayers.Add( persistedLayer );

                persistedLayer.LayerName = l.LayerName;
                foreach( IConfigurationItem i in l.Items )
                {
                    PersistedConfigurationItem persistedItem = new PersistedConfigurationItem();
                    persistedItem.ServiceOrPluginId = i.ServiceOrPluginFullName;
                    persistedItem.Status = i.Status;
                    persistedItem.StatusReason = i.StatusReason;

                    persistedLayer.Items.Add( persistedItem );
                }
            }

            // Persist service and plugins -- We already have the mocks, so we can use them.
            foreach( ServiceInfo s in runningState.ServiceInfos )
            {
                persistedState.Services.Add( s );
            }
            foreach( PluginInfo p in runningState.PluginInfos )
            {
                persistedState.Plugins.Add( p );
            }

            return persistedState;
        }
        public static void SerializeToXml( LabStateManager state, XmlWriter w )
        {
            PersistedLabState stateToSerialize = CreatePersistentObject( state );

            w.WriteStartElement( "Yodii.Lab" );

            w.WriteStartElement( "Services" );
            foreach( ServiceInfo si in state.ServiceInfos )
            {
                w.WriteStartElement( "Service" );
                SerializeServiceInfoToXmlWriter( si, w );
                w.WriteEndElement();
            }
            w.WriteEndElement();

            w.WriteStartElement( "Plugins" );
            foreach( PluginInfo pi in state.PluginInfos )
            {
                w.WriteStartElement( "Plugin" );
                SerializePluginInfoToXmlWriter( pi, w );
                w.WriteEndElement();
            }
            w.WriteEndElement();

            w.WriteStartElement( "Configuration" );
            SerializeConfigurationManager( stateToSerialize, w );
            w.WriteEndElement();

            w.WriteEndElement();
        }
示例#9
0
        public static void DeserializeAndResetStateFromXml(this LabStateManager state, XmlReader r)
        {
            LabXmlDeserializer helper = new LabXmlDeserializer(state, r);

            helper.Deserialize();
        }