コード例 #1
0
        private Bitmap ScanDocument()
        {
            var deviceCount = _wiaManager.GetDeviceCount();

            if (deviceCount == 0)
            {
                _actionResult.AddError("No devices found.");
                return(null);
            }

            Scanner scanner = null;

            if (!_viewModel.ScanSettings.ShowScanDialog)
            {
                scanner = _wiaManager.GetScanner(_viewModel.ScanSettings.SelectDevice);
                if (scanner == null)
                {
                    _actionResult.AddError("Scanner not found");
                    return(null);
                }
                scanner.ImageColorMode  = _viewModel.ScanSettings.ImageColorMode;
                scanner.ImageResolution = _viewModel.ScanSettings.ImageResolution;
            }

            var image = _wiaManager.ScanDocument(_viewModel.ScanSettings.SelectDevice, scanner, _actionResult);

            if (image != null)
            {
                _actionResult.AddInfo("Image scanned.");
            }
            return(image);
        }
コード例 #2
0
 private static void ValidateArchiveEntry(IArchiveEntry <T> archiveEntry, IActionResult actionResult)
 {
     if (archiveEntry.Entity == null)
     {
         actionResult.AddError(Resources.Message_Entity_information_is_not_defined_for_the_entry_N, archiveEntry.Path);
     }
     if (archiveEntry.EntityType == null)
     {
         actionResult.AddError(Resources.Message_Entity_type_information_is_not_defined_for_the_entry_N, archiveEntry.Path);
     }
     foreach (var subArchiveEntry in archiveEntry.Items)
     {
         ValidateArchiveEntry(subArchiveEntry, actionResult);
     }
 }
コード例 #3
0
        private object UnPackEntity(IArchiveEntry <ZipArchiveEntry> archiveEntry, Type entryType, IActionResult actionResult)
        {
            if (archiveEntry.Entity != null)
            {
                return(UnPackEntity(archiveEntry.Entity, entryType, actionResult));
            }

            actionResult.AddError(Resources.Message_Archive_entry_entity_is_empty_for_path_N, archiveEntry.Path);
            return(null);
        }
コード例 #4
0
        private Type UnPackEntityType(IArchiveEntry <ZipArchiveEntry> archiveEntry, IActionResult actionResult)
        {
            if (archiveEntry.EntityType != null)
            {
                return(UnPackEntity(archiveEntry.EntityType, typeof(TypeInfo), actionResult) as Type);
            }

            actionResult.AddError(String.Format(Resources.Message_Archive_entry_entity_type_is_empty_for_path_N, archiveEntry.Path));
            return(null);
        }
コード例 #5
0
 private static void ValidateEntity <T>(object entity, IActionResult actionResult)
 {
     if (entity == null || !actionResult.Success)
     {
         return;
     }
     if (!(entity is T))
     {
         actionResult.AddError(Resources.Message_A_type_N_was_expected_by_the_following_type_was_loaded_M, typeof(T), entity.GetType());
     }
 }
コード例 #6
0
 /// <summary>
 /// Unpach the stage from the archive.
 /// </summary>
 /// <param name="archiveFilePath">The path to the archive with the stage.</param>
 /// <param name="actionResult">The result of the unpacking of the archive.</param>
 /// <returns>The unpacked stage.</returns>
 public IStage UnPack(string archiveFilePath, IActionResult actionResult)
 {
     try
     {
         CreateDirectoryForFileIfNotExists(archiveFilePath);
         using (var fileStream = File.OpenRead(archiveFilePath))
             using (var archive = new ZipArchive(fileStream, ZipArchiveMode.Read))
             {
                 return(UnPackStage(archive, actionResult));
             }
     }
     catch (InvalidDataException e)
     {
         actionResult.AddError(Resources.Message_The_archive_N_with_a_stage_might_be_currupted_M, archiveFilePath, e.Message);
     }
     catch (Exception e)
     {
         actionResult.AddError(Resources.Message_The_archive_N_with_a_stage_cannot_be_processed_due_to_the_error_M, archiveFilePath, e.Message);
     }
     return(null);
 }
コード例 #7
0
 private object UnPackEntity(ZipArchiveEntry archiveEntry, Type type, IActionResult actionResult)
 {
     try
     {
         using (var stream = archiveEntry.Open())
         {
             return(_entityArchiveControllerManager.UnPack(type, stream));
         }
     }
     catch (Exception e)
     {
         actionResult.AddError(Resources.Message_Archive_entry_object_cannot_be_deserialized_N, e.Message);
     }
     return(null);
 }
コード例 #8
0
        private void UnpackGeometryTransformation(IArchiveEntry <ZipArchiveEntry> geometryArchiveEntry, ISceneEntity sceneEntity, IActionResult actionResult)
        {
            var objectSpace = sceneEntity.Geometry as IHasObjectSpace;

            if (objectSpace == null)
            {
                actionResult.AddError(Resources.Message_Transformation_is_found_by_the_entity_does_not_need_it_N, geometryArchiveEntry.Path);
                return;
            }
            var transformationEntity = UnPackEntity(geometryArchiveEntry.Transformation, actionResult);

            ValidateEntity <Transformation>(transformationEntity, actionResult);
            if (!actionResult.Success)
            {
                return;
            }
            ((Transformation)transformationEntity).Transform(objectSpace.Transformation);
        }
コード例 #9
0
        public Bitmap ScanDocument(bool showDevicesDialog, Scanner scanner, IActionResult actionResult)
        {
            Bitmap bitmap = null;

            WrapCOMError(() =>
            {
                ImageFile scannedImageFile;
                try
                {
                    const string bmpFormatID = "{B96B3CAB-0728-11D3-9D7B-0000F81EF32E}";
                    if (scanner != null && scanner.Device != null)
                    {
                        scannedImageFile = CommonDialog.ShowTransfer(scanner.Device, bmpFormatID, true) as ImageFile;
                    }
                    else
                    {
                        scannedImageFile = CommonDialog.ShowAcquireImage(WiaDeviceType.ScannerDeviceType, WiaImageIntent.TextIntent,
                                                                         WiaImageBias.MaximizeQuality, bmpFormatID, showDevicesDialog, false, true) as ImageFile;
                    }
                    if (scannedImageFile == null)
                    {
                        actionResult.AddError("Scanning failed.");
                    }
                }
                catch (COMException e)
                {
                    const int operationCancelledErrorResult = -2145320860;
                    if (e.ErrorCode != operationCancelledErrorResult)
                    {
                        throw;
                    }
                    actionResult.AddInfo("Scanning canceled.");
                    return;
                }
                bitmap = SaveFile(scannedImageFile);
            });
            return(bitmap);
        }