public bool getDocumentByID(string id) { var dStorage = new DocStorage_CouchDB(); Document doc = new Document_Couch(id); var errCode = string.Empty; var errTxt = string.Empty; byte[] fileData; FileStream fStream = null; var CouchConnectorObj = new SecuredCouchConnector(hostname, portName, secWebPort, dbName, userid, pass, isSec); dStorage.SecuredGetDocument(CouchConnectorObj, ref doc, out errCode, out errTxt); if (CouchConnectorObj.Error) { Console.WriteLine(errTxt); return(false); } else { Console.WriteLine(string.Format("Got Doc '{0}' from db '{1}' by userID '{2}'", doc.FileId, dbName, userid)); doc.GetSourceData(out fileData); if (fileData != null) { fStream = File.Create(Directory.GetCurrentDirectory() + "//" + doc.FileId + ".pdf"); fStream.Write(fileData, 0, fileData.Length); Console.WriteLine("written to file :" + Directory.GetCurrentDirectory() + "//" + doc.FileId + ".pdf"); fStream.Flush(); fStream.Close(); } return(true); } }
/// <summary> /// /// </summary> /// <param name="storageId"></param> /// <param name="couchConnector"></param> /// <param name="doc"></param> /// <param name="errorMessage"></param> /// <param name="liteFetch"> </param> /// <returns></returns> public static bool GetDocument( string storageId, SecuredCouchConnector couchConnector, out Document doc, out string errorMessage, bool liteFetch = false) { //Set defaults for outgoing params doc = null; errorMessage = string.Empty; if (!string.IsNullOrEmpty(storageId) && couchConnector != null) { doc = new Document_Couch(storageId); var dStorage = new DocStorage_CouchDB(); string errCode, errTxt; if (dStorage.SecuredGetDocument(couchConnector, ref doc, out errCode, out errTxt, liteFetch)) { return(true); } errorMessage = "Could not retrieve document: " + errCode + " " + errTxt; return(false); } errorMessage = "Could not retrieve document"; return(false); }
public Document GetDocument(out string msg, out bool gotDoc, CouchVo vo, PawnDocRegVO regVO) { setCouchValues(vo); var dStorage = new DocStorage_CouchDB(); var errCode = string.Empty; var errTxt = string.Empty; Document doc = (Document) new Document_Couch(regVO.StorageID); // SecuredCouchConnector CouchConnectorObj = new SecuredCouchConnector(hostname, portName, secWebPort, dbName, userid, pass, isSec); SecuredCouchArchiver CouchConnectorObj = new SecuredCouchArchiver(hostname, portName, secWebPort, dbName, userid, pass, isSec); dStorage.SecuredGetDocument(CouchConnectorObj, ref doc, out errCode, out errTxt); if (CouchConnectorObj.Error) { //log.Error("errTxt :" + errTxt); //log.Error("errCode :" + errCode); msg = errTxt; gotDoc = false; } else { //log.Debug("errTxt :" + errTxt); //log.Debug("errCode :" + errCode); msg = errTxt; gotDoc = true; // return true; } return(doc); }
public void GetDocument(CouchVo vo1, System.Windows.Forms.RichTextBox resultBox) { setCouchValues(vo1); if (process != null && !process.HasExited) { process.Kill(); } var dStorage = new DocStorage_CouchDB(); PawnObjects.Doc.Document doc = (PawnObjects.Doc.Document) new Document_Couch(vo1.documentID); var errCode = string.Empty; var errTxt = string.Empty; byte[] fileData; FileStream fStream = null; SecuredCouchConnector CouchConnectorObj = new SecuredCouchConnector(hostname, portName, secWebPort, dbName, userid, pass, isSec); Stopwatch sw = new Stopwatch(); sw.Start(); dStorage.SecuredGetDocument(CouchConnectorObj, ref doc, out errCode, out errTxt); sw.Stop(); resultBox.AppendText("\n"); resultBox.AppendText("Time Taken to get :" + sw.ElapsedMilliseconds); resultBox.AppendText("\n"); // dStorage.SecuredGetDocumentWithAttachment(CouchConnectorObj, ref doc, out errCode, out errTxt); if (CouchConnectorObj.Error) { Console.WriteLine(errTxt); resultBox.AppendText(errTxt); resultBox.AppendText("\n"); //return false; } else { resultBox.AppendText(string.Format("Got Doc '{0}' from db '{1}' by userID '{2}'", doc.FileId, dbName, userid)); resultBox.AppendText("\n"); doc.GetSourceData(out fileData); string path = FileHandler.createPDFDir(); string fileWithPath = path + "\\" + doc.FileName; if (fileData != null) { fStream = File.Create(fileWithPath); fStream.Write(fileData, 0, fileData.Length); resultBox.AppendText(("written to file :" + fileWithPath)); resultBox.AppendText("\n"); fStream.Flush(); fStream.Close(); process = Process.Start(fileWithPath); } // return true; } }