Example #1
0
        /// <summary>
        /// Gets the SIF_ZoneStatus object
        /// </summary>
        private void GetZoneStatus()
        {
            Console.WriteLine();
            Console.WriteLine("Requesting SIF_ZoneStatus from all zones...");
            // Determine if the synchronous SIF_GetZoneStatus method can be used
            Query zoneStatusQuery = new Query(InfraDTD.SIF_ZONESTATUS);

            zoneStatusQuery.AddFieldRestriction(InfraDTD.SIF_ZONESTATUS_SIF_PROVIDERS);
            zoneStatusQuery.UserData = fSessionId;

            foreach (IZone zone in ZoneFactory.GetAllZones())
            {
                if (zone.Properties.UseZoneStatusSystemControl)
                {
                    SIF_ZoneStatus zs = zone.GetZoneStatus();
                    _processSIF_ZoneStatus(zs, zone);
                }
                else
                {
                    // Just create a SIF_Request and it will be handled by the
                    // OnQueryResults method
                    zone.Query(zoneStatusQuery);
                }
            }
        }
Example #2
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
            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);

            // Now, connect to all zones and just get the zone status
            foreach (IZone zone in ZoneFactory.GetAllZones())
            {
                if (getChameleonProperty(zone, "logRaw", false))
                {
                    zone.Properties.KeepMessageContent = true;
                    zone.AddMessagingListener(fLogger);
                    // Set this class as the recipient of all SIF_ZoneStatus
                    // query results
                    zone.SetQueryResults(this, InfraDTD.SIF_ZONESTATUS);
                }

                // Provision the logger class to log all QueryResults

                zone.Connect(ProvisioningFlags.Register);
            }

            // On a seperate thread, go through the exercise of getting the
            // SIF_ZoneStatus object from all zones
            AsyncUtils.QueueTaskToThreadPool(new SimpleMethod(GetZoneStatus));
        }
Example #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
            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 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);
        }
        /// <summary>
        /// Connect to the Zones and configure the Subscribers.
        /// </summary>
        /// <exception cref="System.InvalidOperationException">The Agent has not been initialised first.</exception>
        /// <exception cref="Edustructures.SifWorks.AdkException">The Agent was unable to connect to a Zone, or there is an error with the event processing for a Subscriber.</exception>
        protected override void StartAgent()
        {
            // If the Agent has not been initialised, throw an exception.
            if (!Initialized)
            {
                throw new InvalidOperationException("Subscribing Agent " + this.Id + " has not been initialised.");
            }

            IList <IBaseSubscriber> subscribers;

            try
            {
                // Get the Subscribers handled by this Agent.
                subscribers = GetSubscribers();
            }
            catch (TargetException)
            {
                Shutdown();
                throw;
            }

            if (log.IsDebugEnabled)
            {
                log.Debug("Starting subscribing Agent " + this.Id + "...");
            }

            IZone[] zones = ZoneFactory.GetAllZones();

            if (zones.Length == 0)
            {
                if (log.IsWarnEnabled)
                {
                    log.Warn("No Zones specified for subscribing Agent " + this.Id + ". This subscribing Agent will do nothing.");
                }
            }
            else
            {
                try
                {
                    // Connect to each Zone specified in the Agent configuration file.
                    foreach (IZone zone in zones)
                    {
                        // For each Subscriber, register (provision) it with the Zone.
                        foreach (IBaseSubscriber subscriber in subscribers)
                        {
                            zone.SetSubscriber(subscriber, subscriber.SifObjectType, new SubscriptionOptions());
                            zone.SetQueryResults(subscriber, subscriber.SifObjectType, new QueryResultsOptions());
                            if (log.IsDebugEnabled)
                            {
                                log.Debug("Registered Subscriber " + subscriber.GetType().FullName + " with Zone " + zone.ZoneId + ".");
                            }
                        }

                        try
                        {
                            // Connect to the Zone.
                            zone.Connect(ProvisioningFlags.Register);
                            if (log.IsDebugEnabled)
                            {
                                log.Debug("Connected subscribing Agent " + this.Id + " to Zone " + zone.ZoneId + ".");
                            }
                        }
                        catch (AdkException e)
                        {
                            if (log.IsErrorEnabled)
                            {
                                log.Error("Subscribing Agent " + this.Id + " was unable to connect to Zone " + zone.ZoneId + ".", e);
                            }
                            throw;
                        }
                    }

                    // Start request processing for each Subscriber.
                    foreach (IBaseSubscriber subscriber in subscribers)
                    {
                        try
                        {
                            subscriber.StartRequestProcessing(zones);
                        }
                        catch (AdkException e)
                        {
                            if (log.IsErrorEnabled)
                            {
                                log.Error("Error with request processing of Subscriber " + subscriber.GetType().FullName + ".", e);
                            }
                            throw;
                        }
                    }
                }
                catch (AdkException)
                {
                    // In the event of an error, disconnect from the Zones.
                    foreach (IZone zone in zones)
                    {
                        if (zone.Connected)
                        {
                            zone.Disconnect(ProvisioningFlags.Unregister);
                        }
                    }

                    throw;
                }
            }
        }
