" /> Cannot get real time Statistics with asp.net - Genesys CTI User Forum

Author Topic: Cannot get real time Statistics with asp.net  (Read 2697 times)

This topic contains a post which is marked as Best Answer. Press here if you would like to see it.

Offline Harifidy

  • Newbie
  • *
  • Posts: 26
  • Karma: 0
Cannot get real time Statistics with asp.net
« on: June 08, 2021, 02:22:38 PM »
Advertisement
:)  Hi,
It' s been a while I've stuck on this. I don't know what to do.
I use RequestOpenStatic to get statistics (I followed the Genesys PSDK documents)
It works perfectly when I implemented the code using Windows form c# and App console c#, I got a real time response.
But when I use the same code with asp.net I doesn't work. I manage to connect to the stat server, but could not get the statistics instantly.
I added log to trace it, it seems there is a problem on handling event from the server. The event is not raised, I think, I don t know.

// code send request
...
// Handling event
StatServerProtocol.Received +=(sender, evArg) =>
{
IMessage mes=((MessageEventArgs)EventArgs).Message;
WriteInFile("result is"+mes) // All things inside this function doesn t work.
}

Help me please.
Thank you.

Offline hsujdik

  • Hero Member
  • *****
  • Posts: 541
  • Karma: 30
Re: Cannot get real time Statistics with asp.net
« Reply #1 on: June 08, 2021, 02:58:51 PM »
So, where is your StatServerProtocol instantiated? It probably should be a static element initialized on the Application_Start with a preload...

Offline Harifidy

  • Newbie
  • *
  • Posts: 26
  • Karma: 0
Re: Cannot get real time Statistics with asp.net
« Reply #2 on: June 08, 2021, 06:36:38 PM »
Thank you for your reply.
I initialized it in the same class where it is implemented.
public class MyClass{
private static StatServerProtocol statSrvProt;

public static ResultMessage ConnectServer()
{
  statSrvProt= new StatServerProtocol(new
  Endpoint(statSrv,host,port));
  statSrvProt.open()
  }

  public static void SendRequest(){
  // create request with RequestOpenStatistic
  // use statSrvProt
  }
}

Maybe I do it in a wrong way.
Can you show how to initialize it in App_Start?

Offline hsujdik

  • Hero Member
  • *****
  • Posts: 541
  • Karma: 30
Re: Cannot get real time Statistics with asp.net
« Reply #3 on: June 08, 2021, 07:05:15 PM »
I don't have any ready example for .Net (I do have one for Java though). But I suggest reading the application lifecycle of ASP NET applications on:

https://docs.microsoft.com/en-us/previous-versions/ms178473(v=vs.140)?redirectedfrom=MSDN
Check the topic "Life Cycle Events and the Global.asax file" on this link.

And also check https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/advanced?view=aspnetcore-5.0

Look at the topic "Application Initialization Module" to change your application to AlwaysRunning

Offline Harifidy

  • Newbie
  • *
  • Posts: 26
  • Karma: 0
Re: Cannot get real time Statistics with asp.net
« Reply #4 on: June 08, 2021, 07:10:38 PM »
Oki, thank you.
I am going to check it.

Offline Harifidy

  • Newbie
  • *
  • Posts: 26
  • Karma: 0
Re: Cannot get real time Statistics with asp.net
« Reply #5 on: June 14, 2021, 09:01:21 AM »
Hi,
I updated the peoject, but it doesn t work yet.
Here are the changes I made.
1- I instantiate the StatServerProtocol in global.asax
Global.asax:
[i]
public class WebAppli: HttpApplication{
public static StatServerProtocol statSrv;

protected void Application_start(object send, EventArgs e){
statSrv=new StatServerProtocol(new Endpoint(statserv,host,port));
statSrv.open();
}
}
[/i]

Controller.cs
[i]
// create RequestOpenStatic
// use statServerProtocol in global.asax
WebAppli.statSrv.Request((IMessage)requestOpenStat);
WebAppli.statSrv.Received += (sen,event)=>
{
// to test I write in a file the statistic
}
[/i]

2- I also did all configurations in IIS, on the
Application pool and the application setting.
« Last Edit: June 14, 2021, 11:36:17 AM by Harifidy »

Offline cavagnaro

  • Administrator
  • Hero Member
  • *****
  • Posts: 7641
  • Karma: 56330
Re: Cannot get real time Statistics with asp.net
« Reply #6 on: June 14, 2021, 08:36:04 PM »
ASP.Net, like in a web page where content is built dynamically?
If so, there is no active component to behave like a listener, right? Is quite different from a desktop application.
Your request ended when the HTTP content was delivered and even if you created an object instace, the HTTP request is over...so you won't receive new events for it.

Marked as best answer by Harifidy on June 18, 2021, 05:35:27 AM

Offline hsujdik

  • Hero Member
  • *****
  • Posts: 541
  • Karma: 30
Re: Cannot get real time Statistics with asp.net
« Reply #7 on: June 15, 2021, 01:38:45 PM »
I have created a simple example to open the connection to the Stat Server on the Application context as a static object:
https://1drv.ms/u/s!AvfK0JSyglrHheU23KcvwFOVA2k38A?e=hZtyu2

Check the class StatServerController on the root folder of the project (not the solution folder).

The connection should remain open for as long as the Application is running on IIS. You can create static methods on that class in order to communicate with StatServer (or use the publicly accessible "StatServer" property of the class)

Refer to the previous links I sent in order to see how to keep the application always running and how to give it a "hot start" using the IIS Application Initialization feature.


This example was created using the default MVC template for ASP.NET with .Net Framework 4.7.2 (not DotNet Core). You might be able to change it to suit your needs.

Offline Harifidy

  • Newbie
  • *
  • Posts: 26
  • Karma: 0
Re: Cannot get real time Statistics with asp.net
« Reply #8 on: June 17, 2021, 04:34:36 PM »
My sincere apologies for the slow reply.
That works fine.
Thank you for your help.  :)

Offline Harifidy

  • Newbie
  • *
  • Posts: 26
  • Karma: 0
Re: Cannot get real time Statistics with asp.net
« Reply #9 on: June 21, 2021, 01:17:21 PM »
Hi all.
I don't know if I can use this post or I should create one to ask a question.
Is it possible to request differents statistics at the same time.
For example:
- TotalLoginTime of the Agent agent0
- TotalLoginTime of the agent agent1
- CurrentTime of 30002@mt_out
- ...
We use the same host, port and statServer for all requests.
Thank you very much.

Offline hsujdik

  • Hero Member
  • *****
  • Posts: 541
  • Karma: 30
Re: Cannot get real time Statistics with asp.net
« Reply #10 on: June 21, 2021, 01:39:22 PM »
Yes, you can. For each RequestOpenStatistic or RequestOpenStatisticEx that you create, there is a related "RequestId" (either auto-generated by the SDK, or provided by yourself the way you want).
Every EventInfo will come with this same RequestId (REQ_ID on the EventInfo) so you know to which statistic it relates to.

Offline Harifidy

  • Newbie
  • *
  • Posts: 26
  • Karma: 0
Re: Cannot get real time Statistics with asp.net
« Reply #11 on: June 21, 2021, 01:54:07 PM »
Ah okey I see.
Thank you.
I am going to work on it.
:)