I am a beginner both with MIP SDK and C#. I am using your integration elearning portal as an example. I have a background plugin which talks to an extrernal system. When data is received from the system, I need to populate, say, a ListBox control which is located in the Client plugin with the data received. How do I achive that? Do I use Messaging system? Or is it possible to obtain an instance of the Client plugin and simply pass the data through a custom method?
Thanks
I’d go for the messaging system. Very easy to setup, and you can send any (serializable?) object. Just create your own filter and you’re good to go. See the Chat sample if you don’t know where to start.
I have tried the messaging system as you suggested, but I don’t see any incoming messages:
- In “MyCompanyDefinition.cs”, I added:
internal static string MyCompanyMsgId = “MyCompany.MessageID”;
- In the “SetUpApplicationEventListeners” method of the MyCompanyViewItemUserControl.cs I registered a receiver:
_dataReceived = EnvironmentManager.Instance.RegisterReceiver(DataListener, new MessageIdFilter( MyCompanyDefinition.MyCompanyMsgId) );
- Now in the Init() method of “MyCompanyBackgroundPlugin.cs” I try to send a message:
Message msg = new Message(MyCompanyDefinition.MyCompanyMsgId, “this is a test object being attached to the message”);
EnvironmentManager.Instance.SendMessage(msg);
But the method “DataListener” is never called.
What am I doing wrong?
Thanks
Be aware that the message name ending is checked for security - e.g. dont send anything ending with a ‘Command’ at the end for your messageId.
Also, the ‘SendMessage’ works within same application execution, while ‘TransmitMessage’ works for app to app execution (Via MessageCommunication class).
So I tried the suggested method and it seem to work, but there are some quirks:
I construct and send a message as following:
msg = new Message(“custom id”, data);
messageCommunication.TransmitMessage(msg, null, null, null);
However,
If data is, say, a string type, for example. data = “test string”, I get this exception:
CommunicationClient.MessageDispatcher Unable to cast object of type ‘System.String’ to type ‘System.Object[]’
Why?
So, If i wrap the string into an array: data = new object[{ “test string”}], it works.
But If I try to insert an object of “RectangleF” class:
data = new object[{ “test string”, new RectangleF()}],
I get another exception:
CommunicationClient.MessageDispatcher Object reference not set to an instance of an object.
Why can’t I insert this class into the data?
Thanks
Please note that MessageCommunication is intended for plugins in different applications to communicate. When communicating within same application please use SendMessage / RegisterReceiver on the EnvironmentManager, or simply use normal C# coding stile like static or singleton handling within same DLL.
As to your question: MessageCommunication needs to be able to serialize all data, so you cannot use ‘object’ directly and all your own classes need to be Serializable.