Example #5
0
        /// <summary>
        /// Connect to the Zones and configure the Publisher.
        /// </summary>
        /// <exception cref="System.InvalidOperationException">The Agent has not been initialised first.</exception>
        /// <exception cref="Edustructures.SifWorks.AdkException">The Agent was unable to connect to a Zone, or there is an error with the event processing for a Publisher.</exception>
        protected override void StartAgent()
        {
            // If the Agent has not been initialised, throw an exception.
            if (!Initialized)
            {
                throw new InvalidOperationException("Publishing Agent " + this.Id + " has not been initialised.");
            }

            IList <IBasePublisher> publishers;

            try
            {
                // Get the Publishers handled by this agent.
                publishers = GetPublishers();
            }
            catch (TargetException)
            {
                Shutdown();
                throw;
            }

            if (log.IsDebugEnabled)
            {
                log.Debug("Starting publishing Agent " + this.Id + "...");
            }

            IZone[] zones = ZoneFactory.GetAllZones();

            if (zones.Length == 0)
            {
                if (log.IsWarnEnabled)
                {
                    log.Warn("No Zones specified for publishing Agent " + this.Id + ". This publishing Agent will do nothing.");
                }
            }
            else
            {
                try
                {
                    // Connect to each Zone specified in the Agent configuration file.
                    foreach (IZone zone in zones)
                    {
                        // For each Publisher, register (provision) it with the Zone.
                        foreach (IBasePublisher publisher in publishers)
                        {
                            zone.SetPublisher(publisher, publisher.SifObjectType, new PublishingOptions(true));
                            if (log.IsDebugEnabled)
                            {
                                log.Debug("Registered Publisher " + publisher.GetType().FullName + " with Zone " + zone.ZoneId + ".");
                            }
                        }

                        try
                        {
                            // Connect to the Zone.
                            zone.Connect(ProvisioningFlags.Register);
                            if (log.IsDebugEnabled)
                            {
                                log.Debug("Connected publishing Agent " + this.Id + " to Zone " + zone.ZoneId + ".");
                            }
                        }
                        catch (AdkException e)
                        {
                            if (log.IsErrorEnabled)
                            {
                                log.Error("Publishing Agent " + this.Id + " was unable to connect to Zone " + zone.ZoneId + ".", e);
                            }
                            throw;
                        }
                    }

                    // Start event processing for each Publisher.
                    foreach (IBasePublisher publisher in publishers)
                    {
                        try
                        {
                            publisher.StartEventProcessing(zones);
                        }
                        catch (AdkException e)
                        {
                            if (log.IsErrorEnabled)
                            {
                                log.Error("Error with event processing of Publisher " + publisher.GetType().FullName + ".", e);
                            }
                            throw;
                        }
                    }
                }
                catch (AdkException)
                {
                    // In the event of an error, disconnect from the Zones.
                    foreach (IZone zone in zones)
                    {
                        if (zone.Connected)
                        {
                            zone.Disconnect(ProvisioningFlags.Unregister);
                        }
                    }

                    throw;
                }
            }
        }
Example #6
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);
            }
        }
    }