Esempio n. 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);
            }
        }
    }