コード例 #1
0
ファイル: LabPluginInfo.cs プロジェクト: julien-moreau/yodii
        internal LabPluginInfo( PluginInfo pluginInfo )
        {
            Debug.Assert( pluginInfo != null );

            _pluginInfo = pluginInfo;

            StartPluginCommand = new RelayCommand( ExecuteStartPlugin, CanExecuteStartPlugin );
            StopPluginCommand = new RelayCommand( ExecuteStopPlugin, CanExecuteStopPlugin );
        }
コード例 #2
0
        internal MockServiceReferenceInfo( PluginInfo ownerPlugin, ServiceInfo referencedService, DependencyRequirement requirement )
        {
            Debug.Assert( ownerPlugin != null );
            Debug.Assert( referencedService != null );

            _owner = ownerPlugin;
            _reference = referencedService;
            _requirement = requirement;
        }
コード例 #3
0
 internal PendingServiceReference( PluginInfo plugin, string pendingServiceFullName, DependencyRequirement requirement )
 {
     Plugin = plugin;
     PendingServiceFullName = pendingServiceFullName;
     Requirement = requirement;
 }
コード例 #4
0
 internal PendingPluginService( PluginInfo plugin, string pendingServiceFullName )
 {
     Plugin = plugin;
     PendingServiceFullName = pendingServiceFullName;
 }
コード例 #5
0
        private static void SerializePluginInfoToXmlWriter( PluginInfo pi, XmlWriter w )
        {
            w.WriteStartElement( "FullName" );
            if( pi.PluginFullName != null ) w.WriteValue( pi.PluginFullName );
            w.WriteEndElement();

            w.WriteStartElement( "Service" );
            if( pi.Service != null ) w.WriteValue( pi.Service.ServiceFullName );
            w.WriteEndElement();

            w.WriteStartElement( "ServiceReferences" );
            foreach( var serviceRef in pi.ServiceReferences )
            {
                Debug.Assert( serviceRef.Owner == pi );

                w.WriteStartElement( "ServiceReference" );

                w.WriteStartAttribute( "Service" );
                w.WriteValue( serviceRef.Reference.ServiceFullName );
                w.WriteEndAttribute();

                w.WriteStartAttribute( "Requirement" );
                w.WriteValue( serviceRef.Requirement.ToString() );
                w.WriteEndAttribute();

                w.WriteEndElement();
            }
            w.WriteEndElement();

            w.WriteStartElement( "X" );
            if( pi.PositionInGraph.IsValid() ) w.WriteValue( pi.PositionInGraph.X.ToString( CultureInfo.InvariantCulture ) );
            w.WriteEndElement();

            w.WriteStartElement( "Y" );
            if( pi.PositionInGraph.IsValid() ) w.WriteValue( pi.PositionInGraph.Y.ToString( CultureInfo.InvariantCulture ) );
            w.WriteEndElement();
        }
コード例 #6
0
        private void ReadPlugin( XmlReader r )
        {
            r.Read();

            PluginInfo p = new PluginInfo( null, AssemblyInfoHelper.ExecutingAssemblyInfo );
            loadedPlugins.Add( p );

            Point pos = new Point();
            pos.X = Double.NaN;
            pos.Y = Double.NaN;

            while( r.Read() )
            {
                if( r.IsStartElement() && !r.IsEmptyElement )
                {
                    switch( r.Name )
                    {
                        case "FullName":
                            if( r.Read() )
                            {
                                string fullName = r.Value;
                                p.PluginFullName = fullName;
                            }
                            break;
                        case "Service":
                            if( r.Read() )
                            {
                                string serviceFullName = r.Value;
                                if( !String.IsNullOrEmpty( serviceFullName ) )
                                {
                                    if( loadedServices.Contains( serviceFullName ) )
                                    {
                                        var service = loadedServices.GetByKey( serviceFullName );
                                        p.Service = service;
                                        service.InternalImplementations.Add( p );
                                    }
                                    else
                                    {
                                        pendingPluginServices.Add( new PendingPluginService( p, serviceFullName ) );
                                    }
                                }
                            }
                            break;
                        case "ServiceReferences":
                            var s = r.ReadSubtree();
                            while( s.Read() )
                            {
                                if( s.IsStartElement() && s.Name == "ServiceReference" )
                                {
                                    string serviceFullName2 = s.GetAttribute( "Service" );
                                    if( !String.IsNullOrEmpty( serviceFullName2 ) )
                                    {
                                        DependencyRequirement requirement = (DependencyRequirement)Enum.Parse( typeof( DependencyRequirement ), s.GetAttribute( "Requirement" ) );

                                        if( loadedServices.Contains( serviceFullName2 ) )
                                        {
                                            MockServiceReferenceInfo i = new MockServiceReferenceInfo( p, loadedServices.GetByKey( serviceFullName2 ), requirement );
                                            p.InternalServiceReferences.Add( i );
                                        }
                                        else
                                        {
                                            pendingServiceReferences.Add( new PendingServiceReference( p, serviceFullName2, requirement ) );
                                        }
                                    }
                                }
                            }
                            break;
                        case "X":
                            if( r.Read() )
                            {
                                double posX;
                                if( Double.TryParse( r.Value, NumberStyles.Any, CultureInfo.InvariantCulture, out posX) ) pos.X = posX;
                            }
                            break;
                        case "Y":
                            if( r.Read() )
                            {
                                double posY;
                                if( Double.TryParse( r.Value, NumberStyles.Any, CultureInfo.InvariantCulture, out posY ) ) pos.Y = posY;
                            }
                            break;
                    }
                }
            }

            p.PositionInGraph = pos;
        }
