Exemplo n.º 1
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);
        }
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);
            }
        }
        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.º 4
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.º 5
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);
        }