Genesys CTI User Forum > Genesys-related Development
How to handle-if config server sends EventObjectsSent response to RequestReadObj
Vegeta:
[quote author=hsujdik link=topic=9642.msg43602#msg43602 date=1465338666]
I don't currently have Visual Studio installed, so I didn't test the code below, but I feel that would be way easier if you used ConfService. You would get rid of all the XmlDocument manipulation hell. For example:
[code]
/// Step 1 Opening a connection ////
// HSUJDIK: create the ConfService before opening the ConfServerProtocol:
EventBrokerService brokerService = BrokerServiceFactory.CreateEventBroker(protocol);
ConfService service = ConfServiceFactory.CreateConfService(confServerProtocol, brokerService);
confServerProtocol.Open(); // opening a connection
///Step 2 Authenticating a Username and password of a User whose details are available in CME ... ///
RequestAuthenticate RequestAuthenticateObj = RequestAuthenticate.Create(AgentName, Agentpassw);
// HSUJDIK: use the method .Request instead of .Send so you will get the message back
// without need to use the method .Receive()
(Message) authResponse = confServerProtocol.Request(RequestAuthenticateObj);
// HSUJDIK: check if EventAuthenticated or EventError was returned.
/// Step 3 Once authenticated I am trying to get the DBID of that User from Cfgperson ... the user who is authenticated above ///
/// and once done I am trying to further fetch his Login code from CfgAgentLogin ///
// HSUJDIK:
CfgPersonQuery query = new CfgPersonQuery(confservice);
query.UserName("user_name");
CfgPerson person = null;
try {
person = query.ExecuteSingleResult();
} catch (Exception e) {
// ERROR TRYING TO GET THE USER PROPERTIES. Proceed as you wish
}
List<CfgAgentLogin> agentLogins = person.AgentInfo.AgentLogins;
foreach (CfgAgentLogin agentLogin in agentLogins) {
// HSUJDIK: Do whatever you need with each CfgAgentLogin
}
/// Step 4 pass a filter query again with the DBID obtained from previous step.. to get his tenant id / logithis time I am getting below exception
// HSUJDIK:
int dbid = person.Tenant.DBID;
[/code]
[/quote]
********************************************************************************
Hi Hsujdik
I tried your method to remove those XML handling and tried with Confservice.
I am seeing one odd event .. the 2nd var Agentinfo = queryforLoginID.Execute(); for agentloginQuery is returning null
please advice
[code] // CfgAgentLoginQuery query = new CfgAgentLoginQuery(service);
var query = new CfgPersonQuery(service) { UserName = AgentName };
//testing Dbid = DBID UserName = AgentName
// retrieve all persons with given parameter UserName
var readedPersons = query.Execute();
if ((readedPersons != null) && (readedPersons.Count > 0))
{
foreach (CfgPerson readedPerson in readedPersons)
{
// notify to a view that person has been read
MessageBox.Show(readedPerson.DBID.ToString());
DBID = readedPerson.DBID;
}
}
var queryforLoginID = new CfgAgentLoginQuery(service) { Dbid = DBID };
//retrieve all persons with given parameter UserName
var Agentinfo = queryforLoginID.Execute(); //// I am seeing that this query is returning null value.. am I missing something :(
// List<CfgAgentLogin> Agentinfo = queryforLoginID.Execute();
if ((Agentinfo != null) && (Agentinfo.Count > 0))
{
foreach (CfgAgentLogin info in Agentinfo)
{
// notify to a view that person has been read
MessageBox.Show(info.LoginCode.ToString());
}
}
[/code]
hsujdik:
For the CfgPersonQuery, I would use the ExecuteSingleResult method... as far as I know (assuming single tenant environment) you cannot have more than one person with the same username on the environment. So, there would be no need to loop for each person once you will have only one result...
Also, you are querying the AgentLogin with the DBID of the person. Note that they are different.
Agent can have the DBID "1" whereas its AgentLogin may have DBID "2", for instance.
If you use properly, you don't even need to perform a second Query. All the info you will get from the first query. Like this (based on your last code):
[code]
var query = new CfgPersonQuery(service) { UserName = AgentName };
// retrieve THE ONLY person with given parameter UserName
var readedPerson = query.ExecuteSingleResult();
if (readedPerson != null)
{
foreach (CfgAgentLogin info in readedPerson.LoginInfo.AgentLogins)
{
// notify the Login Infos
MessageBox.Show(info.LoginCode.ToString());
}
}
[/code]
spin:
[quote author=Vegeta link=topic=9642.msg43652#msg43652 date=1465567320]
But I still have a doubt .. even if I handle the ..EventObjectsSent .. I can open a handler and to capture that and avoid case but still is there any other better methods which I can raise from this event handler to extract the one/more messages other way around.
Sorry I have no clue how to do that.. :( hence the ask.
Thanks
[/quote]
Hello - if you do async messaging you can just have a sub to do the message handling. Something like this (vb)
[code]
Imports Genesyslab.Platform.Commons.Protocols
Private Sub ConfMessageReceived(ByVal sender As Object, ByVal e As EventArgs) Handles ConfProtocol.Received
Dim y As MessageEventArgs = TryCast(e, MessageEventArgs)
If (IsNothing(y) = False) Then
Select Case y.Message.Name
Case "EventObjectsRead"
'do stuff
ASubThatHandlesIMessage(y.Message)
Case "EventObjectsSent"
'don't do stuff
Case "AnotherEvent"
'do something else
End Select
End If
End Sub
[/code]
Vegeta:
[quote author=hsujdik link=topic=9642.msg43669#msg43669 date=1465847994]
For the CfgPersonQuery, I would use the ExecuteSingleResult method... as far as I know (assuming single tenant environment) you cannot have more than one person with the same username on the environment. So, there would be no need to loop for each person once you will have only one result...
Also, you are querying the AgentLogin with the DBID of the person. Note that they are different.
Agent can have the DBID "1" whereas its AgentLogin may have DBID "2", for instance.
If you use properly, you don't even need to perform a second Query. All the info you will get from the first query. Like this (based on your last code):
[code]
var query = new CfgPersonQuery(service) { UserName = AgentName };
// retrieve THE ONLY person with given parameter UserName
var readedPerson = query.ExecuteSingleResult();
if (readedPerson != null)
{
foreach (CfgAgentLogin info in readedPerson.LoginInfo.AgentLogins)
{
// notify the Login Infos
MessageBox.Show(info.LoginCode.ToString());
}
}
[/code]
[/quote]
Thanks so much Hsujdik, I am able to retrieve the value 8) for login code.
[code] var query = new CfgPersonQuery(service) { UserName = AgentName };
var readedPerson = query.ExecuteSingleResult();
if (readedPerson != null)
{
foreach (CfgAgentLoginInfo info in readedPerson.AgentInfo.AgentLogins)
{
// notify the Login Infos
MessageBox.Show(info.AgentLogin.LoginCode.ToString());
}
}}[/code]
Navigation
[0] Message Index
[*] Previous page
Go to full version