コード例 #7
0
        /// <summary>
        /// Creates a lab wrapper item around an existing mock plugin, and adds it to our collection.
        /// </summary>
        /// <param name="p">Existing mock plugin</param>
        private void CreateLabPlugin( PluginInfo p )
        {
            LabPluginInfo lp;

            if( p.Service != null )
            {
                p.Service.InternalImplementations.Add( p );
                LabServiceInfo liveService = _labServiceInfos.GetByKey( p.Service );
                lp = new LabPluginInfo( p );
            }
            else
            {
                lp = new LabPluginInfo( p );
            }

            _labPluginInfos.Add( lp );
        }
コード例 #8
0
        /// <summary>
        /// Set an existing plugin's dependency to an existing service.
        /// </summary>
        /// <param name="plugin">Plugin</param>
        /// <param name="service">Service the plugin depends on</param>
        /// <param name="runningRequirement">How the plugin depends on the service</param>
        internal void SetPluginDependency( PluginInfo plugin, ServiceInfo service, DependencyRequirement runningRequirement )
        {
            Debug.Assert( plugin != null );
            Debug.Assert( service != null );
            Debug.Assert( ServiceInfos.Contains( service ) );
            Debug.Assert( PluginInfos.Contains( plugin ) );

            MockServiceReferenceInfo reference = new MockServiceReferenceInfo( plugin, service, runningRequirement );
            plugin.InternalServiceReferences.Add( reference );
        }
コード例 #9
0
        /// <summary>
        /// Removes an existing plugin dependency.
        /// </summary>
        /// <param name="plugin">Plugin owner.</param>
        /// <param name="service">Service reference</param>
        internal void RemovePluginDependency( PluginInfo plugin, ServiceInfo service )
        {
            Debug.Assert( plugin != null );
            Debug.Assert( service != null );
            Debug.Assert( ServiceInfos.Contains( service ) );
            Debug.Assert( PluginInfos.Contains( plugin ) );

            MockServiceReferenceInfo reference = plugin.InternalServiceReferences.First( x => x.Reference == service );
            if( reference != null ) plugin.InternalServiceReferences.Remove( reference );
        }
コード例 #10
0
        /// <summary>
        /// Removes a mock plugin info from our collections.
        /// </summary>
        /// <param name="pluginInfo">Mock plugin info to remove</param>
        internal void RemovePlugin( PluginInfo pluginInfo )
        {
            if( pluginInfo.Service != null )
            {
                pluginInfo.InternalService.InternalImplementations.Remove( pluginInfo );
            }

            LabPluginInfo livePlugin = _labPluginInfos.GetByKey( pluginInfo );
            _labPluginInfos.Remove( livePlugin );
            _pluginInfos.Remove( pluginInfo );
        }
コード例 #11
0
        /// <summary>
        /// Loads a foreign mock plugin info and al it depends on into our collections.
        /// </summary>
        /// <param name="pluginInfo">Foreign mock plugin info</param>
        internal void LoadPluginInfo( PluginInfo pluginInfo )
        {
            if( _pluginInfos.Contains( pluginInfo ) ) return; // Already loaded
            _pluginInfos.Add( pluginInfo );

            if( pluginInfo.Service != null )
            {
                LoadServiceInfo( pluginInfo.Service );
            }

            foreach( var serviceRef in pluginInfo.ServiceReferences )
            {
                Debug.Assert( serviceRef.Owner == pluginInfo );
                LoadServiceInfo( (ServiceInfo)serviceRef.Reference );
            }

            CreateLabPlugin( pluginInfo );
        }
コード例 #12
0
        /// <summary>
        /// Creates a new named plugin, which implements an existing service.
        /// </summary>
        /// <param name="pluginName">Name of the new plugin</param>
        /// <param name="service">Implemented service</param>
        /// <returns>New plugin</returns>
        internal PluginInfo CreateNewPlugin( string pluginName, ServiceInfo service = null )
        {
            Debug.Assert( !String.IsNullOrWhiteSpace( pluginName ) );

            if( service != null ) Debug.Assert( ServiceInfos.Contains( service ) );

            PluginInfo plugin = new PluginInfo( pluginName, AssemblyInfoHelper.ExecutingAssemblyInfo, service );

            CreateLabPlugin( plugin );
            _pluginInfos.Add( plugin ); // Throws on duplicate

            return plugin;
        }