AminRostami
AminRostami

Reputation: 2772

create AGIScript in classLibrary project

I have a simple project create with c# (.Net Core 6.0)

I create a AGIScript class with Asternet and recieve the data from asterisk server.

it's working well, As long as both are in the same project (exe project).

public void ListenToAgi()
{
    var agi = new AsteriskFastAGI();
    
    agi.MappingStrategy = new GeneralMappingStrategy(new List<ScriptMapping>()
    {
            new ScriptMapping() {
            ScriptClass = "HI.agiSample.MyAgi",
            ScriptName = "getvariable"
            }
     });
     agi.Start();
}

MyAgi class is:

using AsterNET.NetStandard.FastAGI;

namespace HI.agiSample
{
    public class MyAgi : AGIScript
    {
        public override void Service(AGIRequest request, AGIChannel channel)
        {
            string result = GetVariable("result");
        }
    }
}

My problem is, when I move the MyAgi class to ClassLibrary project, it doesn’t work; the AGI listener doesn’t start listening. But if both classes are in the same project (exe), it's working well.

NOTES:

  1. namespace is same in both project , Only the assembly name is different.

  2. Project A is windows desktop application and Project B is ClassLibrary.

Upvotes: 1

Views: 150

Answers (1)

Rajeev Upadhyay
Rajeev Upadhyay

Reputation: 11

One possible reason why your AGI listener is not working when you move the MyAgi class to a ClassLibrary project is because the AGI listener is instantiated and started in the executable project (Project A), but the MyAgi class is now in a separate ClassLibrary project (Project B).

When you move the MyAgi class to a ClassLibrary project, you need to make sure that the executable project (Project A) is still referencing the ClassLibrary project (Project B) and that the AGI listener is being instantiated and started from the executable project (Project A).

Here are some steps you can try:

Make sure that the ClassLibrary project (Project B) is referenced by the executable project (Project A). To do this, right-click on the References node in the Solution Explorer for Project A, and select "Add Reference". Then, select the ClassLibrary project (Project B) from the list of projects.

Make sure that the MyAgi class in the ClassLibrary project (Project B) has the same namespace and assembly name as the executable project (Project A).

In the executable project (Project A), make sure that you are instantiating the AGI listener from the ClassLibrary project (Project B). For example, if the ClassLibrary project (Project B) is named "MyLibrary", you would need to change your code to something like this:


var agi = new AsteriskFastAGI();
    
agi.MappingStrategy = new GeneralMappingStrategy(new List<ScriptMapping>()
{
    new ScriptMapping() {
        ScriptClass = "MyLibrary.MyAgi",
        ScriptName = "getvariable"
    }
});
agi.Start();

By specifying the full namespace of the MyAgi class in the ClassLibrary project (Project B), you should be able to instantiate the AGI listener from the executable project (Project A) and still have access to the MyAgi class in the ClassLibrary project (Project B).

I hope this helps you get your AGI listener working again!

Upvotes: -1

Related Questions