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); }
public bool AddNewVersionOfDocumentItem(int documentId, Guid originalItemId, string description, Stream content, string mimeType, string name, DocumentItemCategory uploadMode) { IItemStorage storage = ItemStorageFactory.Create(); Guid itemId = storage.Save(content); Database db = DatabaseFactory.CreateDatabase(); try { db.ExecuteNonQuery("[Dokumenty].dodajNowaWersjeElementuDokumentu", documentId, itemId, originalItemId, description, mimeType, name, uploadMode); return(true); } catch { storage.Delete(itemId); return(false); } }
public bool AddNewDocumentItem(int documentId, string originalName, string description, Stream content, string mimeType, ref Guid itemGuid, DocumentItemCategory uploadMode) { IItemStorage storage = ItemStorageFactory.Create(); Guid itemId = storage.Save(content); Database db = DatabaseFactory.CreateDatabase(); bool browsable = (mimeType == "image/tiff"); try { object res = db.ExecuteScalar("[Dokumenty].[dodajNowyElementDokumentu]", documentId, itemId, originalName, description, mimeType, false, browsable, uploadMode); itemGuid = res != null ? (Guid)res : Guid.Empty; return(true); } catch { storage.Delete(itemId); return(false); } }
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; } }