示例#1
0
        private void ScanningThread(PlatformIO.DriveInfo drive,
                                    TVolume volume,
                                    BufferedVolumeItemWriter writer)
        {
            TVolume   returnVolume = null;
            Exception fatalError   = null;
            bool      cancelled    = false;

            try {
                if (this.HasDB)
                {
                    Database.TransactionBegin();                      // locks VolumeDatabase
                }
                ScanningThreadMain(drive, volume, writer);
                if (this.HasDB)
                {
                    writer.Close();
                    if (!volume.IsInserted)
                    {
                        volume.InsertIntoDB();
                    }

                    returnVolume = volume;

                    database.TransactionCommit();                     // unlocks VolumeDatabase
                }

                //result = ScanningResult.Success;
                scanSucceeded = true;
            } catch (Exception ex) {
                Exception rollbackException = null;
                try {
                    // rollback all database changes
                    if (this.HasDB)
                    {
                        database.TransactionRollback();                         // unlocks VolumeDatabase
                    }
                } catch (Exception e) {
                    rollbackException = e;
                }


                if (ex is ScanCancelledException)
                {
                    //result = ScanningResult.Cancelled;
                    cancelled = true;
                }
                else
                {
                    //result = ScanningResult.FatalError;

                    /* save the error that caused the scanner to stop (scanning failure) */
                    fatalError = ex;
                    //OnError(new ErrorEventArgs(ex));
                    PostError(ex);

                    Debug.WriteLine("Details for exception in ScanningThread():\n" + ex.ToString());
                }

                // in case an error occured while rollig back,
                // post the error here, _after_ the initial error that made the scan fail.
                if (rollbackException != null)
                {
                    //OnError(new ErrorEventArgs(rollbackException));
                    PostError(rollbackException);
                }

//#if THROW_EXCEPTIONS_ON_ALL_THREADS
//				  if (!(ex is ScanCancelledException))
//					  throw;
//#endif
            } finally {
                /*
                 * TODO : unlock db / thread // (in try / catch / PostError !!) */

                //if (result == ScanningResult.Success)
                //	  m_scanSucceeded = true;

                //m_cancellationRequested = false;
                isRunning = false;

                //try { OnScanCompleted(new ScanCompletedEventArgs(result, mediaID, fatalError)); }
                //catch (Exception e) { OnError(new ErrorEventArgs(e)); }

                PostCompleted(returnVolume, fatalError, cancelled);
            }
        }
示例#2
0
        private void ImportThread(string sourceDbPath,
                                  VolumeDatabase targetDb,
                                  string dbDataPath,
                                  int buferSize)
        {
            Exception fatalError = null;
            bool      cancelled  = false;

            try {
                // must be the first call within the try block
                targetDb.TransactionBegin();                 // locks VolumeDatabase

                if (!File.Exists(sourceDbPath))
                {
                    throw new FileNotFoundException("Source database not found");
                }

                // note:
                // don't use the writer in a using() block here as dispose() would write
                // buffered items after an exception has been thrown.
                BufferedVolumeItemWriter writer = new BufferedVolumeItemWriter(targetDb, true, bufferSize);

                ImportThreadMain(sourceDbPath,
                                 targetDb,
                                 dbDataPath,
                                 writer);

                writer.Close();

                targetDb.TransactionCommit();                 // unlocks VolumeDatabase
                importSucceeded = true;
            } catch (Exception ex) {
                Exception cleanupException = null;
                try {
                    targetDb.TransactionRollback();                      // unlocks VolumeDatabase

                    foreach (string path in volumeDataPaths)
                    {
                        Directory.Delete(path, true);
                    }
                } catch (Exception e) {
                    cleanupException = e;
                }

                if (ex is ImportCancelledException)
                {
                    cancelled = true;
                }
                else
                {
                    /* save the error that caused the import to stop (import failure) */
                    fatalError = ex;
                    PostError(ex);

                    Debug.WriteLine("Details for exception in ImportThread():\n" + ex.ToString());
                }

                // in case an error occured while cleaning up,
                // post the error here, _after_ the initial error that made the import fail.
                if (cleanupException != null)
                {
                    PostError(cleanupException);
                }

//#if THROW_EXCEPTIONS_ON_ALL_THREADS
//				  if (!(ex is ScanCancelledException))
//					  throw;
//#endif
            } finally {
                isRunning = false;
                PostCompleted(fatalError, cancelled);
            }
        }
示例#3
0
        private void ImportThread(string sourceDbPath,
		                          VolumeDatabase targetDb,
		                          string dbDataPath,
		                          int buferSize)
        {
            Exception fatalError = null;
            bool cancelled = false;

            try {
                // must be the first call within the try block
                targetDb.TransactionBegin(); // locks VolumeDatabase

                if (!File.Exists(sourceDbPath))
                    throw new FileNotFoundException("Source database not found");

                // note:
                // don't use the writer in a using() block here as dispose() would write
                // buffered items after an exception has been thrown.
                BufferedVolumeItemWriter writer = new BufferedVolumeItemWriter(targetDb, true, bufferSize);

                ImportThreadMain(sourceDbPath,
                                 targetDb,
                                 dbDataPath,
                                 writer);

                writer.Close();

                targetDb.TransactionCommit(); // unlocks VolumeDatabase
                importSucceeded = true;

            } catch (Exception ex) {

                Exception cleanupException = null;
                try {
                    targetDb.TransactionRollback();  // unlocks VolumeDatabase

                    foreach (string path in volumeDataPaths)
                        Directory.Delete(path, true);
                } catch (Exception e) {
                    cleanupException = e;
                }

                if (ex is ImportCancelledException) {
                    cancelled = true;
                } else {
                    /* save the error that caused the import to stop (import failure) */
                    fatalError = ex;
                    PostError(ex);

                    Debug.WriteLine("Details for exception in ImportThread():\n" + ex.ToString());
                }

                // in case an error occured while cleaning up,
                // post the error here, _after_ the initial error that made the import fail.
                if (cleanupException != null) {
                    PostError(cleanupException);
                }

            //#if THROW_EXCEPTIONS_ON_ALL_THREADS
            //				  if (!(ex is ScanCancelledException))
            //					  throw;
            //#endif
            } finally {
                isRunning = false;
                PostCompleted(fatalError, cancelled);
            }
        }