Пример #1
0
            public void Dispose()
            {
                engine = null;
                GC.Collect();
                GC.WaitForPendingFinalizers();
                if (engineLoader != null)
                {
                    engineLoader.ExplicitlyUnload();
                    engineLoader = null;
                    GC.Collect();
                    GC.WaitForPendingFinalizers();
                }

                if (!process.WaitForExit(5000))
                {
                    try
                    {
                        process.Kill();
                    }
                    catch (InvalidOperationException)
                    {
                        // The process could exit between a decision to kill it and this code
                        // Skip this error
                    }
                }

                process.Dispose();
                process = null;
            }
Пример #2
0
        static IEngine loadEngine(EngineLoadingMode _engineLoadingMode, out IEngineLoader engineLoader)
        {
            engineLoadingMode = _engineLoadingMode;
            switch (engineLoadingMode)
            {
            case EngineLoadingMode.LoadDirectlyUseNakedInterfaces:
            {
                engineLoader = null;                         // Not used
                IEngine engine  = null;
                int     hresult = InitializeEngine(FceConfig.GetDeveloperSN(), null, null, out engine);
                Marshal.ThrowExceptionForHR(hresult);
                assert(engine != null);
                return(engine);
            }

            case EngineLoadingMode.LoadAsInprocServer:
            {
                engineLoader = new FCEngine.InprocLoader();
                IEngine engine = engineLoader.Load(FceConfig.GetDeveloperSN(), "");
                assert(engine != null);
                return(engine);
            }

            case EngineLoadingMode.LoadAsWorkprocess:
            {
                engineLoader = new FCEngine.OutprocLoader();
                IEngine engine = engineLoader.Load(FceConfig.GetDeveloperSN(), "");
                assert(engine != null);
                return(engine);
            }
            }
            assert(false);
            engineLoader = null;
            return(null);
        }
