Routing ProfilerMessage through our own IChannel implementation

Posts   
 
    
AlexP
User
Posts: 17
Joined: 24-Jan-2020
# Posted on: 26-Oct-2023 09:44:26   

Hi,

I'm trying to implement my own IChannel implementation for eventually routing ProfilerMessages through a DiagnosticSource. But it's not being called, why .. do we have to enable something?

We're using LLBLGen 5.10.2 and Interceptor 2.0.7

Our very basic (for now) Channel

public class MyChannel : IChannel
{
    // private DiagnosticSource _source = new DiagnosticListener("LLBLGen");

    public void Send(ProfilerMessage message)
    {
        Debug.WriteLine(message.GetType(), nameof(LLBLGenDiagnosticsChannel));

        //switch (message)
        //{
        //  case CommandExecutionStartedMessage msg:
        //      _source.Write("QueryStart", null);
        //      break;
        //  case CommandExecutionEndedMessage msg:
        //      _source.Write("QueryEnd", null);
        //      break;
        //}    
    }

    public void Flush() { }

    public void DisableMessageSending()
    {
        /* ignore, it should always keep running */
    }

    public void EnableMessageSending()
    {
        /* ignore, it will always be running */
    }
}

Initialization

InterceptorCore.Initialize("MyApplicationName");
InterceptorCore.RegisterChannel(new MyChannel());
InterceptorCore.EnableMessageSending(); 

// Disable all channels (as we can't remove them), our own channel will not be listening to this instruction
// eventually we will replace/create the factories using ProfilerDbProviderFactory<T> ourselves to prevent 
// the NamedPipeChannel+threads to be registered ...  or LLBLGen should provide a way of unregistering channels
// InterceptorCore.DisableMessageSending(); 

Using DbProviderFactories.GetFactoryClasses() I can see all factories have correctly be replaced by the ProfilerDbProviderFactory.

Kind regards, Alexander

AlexP
User
Posts: 17
Joined: 24-Jan-2020
# Posted on: 26-Oct-2023 10:13:03   

I think I found it, when I do the InterceptorCore Initialization first, before initliazing llblgen, it grabs the correct ProfilerDbProviderFactory.

Or isn't this the trick?

Walaa avatar
Walaa
Support Team
Posts: 14983
Joined: 21-Aug-2005
# Posted on: 26-Oct-2023 11:40:44   

That's it.

AlexP
User
Posts: 17
Joined: 24-Jan-2020
# Posted on: 26-Oct-2023 21:34:12   

Walaa wrote:

That's it.

I understand that invoking InterceptorCore.Initialize registers a NamedPipe channel. One that starts several threads and keeps a queue of ProfileMessage’s. Is it possible to NOT have this channel created? Right now we’re doing the replacement of the registered DbProviderFactory ourselves … using the ProfilerDbProviderFactory<T> provided by LLBLGen . This works and provides us with everything we need… but we would prefer using LLBLGen functionality. For obvious reasons.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39752
Joined: 17-Aug-2003
# Posted on: 27-Oct-2023 09:11:32   

The initialize method creates the channel so the messages will be send to the client. If you just want to wrap things, you can pass the factory to our framework with a wrapper factory and do the interception yourself. So if you do the wrapping but not calling initialize, you'll have to gather the messages / data yourself but you also don't get the channel. Isn't that what you're after?

Frans Bouma | Lead developer LLBLGen Pro