Poll

Need assistance in event handling received by configuration server while querying for person details

Need assistance in event handling received by configuration server while querying for person details
0 (0%)
Need assistance in event handling received by configuration server while querying for person details
0 (0%)

Total Members Voted: 0

Author Topic: Need assistance in event handling received by configuration server.  (Read 3350 times)

Offline Rajnish@49

  • Jr. Member
  • **
  • Posts: 58
  • Karma: -1
Need assistance in event handling received by configuration server while querying for person details.

I am new to platform SDK .net. I am trying to query person details from configuration server using platform SDK .net. We are able to open connection with configuration server and send request "RequestReadObjects" for person details. I am not sure what mistake i am making while event handling, Hence not receiving anything from configuration server. Please find below my SDK .net code for event handling code.

try
{
ProtocolManagementService protocolManagementService = new ProtocolManagementService();
ConfServerConfiguration confserv = new ConfServerConfiguration("confserv");
confserv.Uri = new Uri("tcp://<cfg_host>:2020");
confserv.ClientApplicationType = CfgAppType.CFGSCE;
confserv.ClientName = "default";
confserv.UserName = "<username>";
confserv.UserPassword = "<password>";
protocolManagementService.Register(confserv);
EventBrokerService eventbrokerservice;
eventbrokerservice = new EventBrokerService(protocolManagementService.Receiver);
eventbrokerservice.Register(this.OnConfEventError, new MessageIdFilter(EventError.MessageId));
eventbrokerservice.Register(this.OnConfEventObjectsRead, new MessageIdFilter(EventObjectsRead.MessageId));
eventbrokerservice.Register(this.OnConfEventObjectsSent, new MessageIdFilter(EventObjectsSent.MessageId));
protocolManagementService["confserv"].Open();
KeyValueCollection filterkey = new KeyValueCollection();
filterkey.Add("user_name", "rajnish");
RequestReadObject requestreadObject = RequestCreateObject.Create((int)CfgObjectType.CFGPerson, filterkey);
IMessage msg = protocolManagementService["confserv"].Request(requestreadObject);
Console.WriteLine("response "+msg);
}
catch (Exception X)
{
Console.WriteLine(X);
Console.ReadLine();
}




Code for event handling:-

private void OnConfEventObjectsRead(IMessage theMessage)
{
Console.WriteLine("I'm event!");
EventObjectsRead objectsRead = theMessage as EventObjectsRead;

StringBuilder xmlAsText = new StringBuilder();
XmlWriterSettings xmlSettings = new XmlWriterSettings();
xmlSettings.Indent = true;
using (XmlWriter xmlWriter =
XmlWriter.Create(xmlAsText, xmlSettings))
{
XDocument resultDocument = objectsRead.ConfObject;
resultDocument.WriteTo(xmlWriter);
}
Console.WriteLine("This is the response:\n"
+ xmlAsText.ToString() + "\n\n");
// Console.ReadLine();
}


private void OnConfEventError(IMessage theMessage)
{
EventError eventError = theMessage as EventError;
Console.WriteLine("error");
}
private void OnConfEventObjectsSent(IMessage theMessage)
{
Console.WriteLine("I'm event!");

}

Offline kerry.finlayson

  • Newbie
  • *
  • Posts: 4
  • Karma: 0
Re: Need assistance in event handling received by configuration server.
« Reply #1 on: January 23, 2015, 08:13:52 AM »
Hey,

If I were you, I would split out the connection code and the query code.  Connect to config server first then send your request.  You aren't waiting for an event to come back you will be sending a request and getting a response back such as:

CfgPersonQuery personQuery = new CfgPersonQuery(confService);
                personQuery.State = CfgObjectState.CFGEnabled;
                personQuery.Username = "rajnish";
                personQuery.IsAgent = 0;
                CfgPerson agent = CfgPerson(_confService.RetrieveObject<CfgPerson>(personQuery);

I haven't tested this but it should hopefully point you in the right direction.
Kerry.

Offline Rajnish@49

  • Jr. Member
  • **
  • Posts: 58
  • Karma: -1
Re: Need assistance in event handling received by configuration server.
« Reply #2 on: February 06, 2015, 11:55:14 AM »
Thanks Kerry... got confused in declaring RetrieveObject method, request you to provide a sample to use RetrieveObject method. Since filterkey.Add("user_name", "rajnish");
RequestReadObject requestreadObject = RequestCreateObject.Create((int)CfgObjectType.CFGPerson, filterkey);

leads to retrieve all agents  information from configuration server.

Thanks in advance.