void IAddItemScanTask.AssignScanWithRegistryItem(string fileName, int ownerID, int registryID, int itemNumber, string documentName, string documentDescription, string elementDescription, bool isMain, bool isRF) { IItemStorage storage = ItemStorageFactory.Create(); TypMime mimeType = MimeHelper.PobierzTypDlaRozszerzenia(Path.GetExtension(fileName)); Guid scanGuid = Guid.Empty; using (FileStream fs = File.OpenRead(fileName)) { scanGuid = storage.Save(fs); } XPathDocument xpd = new XPathDocument(File.OpenRead(Path.GetDirectoryName(fileName) + "\\" + Path.GetFileNameWithoutExtension(fileName) + ".xml")); XPathNavigator xpn = xpd.CreateNavigator(); Metadata md = new Metadata(); md.Add("dataPobrania", xpn.SelectSingleNode("/dokument/dataPobrania").Value); md.Add("nazwaPlikuSkanu", xpn.SelectSingleNode("/dokument/nazwaPlikuDokumentu").Value); md.Add("liczbaStron", xpn.SelectSingleNode("/dokument/liczbaStron").Value); md.Add("lokalizacjaSkanu", xpn.SelectSingleNode("/dokument/pochodzenie/lokalizacja").Value); md.Add("urzadzenie", xpn.SelectSingleNode("/dokument/pochodzenie/urzadzenie").Value); md.Add("rodzajSkanu", xpn.SelectSingleNode("/dokument/pochodzenie/rodzaj").Value); md.Add("zrodloSkanu", xpn.SelectSingleNode("/dokument/pochodzenie/zrodlo").Value); rdao.AddNewScan(ownerID, registryID, itemNumber, documentName, documentDescription, scanGuid, Path.GetFileName(fileName), elementDescription, mimeType.Nazwa, isMain, mimeType.Browsable, md.GetXml(), isRF); }
//Stream IDownloadFileTask.GetTempFileToPDF(string path, out string mimeType, out string fileName) //{ // if (!File.Exists(path)) // throw new ArgumentException("Nie ma takiego pliku"); // FileStream fs = File.OpenRead(path); // Image img = Image.FromStream(fs); // TiffImageSplitter tiff = new TiffImageSplitter(); // PdfDocument doc = new PdfDocument(); // int pageCount = tiff.getPageCount(img); // for (int i = 0; i < pageCount; i++) // { // PdfPage page = new PdfPage(); // Image tiffImg = tiff.getTiffImage(img, i); // XImage ximg = XImage.FromGdiPlusImage(tiffImg); // page.Width = ximg.PointWidth; // page.Height = ximg.PointHeight; // doc.Pages.Add(page); // XGraphics xgr = XGraphics.FromPdfPage(doc.Pages[i]); // xgr.DrawImage(ximg, 0, 0); // } // mimeType = "application/pdf"; // fileName = Path.ChangeExtension(Path.GetFileName(path), "pdf"); // MemoryStream ms = new MemoryStream(); // doc.Save(ms, false); // return ms; //} Stream IDownloadFileTask.GetFile(Guid imageID, out string mimeType, out string fileName, int pageNumber) { IItemStorage storage = ItemStorageFactory.Create(); DocumentDAO dao = new DocumentDAO(); DTO.DocumentItemDTO item = dao.GetItem(imageID); if (item == null) { throw new ArgumentException("Nie ma takiego pliku"); } mimeType = item.MimeType; fileName = item.OriginalName; if (pageNumber > 0 && mimeType.ToLower() == "image/tiff") { Image img = new Bitmap(storage.Load(imageID)); img.SelectActiveFrame(FrameDimension.Page, pageNumber - 1); MemoryStream ms = new MemoryStream(); img.Save(ms, System.Drawing.Imaging.ImageFormat.Tiff); return(ms); } else { return(storage.Load(imageID)); } }
System.IO.Stream IGetImageTask.GetImage(Guid imageID) { IItemStorage storage = ItemStorageFactory.Create(); if (storage.Exists(imageID)) { return(storage.Load(imageID)); } return(null); }
Stream IDownloadFileTask.GetTiffToPDF(Guid imageID, out string mimeType, out string fileName) { IItemStorage storage = ItemStorageFactory.Create(); DocumentDAO dao = new DocumentDAO(); DTO.DocumentItemDTO item = dao.GetItem(imageID); if (item == null) { throw new ArgumentException("Nie ma takiego pliku"); } if (item.MimeType.ToLower() == "image/tiff") { Image img = new Bitmap(storage.Load(imageID)); TiffImageSplitter tiff = new TiffImageSplitter(); PdfDocument doc = new PdfDocument(); int pageCount = tiff.getPageCount(img); for (int i = 0; i < pageCount; i++) { PdfPage page = new PdfPage(); Image tiffImg = tiff.getTiffImage(img, i); XImage ximg = XImage.FromGdiPlusImage(tiffImg); page.Width = ximg.PointWidth; page.Height = ximg.PointHeight; doc.Pages.Add(page); XGraphics xgr = XGraphics.FromPdfPage(doc.Pages[i]); xgr.DrawImage(ximg, 0, 0); } mimeType = "application/pdf"; fileName = Path.ChangeExtension(item.OriginalName, "pdf"); MemoryStream ms = new MemoryStream(); doc.Save(ms, false); return(ms); } else { throw new ArgumentException("Podany plik nie jest plikiem TIFF"); } }
public ImageHelper(Guid id) { this._nazwaPlikuOryginalu = id.ToString() + "p"; IItemStorage storage = ItemStorageFactory.Create(); if (!storage.Exists(id)) { throw new ArgumentException("Nie ma takiego skanu"); } _obrazekRoboczy = System.Drawing.Image.FromStream(storage.Load(id), false, false); this._liczbaStron = _obrazekRoboczy.GetFrameCount(System.Drawing.Imaging.FrameDimension.Page); this._aktualnaStrona = 0; this._szerokosc = _obrazekRoboczy.Width; this._wysokosc = _obrazekRoboczy.Height; this._skala = poczatkowaSzerokosc * 100 / this._szerokosc; this.generujAktualnyObrazek(); }
void SaveESPDocumentAttachments(Guid docId, int newDocId) { IItemStorage storage = ItemStorageFactory.Create(); using (DbDataReader dr = (DbDataReader)(new DocumentDAO()).GetESPDocumentData(docId)) { if (dr.Read()) { string zalaczniki = dr["zalaczniki"].ToString(); XmlDocument attachments = new XmlDocument(); attachments.LoadXml(zalaczniki); foreach (XmlNode attachment in attachments.SelectNodes("//zalacznik")) { Guid attachId = new Guid(attachment.Attributes["id"].Value); Guid newItemId = new Guid(); Stream attachStream = storage.LoadGuid(attachId); attachStream.Seek(0, SeekOrigin.Begin); (new DocumentDAO()).AddNewDocumentItem(newDocId, attachment.Attributes["nazwa"].Value, "za³¹cznik", attachStream, attachment.Attributes["mime"].Value, ref newItemId, DocumentItemCategory.Uploaded); } } } }
public Guid Save(Stream itemContent) { IItemStorage storage = ItemStorageFactory.Create(); return(storage.Save(itemContent)); }
protected void gvESPDocumentsList_RowCommand(object sender, GridViewCommandEventArgs e) { DocumentDAO docDao = new DocumentDAO(); string sTicket = (ConfigurationManager.AppSettings["espticket"] != null) ? ConfigurationManager.AppSettings["espticket"].ToString() : string.Empty; switch (e.CommandName) { case "preview": Session["ESPDocId"] = e.CommandArgument; using (DbDataReader dr = (DbDataReader)docDao.GetESPDocumentData(new Guid(e.CommandArgument.ToString()))) { if (dr.Read()) { lnkAddDocument.Visible = dr["idStatusu"].ToString().Equals("3"); docPreview.DocGuid = new Guid(e.CommandArgument.ToString()); } } break; case "download": ESPWebService ws = new ESPWebService(); if (ws != null) { Guid docGuid = new Guid(e.CommandArgument.ToString()); docDao.SetESPDocumentStatus(docGuid, DocumentDAO.ESPDocumentStatus.Downloading); try { string docId = docDao.GetESPDocId(docGuid); if (docId != string.Empty) { string docData = ws.GetDocument(sTicket, docId); if (docData.Contains("<error>")) { WebMsgBox.Show(this, "Błąd pobierania dokumentu ESP"); } else { byte[] data = Convert.FromBase64String(docData); ws.Dispose(); string xmlDoc = Encoding.UTF8.GetString(data); // pobranie XML i XSLT dokumentu XmlDocument doc = new XmlDocument(); doc.LoadXml(xmlDoc); data = Convert.FromBase64String(doc.SelectSingleNode("//Dokument[@typ='Dane']").InnerText); XmlDocument xmlData = new XmlDocument(); xmlData.LoadXml(Encoding.UTF8.GetString(data).Replace("UTF-8", "UTF-16").Replace("utf-8", "utf-16")); data = Convert.FromBase64String(doc.SelectSingleNode("//Dokument[@typ='Styl']").InnerText); XmlDocument xslData = new XmlDocument(); xslData.LoadXml(Encoding.UTF8.GetString(data).Replace("UTF-8", "UTF-16").Replace("utf-8", "utf-16")); IItemStorage storage = ItemStorageFactory.Create(); StringBuilder sb = new StringBuilder(); XmlWriter xw = XmlWriter.Create(sb); xw.WriteStartElement("zalaczniki"); foreach (XmlNode node in doc.SelectNodes("//Dokument[@typ='Zalacznik']")) { // dodawanie zalacznikow data = Convert.FromBase64String(node.InnerText); MemoryStream ms = new MemoryStream(data); Guid attachmentGuid = storage.Save(ms); xw.WriteStartElement("zalacznik"); xw.WriteAttributeString("id", attachmentGuid.ToString()); xw.WriteAttributeString("nazwa", node.Attributes["Nazwa"].Value); xw.WriteAttributeString("mime", node.Attributes["Mime"].Value); xw.WriteEndElement(); } xw.WriteEndElement(); xw.Close(); docDao.SetESPDocumentData(docGuid, xmlData.InnerXml, xslData.InnerXml, sb.ToString()); docDao.SetESPDocumentStatus(docGuid, DocumentDAO.ESPDocumentStatus.Downloaded); ws.ConfirmDocumentReceive(sTicket, docGuid.ToString()); gvESPDocumentsList.DataBind(); } } else { WebMsgBox.Show(this, "Nie można pobrać ID dokumentu ESP"); } } catch //(Exception ex) { docDao.SetESPDocumentStatus(docGuid, DocumentDAO.ESPDocumentStatus.Awaiting); } } break; default: docPreview.XmlData = string.Empty; lnkAddDocument.Visible = false; break; } }