internal MockServiceReferenceInfo( PluginInfo ownerPlugin, ServiceInfo referencedService, DependencyRequirement requirement )
        {
            Debug.Assert( ownerPlugin != null );
            Debug.Assert( referencedService != null );

            _owner = ownerPlugin;
            _reference = referencedService;
            _requirement = requirement;
        }
Exemplo n.º 2
0
        internal LabServiceInfo( ServiceInfo serviceInfo)
        {
            Debug.Assert( serviceInfo != null );

            _serviceInfo = serviceInfo;

            StartServiceCommand = new RelayCommand( ExecuteStartService, CanExecuteStartService );
            StopServiceCommand = new RelayCommand( ExecuteStopService, CanExecuteStopService );
        }
Exemplo n.º 3
0
        internal PluginInfo( string pluginFullName, IAssemblyInfo assemblyInfo, ServiceInfo service = null )
        {
            Debug.Assert( assemblyInfo != null );

            _pluginFullName = pluginFullName;
            _assemblyInfo = assemblyInfo;

            _service = service;
            _serviceReferences = new CKObservableSortedArrayList<MockServiceReferenceInfo>( ( x, y ) => String.CompareOrdinal( x.Reference.ServiceFullName, y.Reference.ServiceFullName ), false );
        }
Exemplo n.º 4
0
 /// <summary>
 /// Attempts to rename a service.
 /// </summary>
 /// <param name="serviceInfo">Service to rename</param>
 /// <param name="newName">New service name</param>
 /// <returns>Operation result</returns>
 internal DetailedOperationResult RenameService( ServiceInfo serviceInfo, string newName )
 {
     return _labStateManager.RenameService( serviceInfo, newName );
 }
Exemplo n.º 5
0
 internal PendingGeneralization( ServiceInfo service, string pendingServiceFullName )
 {
     Service = service;
     PendingServiceFullName = pendingServiceFullName;
 }
Exemplo n.º 6
0
        private static void SerializeServiceInfoToXmlWriter( ServiceInfo si, XmlWriter w )
        {
            w.WriteStartAttribute( "FullName" );
            w.WriteValue( si.ServiceFullName );
            w.WriteEndAttribute();

            w.WriteStartElement( "Generalization" );
            if( si.Generalization != null ) w.WriteValue( si.Generalization.ServiceFullName );
            w.WriteEndElement();

            // That's pretty much all we need. Implementations will be guessed from the plugins themselves.
            // HasError, AssemblyInfo and others aren't supported at this time, but can be added here later on.

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

            w.WriteStartElement( "Y" );
            if( si.PositionInGraph.IsValid() ) w.WriteValue( si.PositionInGraph.Y.ToString( CultureInfo.InvariantCulture ) );
            w.WriteEndElement();
        }
Exemplo n.º 7
0
        private void ReadService( XmlReader r )
        {
            r.Read();
            string serviceFullName = r.GetAttribute( "FullName" );
            Debug.Assert( serviceFullName != null, "FullName attribute was found in Service XML element." );

            ServiceInfo s = new ServiceInfo( serviceFullName, AssemblyInfoHelper.ExecutingAssemblyInfo );
            loadedServices.Add( s );

            ServiceInfo generalization = null;

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

            while( r.Read() )
            {
                if( r.IsStartElement() && !r.IsEmptyElement )
                {
                    switch( r.Name )
                    {
                        case "Generalization":
                            if( r.Read() )
                            {
                                string generalizationName = r.Value;
                                if( !String.IsNullOrEmpty( generalizationName ) )
                                {
                                    if( loadedServices.Contains( generalizationName ) )
                                    {
                                        generalization = loadedServices.GetByKey( generalizationName );
                                        s.Generalization = generalization;
                                    }
                                    else
                                    {
                                        pendingGeneralizations.Add( new PendingGeneralization( s, generalizationName ) );
                                    }
                                }
                            }
                            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;
                    }
                }
            }

            s.PositionInGraph = pos;

            // Fix pending references of this service
            foreach( var pg in pendingGeneralizations.Where( x => x.PendingServiceFullName == serviceFullName ).ToList() )
            {
                pg.Service.Generalization = s;
                pendingGeneralizations.Remove( pg );
            }

            foreach( var pps in pendingPluginServices.Where( x => x.PendingServiceFullName == serviceFullName ).ToList() )
            {
                pps.Plugin.Service = s;
                s.InternalImplementations.Add( pps.Plugin );
                pendingPluginServices.Remove( pps );
            }

            foreach( var psr in pendingServiceReferences.Where( x => x.PendingServiceFullName == serviceFullName ).ToList() )
            {
                var reference = new MockServiceReferenceInfo( psr.Plugin, s, psr.Requirement );
                psr.Plugin.InternalServiceReferences.Add( reference );
                pendingServiceReferences.Remove( psr );
            }
        }
