Custom C# Import connector

Ascent Collection Server

Custom C# Import connector

Postby » Wed Feb 24, 2010 2:32 pm

Hey Guys,
I've coded a custom module in C# to import batches and fill in some batchindex fields. Works great.... Except that I get this exception when I run the import for a while (like 2 hours or so).

Here is all the code from my Kofax Import Helper class.

Code: Select all
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using Kofax.AscentCaptureModule;
using System.Threading;

namespace KofaxImportHelper
{
    class ImportHelper
    {
        private Application m_oApp = null;
        private KofaxImportHelperUI m_oUI = null;

        public ImportHelper(KofaxImportHelperUI kih)
        {
            m_oUI = kih;
            ImportLoginClass ilc = new ImportLoginClass();
            ilc.Login("", ""); //empty user pass
            m_oApp = ilc.ActiveApplication;
        }

        public string[] getAvailableBatches()
        {
            int iBatchCount = m_oApp.BatchClasses.Count;
            string[] names = new string[iBatchCount];
           
            if (iBatchCount > 0)
            {
                int i = 0;
                foreach(BatchClass bc in m_oApp.BatchClasses)
                {
                    names[i++] = bc.Name;
                }
            }

            return names;
        }


        public void importRepository(object batchName, object pathInput)
        {
            BatchClass bc = getBatchClassFromName((string)batchName);

            DirectoryInfo diInput = new DirectoryInfo((string)pathInput);
           
            foreach (DirectoryInfo numeroDir in diInput.GetDirectories())
            {
                string sBatchName = diInput.Name + " - " + numeroDir.Name;
                m_oUI.Log(sBatchName + Environment.NewLine);
               
                Batch b = m_oApp.CreateBatch(ref bc, sBatchName);
               
                setBatchField(b.BatchFields, "NomRevue", diInput.Name);
                setBatchField(b.BatchFields, "Numero", numeroDir.Name);

                FileInfo[] files = numeroDir.GetFiles();
               
                for(int i = 0; i < files.Length; i++)
                {
                    if (files[i].Extension.ToLower().Equals(".tif") || files[i].Extension.ToLower().Equals(".jpg"))
                    {
                        m_oUI.Log(".");
                       
                        b.ImportFile(files[i].FullName);
                    }
                }
                m_oUI.Log(Environment.NewLine);

                if (b.Documents.Count > 0)
                {
                    m_oApp.CloseBatch();
                }
                else
                {
                    m_oApp.DeleteBatch();
                }
            }
            m_oUI.Log(Environment.NewLine + "Done" + Environment.NewLine);
        }

        private void setBatchField(BatchFields batchFields, string name, string value)
        {
            bool bFound = false;
            foreach (BatchField bf in batchFields)
            {
                if (bf.Name.Equals(name))
                {
                    bFound = true;
                    bf.set_Value(ref value);
                }
            }
            if (bFound == false)
                throw new Exception("Batch index field not found");
        }


        private BatchClass getBatchClassFromName(string batchName)
        {
            foreach (BatchClass bc in m_oApp.BatchClasses)
            {
                if(batchName.Equals(bc.Name))
                    return bc;
            }
            return null;
        }
    }
}



b.ImportFile(files[i].FullName); //Exception is here

So after 2hours or so (its abit random). I get this exception.

Code: Select all
System.Runtime.InteropServices.COMException was unhandled
  Message="Le serveur distant n'existe pas ou n'est pas disponible."
  Source="AscentCaptureModule"
  ErrorCode=-2146827826
  StackTrace:
       à Kofax.AscentCaptureModule.BatchClass_2.ImportFile(String )
       à KofaxImportHelper.ImportHelper.importRepository(Object batchName, Object pathInput)
       à KofaxImportHelper.KofaxImportHelperUI.cmdStartImport_Click(Object sender, EventArgs e)
       à System.Windows.Forms.Control.OnClick(EventArgs e)
       à System.Windows.Forms.Button.OnClick(EventArgs e)
       à System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
       à System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       à System.Windows.Forms.Control.WndProc(Message& m)
       à System.Windows.Forms.ButtonBase.WndProc(Message& m)
       à System.Windows.Forms.Button.WndProc(Message& m)
       à System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       à System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       à System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       à System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       à System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
       à System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       à System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       à System.Windows.Forms.Application.Run(Form mainForm)
       à KofaxImportHelper.Program.Main()
       à System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       à System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       à Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       à System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       à System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       à System.Threading.ThreadHelper.ThreadStart()
  InnerException:


Some of this is in french. Here is the translation for the error message.

Code: Select all
Error Number: -2146827826
Description: The remote server
machine does not exist or is unavailable


My guess is that the login times out after a while. Have you guys encountered any of this ?

Elnono
Participant
 
Posts: 12
Joined: Wed Jan 20, 2010 12:10 pm

Re: Custom C# Import connector

Postby » Mon Jul 26, 2010 11:04 am

Bump... I still have that problem
Participant
 
Posts: 12
Joined: Wed Jan 20, 2010 12:10 pm

Re: Custom C# Import connector

Postby » Wed Sep 29, 2010 3:29 am

I'm not a C expert, but my guess is that you may not be cleaning up, and so there is a memory leak.

for example, when iterating through the batches in Visual Basic, you need to:

Code: Select all
Try
   For Each oBatch In oBatchColl
      'use oBatch somehow

      Marshal.ReleaseComObject(oBatch)
      oBatch = Nothing
   Next oBatch
Catch ex As COMException
   Throw
Finally
   If Not oBatch Is Nothing Then
      Marshal.ReleaseComObject(oBatch)
      oBatch = Nothing
   End If
End Try
Participant
 
Posts: 43
Joined: Tue May 01, 2007 7:45 am
Location: London (UK)


Return to Kofax Capture Import Connector

Who is online

Users browsing this forum: No registered users and 1 guest