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

Question

Question

SDK Automation - Scanning Option Connection String (Serialized) Is Not Working

asked on March 16, 2015 Show version history

Hello everyone, 

I'm using SDK Automation to create simple tool to launch scanning with specific options, I pass serialized connection string with scanoptions.ConnectionString parameter to LaunchScanning() on Laserfiche.ClientAutomation to use current connection instead of creating new one, but it doesn't work.

I don't get any errors when I use serialized connection but the scanning interface is not working, on the other hand when I use ServerName, RepositoryName, UserName and Password parameters it's working. 

I tried debugging the code and the serialized connection string is being passed correctly.

Can any one help please?

  • LF SDK Version: 9.2
  • OS: Windows 8.1 single language

 

Below you find my code:

LFSO92Lib.LFDatabase lfdb;
private void ButtonScan_Click(object sender, EventArgs e)
{	                                        
    try {                                       
         //---------------------
        Laserfiche.ClientAutomation.ClientManager lfclient = new Laserfiche.ClientAutomation.ClientManager();
        IList<int> selectedentries = (IList<int>)lfclient.GetAllSelectedEntries();                    
        IEnumerable<ClientInstance> clients = lfclient.GetAllClientInstances();
        string strSerializedConnection = "";                    
        foreach (ClientInstance _client in clients)
        {                       
            IEnumerable<RepositoryConnection> repos = _client.RepositoryConnections;
            foreach (RepositoryConnection repo in repos)
            {
                if (lfdb == null)
                {                              
                    // Retrieve the serialized connection string and use it to initialize the LFSO connection object
                    strSerializedConnection = repo.GetConnectionString();                                                                                                                                                             
                }
            }
        }                  
        LFSO92Lib.LFConnection lfsoconn = new LFConnection();
        lfsoconn.CloneFromSerializedConnectionString(strSerializedConnection);
        lfdb = lfsoconn.Database;
        //---------------------                                       
        ILFDocument doc = new LFDocument();                    
        LFFolder path = (LFFolder)lfdb.GetEntryByPath("Demo\\Backlog");
        LFVolume vol = (LFVolume)lfdb.GetVolumeByName("DEFAULT");                    
        doc.Create(TextBoxPatientNumber.Text, path, vol, true);
        string serializedconn = strSerializedConnection;
        //string servername = "localhost";
        //string repository = "Demo";                    
        //string username = "lfadmin";
        //string password = "123";                   
        //bool usessl = false;
        //int folderid = 0;
        int documentid = doc.ID;                    
        int insertat = 0; // -3 = Default, -2 = Ask, -1 = End, 0 = Beginning
        bool waitforclose = false;
        bool closeafterstoring = true;
        ScanMode scanmode = ScanMode.Standard;
        //---
        lfsoconn.Terminate(); // To unlock the document after creation
        //---                 
        ScanOptions scanoptions = new ScanOptions();
        scanoptions.ConnectionString = strSerializedConnection;
        //scanoptions.ServerName = servername;
        //scanoptions.RepositoryName = repository;                    
        //scanoptions.UserName = username;
        //scanoptions.Password = password;
        //scanoptions.IsSecureConnection = usessl;
        scanoptions.WaitForExit = waitforclose;
        scanoptions.CloseAfterStoring = closeafterstoring;
        scanoptions.ScanMode = scanmode;
        scanoptions.EntryId = documentid;
        scanoptions.IsDocument = true;
        scanoptions.InsertPagesAt = insertat;                   
        lfclient.LaunchScanning(scanoptions); 
    }
    catch (Exception exc) {
        MessageBox.Show(exc.Message);                    
    }                            
}

 

0 0

Replies

replied on March 16, 2015

The call to lfsoconn.Terminate() logs out the client connection, but you are trying to use that same connection for Scanning. The document should be unlocked automatically when scanning closes, I think you should try generating the serialized connection after creating the document so that it knows about the lock on the document.

0 0
replied on March 16, 2015 Show version history

Thank you Robert for quick reply. 

 

In the code I'm taking the serialized connection string from current connection to two different tasks:

     1. To create new document by establishing new connection based on current connection (Cloning):

               LFSO92Lib.LFConnection lfsoconn = new LFConnection();
               lfsoconn.CloneFromSerializedConnectionString(strSerializedConnection);

     2. To launch scanning interface by Laserfiche automation library which require serialized connection string in order to establish new one for scanning:

               scanoptions.ConnectionString = serializedconn;

So lfsoconn.Terminate() is only to terminate the cloned connection at point 1 (for creation document) and original connection shouldn't affected.

And for point 2 I take the serialized connection string which has the correct value from original connection and pass it to scan option as required to launch scanning but for some reason it doesn't launch nor return any error.

By the way, the same code I've sent it to support team  and they tested it and it worked for them. I'm not sure what is the problem with my case.

0 0
replied on March 26, 2015

It is not working even without calling Terminate().

 

The issue is still exists but I used another way to take user name and password from the current connection to use it with LaunchScanning() which is by using GetDelegatedAccessToken() and it is working fine with me.

 

I found another problem:

When calling LaunchScanning() it will initiate new connection using these username and password but after closing scanning interface; the connection is still remaining for about 3-4 minutes instead of disconnecting immediately, and this causing problem with users when they scan many files they reach the session limit on the fourth file.

0 0
replied on March 26, 2015

I tried your code and found the problem.  It is a bug in ClientAutomation, if you set WaitForExit=false, scanning doesn't get the connection string. Here is what works for me (without using Terminate):

Laserfiche.ClientAutomation.ClientManager lfclient = new Laserfiche.ClientAutomation.ClientManager();
IList<int> selectedentries = (IList<int>)lfclient.GetAllSelectedEntries();
IEnumerable<ClientInstance> clients = lfclient.GetAllClientInstances();
string strSerializedConnection = "";                    
foreach (ClientInstance _client in clients)
{                       
    IEnumerable<RepositoryConnection> repos = _client.RepositoryConnections;
    foreach (RepositoryConnection repo in repos)
    {
        // Retrieve the serialized connection string and use it to initialize the LFSO connection object
        strSerializedConnection = repo.GetConnectionString();
    }
}
LFSO92Lib.LFConnection lfsoconn = new LFConnection();
lfsoconn.CloneFromSerializedConnectionString(strSerializedConnection);
lfdb = lfsoconn.Database;
                          
ILFDocument doc = new LFDocument();
LFFolder path = (LFFolder)lfdb.GetEntryByPath("\\Destination folder");
LFVolume vol = (LFVolume)lfdb.GetVolumeByName("DEFAULT");
doc.Create("new doc for scanning", path, vol, true);
ScanOptions scanoptions = new ScanOptions();

// Get the serialized connection string AGAIN so it includes the lock on the new document
scanoptions.ConnectionString = doc.Database.CurrentConnection.SerializedConnectionString;

// Set true avoid the serialized connection string bug
scanoptions.WaitForExit = true;

scanoptions.CloseAfterStoring = true;
scanoptions.ScanMode = ScanMode.Standard;
scanoptions.EntryId = doc.ID;
scanoptions.IsDocument = true;
scanoptions.InsertPagesAt = 0;
lfclient.LaunchScanning(scanoptions); 

Note that scanoptions.ConnectionString it set by retrieving the serialized connection string again from LFSO. This ensures that the serialized connection string includes the info about the lock new document.

0 0
replied on March 16, 2015

When you call Terminate(), you are logging out all of the cloned connections including the original connection that you called GetConnectionString() on. I am pretty sure you shouldnt' be calling Terminate().

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

Sign in to reply to this post.