public override void setUp()
 {
     base.setUp();
     Adk.SifVersion = SifVersion.SIF15r1;
     fCfg = new AgentConfig();
     fCfg.Read("..\\..\\Library\\Tools\\Mapping\\Destiny2.0.cfg", false);
 }
 public virtual void setUp()
 {
     Adk.Initialize();
     fCfg = new AgentConfig();
     fCfg.Read( "..\\..\\Library\\Tools\\Mapping\\SIF1.5.agent.cfg",
                false );
 }
 public void setUp()
 {
     if( !Adk.Initialized )
     {
         Adk.Initialize( );
     }
     Adk.SifVersion = fVersion;
     fCfg = new AgentConfig();
     fCfg.Read("..\\..\\Library\\Tools\\Mapping\\SASI2.0.cfg", false);
 }
        public void testInBoundMapping50000()
        {
            fCfg = new AgentConfig();
            fCfg
                .Read(
                "..\\..\\Library\\Tools\\Mapping\\MultiVersion.agent.cfg",
                false );

            int mappingIterations = 0;
            //
            // UNCOMMENT THIS LINE TO RUN THE SPEED TEST
            //
            // mappingIterations = 50000;

            Mappings mappings = fCfg.Mappings.GetMappings( "Default" );
            IDictionary map = buildIDictionaryForStudentPersonalTest();
            StringMapAdaptor sma = new StringMapAdaptor( map );

            // Fill out the student personal using outbound mappings first
            StudentPersonal template = new StudentPersonal();
            mappings.MapOutbound( sma, template );
            Console.WriteLine( template.ToXml() );

            DateTime start = DateTime.Now;
            for ( int x = 0; x < mappingIterations; x++ )
            {
                map.Clear();
                mappings.MapInbound( template, sma );
                if ( x%500 == 0 )
                {
                    Console.WriteLine( "Iteration " + x + " of "
                                       + mappingIterations );
                }
            }

            DateTime end = DateTime.Now;
            Console.WriteLine( "Mapping "
                               + mappingIterations
                               + " Students inbound took " + end.Subtract( start ) );
        }
        /// <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();
            }
        }
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 );
            }
        }
    }
Example #7
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);
        }
        public void testOutBoundMappingContext50000()
        {
            fCfg = new AgentConfig();
            fCfg
                .Read(
                "..\\..\\Library\\Tools\\Mapping\\MultiVersion.agent.cfg",
                false );

            int mappingIterations = 0;
            //
            // UNCOMMENT THIS LINE TO RUN THE SPEED TEST
            //
            //mappingIterations = 50000;

            Mappings mappings = fCfg.Mappings.GetMappings( "Default" );
            IDictionary map = buildIDictionaryForStudentPersonalTest();
            StringMapAdaptor sma = new StringMapAdaptor( map );
            StudentPersonal template = new StudentPersonal();

            MappingsContext mc = mappings.SelectOutbound( template.ElementDef,
                                                          SifVersion.SIF20, null, null );
            mc.Map( template, sma );
            Console.WriteLine( template.ToXml() );

            DateTime start = DateTime.Now;
            for ( int x = 0; x < mappingIterations; x++ )
            {
                template = new StudentPersonal();
                mc.Map( template, sma );
                if ( x%500 == 0 )
                {
                    Console.WriteLine( "Iteration " + x + " of "
                                       + mappingIterations );
                }
            }
            Console.WriteLine( template.ToXml() );
            DateTime end = DateTime.Now;
            Console.WriteLine( "Mapping "
                               + mappingIterations
                               + " Students inbound took " + end.Subtract( start ) );
        }
        public void testReadAndWriteMappings()
        {
            String FILE_NAME = "tmp.cfg";

            // TODO: Right now we don't have a way to build up a Mappings hierarchy
            // without reading it from a file. This should be fixed and this
            // test should be updated as a result.
            AgentConfig cfg = createMappings();

            debug( cfg.Document );

            // save the mappings to a file
            FileInfo f = new FileInfo( FILE_NAME );
            if ( f.Exists )
            {
                f.Delete();
            }

            using ( StreamWriter fs = new StreamWriter( FILE_NAME ) )
            {
                try
                {
                    cfg.Save( fs );
                }
                finally
                {
                    fs.Close();
                }
            }

            // Read the new mappings
            cfg = new AgentConfig();
            cfg.Read( FILE_NAME, false );

            Mappings reparsed = cfg.Mappings;
            assertMappings( reparsed );
        }