コード例 #1
0
 public override void setUp()
 {
     base.setUp();
     Adk.SifVersion = fVersion;
     fCfg           = new AgentConfig();
     fCfg.Read(fFileName, false);
 }
コード例 #2
0
 public override void setUp()
 {
     base.setUp();
     Adk.SifVersion = SifVersion.SIF15r1;
     fCfg           = new AgentConfig();
     fCfg.Read("..\\..\\Library\\Tools\\Mapping\\Destiny2.0.cfg", false);
 }
コード例 #3
0
 public virtual void setUp()
 {
     Adk.Initialize();
     fCfg = new AgentConfig();
     fCfg.Read("..\\..\\Library\\Tools\\Mapping\\SIF1.5.agent.cfg",
               false);
 }
コード例 #4
0
        private AgentConfig createConfig(String cfg)
        {
            String fileName = "AdvancedMappings.cfg";

            writeConfig(cfg, fileName);
            AgentConfig config = new AgentConfig();

            config.Read(fileName, false);
            return(config);
        }
コード例 #5
0
 public void setUp()
 {
     if (!Adk.Initialized)
     {
         Adk.Initialize( );
     }
     Adk.SifVersion = fVersion;
     fCfg           = new AgentConfig();
     fCfg.Read("..\\..\\Library\\Tools\\Mapping\\SASI2.0.cfg", false);
 }
コード例 #6
0
ファイル: Chameleon.cs プロジェクト: rubitek/OpenADK-csharp
        /// <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));
        }
コード例 #7
0
        public void testInBoundMappingContext50000()
        {
            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");

            // Fill out the student personal using outbound mappings first
            StudentPersonal template = new StudentPersonal();

            IDictionary      map = buildIDictionaryForStudentPersonalTest();
            StringMapAdaptor sma = new StringMapAdaptor(map);

            mappings.MapOutbound(sma, template);
            Console.WriteLine(template.ToXml());

            MappingsContext mc = mappings.SelectInbound(template.ElementDef,
                                                        SifVersion.SIF20, null, null);

            DateTime start = DateTime.Now;

            for (int x = 0; x < mappingIterations; x++)
            {
                map.Clear();
                mc.Map(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));
        }
コード例 #8
0
        public void testOutBoundMapping50000()
        {
            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();

            mappings.MapOutbound(sma, template);
            Console.WriteLine(template.ToXml());

            DateTime start = DateTime.Now;

            for (int x = 0; x < mappingIterations; x++)
            {
                template = new StudentPersonal();
                mappings.MapOutbound(sma, template);
                if (x % 500 == 0)
                {
                    Console.WriteLine("Iteration " + x + " of "
                                      + mappingIterations);
                }
            }

            DateTime end = DateTime.Now;

            Console.WriteLine("Mapping "
                              + mappingIterations
                              + " Students inbound took " + end.Subtract(start));
        }
コード例 #9
0
        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);
        }
コード例 #10
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);
        }
コード例 #11
0
        /// <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
            {
                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);
                }

                // Initialise the ADK to use the latest SIF version and all SIF Data Object modules?
                Adk.Initialize(Locale);

                // 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);

                // 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();
            }
        }
コード例 #12
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)
        {
            Name = "SIFWorks ADK Example";
            Console.WriteLine("Initializing agent...");

            //  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;
            //SifVersion version = SifVersion.SIF15r1;
            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 = (IDbConnection)ClassFactory.CreateInstance(driver);
            fConn.ConnectionString = url;

            //  Connect to each zone specified in the configuration file, registering
            //  this agent as the Provider of StudentPersonal objects. Once connected,
            //  send a request for StudentPersonal.
            //
            Console.WriteLine("Connecting to zones and requesting StudentPersonal 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, null);
                    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);
                }
            }
        }
コード例 #13
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);
            }
        }
    }
コード例 #14
0
 private AgentConfig createConfig(String cfg)
 {
     String fileName = "AdvancedMappings.cfg";
     writeConfig(cfg, fileName);
     AgentConfig config = new AgentConfig();
     config.Read(fileName, false);
     return config;
 }