示例#1
0
        public PropertiesDialog(ScanFile scanContents, OcrFile ocrContents)
        {
            InitializeComponent();

            this.ScanContents = scanContents;
            this.OcrContents = ocrContents;
        }
示例#2
0
        public ScanFile Create(ScanFile scanFile)
        {
            if (scanFile == null) return null;

            using (var db = new DozpContext())
            {
                db.Entry(scanFile).State = EntityState.Added;
                db.SaveChanges();
            }

            return scanFile;
        }
示例#3
0
        public bool Delete(ScanFile scanFile)
        {
            if (scanFile == null) return false;

            using (var db = new DozpContext())
            {
                db.ScanFiles.Attach(scanFile);
                db.ScanFiles.Remove(scanFile);
                db.SaveChanges();
            }

            return true;
        }
示例#4
0
        /// <summary>
        /// Uloží aktualizovanou obálku nebo obsah na server.
        /// </summary>
        /// <param name="scanFile"></param>
        /// <param name="fullName"></param>
        /// <param name="obalkyKnihCZ"></param>
        /// <returns></returns>
        public static bool UpdateScanImage(ScanFile scanFile, string fullName, bool obalkyKnihCZ = false)
        {
            if (scanFile == null) throw new ArgumentNullException("scanFile");
            if (String.IsNullOrEmpty(fullName)) throw new ArgumentNullException("Nebyla zadána cesta k souboru", "fullName");

            ScanImageRequest request = new ScanImageRequest();
            request.ScanFileID = scanFile.ScanFileID;
            request.BookID = scanFile.BookID;
            request.PartOfBook = scanFile.PartOfBook;
            request.UseOCR = scanFile.UseOCR;
            request.Computer = Environment.MachineName;
            request.Image = ImageFunctions.ReadFile(fullName);
            request.Comment = scanFile.Comment;
            request.ObalkyKnihCZ = obalkyKnihCZ;
            ScanFileResponse response = AuthController.GetProxy().Execute(client => client.SaveScanImage(request));

            return response.Result;
        }
示例#5
0
        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;
        }
示例#6
0
 public PropertiesDialog(Window parent, ScanFile scanContents, OcrFile ocrContents)
     : this(scanContents, ocrContents)
 {
     this.Owner = parent;
 }
示例#7
0
        public bool Import(ScanFile scanFile)
        {
            //#if DEBUG
            //            return true;
            //#endif
            try
            {
                //Import URL ObalkyKnih.cz
                string importUrl = String.Format("https://{0}", OBALKY_KNIH_IMPORT);
                string custom = String.Format("{0}-{1}", this.Sigla, scanFile.Book.SysNo);

                HttpWebRequest requestToServer = (HttpWebRequest)WebRequest.Create(importUrl);
                requestToServer.ContentType = String.Format("multipart/form-data; boundary={0}", PostData.Boundary);
                requestToServer.Method = WebRequestMethods.Http.Post;
                requestToServer.AllowWriteStreamBuffering = false;
                requestToServer.KeepAlive = false;
                requestToServer.Timeout = 60000;

                // Text parameters
                PostData pData = new PostData();
                pData.AddDataParam("login", this.Login);
                pData.AddDataParam("password", this.Password);
                pData.AddDataParam("isbn", scanFile.Book.ISBN);
                pData.AddDataParam("issn", scanFile.Book.ISSN);
                pData.AddDataParam("oclc", scanFile.Book.OCLC);
                pData.AddDataParam("nbn", (String.IsNullOrEmpty(scanFile.Book.NBN) ? custom : scanFile.Book.NBN));
                pData.AddDataParam("author", scanFile.Book.Author);
                pData.AddDataParam("title", scanFile.Book.Title);
                pData.AddDataParam("year", scanFile.Book.Year);
                pData.AddDataParam("ocr", "no");

                // Meta parameters
                string metaXml = GetMetaXmlData(scanFile.PartOfBook, scanFile.PageCount);
                pData.AddFileParam("meta", "meta.xml", metaXml, PostDataContentType.XML);

                // File data
                //string filepath = scanFile.GetScanFilePath();
                //string extension = Path.GetExtension(filepath);
                switch (scanFile.PartOfBook)
                {
                    case PartOfBook.FrontCover:
                        pData.AddFileParam("cover", "cover.jpg", scanFile.GetScanFilePath(), PostDataContentType.JPG);
                        break;
                    case PartOfBook.TableOfContents:
                        pData.AddFileParam("toc", "toc.tif", scanFile.GetScanFilePath(), PostDataContentType.TIFF);
                        break;
                    default:
                        break;
                }

                // Write the http request body directly to the server
                byte[] buffer = pData.GetPostDataBytes();
                requestToServer.ContentLength = buffer.Length;

                using (Stream s = requestToServer.GetRequestStream())
                {
                    s.Write(buffer, 0, buffer.Length);
                    s.Flush();
                    s.Close();
                }

                // Grab the response from the server
                WebResponse response = requestToServer.GetResponse();
                StreamReader responseReader = new StreamReader(response.GetResponseStream());

                //return Encoding.UTF8.GetString(buffer);
                return responseReader.ReadToEnd().Equals("OK", StringComparison.OrdinalIgnoreCase);
            }
            catch (WebException we)
            {
                string message = String.Empty;

                if (we.Response != null)
                {
                    HttpWebResponse response = (we.Response as HttpWebResponse);

                    //WebException will be thrown when a HTTP OK status is not returned
                    switch (response.StatusCode)
                    {
                        case HttpStatusCode.Unauthorized:
                            message = "Chyba autorizace: Přihlašovací údaje nejsou správné.";
                            break;
                        case HttpStatusCode.InternalServerError:
                            message = String.Format("Chyba na straně serveru: {0}", response.StatusDescription);
                            break;
                        default:
                            message = String.Format("{0}: {1}", response.StatusCode, response.StatusDescription);
                            break;
                    }
                }
                else
                {
                    message = String.Format("{0}: {1}", we.Status, we.Message);
                }

                throw new PostDataException(String.Format("Odesílání neúspěšné: {0}", message), we);
            }
            catch (Exception ex)
            {
                throw new PostDataException(String.Format("Počas odesílání nastala neznámá výjimka, je možné, že data nebyla odeslána: {0}", ex.Message), ex);
            }
        }