Пример #1
0
	private void StartAgent(String[] args)
	{
		this.Initialize();
        NameValueCollection parameters = AdkExamples.parseCL(this, args);
		
        string zoneId = parameters["zone"];
		string url = parameters["url"];
		
		if( zoneId == null || url == null ) {
			Console.WriteLine("The /zone and /url parameters are required");
			Environment.Exit(0);
		}

		// only for SIF_Register and versions in SIF_Request messages...
    // this.Properties.OverrideSifVersions = "2.3,2.*";
		// only for SIF_Message Version attribute in SIF_Request messages
    // this.Properties.OverrideSifMessageVersionForSifRequests = "2.3";
		
		// 1) Get an instance of the zone to connect to
		IZone zone = ZoneFactory.GetInstance(zoneId, url);
		zone.SetQueryResults( this );
		
		// 2) Connect to zones
		zone.Connect( AdkExamples.Reg ? ProvisioningFlags.Register : ProvisioningFlags.None );
		
		
	}
Пример #2
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);
                }
            }
        }
Пример #3
0
        public STableController()
        {
            _factory     = new TableFactory();
            _Zonefactory = new ZoneFactory();

            ViewBag.ListStore = GetListStore();
        }
Пример #4
0
 //set focus
 public Game()
 {
     this.Paint += new PaintEventHandler(Screen_Paint);
     this.KeyDown += new KeyEventHandler(Screen_KeyDown);
     this.KeyUp += new KeyEventHandler(Screen_KeyUp);
     //Size = new System.Drawing.Size(900, 600);
     FormBorderStyle = FormBorderStyle.FixedSingle;
     //FormBorderStyle = FormBorderStyle.None;
     ClientSize = new System.Drawing.Size(900, 600); // make this non resizeable
     MaximizeBox = false;
     //DoubleBuffered = true;
     keysDown = new List<Keys>();
     keyHandler = new KeyHandler();
     paintHandler = new PaintHandler();
     SetStyle(ControlStyles.UserPaint, true);
     SetStyle(ControlStyles.AllPaintingInWmPaint, true);
     SetStyle(ControlStyles.DoubleBuffer, true);
     player = new Player();
     player.setGlobalLocation(100, 1000);
     zoneFactory = new ZoneFactory();
     stopwatch = new Stopwatch();
     stopwatch.Start();
     gameState = new GameState();
     menuFactory = new MenuFactory(gameState);
     gameLoop();
 }
Пример #5
0
    /**
     * This method shows how to connect to zones and hook up a basic message handler
     * @param args
     */
    private void startAgent(string[] args)
    {
        this.Initialize();
        NameValueCollection parameters = AdkExamples.parseCL(this, args);

        string zoneId = parameters["zone"];
        string url    = parameters["url"];

        if (zoneId == null || url == null)
        {
            Console.WriteLine("The /zone and /url parameters are required");
            Console.Beep();
            throw new ArgumentException("The /zone and /url parameters are required");
        }

        // 1) Get an instance of the zone to connect to
        IZone zone = ZoneFactory.GetInstance(zoneId, url);

        // 2) Create an instance of the the LearnerPersonalHandler class
        // This class is responsible for dealing with events and responses
        // received that contain LearnerPersonal data objects
        LearnerPersonalHandler sdh = new LearnerPersonalHandler();

        // The LearnerPersonalHandler is allowed to provision itself with the zone
        sdh.provision(zone);

        // Connect
        zone.Connect(AdkExamples.Reg ? ProvisioningFlags.Register : ProvisioningFlags.None);

        // The LearnerPersonalHandler class has a sync() method, which it uses to
        // request data from the SIF zone
        sdh.sync(zone);
    }
Пример #6
0
 public void checkTransitions(Player player, ZoneFactory zoneFactory)
 {
     Point startingPoint = new Point(player.getGlobalLocation().X, player.getGlobalLocation().Y);
     int transNum = isTransition(startingPoint, player, zoneFactory.getCurrentZone());
     if (transNum != 0)
     {
         transitionZones(player, zoneFactory, zoneFactory.getCurrentZone().getZoneNumber(), transNum);
     }
 }
