Exemplo n.º 1
0
        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);
            }
        }
Exemplo n.º 2
0
        public void addDocumentToCouch(CouchVo vo, Document document, out string msg, out bool added)
        {
            added = false;
            msg   = "";
            var sErrCode = string.Empty;
            var sErrText = string.Empty;

            setCouchValues(vo);
            SecuredCouchConnector CouchConnectorObj = null;
            var dStorage = new DocStorage_CouchDB();

            CouchConnectorObj = new SecuredCouchConnector(hostname, portName, secWebPort, dbName, userid, pass, isSec);
            dStorage.SecuredAddDocument(CouchConnectorObj, ref document, out sErrCode, out sErrText);
            msg = sErrText;
            if (sErrCode == "0")
            {
                added = true;
                //log.Debug("Added Document ID:" + document.FileId);
            }
            else
            {
                added = false;
                // log.Debug("Error adding doc :" + sErrText);
            }
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        /// <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);
        }
Exemplo n.º 5
0
        public Document GetDocument(out string errTxt, out bool isError, CouchVo vo, PawnDocRegVO regVO)
        {
            var      dStorage = new DocStorage_CouchDB();
            Document doc      = (Document) new Document_Couch(regVO.StorageID);

            constructDoc(vo, ref doc, out isError, out errTxt);
            return(doc);
        }
Exemplo n.º 6
0
        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;
            }
        }
Exemplo n.º 7
0
        /***
         * This method will be used for couch authentication functionality
         ***/
        private static string couchLoginVerification(String docName, out string msg, out bool added, bool isAdminVerify)
        {
            added = false;
            msg   = string.Empty;

            DocumentType = Document.DocTypeNames.PDF;
            string fileName     = docName;
            int    lastSlashIdx = fileName.LastIndexOf('\\');
            string fName        = fileName.Substring(lastSlashIdx + 1);
            var    sErrCode     = string.Empty;
            var    sErrText     = string.Empty;

            //byte[] fileBytes = File.ReadAllBytes(fileName);
            byte[]   fileBytes   = SimpleHash.convertToByteArr("This is connection test");
            Document couchDocObj = (Document) new Document_Couch(fileName, fName, DocumentType);

            couchDocObj.SetPropertyData("jak prop1", "value");
            string storageID = System.Guid.NewGuid().ToString();

            GldocName = storageID;
            // Console.WriteLine("Added doc name :" + GldocName);
            SecuredCouchConnector CouchConnectorObj = null;

            //StorageID = "1234";
            if (couchDocObj.SetSourceData(fileBytes, storageID, false))
            {
                var dStorage = new DocStorage_CouchDB();
                if (isAdminVerify)
                {
                    CouchConnectorObj = new SecuredCouchConnector(hostname, portName, secWebPort, dbName, adminUserid, adminPass, isSec);
                    dStorage.SecuredAddDocument(CouchConnectorObj, ref couchDocObj, out sErrCode, out sErrText);
                }
                else
                {
                    CouchConnectorObj = new SecuredCouchConnector(hostname, portName, secWebPort, dbName, userid, pass, isSec);
                    dStorage.SecuredAddDocument(CouchConnectorObj, ref couchDocObj, out sErrCode, out sErrText);
                }
                if (sErrCode == "0")
                {
                    added = true;
                    msg   = "Added" + fileName;
                }
                else
                {
                    added = false;
                    msg   = sErrText;
                }
            }
            return(storageID);
        }
        private string addDocumentToCouch(String docName, string storageID, out bool added)
        {
            added = false;
            // msg = string.Empty;

            //DocumentType = PawnObjects.Doc.Document.DocTypeNames.PDF;
            string fileName     = docName;
            int    lastSlashIdx = fileName.LastIndexOf('\\');
            string fName        = fileName.Substring(lastSlashIdx + 1);
            var    sErrCode     = string.Empty;
            var    sErrText     = string.Empty;

            if (fileBytes == null)
            {
                fileBytes = File.ReadAllBytes(fileName);
            }
            Document couchDocObj = (Document) new Document_Couch(fileName, fName, Document.DocTypeNames.PDF);

            couchDocObj.SetPropertyData("jak prop1", "value");
            //string storageID = System.Guid.NewGuid().ToString();

            // Console.WriteLine("Added doc name :" + GldocName);
            SecuredCouchConnector CouchConnectorObj = null;

            //StorageID = "1234";
            if (couchDocObj.SetSourceData(fileBytes, storageID, false))
            {
                var dStorage = new DocStorage_CouchDB();

                CouchConnectorObj = new SecuredCouchConnector(hostname, portName, secWebPort, dbName, userid, pass, isSec);
                dStorage.SecuredAddDocument(CouchConnectorObj, ref couchDocObj, out sErrCode, out sErrText);
                if (sErrCode == "0")
                {
                    added = true;
                    //log.Info("Added Document ID:" + storageID);
                    successCount++;
                }
                else
                {
                    added = false;
                    log.Info("Error adding doc :" + sErrText);
                    failCount++;
                    // msg = sErrText;
                }
            }
            return(storageID);
        }
