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

Question

Question

Launch Search

SDK
asked on May 29, 2019

Hello, 

I've been looking through the SDK and I can't get LaunchSearch to work without opening another instance of Laserfiche Client. I've used the sample code below with minor modifications to run a search on the repo but every time regardless if there is already a LF Client instance already active it still opens up another one. 

 

Is there something that I'm doing wrong here?

using (ClientManager lfclient = new ClientManager())
{
  // Check to see if there is already at least one visible open instance of the Client.
  if (!lfclient.IsClientOpen())
  {
    // If there is none, open the client and log in to the specified repository
    // with Windows authentication.
    LaunchOptions options = new LaunchOptions();
    options.ServerName = "SampleServer";
    options.RepositoryName = "SampleRepository";
    ClientInstance singleLFexe = lfclient.LaunchClient(options);
    // Since we create this new instance of the client and log in,
    // there is only one open window, the Folder Browser. Set the
    // current folder to the specified entry ID.
    IEnumerable<ClientWindow> OpenWindows = singleLFexe.GetAllClientWindows();
    foreach (MainWindow FolderBrowser in OpenWindows)
    {
      FolderBrowser.SetCurrentFolder(123456);
    }
  }
  else
  {
    // If there is already an existing visible open instance of the Client,
    // get a list of the existing Clients.
    IList<ClientInstance> OpenLFClients = lfclient.GetAllClientInstances();
    // Use the first one CAT finds and log in to the desired repository.
    ClientInstance singleLFexe = OpenLFClients[0];
    LaunchOptions options = new LaunchOptions();
    options.ServerName = "SampleServer";
    options.RepositoryName = "SampleRepository";
    MainWindow FolderBrowser;
    singleLFexe = lfclient.LogIn(options, out FolderBrowser);
    // Set the current folder in the Folder Browser to the
    // specified entry ID.
    FolderBrowser.SetCurrentFolder(123456);
  }
}
0 0

Answer

SELECTED ANSWER
replied on May 30, 2019

You shouldn't need the logic for detecting an existing instance of the client, that is handled by the LogIn method. The following code works for me, it will reuse an existing client instance that is signed in to the same repository and launch the search within it:

ClientManager lfclient = new ClientManager();
using (lfclient)
{
    MainWindow mainWindow;
    LaunchOptions options = new LaunchOptions();
    options.ServerName = server;
    options.RepositoryName = repository;
    options.UserName = username;
    options.Password = password;

    lfclient.LogIn(options, out mainWindow);

    SearchOptions searchOption = new SearchOptions();
    searchOption.EagerlyRetrieveResults = true;
    searchOption.NewWindow = false; // tells the client to reuse the window if possible
    searchOption.OpenIfOneResult = false;
    searchOption.Query = "test";
    searchOption.LeftPaneDisplay = LeftPane.FolderTree; // tells the client what to do with the left pane

    List<int> entries = mainWindow.LaunchSearch(searchOption) as List<int>;
}

 

1 0
replied on May 30, 2019

Awesome Robert! thanks for the help I'll try it out and report back here shortly. One other question for you. At what point should I "dispose/terminate/close" out a session?


The little tool I'm creating will grab some data from one section, create a document in LF, assign metadata, and launch scanning with that document to add pages to it. As well as just running a search based off of some other data elsewhere. 

 

But when I look at sessions in LF Admin, even after I close out of my program and it's done running through the "using" statements the sessions still are active, and I'm reaching my max of 4 very quickly. 


Thanks again for the assistance I really appreciate it! 

0 0
replied on May 30, 2019

How are these sessions created, through ClientManger or manually with Laserfiche.RepositoryAccess.Session?

0 0
replied on May 31, 2019

Hey Robert, 

So I tried the code yesterday and it's working (I think), is there anyway for it to not open up another window with the search results?

 

The sessions are being created with Client Manager and it looks like it is correctly killing the sessions after closing out the client. 

0 0
replied on May 31, 2019

Set NewWindow=false to reuse the existing window for the search results.

 

For the extra sessions issue, are you saying that when using LogIn, it will reuse the existing window but still create a new session? That doesn't sound right. I need more information about how your application works to point you in the right direction.

1 0
replied on May 31, 2019

So I have a button then when clicked runs this code:

If I don't have a client opened, it launches the client logs into the repo and runs the search. 

If a client is already opened it does the same thing, I can see it launch the client, login to the repo and run the search, at this point I will have two search result windows opened. 

            ClientManager lfclient = new ClientManager();
            using (lfclient)
            {
                MainWindow mainWindow;
                LaunchOptions options = new LaunchOptions();
                options.ServerName = "XXXX";
                options.RepositoryName = "XXXX";

                lfclient.LogIn(options, out mainWindow);

                SearchOptions searchOption = new SearchOptions();
                searchOption.EagerlyRetrieveResults = true;
                searchOption.NewWindow = false; // tells the client to reuse the window if possible
                searchOption.OpenIfOneResult = false;
                searchOption.Query = "test";
                searchOption.LeftPaneDisplay = LeftPane.FolderTree; // tells the client what to do with the left pane
                List<int> entries = mainWindow.LaunchSearch(searchOption) as List<int>;
            }

 

0 0
replied on July 16, 2019 Show version history

This remaining issue was due to the application logging in using Windows authentication, but with the Windows account linked to a repository trustee. Once the Windows account was unlinked from the repository trustee and configured independently under the Windows Accounts node in the Laserfiche Administration Console, then things worked fine.

 

*Edit* - this behavior is actually a bug and unlinking the Windows account from the repository trustee is a workaround. The issue is fixed in ClientAutomation.dll v10.4+

1 0

Replies

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

Sign in to reply to this post.