Пример #1
0
    /// <summary>  Initialize and start the agent
    /// </summary>
    /// <param name="args">Command-line arguments (run with no arguments to display help)
    /// 
    /// </param>
    public virtual void startAgent( string[] args )
    {
        Console.WriteLine( "Initializing agent..." );
        Adk.Initialize( SifVersion.LATEST, SIFVariant.SIF_AU, (int)SdoLibraryType.Student );

        //  Read the configuration file
        fCfg = new AgentConfig();
        Console.WriteLine( "Reading configuration file..." );
        fCfg.Read( "agent.cfg", false );

        //  Override the SourceId passed to the constructor with the SourceId
        //  specified in the configuration file
        Id = fCfg.SourceId;

        //  Inform the ADK of the version of SIF specified in the sifVersion=
        //  attribute of the <agent> element
        SifVersion version = fCfg.Version;
        Adk.SifVersion = version;

        //  Now call the superclass initialize once the configuration file has been read
        base.Initialize();

        //
        //  Ask the AgentConfig instance to "apply" all configuration settings
        //  to this Agent; for example, all <property> elements that are children
        //  of the root <agent> node are parsed and applied to this Agent's
        //  AgentProperties object; all <zone> elements are parsed and registered
        //  with the Agent's ZoneFactory, and so on.
        //
        fCfg.Apply( this, true );

        //  Establish the ODBC connection to the Students.mdb database file.
        //  The JDBC driver and URL are specified in the agent.cfg configuration
        //  file and were automatically added to the AgentProperties when the
        //  apply method was called above.
        //
        Console.WriteLine( "Opening database..." );

        AgentProperties props = Properties;
        string driver = props.GetProperty( "Connection" );
        string url = props.GetProperty( "ConnectionString" );
        Console.WriteLine( "- Using driver: " + driver );
        Console.WriteLine( "- Connecting to URL: " + url );

        //  Load the DataDriver driver

        //  Get a Connection

        fConn = new OleDbConnection();
        fConn.ConnectionString = url;

        //  Connect to each zone specified in the configuration file, registering
        //  this agent as the Provider of Learner objects. Once connected,
        //  send a request for LearnerPersonal.
        //
        Console.WriteLine( "Connecting to zones and requesting LearnerPersonal objects..." );
        IZone[] allZones = ZoneFactory.GetAllZones();
        for ( int i = 0; i < allZones.Length; i++ )
        {
            try
            {
                //  Connect to this zone
                Console.WriteLine
                    ( "- Connecting to zone \"" + allZones[i].ZoneId + "\" at " +
                      allZones[i].ZoneUrl );
                allZones[i].SetPublisher
                    ( this, StudentDTD.STUDENTPERSONAL, new PublishingOptions() );
                allZones[i].SetQueryResults( this );
                allZones[i].Connect( ProvisioningFlags.Register );

                //  Request all students
                Query q = new Query( StudentDTD.STUDENTPERSONAL );
                q.UserData = "Mappings Demo";
                allZones[i].Query( q );
            }
            catch ( AdkException ex )
            {
                Console.WriteLine( "  " + ex.Message );
            }
        }
    }
        /// <summary>
        /// Configure the Agent based on the Agent configuration file, then initialise.
        /// </summary>
        /// <exception cref="System.IO.IOException">File or resource exception occurred, possibly while reading Agent configuration file.</exception>
        /// <exception cref="System.Reflection.TargetException">Unable to create an instance of a Publisher or Subscriber for the Agent.</exception>
        public override void Initialize()
        {
            if (Initialized)
            {
                if (log.IsInfoEnabled) log.Info("Agent " + this.Id + " has already been initialised and will not be initialised again.");
            }
            else
            {
                // Initialise the ADK to use the latest SIF version and all SIF Data Object modules?
                Adk.Initialize();

                AgentConfig agentConfig = new AgentConfig();

                try
                {
                    // Read the Agent configuration file.
                    agentConfig.Read(this.cfgFileName, false);
                }
                catch (IOException e)
                {
                    throw new IOException("Error reading Agent configuration file " + this.cfgFileName + " when initialising Agent " + this.Id + ".", e);
                }

                // Override the SourceId passed to the constructor with the SourceID specified in the configuration
                // file.
                Id = agentConfig.SourceId;
                // Inform the ADK of the version of SIF specified in the sifVersion= attribute of the <agent> element.
                Adk.SifVersion = agentConfig.Version;

                // Call the superclass initialise once the configuration file has been read.
                try
                {
                    base.Initialize();
                }
                catch (Exception e)
                {
                    throw new IOException("Agent " + this.Id + " is unable to initialise due to a file or resource exception.", e);
                }

                // Ask the AgentConfig instance to "apply" all configuration settings to this Agent. This includes
                // parsing and registering all <zone> elements with the Agent's ZoneFactory.
                agentConfig.Apply(this, true);
                AgentConfiguration = agentConfig;

                // Set the level of debugging applied to the ADK.
                if (Properties.GetProperty("agent.debugAll", false))
                {
                    Adk.Debug = AdkDebugFlags.All;
                }
                else
                {
                    Adk.Debug = AdkDebugFlags.Minimal;
                }

                // Override the Agent display name if provided.
                String displayName = Properties.GetProperty("agent.description", null);

                if (displayName != null)
                {
                    this.fName = displayName;
                }

                if (!Directory.Exists(this.WorkDir))
                {
                    Directory.CreateDirectory(this.WorkDir);
                }

                if (log.IsInfoEnabled) log.Info("Agent " + this.Id + " has been initialised using configuration file " + this.cfgFileName + "...");
                if (log.IsInfoEnabled) log.Info("Agent Property => Display name: " + this.fName);
                if (log.IsInfoEnabled) log.Info("Agent Property => Messaging mode: " + Properties.MessagingMode);
                if (log.IsInfoEnabled) log.Info("Agent Property => Transport protocol: " + Properties.TransportProtocol);
                if (log.IsInfoEnabled) log.Info("Agent Property => Pull frequency: " + Properties.PullFrequency);
                if (log.IsInfoEnabled) log.Info("Agent Property => Maximum buffer size: " + Properties.MaxBufferSize);
                if (log.IsInfoEnabled) log.Info("Agent Property => Override SIF versions: " + Properties.OverrideSifVersions);
                if (log.IsInfoEnabled) log.Info("Agent Property => Home directory: " + this.HomeDir);
                if (log.IsInfoEnabled) log.Info("Agent Property => Work directory: " + this.WorkDir);

                StartAgent();
            }
        }