Пример #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
            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));
        }
Пример #8
0
        public void ZoneLoadedEvent()
        {
            Zone zone = ZoneFactory.Create(1);

            zone.LoadedEvent += new LoadedEventHandler <LoadedEventArgs <IZone> >(DetectZoneEvent);
            zone.Load();
            bool found = zoneLoadedDetected;

            zoneLoadedDetected = false;
            Assert.AreEqual(true, found);
        }
Пример #9
0
 private void testCaveTransition(Player player, ZoneFactory zoneFactory, int transitionNumber)
 {
     Console.WriteLine(transitionNumber);
     switch (transitionNumber)
     {
         case 1:
             Zone currentZone = zoneFactory.getCurrentZone();
             zoneFactory.setCurrentZone(currentZone.getTransitionZones()[0]);
             player.setGlobalLocation(currentZone.getTransitionPoints()[0].X, currentZone.getTransitionPoints()[0].Y);
             break;
         default:
             break;
     }
 }
Пример #10
0
 private void transitionZones(Player player, ZoneFactory zoneFactory, int zoneNumber, int transitionNumber)
 {
     switch (zoneNumber)
     {
         case -1:
             testZoneTransition(player, zoneFactory, transitionNumber);
             break;
         case -2:
             testCaveTransition(player, zoneFactory, transitionNumber);
             break;
         default:
             Console.WriteLine("default");
             break;
     }
 }
Пример #11
0
    /**
     * This method shows how to connect to zones and hook up a basic message handler
     * @param args
     */

    private void startAgent(string[] args)
    {
        Initialize();
        NameValueCollection parameters = AdkExamples.parseCL(this, args);

        string zoneId = parameters["zone"];
        string url    = parameters["url"];

        if (zoneId == null || url == null)
        {
            Console.WriteLine("The /zone and /url parameters are required");
            Console.Beep();
            throw new ArgumentException("The /zone and /url parameters are required");
        }


        // 1) Get an instance of the zone to connect to
        IZone zone = ZoneFactory.GetInstance(zoneId, url);

        // 2) Create an instance of the the LearnerPersonalProvider class
        // This class is responsible for publishing LearnerPersonal
        LearnerPersonalProvider lpp = new LearnerPersonalProvider();

        // The LearnerPersonalProvider is allowed to provision itself with the zone
        lpp.provision(zone);

        // 2) Create an instance of the the LearnerPersonalProvider class
        // This class is responsible for publishing LearnerPersonal
        WorkforcePersonalProvider wpp = new WorkforcePersonalProvider();

        // The LearnerPersonalProvider is allowed to provision itself with the zone

        wpp.provision(zone);

        // Connect
        zone.Connect(AdkExamples.Reg ? ProvisioningFlags.Register : ProvisioningFlags.None);

        // The StudentPersonalProvider will periodically send changes to the StudentPersonal
        // objects
        if (parameters["events"] != null)
        {
            lpp.startEventProcessing(zone);
        }
    }
Пример #12
0
 public void movePlayer(Player player, ZoneFactory zoneFactory, List<Keys> keysDown)
 {
     if (keysDown.Contains(Keys.W))
     {
         movePlayerUp(player, zoneFactory);
     }
     if (keysDown.Contains(Keys.A))
     {
         movePlayerLeft(player, zoneFactory);
     }
     if (keysDown.Contains(Keys.S))
     {
         movePlayerDown(player, zoneFactory);
     }
     if (keysDown.Contains(Keys.D))
     {
         movePlayerRight(player, zoneFactory);
     }
     setCorrectPlayerImage(player, keysDown);
 }
        public SolverDataManager(ProjectDataSet model, ConstraintSolverResult data)
        {
            _model = model;
            _solverResult = data;

            var jobFactory = new JobFactory();
            var skillFactory = new SkillFactory();
            var workerFactory = new WorkerFactory();
            var toolFactory = new ToolFactory();
            var zoneFactory = new ZoneFactory();
            var shiftFactory = new ShiftFactory();
            
            var shiftConverter = new ShiftConverter(shiftFactory);
            var skillConverter = new SkillConverter(skillFactory);
            var toolConverter = new ToolConverter(toolFactory, shiftConverter);
            var zoneConverter = new ZoneConverter(zoneFactory);
            var laborConverter = new LaborConverter(workerFactory, shiftConverter, skillConverter);
            var jobConverter = new JobConverter(jobFactory, skillConverter, toolConverter, zoneConverter);

            _shiftManager = new ShiftManager(shiftConverter, skillConverter, laborConverter, toolConverter);
            _jobManager = new JobManager(jobConverter);
            _zoneManager = new ZoneManager(zoneConverter);
        }
