Code/SifCommonFramework/Systemic.Sif.Demo.Publishing.Database/DemoPublishingAgent.cs
/// <summary>
/// The Publishers handled by this Agent. Publishers for an Agent can be specified either explicitly (using
/// the "publisher.explicit.list" property) or implicitly through the <object/> mappings section of the Agent
/// configuration file.
/// If no Publishers specified, an empty list is returned.
/// </summary>
/// <param name="agentConfig">Configuration information for this Agent.</param>
/// <returns>Publishers handled by this Agent.</returns>
/// <exception cref="System.Reflection.TargetException">Unable to create an instance of a Publisher.</exception>
The Publishers handled by this Agent. Publishers for an Agent can be specified either explicitly (using
the "publisher.explicit.list" property) or implicitly through the  mappings section of the Agent
configuration file.
If no Publishers specified, an empty list is returned.
The Publishers handled by this Agent . Publishers for an Agent can be specified either explicitly ( using the " publisher . explicit . list " property ) or implicitly through the mappings section of the Agent configuration file . If no Publishers specified an empty list is returned .
public override IList<IBasePublisher> GetPublishers()
        {
            IList<IBasePublisher> publishers = new List<IBasePublisher>();
            IList<IElementDef> elementDefinitions = new List<IElementDef>();
            foreach (string publisherName in PublisherNames)
            {
                try
                {
                    if (log.IsDebugEnabled) log.Debug("Publisher name is " + publisherName);
                    Type type = Type.GetType(publisherName);
                    IBasePublisher publisher = (IBasePublisher)Activator.CreateInstance(type);
                    publisher.AgentConfiguration = AgentConfiguration;
                    publishers.Add(publisher);
                    elementDefinitions.Add(publisher.SifObjectType);
                }
                catch (Exception e)
                {
                    throw new TargetException("Unable to create an instance of Publisher " + publisherName + ".", e);
                }
            }
            Mappings mappings = AgentConfiguration.Mappings.GetMappings("Default");
            if (mappings == null)
            {
                if (log.IsInfoEnabled) log.Info("<mappings id=\"Default\"> has not been specified for Agent " + this.Id + ".");
            }
            else
            {
                foreach (ObjectMapping objectMapping in mappings.GetObjectMappings(false))
                {
                    bool enabled = Properties.GetProperty("publisher.implicit." + objectMapping.ObjectType + ".enable", false);
                    if (log.IsInfoEnabled) log.Info("publisher.implicit." + objectMapping.ObjectType + ".enable is " + enabled);
                    if (enabled)
                    {
                        IElementDef elementDef = Adk.Dtd.LookupElementDef(objectMapping.ObjectType);
                        if (!elementDefinitions.Contains(elementDef))
                        {
                            try
                            {
                                SifDataObject sifDataObject = Adk.Dtd.CreateSIFDataObject(elementDef);
                                Type genericPublisherType = typeof(GenericPublisher<>);
                                Type[] typeArgs = { sifDataObject.GetType() };
                                Type constructed = genericPublisherType.MakeGenericType(typeArgs);
                                IBasePublisher publisher = (IBasePublisher)Activator.CreateInstance(constructed);
                                publisher.AgentConfiguration = AgentConfiguration;
                                publishers.Add(publisher);
                            }
                            catch (Exception e)
                            {
                                throw new TargetException("Unable to create an instance of a generic Publisher for " + elementDef.GetType().FullName + ".", e);
                            }
                        }
                    }
                }
            }
            if (publishers.Count == 0)
            {
                if (log.IsInfoEnabled) log.Info("No Publishers have been specified for Agent " + this.Id + ".");
            }
            return publishers;
        }
public override IList < IBasePublisher > GetPublishers ( ) { IList < IBasePublisher > publishers = new List < IBasePublisher > ( ) ; IList < IElementDef > elementDefinitions = new List < IElementDef > ( ) ; foreach ( string publisherName in PublisherNames ) { try { if ( log . IsDebugEnabled ) log . Debug ( " " + publisherName ) ; Type type = Type . GetType ( publisherName ) ; IBasePublisher publisher = ( IBasePublisher ) Activator . CreateInstance ( type ) ; publisher . AgentConfiguration = AgentConfiguration ; publishers . Add ( publisher ) ; elementDefinitions . Add ( publisher . SifObjectType ) ; } catch ( Exception e ) { throw new TargetException ( " " + publisherName + " " , e ) ; } } Mappings mappings = AgentConfiguration . Mappings . GetMappings ( " " ) ; if ( mappings == null ) { if ( log . IsInfoEnabled ) log . Info ( " \" \" " + this . Id + " " ) ; } else { foreach ( ObjectMapping objectMapping in mappings . GetObjectMappings ( false ) ) { bool enabled = Properties . GetProperty ( " " + objectMapping . ObjectType + " " , false ) ; if ( log . IsInfoEnabled ) log . Info ( " " + objectMapping . ObjectType + " " + enabled ) ; if ( enabled ) { IElementDef elementDef = Adk . Dtd . LookupElementDef ( objectMapping . ObjectType ) ; if ( ! elementDefinitions . Contains ( elementDef ) ) { try { SifDataObject sifDataObject = Adk . Dtd . CreateSIFDataObject ( elementDef ) ; Type genericPublisherType = typeof ( GenericPublisher < > ) ; Type [ ] typeArgs = { sifDataObject . GetType ( ) } ; Type constructed = genericPublisherType . MakeGenericType ( typeArgs ) ; IBasePublisher publisher = ( IBasePublisher ) Activator . CreateInstance ( constructed ) ; publisher . AgentConfiguration = AgentConfiguration ; publishers . Add ( publisher ) ; } catch ( Exception e ) { throw new TargetException ( " " + elementDef . GetType ( ) . FullName + " " , e ) ; } } } } } if ( publishers . Count == 0 ) { if ( log . IsInfoEnabled ) log . Info ( " " + this . Id + " " ) ; } return publishers ; }
The Publishers handled by this Agent.
The Publishers handled by this Agent .
// Instantiate each Publisher handled by this Agent. // Create an instance of the Publisher. // Create an instance of the publisher.
Publishers handled by this Agent.
Publishers handled by this Agent .
Unable to create an instance of a Publisher.
Unable to create an instance of a Publisher .
agentConfig
Configuration information for this Agent.
Configuration information for this Agent .