Пример #3
0
        /// <summary>  Initialize and start the agent
        /// </summary>
        /// <param name="args">Command-line arguments (run with no arguments to display help)
        /// </param>
        public virtual void StartAgent(string[] args)
        {
            Console.WriteLine("Initializing agent...");

            //  Read the configuration file
            fCfg = new AgentConfig();
            Console.Out.WriteLine("Reading configuration file...");
            fCfg.Read("agent.cfg", false);

            //  Override the SourceId passed to the constructor with the SourceId
            //  specified in the configuration file
            this.Id = fCfg.SourceId;

            //  Inform the ADK of the version of SIF specified in the sifVersion=
            //  attribute of the <agent> element
            SifVersion version = fCfg.Version;
            Adk.SifVersion = version;

            //  Now call the superclass initialize once the configuration file has been read
            base.Initialize();

            //  Ask the AgentConfig instance to "apply" all configuration settings
            //  to this Agent; for example, all <property> elements that are children
            //  of the root <agent> node are parsed and applied to this Agent's
            //  AgentProperties object; all <zone> elements are parsed and registered
            //  with the Agent's ZoneFactory, and so on.
            //
            fCfg.Apply(this, true);

            // Create the logging object
            fLogger = new ObjectLogger(this);

            Query zoneQuery = new Query(InfraDTD.SIF_ZONESTATUS);
            zoneQuery.AddFieldRestriction(InfraDTD.SIF_ZONESTATUS_SIF_PROVIDERS);
            //zoneQuery.AddFieldRestriction( SifDtd.SIF_ZONESTATUS_SIF_SIFNODES );
            zoneQuery.UserData = fRequestState;

            ITopic zoneTopic = TopicFactory.GetInstance(InfraDTD.SIF_ZONESTATUS);

            zoneTopic.SetQueryResults(this);

            // Now, connect to all zones and just get the zone status
            foreach (IZone zone in this.ZoneFactory.GetAllZones())
            {
                if (getChameleonProperty(zone, "logRaw", false))
                {
                    zone.Properties.KeepMessageContent = true;
                    zone.AddMessagingListener(fLogger);
                }
                zone.Connect(ProvisioningFlags.Register);
                zoneTopic.Join(zone);
            }

            Console.WriteLine();
            Console.WriteLine("Requesting SIF_ZoneStatus from all zones...");
            zoneTopic.Query(zoneQuery);
        }