Exemplo n.º 1
0
        public bool Start(DirectImageTransfer data, bool copy, Action<ScannedImage> imageCallback)
        {
            ProgressTitle = copy ? MiscResources.CopyProgress : MiscResources.ImportProgress;
            Status = new OperationStatus
            {
                StatusText = copy ? MiscResources.Copying : MiscResources.Importing,
                MaxProgress = data.ImageRecovery.Length
            };
            cancel = false;

            thread = threadFactory.StartThread(() =>
            {
                Exception error = null;
                foreach (var ir in data.ImageRecovery)
                {
                    try
                    {
                        using (var bitmap = new Bitmap(Path.Combine(data.RecoveryFolder, ir.FileName)))
                        {
                            var img = new ScannedImage(bitmap, ir.BitDepth, ir.HighQuality, -1);
                            foreach (var transform in ir.TransformList)
                            {
                                img.AddTransform(transform);
                            }
                            img.SetThumbnail(img.RenderThumbnail(userConfigManager.Config.ThumbnailSize));
                            imageCallback(img);

                            Status.CurrentProgress++;
                            InvokeStatusChanged();
                            if (cancel)
                            {
                                break;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        error = ex;
                    }
                }
                if (error != null)
                {
                    Log.ErrorException(string.Format(MiscResources.ImportErrorCouldNot, data.RecoveryFolder), error);
                }
                Status.Success = true;
                InvokeFinished();
            });
            return true;
        }
Exemplo n.º 2
0
            private bool DoRecover(Action<ScannedImage> imageCallback)
            {
                Status.MaxProgress = recoveryIndexManager.Index.Images.Count;
                InvokeStatusChanged();

                foreach (RecoveryIndexImage indexImage in recoveryIndexManager.Index.Images)
                {
                    if (cancel)
                    {
                        return false;
                    }

                    string imagePath = Path.Combine(folderToRecoverFrom.FullName, indexImage.FileName);
                    using (var bitmap = new Bitmap(imagePath))
                    {
                        var scannedImage = new ScannedImage(bitmap, indexImage.BitDepth,
                            indexImage.HighQuality, -1);
                        foreach (var transform in indexImage.TransformList)
                        {
                            scannedImage.AddTransform(transform);
                        }
                        scannedImage.SetThumbnail(
                            scannedImage.RenderThumbnail(userConfigManager.Config.ThumbnailSize));
                        imageCallback(scannedImage);
                    }

                    Status.CurrentProgress++;
                    InvokeStatusChanged();
                }
                return true;
            }