⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 addagentcaller.cs

📁 SRI international 发布的OAA框架软件
💻 CS
字号:
using System;
using jnb.com.sri.sedc.javanetbridge;
using jnb.com.sri.oaa2.lib;
using jnb.com.sri.oaa2.icl;
using jnb.com.sri.oaa2.com;
using jnb.java.lang;

namespace com.sri.oaa2.agent.add
{
	/// <summary>
	/// </summary>
	class AddAgentCaller
	{
		const String AGENT_NAME = "csharp_addAgentCaller";
		const String CONNECTION_ID = "parent";

		private LibOaa myOaa;

		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		/// Important: The thread must be MTA
		[MTAThread]
		static void Main(string[] args)
		{
			// These commands can be used to change the ip address and port of the proxy agent.
			// They must be called before any .NET APIs are acccessed below. By default it is
			// assumed the java proxy is running on this machine on port 4016.
			//JavaNetBridgeInteropClass.setConnectAddress(System.Net.IPAddress.Parse("128.18.233.111"));
			//JavaNetBridgeInteropClass.setConnectPort(4080);

			AddAgentCaller agent = new AddAgentCaller();
			agent.init();
			int sum = agent.addOaa(10, 5);
			Console.WriteLine("sum = " + sum);
			sum = agent.addOaa(100, 5008);
			Console.WriteLine("sum = " + sum);
			sum = agent.addOaa(-20, 60);
			Console.WriteLine("sum = " + sum);
			sum = agent.addOaa(-1, 55);
			Console.WriteLine("sum = " + sum);
		}

		public int addOaa(int x, int y) 
		{
			IclStruct addSolveable = new IclStruct("add", 
				new IclInt(x), new IclInt(y), new IclVar("Sum"));
			IclList solveParams = new IclList();
			IclList solutions = new IclList();
			if (myOaa.oaaSolve(addSolveable, solveParams, solutions)) 
			{
				if (solutions.size() > 0) 
				{
					// Just examine the first solution
					IclTerm solution = solutions.getTerm(0);
					int sum = solution.getTerm(2).iclInt();
					return sum;
				} 
				else 
				{
					throw new System.Exception("Failed to add, but received a true return value.");
				}
			} 
			else 
			{
				throw new System.Exception("Failed to add. Is the AddAgent running?");
			}
		}

		private void debug(String msg)
		{
			Console.WriteLine(AGENT_NAME + ": " + msg);
		}

		public String getAgentCapabilities()
		{
			return "[]";
		}

		public String getAgentName()
		{
			return AGENT_NAME;
		}

		public void init()
		{
			LibComTcpProtocol protocol = new LibComTcpProtocol();
			LibCom com = new LibCom(protocol, null);
			myOaa = new LibOaa(com);

			if (!myOaa.oaaSetupCommunication(getAgentName()))
			{
				throw new System.Exception("Failed to setup OAA communication");
			}

			debug("Connection Made");

			IclTerm solveables = IclTerm.fromString(true, getAgentCapabilities());

			debug("Registering " + getAgentName());
			if (!myOaa.oaaRegister(CONNECTION_ID, getAgentName(), solveables, new IclList()))
			{
				throw new System.Exception("Failed to register");
			}

			myOaa.oaaReady(true);
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -