11-23-2016 9:24 AM - edited 02-03-2024 6:03 PM
I am using SAP Business One 9.2 SDK UI and DI API in C# to write an addon which executes business logic and creates numerous forms on many parts of B1. I am thinking about making it modular, so every module has its own event handlers, menu registers and event filters. Is it a good idea to create multiple SAPbouiCOM.Application instances and pass them to the modules? Let's say I have 10-20 different modules and they subscribe to different Application.*events* and set different Application.SetFilters(). Will It slow down B1 like If I am running too many addons?
Edit.: All the modules register their events on the same thread and created on the same thread, becouse the SDK is single threaded/ not thread safe.
Hi Szabolcs,
The SAPbouiCOM.Application object is created when you connect with B1. You shouldn't create many connections (issues with memory and speed will rise).
You can create a connection and pass the created application object to your modules, they can then register their events with that application object. On a side note, you should probably pass also the SAPbobsCOM.Company to your modules.
When registering directly with the application object you'll have to manage the bubbleEvent flag carefully.
Pedro Magueija
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It I use one Application, I will slowly defeat the purpose of event filters, because as I add my modules to the addon, I will add more and more filters and every module will get notified by the application. If there are multiple applications, each has its own filters and will only notify the modules it supports. The question is the balance, does it worth it?
Hi Szabolcs,
Not quite, if you add more and more filters it will still be for specific forms (and in 9.2 even specific items), thus you'll only receive the events on those forms (which is what you want).
Also, note that the filters are valuable in the sense that in the same form you only get the events that you are interested in. If you have many filters registered but you never get to the point where they are triggered that is fine. But being in a form where 100 events are triggered but you are only interested in one, that is where filters show their worth.
Having multiple application (connections) will be very heavy in terms of memory consumption and speed once you start having many modules.
My recommendation is that you use only one connection, but ultimately it's your decision.
Pedro Magueija
I just realized something. Correct me if I am wrong please.
If I register two different methods for the same event and one would like to set the BubbleEvent to false, then the one that would like to set the BubbleEvent to false needs to be registered last, otherwise the ones that would leave it as true would set the flag to true in the sdk and even if the last one sets it to false, it wouldn't work., because its get overwritten by a true value later.
This creates some pretty nasty dependency between my modules. That is why I first thought about creating multiple Application objects.
I think I should just introduce a rule for my modules which wouldn't allow the handling of the same event for different modules.
Hi Szabolcs,
Yep, that is what I meant with my above post:
- When registering directly with the application object you'll have to manage the bubbleEvent flag carefully.
One common approach is to check the current value of BubbleEvent before handling the event.
If the value is false, don't call your handler.
Pedro Magueija
Hi
I am also on a Addon with different Modules with there own different Events. My Addon is written in VB.Net for SAP B1 9.2 (I also understand C#)
My Quest is: how do I get different Events for different Forms with the same application object?
I understand how to connect to SAP B1:
Public Module SAPConnect
Public Shared SAPApp As SAPbouiCOM.Application = Nothing
Public Shared SAPCom As SAPbobsCOM.Company = Nothing
Public Sub Connect(sSAPConnectString As String)
Try
If SAPApp Is Nothing Then
Dim SboGuiApi As SAPbouiCOM.SboGuiApi = New SAPbouiCOM.SboGuiApi
' connect to a running SBO Application
SboGuiApi.Connect(sSAPConnectString)
' get an initialized application object
SAPApp = SboGuiApi.GetApplication()
SAPCom = SAPApp.Company.GetDICompany()
End If
Catch ex As Exception
MsgBox("CSTCore.SAPConnect.Connect: Connection fail:" & ex.Message,, "CSTCore")
End Try
End Sub
End Module
But how do I get different EventFilters for the different Modules/Forms?
If I do the following, it overwrites the first Filter and both Events are rising on Form '139'
But SAPApp_TestModule1.ItemEvent should rise on Form 150 and SAPApp_TestModule2.ItemEventshould rise on Form 139.
Public Module TestModule1
Private WithEvents SAPApp_TestModule1 As SAPbouiCOM.Application
Public Sub Initalize()
'Get the App
SAPApp_TestModule1 = SAPConnect.SAPApp
'Add EventFilter
Dim oFilters As New SAPbouiCOM.EventFilters
Dim oFilter As SAPbouiCOM.EventFilter
oFilter = oFilters.Add(SAPbouiCOM.BoEventTypes.et_CLICK)
oFilter.AddEx("150")
SAPApp_TestModule1.SetFilter(oFilters)
End Sub
Private Sub SAPApp_ItemEvent(ByVal FormUID As String, ByRef pVal As SAPbouiCOM.ItemEvent, ByRef BubbleEvent As Boolean) Handles SAPApp_TestModule1.ItemEvent
Call Debug.Print("SAPApp_ItemEven;TestModule1;" & pVal.EventType.ToString & ";" & pVal.FormType)
End Sub
End Module
Public Module TestModule2
Private WithEvents SAPApp_TestModule2 As SAPbouiCOM.Application
Public Sub Initalize()
'Get the App
SAPApp_TestModule2 = SAPConnect.SAPApp
'Add EventFilter
Dim oFilters As New SAPbouiCOM.EventFilters
Dim oFilter As SAPbouiCOM.EventFilter
oFilter = oFilters.Add(SAPbouiCOM.BoEventTypes.et_CLICK)
oFilter.AddEx("139")
SAPApp_TestModule2.SetFilter(oFilters)
End Sub
Private Sub SAPApp_ItemEvent(ByVal FormUID As String, ByRef pVal As SAPbouiCOM.ItemEvent, ByRef BubbleEvent As Boolean) Handles SAPApp_TestModule2.ItemEvent
Call Debug.Print("SAPApp_ItemEven;TestModule2;" & pVal.EventType.ToString & ";" & pVal.FormType)
End Sub
End Module
Is that possible without do something like:
If pVal.FormType = 150 Then...
Thanks
Andy
You're right because you are registering with the application object event.
You can raise your own event (same arguments, except for the out bubbleEvent, make it a simple argument).
You can then use stopEvent &= true or false; in your handlers.
Finally, assign your bubbleEvent to B1's BubbleEvent.
pseudo code:
... OnItemEvent(ItemEvent pVal, out bool BubbleEvent)
{
bool stopEvent;
RaiseMyItemEvent(pVal, ref stopEvent);
BubbleEvent = stopEvent;
}
Does it make sense?
ps: sorry about the poor indenting but this new editor is getting on my nerves (I wrote this reply twice now).
Pedro Magueija
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
108 | |
12 | |
11 | |
6 | |
6 | |
4 | |
4 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.