Custom Message send from SmartClient To EventServer

Hey in the SmartClient i am raising a custom UserControl,

in the UserControl i have this button the should be doing things over the EventServer.

from the UserControl, i have used

  var msg = new VideoOS.Platform.Messaging.Message(MyPluginDefinition.SetCommandMessage);

msg.Data = *Some data model instance*

EnvironmentManager.Instance.SendMessage(msg);

in the BackgroundPlugin Init() there is IF that does:

if (EnvironmentManager.Instance.EnvironmentType == EnvironmentType.SmartClient)

  {

    SetSmartClientListeners();

  }

  if (EnvironmentManager.Instance.EnvironmentType == EnvironmentType.Service)

  {

    SetEventServersListeners();

  }

if i registerReceiver in the SmartClient ENV it gets triggered when i send my msg,

but if i set it up in the EventServer, my RegisterReceiver do NOT get triggered.

i tried to use the BroadcastFQID, tried MessageCommunication.TransmitMessage

but with no success.

how can i send the EventServer EventListener a data message which is not Event or Alarm , only Command on just a Custom message.

Please notice that i need to send some Data in the message to inform event server.

Have you overrided TargetEnvironment adding both Service and Smart Client?

It looks like background plugin operates only in SC environmet

Freddy

Please note that

abstract object VideoOS.Platform.EnvironmentManager.RegisterReceiver 	( 	MessageReceiver  	messageReceiver,		MessageFilter  	messageFilter) 	
abstract Collection<object> VideoOS.Platform.EnvironmentManager.SendMessage 	( 	Message  	message,		FQID  	destination,		FQID  	sender) 		

are for communication within the application.

object VideoOS.Platform.Messaging.MessageCommunication.RegisterCommunicationFilter 	( 	MessageReceiver  	messageReceiver,		CommunicationIdFilter  	messageFilter) 	
void VideoOS.Platform.Messaging.MessageCommunication.TransmitMessage 	( 	Message  	message,		FQID  	destinationEndPoint,		FQID  	destinationObject,		FQID  	source) 

are for communication across applications.

I have a hunch that if you change both the receiver registration and the transmit of messages it might work.

hey, we encountered this situation again, neigther one is working,

is there any way to send messages from SmartClient (ui button or something) to invoke a listener on the event server side?

from SmartClient we use:

string someData = “SomeData”;

  \_messageCommunication.TransmitMessage(new Message(SmartSecurityDefinition.ActivateAutoCameraTrack, someData ), null, null, null);

in the event server Init Method we use:

MessageCommunicationManager.Start(EnvironmentManager.Instance.MasterSite.ServerId);
            messageCommunication = MessageCommunicationManager.Get(EnvironmentManager.Instance.MasterSite.ServerId);
            _magosActionsReceiver = messageCommunication.RegisterCommunicationFilter(
                      OurCommandReceiverHandler,
                      new CommunicationIdFilter(SmartSecurityDefinition.ActivateAutoCameraTrack)
                      );

and the eventserver receive method is:

private object OurCommandReceiverHandler(Message message, FQID destination, FQID sender)
        {
            var data = message.Data as string;
            if(data is null) { return null; }
            return null;
        }

In VisualStudio we use Attach to process and attaching the VideoOS.Event.Server.exe and add a break poing to this handler,

the method is not being invoked.

is there alternative? is the something else left to do?

we also tested “EnvironmentManager.Instance.SendMessage” method but we no success.

Thanks