Пример #14
0
        private void StartAgent(String[] args)
        {
            this.Initialize();
            NameValueCollection parameters = AdkExamples.parseCL(this, args);

            string zoneId = parameters["zone"];
            string url    = parameters["url"];

            if (zoneId == null || url == null)
            {
                Console.WriteLine("The /zone and /url parameters are required");
                Environment.Exit(0);
            }


            // 1) Get an instance of the zone to connect to
            IZone zone = ZoneFactory.GetInstance(zoneId, url);

            zone.SetQueryResults(this);

            // 2) Connect to zones
            zone.Connect(AdkExamples.Reg ? ProvisioningFlags.Register : ProvisioningFlags.None);
        }
        public SolverDataManager(ProjectDataSet model, ConstraintSolverResult data)
        {
            _model        = model;
            _solverResult = data;

            var jobFactory    = new JobFactory();
            var skillFactory  = new SkillFactory();
            var workerFactory = new WorkerFactory();
            var toolFactory   = new ToolFactory();
            var zoneFactory   = new ZoneFactory();
            var shiftFactory  = new ShiftFactory();

            var shiftConverter = new ShiftConverter(shiftFactory);
            var skillConverter = new SkillConverter(skillFactory);
            var toolConverter  = new ToolConverter(toolFactory, shiftConverter);
            var zoneConverter  = new ZoneConverter(zoneFactory);
            var laborConverter = new LaborConverter(workerFactory, shiftConverter, skillConverter);
            var jobConverter   = new JobConverter(jobFactory, skillConverter, toolConverter, zoneConverter);

            _shiftManager = new ShiftManager(shiftConverter, skillConverter, laborConverter, toolConverter);
            _jobManager   = new JobManager(jobConverter);
            _zoneManager  = new ZoneManager(zoneConverter);
        }
Пример #16
0
        /**
         * This method shows how to connect to zones and hook up a basic message handler
         * @param args
         */
        private void StartAgent(String[] args)
        {
            this.Initialize();
            NameValueCollection parameters = AdkExamples.parseCL(this, args);
            //    /url http://127.0.0.1:7080/test /zone test /pull /sourceID SimpleProvider
            String zoneId = parameters["zone"];
            String url    = parameters["url"];

            if (zoneId == null || url == null)
            {
                Console.WriteLine("The /zone and /url parameters are required");
                Environment.Exit(0);
            }


            // 1) Get an instance of the zone to connect to
            IZone zone = ZoneFactory.GetInstance(zoneId, url);

            // 2) Create an instance of the the StudentPersonalProvider class
            // This class is responsible for publishing LearnerPersonal
            StudentPersonalProvider lpp = new StudentPersonalProvider();

            // The StudentPersonalProvider is allowed to provision itself with the zone
            lpp.Provision(zone);


            // 3) Connect to zones

            zone.Connect(AdkExamples.Reg ? ProvisioningFlags.Register : ProvisioningFlags.None);

            // The StudentPersonalProvider will periodically send changes to the StudentPersonal
            // objects
            if (parameters["events"] != null)
            {
                lpp.StartEventProcessing(zone);
            }
        }