Exemplo n.º 8
0
 /// <summary>
 /// Creates a lab wrapper item around an existing mock service, and adds it to our collection.
 /// </summary>
 /// <param name="s">Existing mock service</param>
 private void CreateLabService( ServiceInfo s )
 {
     LabServiceInfo newServiceInfo;
     if( s.Generalization != null )
     {
         LabServiceInfo generalizationLiveInfo = _labServiceInfos.GetByKey( (ServiceInfo)s.Generalization );
         newServiceInfo = new LabServiceInfo( s ); // TODO: Running requirement
     }
     else
     {
         newServiceInfo = new LabServiceInfo( s );
     }
     _labServiceInfos.Add( newServiceInfo );
 }
Exemplo n.º 9
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 );
        }
Exemplo n.º 10
0
        /// <summary>
        /// Attempts to change one of our services' ServiceFullName.
        /// </summary>
        /// <param name="serviceInfo">ServiceInfo to rename</param>
        /// <param name="newName">New name</param>
        /// <returns>DetailedOperationResult on renaming attempt.</returns>
        /// <remarks>
        /// Can fail: Two services cannot coexist with the same name.
        /// </remarks>
        internal Utils.DetailedOperationResult RenameService( ServiceInfo serviceInfo, string newName )
        {
            if( _engine.IsRunning )
            {
                throw new InvalidOperationException( "Cannot rename Service while Engine is running." );
            }

            bool exists;
            ServiceInfo existingInfo = _serviceInfos.GetByKey( newName, out exists );

            if( exists ) return new Utils.DetailedOperationResult( false, "A service with this name already exists." );

            serviceInfo.ServiceFullName = newName;

            return new Utils.DetailedOperationResult( true );
        }
Exemplo n.º 11
0
        /// <summary>
        /// Removes a mock service info from our collections.
        /// </summary>
        /// <param name="serviceInfo">Mock service info to remove</param>
        internal void RemoveService( ServiceInfo serviceInfo )
        {
            // If we delete a service : Unbind linked plugins and services.

            // Unbind generalized services
            foreach( ServiceInfo s in ServiceInfos.Where( si => si.Generalization == serviceInfo ).ToList() )
            {
                s.Generalization = null;
            }

            // Unbind implementations
            foreach( PluginInfo p in PluginInfos.Where( pi => pi.Service == serviceInfo ).ToList() )
            {
                p.Service = null;
            }

            // Delete all existing service references

            foreach( PluginInfo p in PluginInfos )
            {
                foreach( MockServiceReferenceInfo reference in p.InternalServiceReferences.Where( r => r.Reference == serviceInfo ).ToList() )
                {
                    p.InternalServiceReferences.Remove( reference );
                }
            }

            _labServiceInfos.Remove( serviceInfo );
            _serviceInfos.Remove( serviceInfo );
        }
Exemplo n.º 12
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 );
        }
Exemplo n.º 13
0
        /// <summary>
        /// Loads a foreign mock service info and all it depends on into our collections.
        /// </summary>
        /// <param name="serviceInfo">Foreign mock service info</param>
        internal void LoadServiceInfo( ServiceInfo serviceInfo )
        {
            if( _serviceInfos.Contains( serviceInfo ) ) return; // Already loaded
            CreateLabService( serviceInfo );
            _serviceInfos.Add( serviceInfo );

            if( serviceInfo.Generalization != null )
            {
                LoadServiceInfo( (ServiceInfo)serviceInfo.Generalization );
            }
        }
Exemplo n.º 14
0
        /// <summary>
        /// Creates a new named service, which specializes another service.
        /// </summary>
        /// <param name="serviceName">Name of the new service</param>
        /// <param name="generalization">Specialized service</param>
        /// <returns>New service</returns>
        /// <remarks>Cannot be used when engine is running.</remarks>
        internal ServiceInfo CreateNewService( string serviceName, ServiceInfo generalization = null )
        {
            Debug.Assert( serviceName != null );
            Debug.Assert( _serviceInfos.Any( x => x.ServiceFullName == serviceName ) == false, "Service does not exist and can be added" );

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

            ServiceInfo newService = new ServiceInfo( serviceName, AssemblyInfoHelper.ExecutingAssemblyInfo, generalization );

            CreateLabService( newService );
            _serviceInfos.Add( newService ); // Throws on duplicate

            return newService;
        }
Exemplo n.º 15
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;
        }