Hereafter my working code.

            MessageCommunicationManager.Start(EnvironmentManager.Instance.MasterSite.ServerId);
            MsgCommHandler = MessageCommunicationManager.Get(EnvironmentManager.Instance.MasterSite.ServerId);
            EventServerResponder = MsgCommHandler.RegisterCommunicationFilter(RefreshConfigurationReceiver, new CommunicationIdFilter(RefreshConfigurationsResponse));
            EventServerSender    = MsgCommHandler.RegisterCommunicationFilter(EventServerMessageReceiver, new CommunicationIdFilter(EventServerMessage));
 
            Item item = new Item(EnvironmentManager.Instance.MasterSite, AssemblyInfo.ProductNameShort);
            try
            {
                // Genera l'Evento per la Richiesta all'ES
                EventHeader eventHeader = new EventHeader()
                {
                    ID = Guid.NewGuid(),
                    Class = "Operational",
                    Type = requestType,
                    Timestamp = DateTime.Now,
                    Message = "KS.EventServerRequest",
                    Name = item.Name,
                    Source = new EventSource { FQID = item.FQID, Name = item.Name, Description = requestType },
                    MessageId = Guid.Empty,
                    CustomTag = Thread.CurrentThread.CurrentUICulture.TwoLetterISOLanguageName.ToLower()
                };
 
                AnalyticsEvent eventData = new AnalyticsEvent { EventHeader = eventHeader };
                EnvironmentManager.Instance.SendMessage(new Message(MessageId.Server.NewEventCommand, null, eventData), null, item.FQID);
            }
            catch (Exception ex) { Helper.myLog(true, "Error: " + ex.Message); }

Where:

  1.  internal const string RefreshConfigurationsRequest = "REFRESH\_CONFIGURATIONS\_REQUEST";
    
  2.  internal const string RefreshConfigurationsResponse = "REFRESH\_CONFIGURATIONS\_RESPONSE";
    
  3.  internal const string EventServerMessage      = "EVENT\_SERVER\_MESSAGE";
    

Freddy

CustomTag is used to notify to ES the SC language

Freddy

so i implemented your code

in the smart client ViewItemUserControl i have a button who does this:

Item item = new Item(EnvironmentManager.Instance.MasterSite, AssemblyInfo.ProductName);
            try
            {
                // Genera l'Evento per la Richiesta all'ES
                EventHeader eventHeader = new EventHeader()
                {
                    ID = Guid.NewGuid(),
                    Class = "Operational",
                    Type = "",
                    Timestamp = DateTime.Now,
                    Message = "KS.EventServerRequest",
                    Name = item.Name,
                    Source = new EventSource { FQID = item.FQID, Name = item.Name, Description = "" },
                    MessageId = Guid.Empty,
                    CustomTag = Thread.CurrentThread.CurrentUICulture.TwoLetterISOLanguageName.ToLower()
                };
 
                AnalyticsEvent eventData = new AnalyticsEvent { EventHeader = eventHeader };
                EnvironmentManager.Instance.SendMessage(new Message(MessageId.Server.NewEventCommand, null, eventData), null, item.FQID);
            }
            catch (Exception ex) { }

and in the MyPluginBackgroundPlugin:

if (EnvironmentManager.Instance.EnvironmentType == EnvironmentType.Service)
            {
               MessageCommunicationManager.Start(EnvironmentManager.Instance.MasterSite.ServerId);
            MsgCommHandler = MessageCommunicationManager.Get(EnvironmentManager.Instance.MasterSite.ServerId);
            EventServerResponder = MsgCommHandler.RegisterCommunicationFilter(RefreshConfigurationReceiver, new CommunicationIdFilter(RefreshConfigurationsResponse));
            EventServerSender = MsgCommHandler.RegisterCommunicationFilter(EventServerMessageReceiver, new CommunicationIdFilter(EventServerMessage));
 
            }

again, i put a break points on the EventServerMessageReceiver and RefreshConfigurationReceiver and attached to debugger to eventserver process, and still got no hit after SendMessage.

am i missing something? am i doing something wrong?

Thank you.

As you can see on row 19 of SC code, you are sending an Event (MessageId.Server.NewEventCommand), so in ES you just need

PluginEventReceiverInstance = EnvironmentManager.Instance.RegisterReceiver(PluginEventReceiver, new MessageIdFilter(MessageId.Server.NewEventIndication));

where PluginEventReceiver method will be called by Message

Freddy