You are viewing limited content. For full access, please sign in.

Question

Question

Share connection between two processes

asked on November 6, 2013

Dears,

 

According to the subject of the question look at this scenario:

 

I have two different tools (processes) each one hase its own button in laserfiche toolbar,

When I open both in Laserfiche, I need to share the same connection.

If i opened first one, I can take the the same connection to be used in the second one.

 

 Who i can do that, worth mentioning that I alread know how to use LFClient library to get the current user connection of the running client application.

 

It's an urgent and it's appreciated if you answered quickly...

 

Thanks,

1 0

Replies

replied on November 6, 2013 Show version history

You can use the following way to piggyback on an existing connection and use the "LFDB" output to get entry from Laserfiche:

 

// Get the open client object
LFClient.Document client = (LFClient.Document)System.Runtime.InteropServices.Marshal.GetActiveObject("LFClient.Document");

// Create a connection object
LFSO90Lib.LFConnection ClonedConn = new LFSO90Lib.LFConnection();

// Clone connection from open client
ClonedConn.CloneFromSerializedConnection(client.GetEngineConnection());

// Get LFDatabase from cloned connection
LFDB = ClonedConn.Database;

edit: this is assuming that you have Laserfiche Client open where you are using its connection on each of your processes.

3 0
replied on November 6, 2013

You could try my solution from https://support.laserfiche.com/ForumsFrames.aspx?Link=viewtopic.php%3ft%3d20022%26amp%3bhighlight%3ddelegated%26amp

 

Which I'm reposting here... Cliff was asking how to pass a connection through WCF.

 

I'd recommend using the method GetDelegatedAccessToken on the connection object (ILFConnection). It should return a two element string array. The first value is the 'user name' and the second value is the 'password'. You should then be able to use those to login on the other side of your WCF call.

The 4 parameters

1) Expiration Time - Time for the token to expire (recommend a value as small as possible)
2) Max Uses - The number of times it can be used (recommend 1)
3) Privileges - the privileges of the current connection to be delegated
4) Readonly - indicates the delegated connection be read only

 

 

Alternatively, you could get your own serialized connection from your current connection, but its harder to send that byte[] array between machines from my experience.

1 0
replied on November 13, 2013 Show version history

Each Avante license is allowed about four simultaneous connections to Laserfiche. Cloning allows many application to share one connection.

 

It sound like what you need to achive your goal.

 

Also, what do you think is the cause of the five secoind delay?

 

-Ben

 

1 0
replied on November 13, 2013

I don't know what is the reason on of that delay!

you said that many application shares one connection. HOW????

How can I use this cloning to share the connection between applications?

 

Thanks,

0 0
replied on November 14, 2013 Show version history

Hi,

 

Actually, I've misinformed.  Each Avante license gets a number of connections - I don't know what the official number is but I always get four.

 

Each one of those connections can be used by multiple programs. I have no idea how many programs can share a connection but to do so, I use the LFConnection.CloneFromSerializedConnection method.

 

Ed recommended the GetDelegatedAccessToken method which might be better in some situations that I've used CloneFromSerializedConnection. It uses a login, so is isolated against accidentally disconnecting lf.exe and allows login with out presenting an additional login screen _and_ seems fast in my petri-dish test. 

 

Using a COM example:

Dim l_oClient As Object = GetObject(Nothing, "LFClient.Document")
Dim l_oTmpDB As LFDatabase = l_oClient.GetDatabase()
Dim l_oTmp() As Object = l_oTmpDB.CurrentConnection.GetDelegatedAccessToken(CDate("20 january 2014"), 1, Nothing, True)
Dim l_oApp As New LFApplication
l_oTmpDB = l_oApp.ConnectToDatabase("test-repos", "lfserver", l_oTmp(0), l_oTmp(1))
m_oLFConn = l_oTmpDB.CurrentConnection
MsgBox(m_oLFConn.UserName)

easy-peasy and no Base64 encoding in this particular example.

 

Using CloneFromSerializedConnection means that issuing a disconnect on the cloned connection disconnects the originating connection (so if you close LF.exe's connection for your app then call LFConnection.Close (or dispose, I forget at the moment) you will discoonect LF.exe as well. Creating a brand new connection 

 

-Ben

0 0
replied on November 6, 2013

This question is confusing. What exactly is the problem?

0 0
replied on November 6, 2013

Connecting to Laserfiche server by user name and password by code takes around 5 seconds.

when the users open my applications  many times, they bored from the delay, so I need to connect one time and if a new call to whatever application the current connection of the first one will be used (to avoid reconnect again and again).

 

 

Thanks,

0 0
replied on November 6, 2013

I know this, but I need to piggyback a connection from my own application not from LFClient

0 0
replied on November 7, 2013

I don't need to create new connections, I need to use an existing connection, so the first solution doesn't fit my concern.

The second one is exactly what I need, but I need it to be used in the same machine.

Can you tell me how I can serialize and send array of bytes to other application, in order to use the same connection.

 

It will be appriciated if you do so.

 

Thanks in advance,

0 0
replied on November 8, 2013

There are a number of ways to achieve this. It depends on the type of application communication going on.

 

If you are starting a command line program, convert the byte array to base 64 and pass it via the command line.

 

If you want to send it to a running service, look at creating a wcf service (I'd recommend using a named pipe for on machine only communication). The internet is full of examples on how to do this (like say http://stackoverflow.com/questions/4618098/send-string-commands-or-bytes-to-a-windows-service-when-running) .

 

 

 

 

0 0
replied on November 9, 2013

In order to convert the connection object to byte array I have to use serialization, in effect, the Laserfiche connection is com object and doesn't marked as serializable.

so there is no easy way to pass the connection as base 64 string or binary format.

The same thing also applies to shared memory or mapped memory file.

 

I thing it can be done using interprocess commuincation  (IPC) to allow muliple processes to share the same instance of an object in the same machine. In fact, I have no idea about that.

Could you please give me an example in a simple way, or link. It will be highly appreciated.

 

Thanks for your intersting.

0 0
replied on November 9, 2013

Additionally, I don't know what is the benefit of using "Cloning a connection object from an existing connection" in LFSO library. or what is the benefit of using serializaed connection.

 

I didn't find any complete topic discuss this point. or real world example.

 

could you please give me any real example of using them, and the real purpose of them.

 

Thank you

0 0
replied on November 15, 2013

OK, I apologize, no one answered my question.

simply, how to call/use the clonned connection from application to application NOT from LFClient application to other application.

application means my customized application.

 

EX. I need to expose lfconnection object to be used from other application. like LFClient.Document does.

 

when my application runs, I need to call it (getObject) like calling LFClient.document

 

thanks

 

0 0
replied on November 18, 2013 Show version history

Sounds like a DCOM, ActiveX or webservice type scenario to me. I'm guessing you'd like to create a conncetion-server type of scenario, perhaps?

 

Sounds unusual. What's the purpose? Laserfiche API allows a interrogation of existing connections, if using a particular is important.

 

-Ben

 

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.