Пример #3
0
            public EngineHolder(string projectId)
            {
                try
                {
                    engineLoader = new OutprocLoader();

                    // When a process finishes normally, all COM objects are released and work processes hosting these objects also finish
                    // normally. If the process terminates abnormally (hard exception or manually killed) the COM objects are not released
                    // and work processes will remain loaded. To address this issue and make your server more robust you can make
                    // each work process watch if its parent process is still alive and terminate if not.
                    var processControl = (IHostProcessControl)engineLoader;
                    processControl.SetClientProcessId(Process.GetCurrentProcess().Id);

                    process = Process.GetProcessById(processControl.ProcessId);

                    engine = engineLoader.InitializeEngine(projectId, null, null, "", "", false);
                }
                catch (COMException exception)
                {
                    var hResult = (uint)exception.ErrorCode;
                    if (hResult == 0x80070005)
                    {
                        // To use LocalServer under a special account you must add this account to
                        // the COM-object's launch permissions (using DCOMCNFG or OLE/COM object viewer)
                        throw new Exception(@"Launch permission for the work-process COM-object is not granted.
                            Use DCOMCNFG to change security settings for the object. (" + exception.Message + ")");
                    }

                    throw;
                }

                isEngineLocked   = false;
                engineUsageCount = 0;
            }
        public void Dispose()
        {
            foreach (FineReaderDocument doc in documents.Values)
            {
                try
                {
                    doc.Document.Close();
                }
                catch { }
            }

            try
            {
#if DEBUG
                long memorySizeBefore = GC.GetTotalMemory(false);
#endif
                lock (syncRoot)
                {
                    engine   = null;
                    instance = null;
                    engineLoader.ExplicitlyUnload();
                    engineLoader = null;
                    GC.Collect();
                    System.Threading.Thread.Sleep(1);
                    GC.WaitForPendingFinalizers();
                }
#if DEBUG
                long memorySizeAfter = GC.GetTotalMemory(false);
#endif
            }
            catch { }
        }
        private AbbyyManager()
        {
            engineLoader = new InprocLoader();
            engine       = engineLoader.GetEngineObject(licens);

            prepareImageMode = engine.CreatePrepareImageMode();
            prepareImageMode.EnhanceLocalContrast = true;
        }
Пример #6
0
 static void unloadEngine(ref IEngine engine, ref IEngineLoader engineLoader)
 {
     if (engine != null)
     {
         if (engineLoader == null)
         {
             int hresult = DeinitializeEngine();
             Marshal.ThrowExceptionForHR(hresult);
         }
         else
         {
             engineLoader.Unload();
             engineLoader = null;
         }
         engine = null;
     }
 }
        public MainForm(string workDirectory, string fileLoad)
        {
            InitializeComponent();

            // инициализация движка ABBYY
            try
            {
                _engineLoader = new FCEngine.InprocLoader
                {
                    CustomerProjectId = FceConfig.GetCustomerProjectId(), LicensePassword = "", LicensePath = ""
                };
                _engine = _engineLoader.GetEngine();

                //engine = engineLoader.Load(FceConfig.GetCustomerProjectId(), "");
                _processor = _engine.CreateFlexiCaptureProcessor();
                // Initialize DocumentView component
                documentView.Engine = _engine;

                _pathFolderWork = workDirectory;

                if (_pathFolderWork.EndsWith("\\"))
                {
                    _pathFolderWork = _pathFolderWork.Substring(0, _pathFolderWork.Length - 1);
                }

                if (String.IsNullOrEmpty(Path.GetDirectoryName(_pathFolderWork)))
                {
                    throw new Exception(_pathFolderWork + " не является корректной директорией");
                }

                _pathFolderWork += "\\visualeditorfiles\\";
                if (!String.IsNullOrEmpty(fileLoad))
                {
                    _nameCurrentFile = Path.GetFileNameWithoutExtension(fileLoad);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Не удалось загрузить компоненту ABBYY по причине: " + ex.Message);
                Application.Exit();
            }
            //updateButtonsState();
            LoadWorkDocument();
        }
        private void CleanUp()
        {
            // Clear all views
            documentView.Document = null;

            // чистка папок
            new Thread(() =>
            {
                var directoryInfo = Directory.GetParent(_pathFolderWork).Parent;
                if (directoryInfo != null)
                {
                    CleanDirectories(directoryInfo.FullName);
                }
            }).Start();


            // Unload the engine
            if (_engineLoader != null)
            {
                _engineLoader.Unload();
                _engineLoader = null;
            }
            _engine = null;
        }
 static void unloadEngine( ref IEngine engine, ref IEngineLoader engineLoader )
 {
     if( engine != null ) {
         if( engineLoader == null ) {
             int hresult = DeinitializeEngine();
             Marshal.ThrowExceptionForHR( hresult );
         } else {
             engineLoader.Unload();
             engineLoader = null;
         }
         engine = null;
     }
 }
 static IEngine loadEngine( EngineLoadingMode _engineLoadingMode, out IEngineLoader engineLoader )
 {
     engineLoadingMode = _engineLoadingMode;
     switch( engineLoadingMode ) {
         case EngineLoadingMode.LoadDirectlyUseNakedInterfaces:
         {
             engineLoader = null; // Not used
             IEngine engine = null;
             int hresult = InitializeEngine( FceConfig.GetDeveloperSN(), null, null, out engine );
             Marshal.ThrowExceptionForHR( hresult );
             assert( engine != null );
             return engine;
         }
         case EngineLoadingMode.LoadAsInprocServer:
         {
             engineLoader = new FCEngine.InprocLoader();
             IEngine engine = engineLoader.Load( FceConfig.GetDeveloperSN(), "" );
             assert( engine != null );
             return engine;
         }
         case EngineLoadingMode.LoadAsWorkprocess:
         {
             engineLoader = new FCEngine.OutprocLoader();
             IEngine engine = engineLoader.Load( FceConfig.GetDeveloperSN(), "" );
             assert( engine != null );
             return engine;
         }
     }
     assert( false );
     engineLoader = null;
     return null;
 }