SBarnes wrote:Hi Guys
Is it possible to have Jiwa Login as multiple users within the one application space?
As currentlyly logging in involves a call like the line below:
JiwaFinancials.Jiwa.JiwaApplication.Manager.Instance.Logon("MYSERVER", "JiwaDemo", JiwaFinancials.Jiwa.JiwaODBC.database.AuthenticationModes.JiwaAuthentication, "Admin", "password");
My question is related to the use of Jiwa through say an ASP.Net site or self hosted server where multiple users may need to login as themselves (Jiwa Login details) but obviously the code that then interacts with Jiwa will be running within the one application that could possilbly have Jiwa talking to multiple users at the same time.
Whilst as each action takes place the server can logon do what it needs to do and log off rather than try and keep connections open, I think there is still the possiblility of conflict.
Yes, this is possible but I'm not sure how performant it will be.
The JiwaApplication.Manager appears as a singleton, but you can coerce it to behave as a multiton - take a look at the code in this
plugin in the samples an examples forum.
The code of interest is in the "SalesOrder_SaveEnd" method:
- Code: Select all
Public Sub SalesOrder_SaveEnd(sender As Object, e As System.EventArgs)
'Grab a copy of the sessionid that is for the currently logged in database
Dim databaseSessionID As String = JiwaFinancials.Jiwa.JiwaApplication.Session.Instance.SessionID
'Generate a new sessionid to use to identify the connection to the remote jiwa database
Dim remoteDatabaseSessionID = System.Guid.NewGuid().ToString
Try
'Switch sessions (to a new one)
JiwaFinancials.Jiwa.JiwaApplication.Session.Instance.SessionID = remoteDatabaseSessionID
Try
'Logon to remote database
JiwaFinancials.Jiwa.JiwaApplication.Manager.Instance.Logon("ServerName", "DatabaseName", JiwaFinancials.Jiwa.JiwaODBC.database.AuthenticationModes.JiwaAuthentication, "Admin", "password")
'Create a stock transfer
Dim stockTransferObject As JiwaStockTransfer.StockTransfer
stockTransferObject = JiwaApplication.Manager.Instance.BusinessLogicFactory.CreateBusinessLogic(Of JiwaStockTransfer.StockTransfer)(Nothing)
stockTransferObject.CreateNew
'Add a line
Dim someInventoryID As String = "000000000K00000000BQ" 'Part No. 1170 in jiwa demo database
stockTransferObject.Lines.AddLine("", "", someInventoryID)
stockTransferObject.Lines(stockTransferObject.Lines.Count).TransferQuantity = 1
'Save
stockTransferObject.Save
'Re-read after the save
stockTransferObject.Read(stockTransferObject.RecID)
'Activate
stockTransferObject.ActivateRecord
Finally
'Logoff from remote database
JiwaFinancials.Jiwa.JiwaApplication.Manager.Instance.LogOff
End Try
Finally
'Set our session back to the currently logged in database
JiwaFinancials.Jiwa.JiwaApplication.Session.Instance.SessionID = databaseSessionID
End Try
End Sub
You can see we note the current "SessionID", and then establish a new connection with a new sessionID, perform some actions then restore the sessionID in the finally block. In the context of a web server, you can maintain multiple simultaneous users from one process. You'd need to track and associate Jiwa SessionID's with a session variable in your webserver, but this should be quite easy. You can index the particular session when you have many currently established with the JiwaApplication.Manager using the Instances property - i.e.: JiwaApplication.Manager.Instances(MySessionID).