cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Did you get an answer that solved your problem? Please mark it as an Accepted Solution so others with the same problem can find the answer easily. X

How to use TaskId on BaseSession::RegisterTask?

MichelH
12-Amethyst

How to use TaskId on BaseSession::RegisterTask?

Dear Community,

inside OTK Java free I am registering another JLink application using BaseSession::StartJLinkApplication. This works fine. JLinkApplication::IsActive returns true and I can see the registered app in Creo (4.0). Furthermore I can register a task by using BaseSession::RegisterTask. But if I want to excecute the task (JLinkApplication::ExecuteTask) with the same TaskId that I used for registering the task I get a XToolkitNotFound exception. If I want to register another task with the same TaskId I get a XJLinkTaskExists exception.

I do not understand why! I also do not understand why I have to register a task on the BaseSession object but execute it on the JLinkApplication object.

 

Could anybody help?

 

Thank you and kind regards

Michael

1 ACCEPTED SOLUTION

Accepted Solutions
MichelH
12-Amethyst
(To:VladimirN)

It got it working now. As a matter of fact the registering of the task needs to happen inside the external application. That's where I got it wrong before. If you are interested see my example code.

 

The base application executing the task of the external application:

 

public class ExternalJLinkApplicationLauncher extends DefaultUICommandActionListener {
	@Override
	public void OnCommand() {
		try {
			JLinkApplication externalJLinkApp = pfcGlobal.GetProESession().StartJLinkApplication("externalJLinkApp",
					"com.testing.ExternalJLinkApplication", "start", "stop", "C:\\path\\to\\classfiles", "C:\\path\\to\\textfolder", true);

			String taskId = "externalJLinkApp001";

			Argument dummyArgument = pfcArgument.Argument_Create("dummyArgument", pfcArgument.CreateASCIIStringArgValue("value"));
			Arguments arguments = Arguments.create();
			arguments.append(dummyArgument);
			try {
				externalJLinkApp.ExecuteTask(taskId, arguments);
			} catch (XToolkitNotFound e) {
				System.out.println("Task could not be found in target application.");
			}

		} catch (jxthrowable jxt) {
			System.out.println(jxt.getMessage());
		}
	}

	class ExternalJLinkAppListener extends DefaultJLinkTaskListener {
		@Override
		public Arguments OnExecute(Arguments arg0) throws jxthrowable {
			System.out.println("externalJLinkApp started.");
			return arg0;
		}
	}
}

 

 

The external application:

 

public class ExternalJLinkApplication  {
	private void registerTask() {
		try {
			String taskId = "externalJLinkApp001";
			try {
				pfcGlobal.GetProESession().RegisterTask(taskId, new ExternalJLinkAppListener());
			} catch (XJLinkTaskExists e) {
				System.out.println("Task " + e.GetTaskId() + " already exists.");
				return;
			}

		} catch (jxthrowable jxt) {
			System.out.println(jxt.getMessage());
		}

	}

	public static void start() {
		ExternalTestApp instance = new ExternalTestApp();
		instance.registerTask();
	}
	
	public static void stop() {
		
	}
	
	class ExternalJLinkAppListener extends DefaultJLinkTaskListener {
		@Override
		public Arguments OnExecute(Arguments arg0) throws jxthrowable {
			new JwPrintMessage().messageArea("TEST");
			System.out.println("ExternalJLinkApplication started.");
			return arg0;
		}
	}
}

 

Thank you all for your support and best regards!

View solution in original post

7 REPLIES 7
VladimirN
24-Ruby II
(To:MichelH)

I found only one article that is at least somehow related to your question: https://www.ptc.com/en/support/article/cs331890

Hi,

please ask PTC Support.


Martin Hanák

Difficult to understand what happened without a sources.  Could you provide a sample of your code?

Thank you all for your replies! I will post the code as soon as I have some time, latest this weekend...

Kind regards

Michael

VladimirN
24-Ruby II
(To:MichelH)

You're welcome.

MichelH
12-Amethyst
(To:VladimirN)

It got it working now. As a matter of fact the registering of the task needs to happen inside the external application. That's where I got it wrong before. If you are interested see my example code.

 

The base application executing the task of the external application:

 

public class ExternalJLinkApplicationLauncher extends DefaultUICommandActionListener {
	@Override
	public void OnCommand() {
		try {
			JLinkApplication externalJLinkApp = pfcGlobal.GetProESession().StartJLinkApplication("externalJLinkApp",
					"com.testing.ExternalJLinkApplication", "start", "stop", "C:\\path\\to\\classfiles", "C:\\path\\to\\textfolder", true);

			String taskId = "externalJLinkApp001";

			Argument dummyArgument = pfcArgument.Argument_Create("dummyArgument", pfcArgument.CreateASCIIStringArgValue("value"));
			Arguments arguments = Arguments.create();
			arguments.append(dummyArgument);
			try {
				externalJLinkApp.ExecuteTask(taskId, arguments);
			} catch (XToolkitNotFound e) {
				System.out.println("Task could not be found in target application.");
			}

		} catch (jxthrowable jxt) {
			System.out.println(jxt.getMessage());
		}
	}

	class ExternalJLinkAppListener extends DefaultJLinkTaskListener {
		@Override
		public Arguments OnExecute(Arguments arg0) throws jxthrowable {
			System.out.println("externalJLinkApp started.");
			return arg0;
		}
	}
}

 

 

The external application:

 

public class ExternalJLinkApplication  {
	private void registerTask() {
		try {
			String taskId = "externalJLinkApp001";
			try {
				pfcGlobal.GetProESession().RegisterTask(taskId, new ExternalJLinkAppListener());
			} catch (XJLinkTaskExists e) {
				System.out.println("Task " + e.GetTaskId() + " already exists.");
				return;
			}

		} catch (jxthrowable jxt) {
			System.out.println(jxt.getMessage());
		}

	}

	public static void start() {
		ExternalTestApp instance = new ExternalTestApp();
		instance.registerTask();
	}
	
	public static void stop() {
		
	}
	
	class ExternalJLinkAppListener extends DefaultJLinkTaskListener {
		@Override
		public Arguments OnExecute(Arguments arg0) throws jxthrowable {
			new JwPrintMessage().messageArea("TEST");
			System.out.println("ExternalJLinkApplication started.");
			return arg0;
		}
	}
}

 

Thank you all for your support and best regards!

Top Tags