Пример #17
0
 public void movePlayer(Player player, ZoneFactory zoneFactory)
 {
     movementHandler.movePlayer(player, zoneFactory, keysDown);
 }
Пример #18
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);
        }
Пример #19
0
 public SZoneController()
 {
     _factory          = new ZoneFactory();
     ViewBag.ListStore = GetListStore();
 }
Пример #20
0
 public Valhalla(int size, ZoneFactory factory) : base(size, factory)
 {
 }
Пример #21
0
 void Constructor(ZoneFactory zf)
 {
     _zoneFactory = zf;
 }
Пример #22
0
 private void movePlayerUp(Player player, ZoneFactory zoneFactory)
 {
     player.moveGlobalUp(checkUpCollision(player, zoneFactory.getCurrentZone()));
     transitionHandler.checkTransitions(player, zoneFactory);
 }
Пример #23
0
        public virtual void Init()
        {
            try
            {
                EditorTemplates.RUNTIME_IN_SERVER = true;
                RPGServerTemplateManager.Instance.ToString();
                if (ZoneFactory == null)
                {
                    log.Info("********************************************************");
                    log.Info("# 初始化战斗编辑器扩展 ");
                    log.Info("********************************************************");
                    DataFactory = ReflectionUtil.CreateInterface <ZoneDataFactory>(GlobalConfig.ZoneDataFactory);
                    ZoneFactory = ReflectionUtil.CreateInterface <ZoneHostFactory>(GlobalConfig.InstanceZoneFactory, GlobalConfig.GameEditorRoot);
                    log.Info(" 战斗编辑器插件 : " + ZoneFactory);
                }
                if (NodeConfig == null)
                {
                    log.Info("********************************************************");
                    log.Info("# 加载配置文件");
                    log.Info("********************************************************");
                    NodeConfig = ZoneFactory.GetServerConfig();
                    var node_cfg = GlobalConfig.ZoneNodeConfig;
                    if (node_cfg != null)
                    {
                        log.Info(node_cfg.ToString());
                        node_cfg.LoadFields(NodeConfig);
                    }
                }
                if (DataRoot == null)
                {
                    log.Info("********************************************************");
                    log.Info("# 加载模板数据");
                    log.Info("********************************************************");
                    try
                    {
                        DataRoot         = DataFactory.CreateEditorTemplates(GlobalConfig.BattleDataRoot);
                        DataRoot.Verbose = true;
                        DataRoot.LoadAllTemplates();
                        DataRoot.CacheAllScenes();
                        Templates = DataRoot.Templates;
                    }
                    catch (Exception err)
                    {
                        throw new Exception("EditorTemplates init error : " + err.Message + "\n" + err.StackTrace, err);
                    }

                    if (CACHE_ALL_VOXEL)
                    {
                        GC.Collect();
                        GC.Collect();
                        GC.WaitForPendingFinalizers();
                        GC.WaitForFullGCApproach();
                        GC.WaitForFullGCComplete();
                        log.Info("********************************************************");
                        log.Info("# 缓存体素");
                        log.Info("********************************************************");
                        var list   = new HashMap <string, SceneData>();
                        var caches = new ConcurrentDictionary <string, VoxelWorld>();
                        foreach (var sd in DataRoot.CacheAllScenes())
                        {
                            if (string.IsNullOrEmpty(sd.VoxelFileName) is false)
                            {
                                list.TryAdd(GlobalConfig.GameEditorRoot + sd.VoxelFileName, sd);
                            }
                        }
                        var cacheTasks = new ActionBlock <KeyValuePair <string, SceneData> >(run_CacheScene, new ExecutionDataflowBlockOptions()
                        {
                            MaxDegreeOfParallelism    = Environment.ProcessorCount - 1,
                            SingleProducerConstrained = false,
                        });
                        var watch = Stopwatch.StartNew();
                        foreach (var path in list)
                        {
                            cacheTasks.Post(path);
                        }
                        void run_CacheScene(KeyValuePair <string, SceneData> sd)
                        {
                            try
                            {
                                log.Info($"Cache voxel data : {sd.Key}");
                                var wx = VoxelWorld.LoadFromFile(sd.Key);
                                caches.TryAdd(sd.Key, wx);
                                log.Info($"Cache voxel data : {sd.Key} : OK ({caches.Count}/{list.Count})");
                            }
                            catch (Exception err)
                            {
                                log.Error($"Load Voxel Error : >>>{sd.Value}<<< {sd.Key}");
                                log.Error(err);
                            }
                        }
                        cacheTasks.Complete();
                        cacheTasks.Completion.Wait();
                        watch.Stop();
                        log.Warn($"Load Voxel Complete Use : {watch.Elapsed}");
                        VoxelWorldManager.Instance.CacheAll(caches);
                    }

                    log.Info("********************************************************");
                    log.Info("# 从地图配置表重新构建场景传送点");
                    log.Info("********************************************************");
                    FillSceneTransport();
                    SceneGrapAstar = new MapSceneGrapAstar(RPGServerTemplateManager.Instance.AllMapTemplates);
                }
                {
                    log.Info("********************************************************");
                    log.Info("# 战斗编解码器");
                    log.Info("********************************************************");
                    if (DataFactory.MessageCodec is MessageFactoryGenerator)
                    {
                        log.Info(DataFactory.MessageCodec);
                    }
                }
                log.Info("********************************************************");
            }
            catch
            {
                log.Error("检查战斗编辑器是否重新保存");

                throw;
            }
        }
