public void SetVaule(PartOfBook partOfBook, StatusCode status, int count, int pages, int? seconds) { this.SetVaule(partOfBook, status, count); this.AddPages(pages); if (seconds.HasValue) { this.AddOcrTime(seconds.Value); } }
/// <summary> /// /// </summary> /// <param name="partOfBook"></param> public void SetImageChanged(PartOfBook partOfBook) { switch (partOfBook) { case PartOfBook.FrontCover: if (this.FrontCover != null) this.FrontCover.ImageChanged = true; break; case PartOfBook.TableOfContents: if (this.TableOfContents != null) this.TableOfContents.ImageChanged = true; break; default: break; } }
public void SetVaule(PartOfBook partOfBook, StatusCode status, int count) { switch (status) { case StatusCode.Scanned: switch (partOfBook) { case PartOfBook.FrontCover: FrontCoverScanned = count; break; case PartOfBook.TableOfContents: TableOfContentsScanned = count; break; default: break; } break; case StatusCode.InProgress: switch (partOfBook) { case PartOfBook.FrontCover: break; case PartOfBook.TableOfContents: TableOfContentsInProgress = count; break; default: break; } break; case StatusCode.Discarded: switch (partOfBook) { case PartOfBook.FrontCover: break; case PartOfBook.TableOfContents: TableOfContentsDiscarded = count; break; default: break; } break; case StatusCode.Complete: switch (partOfBook) { case PartOfBook.FrontCover: FrontCoverComplete = count; break; case PartOfBook.TableOfContents: TableOfContentsComplete = count; break; default: break; } break; case StatusCode.Exported: switch (partOfBook) { case PartOfBook.FrontCover: FrontCoverExported = count; break; case PartOfBook.TableOfContents: TableOfContentsExported = count; break; default: break; } break; } }
/// <summary> /// Textuje existenci skenovaní èásti publikace /// </summary> /// <param name="partOfBook"></param> /// <returns></returns> public bool HasPartOfBook(PartOfBook partOfBook) { return (ScanFiles != null ? ScanFiles.Count(f => f.PartOfBook == partOfBook) > 0 : false); }
public bool IsExported(PartOfBook partOfBook) { switch (partOfBook) { case PartOfBook.FrontCover: return (this.FrontCover != null && this.FrontCover.Status == StatusCode.Exported); case PartOfBook.TableOfContents: return (this.TableOfContents != null && this.TableOfContents.Status == StatusCode.Exported); default: return false; } }
public bool IsImageExported(PartOfBook? partOfBook) { return (this.Book != null && partOfBook.HasValue && this.Book.IsExported(partOfBook.Value)); }
/// <summary> /// /// </summary> /// <param name="partOfBook"></param> /// <returns></returns> public bool CanImageChanged(PartOfBook partOfBook) { switch (partOfBook) { case PartOfBook.FrontCover: return (FrontCover == null || FrontCover.Status == StatusCode.Scanned || FrontCover.Status == StatusCode.Discarded || FrontCover.Status == StatusCode.Complete); case PartOfBook.TableOfContents: return (TableOfContents == null || TableOfContents.Status == StatusCode.Scanned || TableOfContents.Status == StatusCode.Discarded || TableOfContents.Status == StatusCode.Complete); default: return false; } }
private void ShowMainImgEdit(PartOfBook? partOfBook) { FrontCoverImgEdit.Visibility = (partOfBook.HasValue && partOfBook.Value == PartOfBook.FrontCover ? Visibility.Visible : Visibility.Hidden); TableOfContentsImgEdit.Visibility = (partOfBook.HasValue && partOfBook.Value == PartOfBook.TableOfContents ? Visibility.Visible : Visibility.Hidden); SetMenuButtonsEnabled(); }
private void StartImageScan(PartOfBook partOfBook) { ShowMainImgEdit(partOfBook); try { if (CheckScannerSettings()) { StartTimer(); this.WorkingGifImage.Visibility = Visibility.Visible; if (Settings.Default.ScanEnablePreview) { if (_scannerThread == null) { _scannerThread = new System.Threading.Thread(() => { lock (_locker) { switch (partOfBook) { case PartOfBook.FrontCover: FrontCoverImgScan.Acquire(); break; case PartOfBook.TableOfContents: TableOfContentsImgScan.Acquire(); break; default: break; } } }); _scannerThread.SetApartmentState(System.Threading.ApartmentState.STA); _scannerThread.IsBackground = true; _scannerThread.Start(); } else { if (_scannerThread.ThreadState == System.Threading.ThreadState.Stopped) { _scannerThread = null; } else { MessageBox.Show("Proces skenování nebyl ukončen.", "StartImageScan", MessageBoxButton.OK, MessageBoxImage.Exclamation); return; } } } else { switch (partOfBook) { case PartOfBook.FrontCover: FrontCoverImgScan.Acquire(); break; case PartOfBook.TableOfContents: TableOfContentsImgScan.Acquire(); break; default: break; } } } else { this.WorkingGifImage.Visibility = Visibility.Hidden; this.Cursor = null; OpenOptionsSettings(); } } catch (Exception ex) { throw ex; } }
private void LoadMainImgEdit(PartOfBook partOfBook, string imageFilePath, int thumbnailIndex = 0) { ShowMainImgEdit(partOfBook); if (String.IsNullOrEmpty(imageFilePath)) { CurrentImgEdit.Close(); return; } if (File.Exists(imageFilePath)) { //if (imageFilePath != MainImgEdit.ImageFilePath) //{ // //MainImgEdit.Close(); // MainImgEdit.ImageFilePath = imageFilePath; // MainImgEdit.Display(); //} //if (MainImgEdit.Page != thumbnailIndex) //{ // MainImgEdit.Page = thumbnailIndex; //} CurrentImgEdit.ImageFilePath = imageFilePath; CurrentImgEdit.Display(); CurrentImgEdit.Page = thumbnailIndex; } else { string message = String.Format("Soubor {0} neexistuje.", imageFilePath); MessageBox.Show(message, "LoadTableOfContentsImgEdit", MessageBoxButton.OK, MessageBoxImage.Exclamation); Logger.Log(message); } }
private void SaveMainImgEdit(PartOfBook partOfBook) { switch (partOfBook) { case PartOfBook.FrontCover: if (HasScannedFrontCover) { int page = FrontCoverImgEdit.Page; FrontCoverImgEdit.SaveImageFormat = ImgEdit.ICImageOutputFormat.JPEG; FrontCoverImgEdit.SaveImageCompression = ImgEdit.ICImageCompression.JPEG; FrontCoverImgEdit.SaveJPGQuality = 80; FrontCoverImgEdit.SaveImageAs(FrontCoverImgEdit.ImageFilePath); //FrontCoverImgEdit.SaveImage(); FrontCoverImgEdit.Page = page; } break; case PartOfBook.TableOfContents: if (HasScannedTableOfContents) { bool bw = (Enumeration.Parse<TwainPixelTypes>(Settings.Default.ScanContentsPixelType).Equals(TwainPixelTypes.BW)); int page = TableOfContentsImgEdit.Page; TableOfContentsImgEdit.SaveImageFormat = ImgEdit.ICImageOutputFormat.TIFF; TableOfContentsImgEdit.SaveImageCompression = (bw ? ImgEdit.ICImageCompression.CCITT4 : ImgEdit.ICImageCompression.LZW); //TableOfContentsImgEdit.SaveImageAs(TableOfContentsImgEdit.ImageFilePath); TableOfContentsImgEdit.SaveImage(); TableOfContentsImgEdit.Page = page; } break; default: break; } }
public string GetFullName(PartOfBook? partOfBook) { string fullName = null; if (this.Book != null && partOfBook.HasValue) { string fileName = null; switch (partOfBook) { case PartOfBook.FrontCover: fileName = String.Format("{0}.jpg", this.Book.GetFileName()); break; case PartOfBook.TableOfContents: fileName = String.Format("{0}.tif", this.Book.GetFileName()); break; default: break; } if (!String.IsNullOrEmpty(fileName)) { fullName = System.IO.Path.Combine(Settings.Default.ScanFolderPath, fileName); } } return fullName; }
public bool CanImageChanged(PartOfBook? partOfBook) { return (this.Book != null && partOfBook.HasValue && this.Book.CanImageChanged(partOfBook.Value)); }
public void SetImageChanged(PartOfBook? partOfBook) { if (!IsBookLoaded) { MessageBox.Show("Není načten záznam publikace.", "Informace o publikaci", MessageBoxButton.OK, MessageBoxImage.Information); } if (this.Book != null && partOfBook.HasValue) { this.Book.SetImageChanged(partOfBook.Value); } }
public ScanFile InsertScanImage(int bookID, PartOfBook partOfBook, bool useOCR, string userName, string computer, string comment, byte[] image, bool obalkyKnihCZ) { //kontrola vstupnich parametru if (bookID == 0) throw new ArgumentNullException("Neplatný parametr identifikátor publikace."); string extension = null; switch (partOfBook) { case PartOfBook.FrontCover: extension = FileFormat.Jpg.ToString(); break; case PartOfBook.TableOfContents: extension = FileFormat.Tif.ToString(); break; default: throw new ArgumentException(String.Format("Neplatný parametr '{0}' skenovaná část publikace.", partOfBook)); } if (String.IsNullOrEmpty(userName)) throw new ArgumentNullException("Neplatný parametr jméno uživatele."); if (String.IsNullOrEmpty(computer)) throw new ArgumentNullException("Neplatný parametr název počítače."); if ((image == null) || (image.Length == 0)) throw new ArgumentNullException("Naskenovaný obrázek je prázdný."); //kontrola existence publikace Book book = BookComponent.Instance.GetByID(bookID); if (book == null) throw new ApplicationException(String.Format("Záznam publikace (ID={0}) neexistuje.", bookID)); if (book.HasPartOfBook(partOfBook)) throw new ApplicationException(String.Format("Záznam publikace (ID={0}) již obsahuje část '{1}'.", bookID, partOfBook.ToDisplay())); //vytvoreni nazvu souboru ScanFile result = new ScanFile(); result.FileName = String.Format("{0}.{1}", book.GetFileName(), extension.ToLower()); //ulozenie souboru naskenovaneho obrazku string filePath = null; try { filePath = Path.Combine(book.GetDirectoryPath(), result.FileName); result.PageCount = ImageFunctions.WriteFile(filePath, image); } catch (Exception ex) { throw new ApplicationException(String.Format("Nepodařilo se uložit naskenovaný soubor '{0}' na disk: {1}.", filePath, ex.Message)); } //ulozenie zaznamu do databaze ScanFileRepository repository = new ScanFileRepository(); using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Required)) { try { result.BookID = book.BookID; result.PartOfBook = partOfBook; result.UseOCR = (partOfBook == PartOfBook.FrontCover ? false : useOCR); result.Comment = comment.Left(1000); result.Created = DateTime.Now; result.Modified = result.Created; result.Status = StatusCode.Scanned; repository.Create(result); LogOperation(result.ScanFileID, userName, computer, result.Modified, result.Comment, result.Status); ts.Complete(); } catch (Exception ex) { throw new ApplicationException(String.Format("Nepodařilo se uložit data souboru publikace (ID={0}) do databáze.", bookID), ex); } } //operace dokonceni pro obalky a obsahy bez OCR switch (result.PartOfBook) { case PartOfBook.FrontCover: if (obalkyKnihCZ) { result = ImportObalkyKnih(result.ScanFileID, userName, computer); } break; case PartOfBook.TableOfContents: if (!result.UseOCR) { result = CompleteContents(result.ScanFileID, userName, computer); } break; default: break; } return result; }
private string GetMetaXmlData(PartOfBook partOfBook, int pages) { try { XElement rootElement = new XElement("meta"); XDocument xmlDoc = new XDocument(new XDeclaration("1.0", "utf-8", "yes"), rootElement); //autorizace uživatele systému ObalkyKnih.cz, možno zaslat jako HTTP-Basic rootElement.Add(new XElement("sigla", this.Sigla)); rootElement.Add(new XElement("user", this.Login)); //identifikace klientske aplikace XElement clientElement = new XElement("client"); clientElement.Add(new XElement("name", "DOZP")); clientElement.Add(new XElement("version", "1.0")); //IP adresy IPHostEntry host; string localIPv4 = "?"; string localIPv6 = "?"; host = Dns.GetHostEntry(Dns.GetHostName()); foreach (IPAddress ip in host.AddressList) { switch (ip.AddressFamily) { case AddressFamily.InterNetwork: localIPv4 = ip.ToString(); break; case AddressFamily.InterNetworkV6: localIPv6 = ip.ToString(); break; default: break; } } clientElement.Add(new XElement("local-IPv4-address", localIPv4)); clientElement.Add(new XElement("local-IPv6-address", localIPv6)); rootElement.Add(clientElement); switch (partOfBook) { case PartOfBook.FrontCover: XElement coverElement = new XElement("cover"); rootElement.Add(coverElement); break; case PartOfBook.TableOfContents: XElement tocElement = new XElement("toc"); tocElement.Add(new XElement("pages", pages)); rootElement.Add(tocElement); break; default: break; } return xmlDoc.ToString(); } catch (Exception ex) { throw new ApplicationException(String.Format("Nastala chyba při tvorbě metasouboru: {0}", ex.Message)); } }
/// <summary> /// Uloží naskenovanou obálku nebo obsah na server. /// </summary> public static bool InsertScanImage(int bookID, PartOfBook partOfBook, bool useOCR, string fullName, string comment = null, bool obalkyKnihCZ = false) { if (bookID == 0) throw new ArgumentException("Nebyl zadán identifikátor knihy", "bookID"); if (String.IsNullOrEmpty(fullName)) throw new ArgumentNullException("Nebyla zadána cesta k souboru", "fullName"); ScanImageRequest request = new ScanImageRequest(); request.BookID = bookID; request.PartOfBook = partOfBook; request.UseOCR = useOCR; request.Computer = Environment.MachineName; request.Image = ImageFunctions.ReadFile(fullName); request.Comment = comment; request.ObalkyKnihCZ = obalkyKnihCZ; ScanFileResponse response = AuthController.GetProxy().Execute(client => client.SaveScanImage(request)); return response.Result; }
public bool HasPartOfBook(PartOfBook? partOfBook) { return (this.Book != null && partOfBook.HasValue && this.Book.HasPartOfBook(partOfBook.Value)); }