Exemplo n.º 9
0
        private static string addDocumentToCouch(String docName, out string msg, out bool added, System.Windows.Forms.RichTextBox textBox)
        {
            added = false;
            msg   = string.Empty;

            DocumentType = Document.DocTypeNames.PDF;
            string fileName     = docName;
            int    lastSlashIdx = fileName.LastIndexOf('\\');
            string fName        = fileName.Substring(lastSlashIdx + 1);
            var    sErrCode     = string.Empty;
            var    sErrText     = string.Empty;

            byte[]   fileBytes   = File.ReadAllBytes(fileName);
            Document couchDocObj = (Document) new Document_Couch(fileName, fName, DocumentType);

            couchDocObj.SetPropertyData("jak prop1", "value");
            string storageID = System.Guid.NewGuid().ToString();

            GldocName = storageID;
            // Console.WriteLine("Added doc name :" + GldocName);
            SecuredCouchConnector CouchConnectorObj = null;

            //StorageID = "1234";
            if (couchDocObj.SetSourceData(fileBytes, storageID, false))
            {
                var dStorage = new DocStorage_CouchDB();

                CouchConnectorObj = new SecuredCouchConnector(hostname, portName, secWebPort, dbName, userid, pass, isSec);
                dStorage.SecuredAddDocument(CouchConnectorObj, ref couchDocObj, out sErrCode, out sErrText);
                if (sErrCode == "0")
                {
                    added = true;
                    msg   = "Added" + fileName;
                    textBox.AppendText("Document ID:" + GldocName);
                    textBox.AppendText("\n");
                }
                else
                {
                    added = false;
                    msg   = sErrText;
                }
            }
            return(storageID);
        }
Exemplo n.º 10
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="fileName"></param>
        /// <param name="fileId"></param>
        /// <param name="couchConnector"></param>
        /// <param name="overrideDoc"></param>
        /// <param name="fileType"></param>
        /// <param name="docMetaData"></param>
        /// <param name="couchDocObj"></param>
        /// <param name="errorMessage"></param>
        /// <returns></returns>
        public static bool StoreDocument(
            string fileName,
            string fileId,
            SecuredCouchConnector couchConnector,
            bool overrideDoc,
            Document.DocTypeNames fileType,
            Dictionary <string, string> docMetaData,
            out Document couchDocObj,
            out string errorMessage)
        {
            couchDocObj  = null;
            errorMessage = string.Empty;

            if (string.IsNullOrEmpty(fileName) ||
                !System.IO.File.Exists(fileName) ||
                string.IsNullOrEmpty(fileId) ||
                couchConnector == null)
            {
                errorMessage = "Input parameters are invalid";
                return(false);
            }

            var sErrCode = string.Empty;
            var sErrText = string.Empty;

            try
            {
                byte[] fileBytes    = File.ReadAllBytes(fileName);
                int    lastSlashIdx = fileName.LastIndexOf('\\');
                if (lastSlashIdx == -1)
                {
                    errorMessage = "Absolute file name is invalid.";
                    return(false);
                }

                string fName = fileName.Substring(lastSlashIdx + 1);
                couchDocObj = new Document_Couch(fileName, fName, fileType);
                if (couchDocObj.SetSourceData(fileBytes, fileId, overrideDoc))
                {
                    if (CollectionUtilities.isNotEmpty(docMetaData))
                    {
                        foreach (string key in docMetaData.Keys)
                        {
                            if (key == null)
                            {
                                continue;
                            }
                            string val;
                            if (docMetaData.TryGetValue(key, out val))
                            {
                                couchDocObj.SetPropertyData(key, val);
                            }
                        }
                    }
                    var dStorage = new DocStorage_CouchDB();
                    if (dStorage.SecuredAddDocument(couchConnector, ref couchDocObj, out sErrCode, out sErrText))
                    {
                        errorMessage = sErrText;
                        return(true);
                    }
                    errorMessage = sErrText;
                    return(false);
                }
            }
            catch (Exception eX)
            {
                errorMessage = "Exception occurred while storing document: " + eX.Message + " (" + sErrCode + ", " +
                               sErrText + ")";
            }
            return(false);
        }