Пример #24
0
        private static void Main(string[] args)
        {
            Text.Clear();

            Console.WindowWidth  = ConsoleWidth;
            Console.WindowHeight = ConsoleHeight;
            Console.BufferHeight = ConsoleHeight;
            Console.BufferWidth  = ConsoleWidth;

            while (RunningGame)
            {
                switch (GameState)
                {
                case GameState.Menu:
                    RpgController.MainMenu();
                    break;

                case GameState.Start:
                    RpgController.StartNewGame();
                    break;

                case GameState.Playing:
                    if (Player.Instance.CurrentGladiator.CurrentZone == null)
                    {
                        IZone currentZone = ZoneFactory.GetZone(ZoneLevel.One);
                        Header.Map = currentZone.Map;
                        Player.Instance.CurrentGladiator.CurrentZone = currentZone;
                    }

                    Player.Instance.CurrentGladiator.CurrentZone.StateChanged(GameEvent.ZoneEnter);
                    Text.WriteLine("Welcome to the Arena Of Death!.\nNavigate through the arena to kill enemies.\n");
                    RpgController.Navigate();
                    break;

                case GameState.Interacting:
                    InteractionController.Interact(Player.Instance.CurrentGladiator, Player.Instance.CurrentGladiator.Target);
                    break;

                case GameState.Battle:
                    Text.ClearWithAbilities();
                    RpgController.Battle();
                    break;

                case GameState.Quit:
                    RpgController.QuitGame();
                    break;

                case GameState.GameOver:
                    Zone1.Instance.Dispose();
                    var repo = new MongoRepository();
                    //display ladder board
                    repo.AddGladiatorToHistory(Player.Instance.CurrentGladiator);
                    //repo.AddGladiator(Player.Instance.CurrentGladiator);
                    Thread.Sleep(2000);
                    //Console.WriteLine(repo.GetGladiatorHistory("YOMAN").Result.kills);
                    //repo.RemoveGladiatorHistoryRecord("JAVY");
                    GameState = GameState.Menu;
                    Text.Clear();
                    break;
                }
            }
        }
Пример #25
0
 void construct(ZoneFactory aZoneFactory)
 {
     _zoneFactory = aZoneFactory;
 }
Пример #26
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);
            }
        }
    }
Пример #27
0
 public Table(ZoneFactory zoneFactory)
 {
     Zones = zoneFactory.CreateZones();
 }
Пример #28
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;
                }
            }
        }
        /// <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;
                }
            }
        }