How to send information (an image) from Background Plugin to Client ViewItemWpfUserControl?

Hello,

I’ve been trying to figure this out for the last 2 days with no luck. So frustrating because it’s literally the only thing that is left to do.

I have a Background plugin listening to WebSocket events (receiving images). This part works.

I want to send these images to the Client ViewItemWpfUserControl. I tied to follow the “SCExport” example in PlatformSamples solution by declaring a static instance of the Client ViewItem control in the Background plugin (and then setting it in ViewItem init) and this does not work because it looks like ViewItem creates its own instance of Background so Background instance of ViewItem is always null.

Anyway, I decided to try to use EnvironmentManager.Instance.SendMessage instead (I actually think it’s a more elegant solution) but can’t figure out how to make this work… messages are sent but not seen on the ViewItem side.

This is what I register on the Client ViewItem side, where I want to filter messages only from the Background plugin.

EnvironmentManager.Instance.RegisterReceiver(new MessageReceiver(UpdateAlerts), new KindFilter(MyPluginDefinition.MyPluginBackgroundPlugin));

And this is how I try to send the message. I already tried different type of built in message types, etc. and nothing works.

EnvironmentManager.Instance.SendMessage(new Message("EvolvMsg") { Data = myImage }, null, new FQID() { Kind = MyPluginDefinition.MyPluginBackgroundPlugin });

Could someone please let me know how to fix this? Or perhaps there’s a better way. Thank you!

The Chat sample is a sample that utilize a message created for the purpose of the sample, so the sample might hold the clue on getting your code to work.

https://doc.developer.milestonesys.com/html/index.html?base=samples/chat.html&tree=tree_1.html

I have a feeling that you maybe could do a lot less. If I assume that the background and the view item is part of the same plugin, then the communication is all within the same plugin in the same instance of the Smart Client. Then you could simply have a static property in the PluginDefinition class. Both the background and the view item class can then get or set this property. You can also use a static eventhandler in the PluginDefinition class to signal that a value has been updated. This of course is only applicable if it is all within one SC plugin, but if that is the scenario it seems so much simpler.

Thank you for the reply!

Yes, it’s all part of the same plugin project.

Got it to work with the Chat example!

Just a question though… Should the MessageCommunication object be declared as global in one place (say, PluginDefinition) or instance in both Background and ViewItem (which I have now and it works fine).

What you have now is fine. My developer colleagues preferred the method you have used with two separate declarations when I asked around..