public ScanFile CancelOcrContents(int scanFileID, string userName, string computer, string comment) { //kontrola vstupnich parametru if (scanFileID == 0) throw new ArgumentNullException("Neplatný parametr identifikátor souboru."); if (String.IsNullOrEmpty(userName)) throw new ArgumentException("Neplatný parametr jméno uživatele."); if (String.IsNullOrEmpty(computer)) throw new ArgumentException("Neplatný parametr název počítače."); ScanFileRepository repository = new ScanFileRepository(); //kontrola existence naskenovaneho souboru ScanFile result = repository.Select(scanFileID); if (result == null) throw new ApplicationException(String.Format("Soubor (ID={0}) neexistuje.", scanFileID)); if (result.PartOfBook != PartOfBook.TableOfContents) throw new ApplicationException(String.Format("Soubor (ID={0}) není typ pro OCR zpracování.", result.ScanFileID)); if (result.UseOCR == false) throw new ApplicationException(String.Format("Soubor (ID={0}) není určen pro OCR zpracování.", result.ScanFileID)); if (result.Status != StatusCode.Discarded) throw new ApplicationException(String.Format("Soubor (ID={0}) nemá status vyřazen.", result.ScanFileID)); //ulozenie zaznamu do databaze using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Required)) { try { result.UseOCR = false; result.OcrText = null; result.OcrTime = null; result.Comment = comment.Left(1000); result.Modified = DateTime.Now; result.Status = StatusCode.Scanned; repository.Update(result); LogOperation(result.ScanFileID, userName, computer, result.Modified, result.Comment, result.Status); result = CompleteContents(result.ScanFileID, userName, computer); ts.Complete(); } catch (Exception ex) { throw new ApplicationException(String.Format("Nepodařilo se uložit data souboru (ID={0}) do databáze.", scanFileID), ex); } } return result; }
public void CheckIn(int scanFileID, string userName, string computer, string comment, string ocrText, byte[] pdfFile) { //kontrola vstupnich parametru if (scanFileID == 0) throw new ArgumentException("Neplatný parametr identifikátor souboru."); if (String.IsNullOrEmpty(userName)) throw new ArgumentException("Neplatný parametr jméno uživatele."); if (String.IsNullOrEmpty(computer)) throw new ArgumentException("Neplatný parametr název počítače."); if (String.IsNullOrEmpty(ocrText)) throw new ArgumentNullException("Zpracovaný OCR text je prázdný."); if ((pdfFile == null) || (pdfFile.Length == 0)) throw new ArgumentNullException("Zpracovaný PDF soubor je prázdný."); ScanFileRepository repository = new ScanFileRepository(); //kontrola existence naskenovaneho souboru ScanFile result = repository.Select(scanFileID); if (result == null) throw new ApplicationException(String.Format("Soubor (ID={0}) neexistuje.", scanFileID)); //kontrola ulozenych parametrov + CheckOutBook->UserName ??? if (result.PartOfBook != PartOfBook.TableOfContents) throw new ApplicationException(String.Format("Soubor (ID={0}) není typ pro OCR zpracování.", result.ScanFileID)); if (result.UseOCR == false) throw new ApplicationException(String.Format("Soubor (ID={0}) není určen pro OCR zpracování.", result.ScanFileID)); if (result.Status != StatusCode.InProgress) throw new ApplicationException(String.Format("Soubor (ID={0}) nemá status ve zpracování.", result.ScanFileID)); //ulozenie PDF suboru vytvoreneho klientom string filePath = null; try { filePath = result.GetOcrFilePath(); ImageFunctions.WriteFile(filePath, pdfFile); } catch (Exception ex) { throw new ApplicationException(String.Format("Nepodařilo se uložit zpracovaný OCR soubor '{0}' na disk: {1}.", filePath, ex.Message)); } //ulozenie operace do databazy using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Required)) { try { TimeSpan tsOcrTime = DateTime.Now.Subtract(result.Modified); result.OcrTime = (short)tsOcrTime.TotalSeconds; result.OcrText = ocrText; result.Modified = DateTime.Now; result.Comment = comment.Left(1000); result.Status = StatusCode.Complete; repository.Update(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 (ID={0}) do databáze.", scanFileID), ex); } } }
public ScanFile UpdateScanImage(int scanFileID, bool useOCR, string userName, string computer, string comment, byte[] image, bool obalkyKnihCZ) { //kontrola vstupnich parametru if (scanFileID == 0) throw new ArgumentNullException("Neplatný parametr identifikátor souboru."); 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ý."); ScanFileRepository repository = new ScanFileRepository(); //kontrola existence naskenovaneho souboru ScanFile result = repository.Select(scanFileID); if (result == null) throw new ApplicationException(String.Format("Soubor (ID={0}) neexistuje.", scanFileID)); if (result.Status == StatusCode.Exported) throw new ApplicationException(String.Format("Soubor (ID={0}) má status exportován.", result.ScanFileID)); //ulozenie souboru naskenovaneho obrazku string filePath = result.GetScanFilePath(); try { ImageFunctions.DeleteFile(filePath); 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 using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Required)) { try { result.UseOCR = (result.PartOfBook == PartOfBook.FrontCover ? false : useOCR); result.OcrText = null; result.OcrTime = null; result.Comment = comment.Left(1000); result.Modified = DateTime.Now; result.Status = StatusCode.Scanned; repository.Update(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 (ID={0}) do databáze.", scanFileID), 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; }
public void UndoCheckOut(int scanFileID, string userName, string computer, string comment) { //kontrola vstupnich parametru if (scanFileID == 0) throw new ArgumentException("Neplatný parametr identifikátor souboru."); if (String.IsNullOrEmpty(userName)) throw new ArgumentException("Neplatný parametr jméno uživatele."); if (String.IsNullOrEmpty(computer)) throw new ArgumentException("Neplatný parametr název počítače."); ScanFileRepository repository = new ScanFileRepository(); //kontrola existence naskenovaneho souboru ScanFile result = repository.Select(scanFileID); if (result == null) throw new ApplicationException(String.Format("Soubor (ID={0}) neexistuje.", scanFileID)); //kontrola ulozenych parametrov if (result.PartOfBook != PartOfBook.TableOfContents) throw new ApplicationException(String.Format("Soubor (ID={0}) není typ pro OCR zpracování.", result.ScanFileID)); if (result.UseOCR == false) throw new ApplicationException(String.Format("Soubor (ID={0}) není určen pro OCR zpracování.", result.ScanFileID)); if (result.Status != StatusCode.InProgress) throw new ApplicationException(String.Format("Soubor (ID={0}) nemá status ve zpracování.", result.ScanFileID)); Operation lastOperation = result.Operations.LastOrDefault(); if (result.Status != lastOperation.Status) throw new ApplicationException(String.Format("Soubor (ID={0}) nemá poslední operaci ve zpracování.", result.ScanFileID)); //ulozenie operace do databazy using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Required)) { try { OperationRepository operations = new OperationRepository(); operations.Delete(lastOperation); Operation scanOperation = result.Operations.SingleOrDefault(o => o.Status == StatusCode.Scanned); result.Modified = scanOperation.Executed; result.Comment = comment; result.Status = StatusCode.Scanned; repository.Update(result); ts.Complete(); } catch (Exception ex) { throw new ApplicationException(String.Format("Nepodařilo se uložit data souboru (ID={0}) do databáze.", scanFileID), ex); } } }
public ScanFile ImportObalkyKnih(int scanFileID, string userName, string computer) { //kontrola vstupnich parametru if (scanFileID == 0) throw new ArgumentNullException("Neplatný parametr identifikátor souboru."); if (String.IsNullOrEmpty(userName)) throw new ArgumentException("Neplatný parametr jméno uživatele."); if (String.IsNullOrEmpty(computer)) throw new ArgumentException("Neplatný parametr název počítače."); ScanFileRepository repository = new ScanFileRepository(); //kontrola existence naskenovaneho souboru ScanFile result = repository.Select(scanFileID); if (result == null) throw new ApplicationException(String.Format("Soubor (ID={0}) neexistuje.", scanFileID)); //kontrola ulozenych parametrov if (result.PartOfBook != PartOfBook.FrontCover) throw new ApplicationException(String.Format("Soubor (ID={0}) pro import není obálka.", result.ScanFileID)); if (result.Status != StatusCode.Scanned) throw new ApplicationException(String.Format("Soubor (ID={0}) nemá status naskenován.", result.ScanFileID)); using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Required)) { try { ObalkyKnih obalkyKnih = new ObalkyKnih("ABD001", "*****@*****.**", "skenovaniobsahu1425"); if (obalkyKnih.Import(result)) { result.Comment = "Importováno na ObalkyKnih.cz"; result.Modified = DateTime.Now; result.Status = StatusCode.Complete; repository.Update(result); LogOperation(result.ScanFileID, userName, Environment.MachineName, result.Modified, result.Comment, result.Status); ts.Complete(); } } catch { } } return result; }
public void Export(int scanFileID, string userName, string computer, string comment = null) { //kontrola vstupnich parametru if (scanFileID == 0) throw new ArgumentException("Neplatný parametr identifikátor souboru."); if (String.IsNullOrEmpty(userName)) throw new ArgumentException("Neplatný parametr jméno uživatele."); if (String.IsNullOrEmpty(computer)) throw new ArgumentException("Neplatný parametr název počítače."); ScanFileRepository repository = new ScanFileRepository(); //kontrola existence naskenovaneho souboru ScanFile result = repository.Select(scanFileID); if (result == null) throw new ApplicationException(String.Format("Soubor (ID={0}) neexistuje.", scanFileID)); //kontrola ulozenych parametrov if (result.Status != StatusCode.Complete) throw new ApplicationException(String.Format("Soubor (ID={0}) nemá status dokončeno.", result.ScanFileID)); //export ALEPH TxFileManager fileMgr = new TxFileManager(); string filePath = null; string ftpPath = null; using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Required)) { try { filePath = result.GetScanFilePath(); switch (result.PartOfBook) { case PartOfBook.FrontCover: ftpPath = Path.Combine(result.Book.Catalogue.GetDirectoryFTP(true), result.FileName); fileMgr.Copy(filePath, ftpPath, true); break; case PartOfBook.TableOfContents: if (result.UseOCR) { string txtFilePath = Path.Combine(result.Book.Catalogue.GetDirectoryFTP(true), result.TxtFileName); fileMgr.WriteAllText(txtFilePath, result.OcrText); } string pdfFilePath = result.GetOcrFilePath(); ftpPath = Path.Combine(result.Book.Catalogue.GetDirectoryFTP(true), result.OcrFileName); fileMgr.Copy(pdfFilePath, ftpPath, true); break; default: break; } } catch (Exception ex) { throw new ApplicationException(String.Format("Nepodařilo se exportovat soubor '{0}' na FTP: {1}.", filePath, ex.Message)); } //ulozenie operace do databazy try { result.Modified = DateTime.Now; result.Comment = (comment != null ? comment.Left(1000) : null); result.Status = StatusCode.Exported; repository.Update(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 (ID={0}) do databáze.", scanFileID), ex); } } }
public ScanFile CompleteContents(int scanFileID, string userName, string computer) { //kontrola vstupnich parametru if (scanFileID == 0) throw new ArgumentNullException("Neplatný parametr identifikátor souboru."); if (String.IsNullOrEmpty(userName)) throw new ArgumentException("Neplatný parametr jméno uživatele."); if (String.IsNullOrEmpty(computer)) throw new ArgumentException("Neplatný parametr název počítače."); ScanFileRepository repository = new ScanFileRepository(); //kontrola existence naskenovaneho souboru ScanFile result = repository.Select(scanFileID); if (result == null) throw new ApplicationException(String.Format("Soubor (ID={0}) neexistuje.", scanFileID)); //kontrola ulozenych parametrov if (result.PartOfBook != PartOfBook.TableOfContents) throw new ApplicationException(String.Format("Soubor (ID={0}) pro import není obálka.", result.ScanFileID)); if (result.UseOCR == true) throw new ApplicationException(String.Format("Soubor (ID={0}) není obsah bez OCR zpracování.", result.ScanFileID)); if (result.Status != StatusCode.Scanned) throw new ApplicationException(String.Format("Soubor (ID={0}) nemá status naskenován.", result.ScanFileID)); using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Required)) { try { string filePath = result.GetScanFilePath(); string pdfFilePath = result.GetOcrFilePath(); ImageFunctions.DeleteFile(pdfFilePath); if (ImageFunctions.WriteToPdf(filePath, pdfFilePath, result.Book.Author, result.Book.Title, result.Book.ISBN)) { result.Comment = "Automaticky převedeno do PDF formátu"; result.Modified = DateTime.Now; result.Status = StatusCode.Complete; repository.Update(result); LogOperation(result.ScanFileID, userName, Environment.MachineName, result.Modified, result.Comment, result.Status); ts.Complete(); } } catch { } } return result; }
public byte[] CheckOut(int scanFileID, string userName, string computer, string comment) { //kontrola vstupnich parametru if (scanFileID == 0) throw new ArgumentException("Neplatný parametr identifikátor souboru."); if (String.IsNullOrEmpty(userName)) throw new ArgumentException("Neplatný parametr jméno uživatele."); if (String.IsNullOrEmpty(computer)) throw new ArgumentException("Neplatný parametr název počítače."); ScanFileRepository repository = new ScanFileRepository(); //kontrola, jestli uzivatel j*z neco nezpracovava ScanFileFilter filter = new ScanFileFilter() { UserName = userName, Status = StatusCode.InProgress }; if (repository.Select(filter).Count > 0) throw new ApplicationException(String.Format("Nelze stáhnout naskenovaný obsah, uživatel '{0}' již zpracovává obsah.", userName)); //kontrola existence naskenovaneho souboru ScanFile result = repository.Select(scanFileID); if (result == null) throw new ApplicationException(String.Format("Soubor (ID={0}) neexistuje.", scanFileID)); //kontrola ulozenych parametrov if (result.PartOfBook != PartOfBook.TableOfContents) throw new ApplicationException(String.Format("Soubor (ID={0}) není typ pro OCR zpracování.", result.ScanFileID)); if (result.UseOCR == false) throw new ApplicationException(String.Format("Soubor (ID={0}) není určen pro OCR zpracování.", result.ScanFileID)); if (result.Status != StatusCode.Scanned) throw new ApplicationException(String.Format("Soubor (ID={0}) nemá status naskenován.", result.ScanFileID)); //nacitanie souboru naskenovaneho obsahu byte[] image = null; string filePath = null; try { filePath = result.GetScanFilePath(); image = ImageFunctions.ReadFile(filePath); } catch (Exception ex) { throw new ApplicationException(String.Format("Nepodařilo se načíst naskenovaný soubor '{0}' z disku: {1}.", filePath, ex.Message)); } //ulozenie operace do databazy using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Required)) { try { result.Modified = DateTime.Now; result.Comment = comment.Left(1000); result.Status = StatusCode.InProgress; repository.Update(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 (ID={0}) do databáze.", scanFileID), ex); } } return image; }
private static void Rename() { try { ScanFileRepository repository = new ScanFileRepository(); List<Book> books = BookComponent.Instance.GetList(new BookFilter()); int n = 0; if (books != null) { foreach (var book in books) { string bookPath = book.GetDirectoryPath(); string fileName = book.GetFileName(); n++; foreach (var file in book.ScanFiles) { string extension = Path.GetExtension(file.FileName); string newFileName = String.Format("{0}{1}", fileName, extension); if (file.FileName != newFileName) { string sourceFilePath = file.GetScanFilePath(); string destFilePath = Path.Combine(bookPath, newFileName); File.Move(sourceFilePath, destFilePath); Console.WriteLine(String.Format("[{0}] Soubor '{1}' -> {2}", n, file.FileName, destFilePath)); if (file.PartOfBook == PartOfBook.TableOfContents && (file.Status == StatusCode.Complete || file.Status == StatusCode.Exported)) { sourceFilePath = file.GetOcrFilePath(); extension = Path.GetExtension(sourceFilePath); destFilePath = Path.Combine(bookPath, String.Format("{0}{1}", fileName, extension)); File.Move(sourceFilePath, destFilePath); Console.WriteLine(String.Format("[{0}] Soubor '{1}' -> {2}", n, file.OcrFileName, destFilePath)); } file.FileName = newFileName; repository.Update(file); } else { Console.WriteLine(String.Format("[{0}] Soubor '{1}' bez změny", n, file.FileName)); } } } } } catch (Exception ex) { Console.WriteLine(ex.Message); } }