Ejemplo n.º 1
0
            public IEnumerable <IScannedImage> RecoverScannedImages()
            {
                StartRecovery();
                if (folderToRecoverFrom == null)
                {
                    yield break;
                }
                try
                {
                    recoveryIndexManager = new RecoveryIndexManager(folderToRecoverFrom);
                    imageCount           = recoveryIndexManager.Index.Images.Count;
                    scannedDateTime      = folderToRecoverFrom.LastWriteTime;
                    if (imageCount > 0)
                    {
                        // If there are no images, do nothing. Don't delete the folder in case the index was corrupted somehow.
                        switch (PromptToRecover())
                        {
                        case DialogResult.Yes:
                            foreach (var scannedImage in DoRecover())
                            {
                                yield return(scannedImage);
                            }
                            DeleteRecoveryFolder();
                            break;

                        case DialogResult.No:
                            DeleteRecoveryFolder();
                            break;
                        }
                    }
                }
                finally
                {
                    FinishRecovery();
                }
            }
Ejemplo n.º 2
0
            public bool Start(Action <ScannedImage> imageCallback)
            {
                Status = new OperationStatus
                {
                    StatusText = MiscResources.Recovering
                };
                cancel = false;

                folderToRecoverFrom = FindAndLockFolderToRecoverFrom();
                if (folderToRecoverFrom == null)
                {
                    return(false);
                }
                try
                {
                    recoveryIndexManager = new RecoveryIndexManager(folderToRecoverFrom);
                    imageCount           = recoveryIndexManager.Index.Images.Count;
                    scannedDateTime      = folderToRecoverFrom.LastWriteTime;
                    if (imageCount == 0)
                    {
                        // If there are no images, do nothing. Don't delete the folder in case the index was corrupted somehow.
                        ReleaseFolderLock();
                        return(false);
                    }
                    switch (PromptToRecover())
                    {
                    case DialogResult.Yes:     // Recover
                        threadFactory.StartThread(() =>
                        {
                            try
                            {
                                if (DoRecover(imageCallback))
                                {
                                    ReleaseFolderLock();
                                    DeleteFolder();
                                    Status.Success = true;
                                }
                            }
                            finally
                            {
                                ReleaseFolderLock();
                                GC.Collect();
                                InvokeFinished();
                            }
                        });
                        return(true);

                    case DialogResult.No:     // Delete
                        ReleaseFolderLock();
                        DeleteFolder();
                        break;

                    default:     // Not Now
                        ReleaseFolderLock();
                        break;
                    }
                }
                catch (Exception)
                {
                    ReleaseFolderLock();
                    throw;
                }
                return(false);
            }